View Javadoc

1   package net.sf.jldapbeans.lang.annotation;
2   
3   import java.lang.reflect.*;
4   
5   public enum LdapModifier {
6   	/*** Modifier for ASBTRACT <tt>objectClass</tt>es */
7   	ABSTRACT,
8   	/*** Modifier for AUXILIARY <tt>objectClass</tt>es */
9   	AUXILIARY,
10  	REQUIRED,
11  	/*** Modifier for STRUCTURAL <tt>objectClass</tt>es */
12  	STRUCTURAL,
13  	SINGLE_VALUE;
14  	
15  	public static boolean isAbstract(LdapModifier... ldapModifiers) {
16  		for(LdapModifier modifier : ldapModifiers)
17  			if(modifier.equals(ABSTRACT)) return true;
18  		return false;
19  	}
20  	
21  	public static boolean isAuxiliary(LdapModifier... ldapModifiers) {
22  		for(LdapModifier modifier : ldapModifiers)
23  			if(modifier.equals(AUXILIARY)) return true;
24  		return false;
25  	}
26  	
27  	public static boolean isStructural(LdapModifier... ldapModifiers) {
28  		for(LdapModifier modifier : ldapModifiers)
29  			if(modifier.equals(STRUCTURAL)) return true;
30  		return false;
31  	}
32  	
33  	public static boolean isRequired(LdapModifier... ldapModifiers) {
34  		for(LdapModifier modifier : ldapModifiers)
35  			if(modifier.equals(REQUIRED)) return true;
36  		return false;
37  	}
38  	
39  	public static boolean isSingleValue(LdapModifier... ldapModifiers) {
40  		for(LdapModifier modifier : ldapModifiers)
41  			if(modifier.equals(SINGLE_VALUE)) return true;
42  		return false;
43  	}
44  	
45  	/***
46  	 * Identifies the <tt>LdapModifier</tt> of a java class
47  	 * 
48  	 * @param clazz Guesses the object type for this java class.
49  	 * @return The <tt>LdapModifier</tt> for the java class specified of <tt>null</tt> if
50  	 *         doesn't corresponds with a <tt>LdapBean</tt> declaration.
51  	 */
52  	public static LdapModifier forClass(Class<?> clazz) {
53  		if(!clazz.isAnnotationPresent(LdapBean.class)) return null;
54  		LdapBean beanMeta = clazz.getAnnotation(LdapBean.class);
55  		return beanMeta.value();
56  	}
57  	
58  	public static LdapModifier[] forMethod(Method method) {
59  		if(!method.isAnnotationPresent(LdapAttribute.class)) return null;
60  		LdapAttribute attrMeta = method.getAnnotation(LdapAttribute.class);
61  		return attrMeta.value();
62  	}
63  	
64  }