Beispiel #1
0
 private static AttributeDefinition createAttributeDefinition(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   AttributeDefinition attributeDefinition = new AttributeDefinition();
   attributeDefinition.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   attributeDefinition.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName")));
   attributeDefinition.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace")));
   attributeDefinition.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return attributeDefinition;
 }
 @Override
 public AttributeDefinition getAttributeDefinition() {
   AttributeDefinition attr = new AttributeDefinition();
   attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
   attr.setFriendlyName("ldapBaseDN");
   attr.setDisplayName("LDAP base DN");
   attr.setType(String.class.getName());
   attr.setDescription(
       "Base part of DN, which will be used for all entities propagated to facility. Should be like \"ou=sth,dc=example,dc=domain\" (without quotes)");
   return attr;
 }
  /**
   * Process an "attribute" element.
   *
   * @param element The "attribute" element.
   */
  protected void processAttribute(Element element) {

    // Check to see whether this is an attribute reference first.
    String ref = element.getAttributeValue("ref");
    if (ref != null) {

      println("Parsing attribute reference to '" + ref + "'");

      AttributeReference reference = scope.getAttributeReference(ref);

      // Add the attribute reference to the enclosing attribute list.
      attributeList.add(reference);

      // Nothing else to do.
      return;
    }

    // Ensure that the element has a name.
    String name = element.getAttributeValue("name");
    if (name == null) {
      throw new IllegalStateException("Attribute does not have a name");
    }

    println("Parsing attribute definition for '" + name + "'");

    // Create a new AttributeDefinition object in the current scope, this
    // will throw an exception if there is a clash.
    AttributeDefinition definition = scope.addAttributeDefinition(name);

    // Process the attributes.
    List attributes = element.getAttributes();
    for (Iterator i = attributes.iterator(); i.hasNext(); ) {
      Attribute attribute = (Attribute) i.next();
      Namespace attributeNamespace = attribute.getNamespace();
      String attributeName = attribute.getName();

      if (attributeNamespace == xsdNamespace || attributeNamespace == Namespace.NO_NAMESPACE) {

        if ("default".equals(attributeName)) {
          // Set the attribute default value.
          definition.setDefault(attribute.getValue());
        } else if ("name".equals(attributeName)) {
          // Don't do anything else.
        } else if ("fixed".equals(attributeName)) {
          // Don't do anything else.
        } else if ("type".equals(attributeName)) {
          // Set the attribute type.
          definition.setType(attribute.getValue());
        } else if ("use".equals(attributeName)) {
          // Set the attribute use.
          definition.setUse(attribute.getValue());
        } else {
          throw new IllegalStateException("Unknown schema attribute '" + attributeName + "'");
        }
      } else {
        throw new IllegalStateException("Unknown attribute namespace '" + attributeNamespace + "'");
      }
    }

    // Add the attribute definition to the list of attributes.
    attributeList.add(definition);

    // Push the attribute definition object onto the stack.
    schemaObjects.push(definition);

    // Process the contents of the attribute.
    parseContent(element);

    // Pop the attribute definition object from the stack.
    schemaObjects.pop();
  }