Java Code Examples for org.springframework.ldap.odm.annotations.Attribute

The following examples show how to use org.springframework.ldap.odm.annotations.Attribute. These examples are extracted from open source projects. 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 Project: spring-ldap   Source File:    License: Apache License 2.0 5 votes vote down vote up
private boolean processAttributeAnnotation(Field field) {
    // Default to no syntax specified
    syntax = "";
    // Default to a String based attribute
    isBinary = false;
    // Default name of attribute to the name of the field
    name = new CaseIgnoreString(field.getName());
    // We have not yet found the @Attribute annotation
    boolean foundAnnotation=false;
    // Grab the @Attribute annotation
    Attribute attribute = field.getAnnotation(Attribute.class);

    List<String> attrList = new ArrayList<String>();
    // Did we find the annotation?
    if (attribute != null) {
        // Pull attribute name, syntax and whether attribute is binary
        // from the annotation 
        String localAttributeName =;
        // Would be more efficient to use !isEmpty - but that then makes us Java 6 dependent
        if (localAttributeName != null && localAttributeName.length()>0) {
            name = new CaseIgnoreString(localAttributeName);
        syntax = attribute.syntax();
        isBinary = attribute.type() == Attribute.Type.BINARY;
        isReadOnly = attribute.readonly();
    attributes = attrList.toArray(new String[attrList.size()]);
    return foundAnnotation;
Example 2
Source Project: spring-ldap   Source File:    License: Apache License 2.0 5 votes vote down vote up
public AttributeMetaData(Field field) {

    this.dnAttribute = field.getAnnotation(DnAttribute.class);
    if(this.dnAttribute != null && !field.getType().equals(String.class)) {
        throw new MetaDataException(String.format("%s is of type %s, but only String attributes can be declared as @DnAttributes",

    Transient transientAnnotation = field.getAnnotation(Transient.class);
    if(transientAnnotation != null) {
        this.isTransient = true;

    // Reflection data

    // Data from the @Attribute annotation
    boolean foundAttributeAnnotation=processAttributeAnnotation(field);

    // Data from the @Id annotation
    boolean foundIdAnnoation=processIdAnnotation(field, valueClass);

    // Check that the field has not been annotated with both @Attribute and with @Id
    if (foundAttributeAnnotation && foundIdAnnoation) {
        throw new MetaDataException(
                String.format("You may not specifiy an %1$s annoation and an %2$s annotation on the same field, error in field %3$s in Entry class %4$s",
                        Id.class, Attribute.class, field.getName(), field.getDeclaringClass()));
    // If this is the objectclass attribute then it must be of type List<String>
    if (isObjectClass() && (!isCollection() || valueClass!=String.class)) {
        throw new MetaDataException(String.format("The type of the objectclass attribute must be List<String> in classs %1$s",