Schema是LDAP的一个重要组成部分,类似于数据库的模式定义,LDAP的Schema定义了LDAP目录所应遵循的结构和规则,比如一个 objectclass会有哪些属性,这些属性又是什么结构等等,schema给LDAP服务器提供了LDAP目录中类别,属性等信息的识别方式,让这些可以被LDAP服务器识别。
在LDAP的schema中,有四个重要的元素:
1. Objectclass
objectclass定义了一个类别,这个类别会被不同的目录(在LDAP中就是一个Entry)用到,它说明了该目录应该有哪些属性,哪些属性是必须的,哪些又是可选的。一个objectclass的定义包括名称(NAME),说明(DESC),类型(STRUCTURAL或AUXILARY ,表示是结构型的还是辅助型的),必须属性(MUST),可选属性(MAY)等信息。
在BAP产品中,有下面几种类别
# GalaxyTitle objectclass ( 2.16.840.1.153730.3.4.2 NAME 'GalaxyTitle' DESC 'GalaxyTitle use to manage title' SUP top STRUCTURAL MUST ( uid ) MAY ( sortid ) ) # GalaxyPost objectclass ( 2.16.840.1.153730.3.4.32 NAME 'GalaxyPost' DESC 'GalaxyPost use to manage post' SUP top STRUCTURAL MUST ( uid ) MAY ( sortid $ type ) ) # GalaxyDuty objectclass ( 2.16.840.1.153730.3.4.22 NAME 'GalaxyDuty' DESC 'GalaxyDuty use to manage duty' SUP top STRUCTURAL MUST ( dutyuid ) MAY ( sortid ) ) # GalaxyGroup objectclass ( 2.16.840.1.153730.3.2.12 NAME 'GalaxyGroup' DESC 'GalaxyGroup use to manage group' SUP top STRUCTURAL MUST ( uid ) MAY ( sysid $ employeeids $ sortid $ groupType $ searchCondition $ groupManager $ telephone $ email $ gfax $ others1 $ others2 $ others3 $ uniqueMember $ searchConditionXml) ) # GalaxyPeople objectclass ( 2.16.840.1.153730.3.2.22 NAME 'GalaxyPeople' DESC 'GalaxyPeople use to manage people' SUP InetOrgPerson STRUCTURAL MAY ( otherDepartmentNumber $ sortid $ ifactivated $ peopleLevel $ leadermember $ leaderFilter $ title $ post $ globalsortid $ virtualaccount ) ) # GalaxyOrganization objectclass ( 2.16.840.1.153730.3.2.2 NAME 'GalaxyOrganization' DESC 'GalaxyOrganization use to manage dep' SUP top STRUCTURAL MUST ( uid ) MAY ( sysid $ employeeids $ sortid $ depmanager $ telephone $ email $ gfax $ others1 $ others2 $ others3 $ depmanagerFilter $ title $ post) ) # GalaxyContainer objectclass ( 2.16.840.1.153730.3.2.16 NAME 'GalaxyContainer' DESC 'a container,can fill with people,org,group...' SUP top STRUCTURAL MUST ( cn ) ) # GalaxyLevel objectclass ( 2.16.840.1.153730.3.3.18 NAME 'GalaxyLevel' DESC 'level inof' SUP top STRUCTURAL MUST ( cn $ number ) ) # GalaxyAttOfPeople objectclass ( 2.16.840.1.153730.3.3.19 NAME 'GalaxyAttOfPeople' DESC 'att name and sn' SUP top STRUCTURAL MUST ( sn $ cn ) )
2. Attribute
attribute就是一个上面objectclass中可能包含的属性,对其的定义包括名称,数据类型,单值还是多值以及匹配规则等。后面用具体的例子来说明。
3. Syntax
syntax是LDAP中的“语法”,其实就是LDAP中会用到的数据类型和数据约束,这个语法是遵从X.500中数据约束的定义的。其定义需要有一个ID(遵从X.500)以及说明(DESP)
4. Matching Rules
是用来指定某属性的匹配规则,实际上就是定义一个特殊的Syntax的别名,让LDAP服务器可以识别,并对定义的属性进行匹配。
LDAP的schema的主要元素就是这些了,下面列举出了一些LDAP规定好的或是现在比较通用的schema,一般的LDAP服务器都应该可以识别这些定义。
这就是一个名为subschema的objectclass的定义:
(2.5.20.1 NAME 'subschema' AUXILIARY
MAY ( dITStructureRules $ nameForms $ ditContentRules $
objectClasses $ attributeTypes $ matchingRules $ matchingRuleUse ) )
首先是ID,这里是2.5.20.1,接着是NAME,AUXILIARY说明是辅助型,之后是可选属性的定义,subschema中没有定义必须属性,如果需要定义,应该和MAY一样,将属性放在MUST()中并用$隔开
再来看一个属性定义:
( 2.5.4.3 NAME 'cn' SUP name EQUALITY caseIgnoreMatch )
可以看到cn属性的父属性是name,它相等性匹配于caseIgnoreMatch(匹配原则为EQUALITY,还有如SUBSTR是字符串匹配,ORDERING是顺序匹配)
syntax定义一般都比较简单,如:
( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'String' )
这个定义说明,这一串数字1.3.6.1.4.1.1466.115.121.1.5就代表了LDAP中的字符串,这个数字串的定义和X.500相关,包括了它的存储方式,所占空间大小等。
最后看看Matching Rule的例子,前面提到了caseIgnoreMatch,就看他的吧
( 2.5.13.2 NAME 'caseIgnoreMatch'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
其实1.3.6.1.4.1.1466.115.121.1.15 就是LDAP数据类型Directory String的ID,说明前面的cn需要等于这个数据类型才有效。
还有很多常用schema的定义都在了RFC2252中,LDAP服务器都应该支持这些基本的schema。好了,现在基本对LDAP中的schema有个一个大致的说明,可能有不到位或不妥之处,还望大家指正。
if([value isKindOfClass:[NSNumber class]]) { if (strcmp([value objCType], @encode(float)) == 0) { [cell.detailTextLabel.text = [NSString stringWithFormat:@"%.3f", [value floatValue]]]; } else if (strcmp([value objCType], @encode(double)) == 0) { [self.subTitleString appendString:[NSString stringWithFormat:@"%.3f", [value floatValue]]]; } else if (strcmp([value objCType], @encode(int)) == 0) { [self.subTitleString appendString:[NSString stringWithFormat:@"%d", [value intValue]]]; } else [self.subTitleString appendString: [NSString stringWithFormat:@"%d", [value intValue]]]; }
包含给Ui使用的标准静态函数及函数,比如超时、大小和距离。比如,长按(LongPressed)的标准是多少毫秒才算,两次tap的间隔多长才算作是两次的tap。
使用ViewConfiguration.get(context)来获取该实例对象。
方法列举:
getScaledTouchSlop()返回对一个视图touch时应该忽略的最小移动像素。因为即使你是tap,也可能造成移动了几个像素,那么这里将定义移动了大于该函数返回值的像素点数才被定义为移动操作。
package cn.anycall.ju; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.Scroller; /** * 仿Launcher中的WorkSapce,可以左右滑动切换屏幕的类 * */ public class ScrollLayout extends ViewGroup { private static final String TAG = "ScrollLayout"; private Scroller mScroller;//滚动封装类 private VelocityTracker mVelocityTracker;//测量touch事件的触发速度 private int mCurScreen;//当前屏幕 private int mDefaultScreen = 0;//默认屏幕 private static final int TOUCH_STATE_REST = 0;//TOUCH状态为静止 private static final int TOUCH_STATE_SCROLLING = 1;//TOUCH状态为滚动 private static final int SNAP_VELOCITY = 600;//瞬时速度 private int mTouchState = TOUCH_STATE_REST;//当前状态 private int mTouchSlop; private float mLastMotionX;//最终的X方向坐标 private float mLastMotionY;//最终的Y方向坐标 private int currentScreenIndex = 0;//当前屏幕索引值 public int getCurrentScreenIndex() { return currentScreenIndex; } public void setCurrentScreenIndex(int currentScreenIndex) { this.currentScreenIndex = currentScreenIndex; } public ScrollLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); // TODO Auto-generated constructor stub } public ScrollLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub mScroller = new Scroller(context); mCurScreen = mDefaultScreen; mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub int childLeft = 0; final int childCount = getChildCount(); System.out.println("childCount=" + childCount); for (int i = 0; i < childCount; i++) { final View childView = getChildAt(i); if (childView.getVisibility() != View.GONE) { final int childWidth = childView.getMeasuredWidth(); childView.layout(childLeft, 0, childLeft + childWidth, childView.getMeasuredHeight()); childLeft += childWidth; } } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.e(TAG, "onMeasure"); super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int width = MeasureSpec.getSize(widthMeasureSpec); final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { throw new IllegalStateException( "ScrollLayout only canmCurScreen run at EXACTLY mode!"); } final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY) { throw new IllegalStateException( "ScrollLayout only can run at EXACTLY mode!"); } // The children are given the same width and height as the scrollLayout final int count = getChildCount(); for (int i = 0; i < count; i++) { getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec); } System.out.println("moving to screen " + mCurScreen); scrollTo(mCurScreen * width, 0);//移动到当前屏幕,屏幕index*屏幕宽 } /** * 拖动移动(非快速移动) * According to the position of current layout scroll to the destination * page.getScrollX返回值即为拖动以后停留的位置,通过该位置与屏幕宽度相除就可以确定该位置在哪一页, * 若在该基础上添加半页的大小,再舍去小数,就可以确定是停留在原来页还是向左或则右移动到邻居页 */ public void snapToDestination() { final int screenWidth = getWidth(); int sx=getScrollX(); final int destScreen = (sx + screenWidth / 2) / screenWidth;//添加半块屏幕的大小,使得滑动超过半块屏幕算一块,少于半块则回至原处 snapToScreen(destScreen); } /** * 封装scroller的startScroll来实现 * @param whichScreen */ public void snapToScreen(int whichScreen) { // get the valid layout page whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); if (getScrollX() != (whichScreen * getWidth())) {//当拖动后的位置和目的页起始位置不一致,则进行移动 final int delta = whichScreen * getWidth() - getScrollX(); mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);//相当于移动一个像素点要2毫秒 mCurScreen = whichScreen; invalidate(); // Redraw the layout } } public void setToScreen(int whichScreen) {//直接滑动一个屏幕 whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); mCurScreen = whichScreen; scrollTo(whichScreen * getWidth(), 0); } public int getCurScreen() { return mCurScreen; } @Override public void computeScroll() { // TODO Auto-generated method stub if (mScroller.computeScrollOffset()) { scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); postInvalidate(); } } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: Log.e(TAG, "event down!"); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: Log.e(TAG, "event : up"); // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); Log.e(TAG, "velocityX:" + velocityX); if (velocityX > SNAP_VELOCITY && mCurScreen > 0) { // Fling enough to move left Log.e(TAG, "snap left"); onScreenChangeListener.onScreenChange(mCurScreen - 1); System.out.println("mCurScreen=" + (mCurScreen - 1)); snapToScreen(mCurScreen - 1); } else if (velocityX < -SNAP_VELOCITY && mCurScreen < getChildCount() - 1) { // Fling enough to move right Log.e(TAG, "snap right"); onScreenChangeListener.onScreenChange(mCurScreen + 1); //只往右移动才加载数据 onScreenChangeListenerDataLoad.onScreenChange(mCurScreen+1); snapToScreen(mCurScreen + 1); } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } // } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; } //截获(返回true)所有事件,当当前状态是滑动状态时,在此截获将会使事件停留在该viewgroup中被处理 //否则将被传递到下一个viewgroup中处理。 @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop); final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) { return true; } final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_MOVE: final int xDiff = (int) Math.abs(mLastMotionX - x); if (xDiff > mTouchSlop) { mTouchState = TOUCH_STATE_SCROLLING; } break; case MotionEvent.ACTION_DOWN: mLastMotionX = x; mLastMotionY = y; mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mTouchState = TOUCH_STATE_REST; break; } return mTouchState != TOUCH_STATE_REST; } //分页监听 public interface OnScreenChangeListener { void onScreenChange(int currentIndex); } private OnScreenChangeListener onScreenChangeListener; public void setOnScreenChangeListener( OnScreenChangeListener onScreenChangeListener) { this.onScreenChangeListener = onScreenChangeListener; } //动态数据监听 public interface OnScreenChangeListenerDataLoad { void onScreenChange(int currentIndex); } private OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad; public void setOnScreenChangeListenerDataLoad(OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad) { this.onScreenChangeListenerDataLoad = onScreenChangeListenerDataLoad; } }