org.springframework.ldap.odm.annotations.Entry Java Examples
The following examples show how to use
org.springframework.ldap.odm.annotations.Entry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectMetaData.java From spring-ldap with Apache License 2.0 | 4 votes |
public ObjectMetaData(Class<?> clazz) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Extracting metadata from %1$s", clazz)); } // Get object class metadata - the @Entity annotation Entry entity = clazz.getAnnotation(Entry.class); if (entity != null) { // Default objectclass name to the class name unless it's specified // in @Entity(name={objectclass1, objectclass2}); String[] localObjectClasses = entity.objectClasses(); if (localObjectClasses != null && localObjectClasses.length > 0 && localObjectClasses[0].length() > 0) { for (String localObjectClass:localObjectClasses) { objectClasses.add(new CaseIgnoreString(localObjectClass)); } } else { objectClasses.add(new CaseIgnoreString(clazz.getSimpleName())); } String base = entity.base(); if(StringUtils.hasText(base)) { this.base = LdapUtils.newLdapName(base); } } else { throw new MetaDataException(String.format("Class %1$s must have a class level %2$s annotation", clazz, Entry.class)); } // Check the class is final if (!Modifier.isFinal(clazz.getModifiers())) { LOG.warn(String.format("The Entry class %1$s should be declared final", clazz.getSimpleName())); } // Get field meta-data - the @Attribute annotation Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { // So we can write to private fields field.setAccessible(true); // Skip synthetic or static fields if (Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) { continue; } AttributeMetaData currentAttributeMetaData=new AttributeMetaData(field); if (currentAttributeMetaData.isId()) { if (idAttribute!=null) { // There can be only one id field throw new MetaDataException( String.format("You man have only one field with the %1$s annotation in class %2$s", Id.class, clazz)); } idAttribute=currentAttributeMetaData; } fieldToAttribute.put(field, currentAttributeMetaData); if(currentAttributeMetaData.isDnAttribute()) { dnAttributes.add(currentAttributeMetaData); } } if (idAttribute == null) { throw new MetaDataException( String.format("All Entry classes must define a field with the %1$s annotation, error in class %2$s", Id.class, clazz)); } postProcessDnAttributes(clazz); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Extracted metadata from %1$s as %2$s", clazz, this)); } }