Esempio n. 1
0
  /**
   * Gets the "default" attribute value for the given XSDFeature, if there is none then it returns
   * an empty string.
   *
   * @param xsdElem
   * @return the default value string
   */
  public static String getDefaultValue(XSDFeature xsdElem) {
    XSDConstraint constraint = null;
    if (xsdElem instanceof XSDAttributeDeclaration) {
      // attribute declarations store their default values in
      // their containers (attribute uses)
      XSDAttributeUse use = (XSDAttributeUse) xsdElem.getContainer();
      if (use.isSetConstraint()) {
        constraint = use.getConstraint();
      }

      if (constraint != null && constraint.equals(XSDConstraint.DEFAULT_LITERAL)) {
        if (use.getLexicalValue() != null) {
          return use.getLexicalValue();
        }
        return EMPTY_STRING;
      }
    } else if (xsdElem instanceof XSDElementDeclaration) {
      if (xsdElem.isSetConstraint()) constraint = xsdElem.getConstraint();

      if (constraint != null && constraint.equals(XSDConstraint.DEFAULT_LITERAL)) {
        if (xsdElem.getLexicalValue() != null) {
          return xsdElem.getLexicalValue();
        }
        return EMPTY_STRING;
      }
    }

    return EMPTY_STRING;
  }
Esempio n. 2
0
 protected void processAttributeUse(XSDAttributeUse use, Node parentNode)
     throws RepositoryException {
   // Process the attribute declaration ...
   Node attributeDeclaration =
       processAttributeDeclaration(use.getAttributeDeclaration(), parentNode, true);
   if (use.getUse() != null) {
     attributeDeclaration.setProperty(XsdLexicon.USE, use.getUse().getLiteral());
   }
   processNonSchemaAttributes(use, attributeDeclaration);
 }
 public IXSDFragment getFragment(XSDToFragmentConfiguration config, String id, String name) {
   XSDAttributeUse attribute = (XSDAttributeUse) config.getXSDComponent();
   if (attribute != null && attribute.getAttributeDeclaration() != null) {
     XSDAttributeDeclaration resolvedAttribute =
         resolveXSDAttributeDeclaration(attribute.getAttributeDeclaration());
     XSDTypeDefinition typeDef = getXSDTypeDefinition(resolvedAttribute);
     IXSDAttributeFragment attributeFrag =
         new XSDAttributeFragment(id, resolvedAttribute.getName(), config);
     attributeFrag.setXSDTypeDefinition(typeDef);
     XSDToFragmentConfiguration attributeTypeConfig = new XSDToFragmentConfiguration();
     attributeTypeConfig.setXSDComponent(typeDef);
     attributeTypeConfig.setStyle(config.getStyle());
     attributeTypeConfig.setPartEncoding(config.getPartEncoding());
     attributeTypeConfig.setWSDLPartName(config.getWSDLPartName());
     IXSDFragment xsdFragment =
         getController()
             .getFragment(attributeTypeConfig, attributeFrag.genID(), resolvedAttribute.getName());
     attributeFrag.setXSDDelegationFragment(xsdFragment);
     return attributeFrag;
   }
   return getXSDDefaultFragment(config, id, name);
 }
Esempio n. 4
0
  /**
   * Creates an {@link AttributeType} that matches the xsd type definition as much as possible.
   *
   * <p>The original type definition given by the {@link XSDTypeDefinition} is kept as
   * AttributeType's metadata stored as a "user data" property using <code>XSDTypeDefinition.class
   * </code> as key.
   *
   * <p>If it is a complex attribute, it will contain all the properties declared in the <code>
   * typeDefinition</code>, as well as all the properties declared in its super types. TODO: handle
   * the case where the extension mechanism is restriction.
   *
   * @param assignedName
   * @param typeDefinition
   * @return
   */
  private AttributeType createType(
      final Name assignedName,
      final XSDTypeDefinition typeDefinition,
      CoordinateReferenceSystem crs,
      boolean anonymous) {

    AttributeType attType;
    // /////////
    if (processingTypes.contains(assignedName)) {
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("Recursion found for type " + assignedName + ". Proxying it.");
      }
      attType =
          createProxiedType(
              assignedName, typeDefinition, anonymous ? anonTypeRegistry : typeRegistry);
      return attType;
    }
    processingTypes.push(assignedName);
    // //////////

    final XSDTypeDefinition baseType = typeDefinition.getBaseType();

    AttributeType superType = null;
    if (baseType != null) {
      String targetNamespace = baseType.getTargetNamespace();
      String name = baseType.getName();
      if (name != null) {
        Name baseTypeName = new NameImpl(targetNamespace, name);
        superType = getAttributeType(baseTypeName, baseType, crs);
      }
    } else {
      LOGGER.warning(assignedName + " has no super type");
    }

    if (typeDefinition instanceof XSDComplexTypeDefinition) {
      XSDComplexTypeDefinition complexTypeDef;
      complexTypeDef = (XSDComplexTypeDefinition) typeDefinition;
      boolean includeParents = true;
      List<XSDElementDeclaration> children =
          Schemas.getChildElementDeclarations(typeDefinition, includeParents);

      final Collection<PropertyDescriptor> schema =
          new ArrayList<PropertyDescriptor>(children.size());

      XSDElementDeclaration childDecl;
      AttributeDescriptor descriptor;
      for (Iterator it = children.iterator(); it.hasNext(); ) {
        childDecl = (XSDElementDeclaration) it.next();
        try {
          descriptor = createAttributeDescriptor(complexTypeDef, childDecl, crs);
        } catch (NoSuchElementException e) {
          String msg =
              "Failed to create descriptor for '"
                  + childDecl.getTargetNamespace()
                  + "#"
                  + childDecl.getName()
                  + " from container '"
                  + typeDefinition.getTargetNamespace()
                  + "#"
                  + typeDefinition.getName()
                  + "'";
          NoSuchElementException nse = new NoSuchElementException(msg);
          nse.initCause(e);
          throw nse;
        }
        schema.add(descriptor);
      }

      if (includeAttributes) {
        for (XSDAttributeUse attgcontent : complexTypeDef.getAttributeUses()) {
          XSDAttributeDeclaration att = attgcontent.getContent();
          descriptor =
              createAttributeDescriptor(
                  getXmlAttributeType(),
                  null,
                  new NameImpl(null, "@" + att.getName()),
                  0,
                  1,
                  false,
                  null);
          schema.add(descriptor);
        }
      }

      // set substitution group for descriptors here
      for (XSDElementDeclaration elemDecl : children) {
        if (elemDecl.isElementDeclarationReference()) {
          elemDecl = elemDecl.getResolvedElementDeclaration();
        }
        PropertyDescriptor att = null;
        for (PropertyDescriptor desc : schema) {
          if (desc.getName().getLocalPart().equals(elemDecl.getName())
              && desc.getName().getNamespaceURI().equals(elemDecl.getTargetNamespace())) {
            att = desc;
            break;
          }
        }
        setSubstitutionGroup(complexTypeDef, elemDecl, att, crs);
      }
      attType = createComplexAttributeType(assignedName, schema, complexTypeDef, superType);
    } else {
      Class<?> binding = String.class;
      boolean isIdentifiable = false;
      boolean isAbstract = false;
      List<Filter> restrictions = Collections.emptyList();
      InternationalString description = null;
      attType =
          typeFactory.createAttributeType(
              assignedName,
              binding,
              isIdentifiable,
              isAbstract,
              restrictions,
              superType,
              description);
    }

    attType.getUserData().put(XSDTypeDefinition.class, typeDefinition);

    processingTypes.pop();

    // even if the type is anonymous, it still has to be registered somewhere because
    // it's needed for the proxied types to find them. That's why we have 2 registries,
    // typeRegistry
    // and anonTypeRegistry. TypeRegistry is the global one, since anonymous types are meant to
    // be
    // local and shouldn't be searchable.
    register(attType, anonymous);

    return attType;
  }