Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSSimpleTypeDefinition


                                              throws Exception {
       
        XSObjectList memberTypes = simpType.getMemberTypes();
        if (memberTypes.getLength() > 0) {
            // the list item's type has variety 'union'.
            XSSimpleTypeDefinition actualListItemType = getActualListItemTypeForVarietyUnion(memberTypes, value);
            // set a schema 'typed value' to variable $value
            setTypedValueFor$value(value, actualListItemType, null);
        }
        else {
            // the list item's type has variety 'atomic'.
View Full Code Here


       
        boolean validationFailedForUnion = true;
        final int memberTypesLength = memberTypes.getLength();
       
        for (int memberTypeIdx = 0; memberTypeIdx < memberTypesLength; memberTypeIdx++) {
            XSSimpleTypeDefinition memType = (XSSimpleTypeDefinition) memberTypes.item(memberTypeIdx);
           
            // check for assertions on types in an non-schema namespace
            if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(memType.getNamespace()) && simpleTypeHasAsserts(memType)) {
                XSObjectList memberTypeFacets = memType.getMultiValueFacets();
                final int memberTypeFacetsLength = memberTypeFacets.getLength();
                for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < memberTypeFacetsLength; memberTypeFacetIdx++) {
                    XSMultiValueFacet facet = (XSMultiValueFacet) memberTypeFacets.item(memberTypeFacetIdx);
                    if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
                        Vector assertFacets = facet.getAsserts();
View Full Code Here

     * Set value of XPath2 context variable $value, if element has a complex type with simple content.
     */
    private void setValueOf$ValueForCTWithSimpleContent(String value, XSComplexTypeDefinition typeDef) {
       
        XSComplexTypeDefinition cmplxTypeDef = (XSComplexTypeDefinition)typeDef;
        XSSimpleTypeDefinition complexTypeSimplContentType = cmplxTypeDef.getSimpleType();
        if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST) {
            // simple content type has variety xs:list
            XSSimpleTypeDefinition listItemType = complexTypeSimplContentType.getItemType();
            // split the "string value" of list contents, into non white-space tokens.
            StringTokenizer values = new StringTokenizer(value, " \n\t\r");
           
            // construct a list of atomic XDM items, to assign to XPath2 context variable $value.
            List xdmItemList = new ArrayList();
            final XSObjectList memberTypes = listItemType.getMemberTypes();
            if (memberTypes.getLength() > 0) {
               // itemType of xs:list has variety 'union'. here list items may have different types, which are determined below.
               while (values.hasMoreTokens()) {
                   String itemValue = values.nextToken();
                   XSSimpleTypeDefinition listItemTypeForUnion = getActualListItemTypeForVarietyUnion(memberTypes, itemValue);
                   xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemTypeForUnion.getBuiltInKind(), itemValue));
               }                                 
            }
            else {
               // every list item has a same type (the itemType of xs:list).
               while (values.hasMoreTokens()) {
                   String itemValue = values.nextToken();
                   xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemType.getBuiltInKind(), itemValue));
               }                                 
            }

            // assign an XPath2 sequence to xpath context variable $value
            fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                                           "value"), getXPath2ResultSequence(xdmItemList));
        }
        else if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
            // simple content type has variety xs:union
            XSSimpleTypeDefinition simpleContentTypeForUnion = getActualListItemTypeForVarietyUnion
                                                                     (complexTypeSimplContentType.getMemberTypes(), value);
            fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
                                             SchemaTypeValueFactory.newSchemaTypeValue(simpleContentTypeForUnion.getBuiltInKind(),
                                             value));
        }
        else {
            // simple content type has variety atomic
            setValueOf$ValueForSTVarietyAtomic(value, getXercesXSDTypeCodeFor$Value(cmplxTypeDef.getSimpleType()));
View Full Code Here

    /*
     * Find the actual schema type of "list item" instance, if the "item type" of list has variety union.
     */
    private XSSimpleTypeDefinition getActualListItemTypeForVarietyUnion(XSObjectList memberTypes, String value) {

        XSSimpleTypeDefinition simpleTypeDefn = null;
       
        // iterate the member types of union in order, to find that which schema type can successfully validate an
        // atomic value first.
        final int memberTypesLength = memberTypes.getLength();
        for (int memTypeIdx = 0; memTypeIdx < memberTypesLength; memTypeIdx++) {
View Full Code Here

            }
        }
        if (type != base) {
            // If the base is a union, check if "derived" is allowed through any of the member types.
            if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
                XSSimpleTypeDefinition st = (XSSimpleTypeDefinition) base;
                if (st.getVariety() ==  XSSimpleTypeDefinition.VARIETY_UNION) {
                    XSObjectList memberTypes = st.getMemberTypes();
                    final int length = memberTypes.getLength();
                    for (int i = 0; i < length; ++i) {
                        if (typeDerivationOK(derived, (XSTypeDefinition) memberTypes.item(i), blockingConstraint, schemaVersion)) {
                            return true;
                        }
View Full Code Here

            addRestrictionToSimpleContent(document, simpleTypeDecl,
                            simpleTypeDomNode, restrictionDomNode, baseType);
        }
        else if (simpleTypeDecl.getVariety() ==
                       XSSimpleTypeDefinition.VARIETY_LIST) {
           XSSimpleTypeDefinition listType = simpleTypeDecl.getItemType();
           addListDeclToSimpleType(document, simpleTypeDomNode, listType);
        }
        else if (simpleTypeDecl.getVariety() ==
                       XSSimpleTypeDefinition.VARIETY_UNION) {
           XSObjectList unionMemberTypes = simpleTypeDecl.getMemberTypes();          
View Full Code Here

            restrictionDomNode.setAttributeNS(null, "base"
                                       baseType.getName());  
        }               
       
        // simple type definition to be used, to get the facets
        XSSimpleTypeDefinition simpleTypeDefn = null;
       
        if (typeDefn instanceof XSComplexTypeDefinition) {
            XSComplexTypeDefinition complexTypeDefn = (XSComplexTypeDefinition) typeDefn;
            simpleTypeDefn = complexTypeDefn.getSimpleType();
           
        }
        else {
            simpleTypeDefn = (XSSimpleTypeDefinition) typeDefn;    
        }
       
        // handling single-valued Facets
        XSObjectList facets = simpleTypeDefn.getFacets();
        for (int facetIdx = 0; facetIdx < facets.getLength(); facetIdx++) {
            XSFacet facet = (XSFacet) facets.item(facetIdx);                       
            String facetName = getFacetName(facet.getFacetKind());
            String facetValue = facet.getLexicalFacetValue();
            Element facetDomNode = document.createElementNS(
                                            XSD_LANGUAGE_URI,
                                            XSD_LANGUAGE_PREFIX +
                                            facetName);
            facetDomNode.setAttributeNS(null, "value", facetValue);
            restrictionDomNode.appendChild(facetDomNode);
        }
       
        // handling multi-valued Facets ("enumeration" or "pattern")
        XSObjectList mvFacets = simpleTypeDefn.getMultiValueFacets();
        for (int mvFacetIdx = 0; mvFacetIdx < mvFacets.getLength();
                                              mvFacetIdx++) {
           XSMultiValueFacet mvFacet = (XSMultiValueFacet)
                                              mvFacets.item(mvFacetIdx);
           StringList facetValues = mvFacet.getLexicalFacetValues();
View Full Code Here

        processPSVIAttributeWildcard(type.getAttributeWildcard());
        sendIndentedElement("psv:contentType");
        sendElementEvent(
            "psv:variety",
            this.translateContentType(type.getContentType()));
        XSSimpleTypeDefinition simpleType = type.getSimpleType();
        if(simpleType == null || (!simpleType.getAnonymous() || fDefined.contains(this.getID(simpleType)))) {
            processPSVIElementRef("psv:simpleTypeDefinition", simpleType);
        }
        else {
            processPSVISimpleTypeDefinition(simpleType);
        }
View Full Code Here

   private AttributeBinding bindAttribute(XSAttributeUse attrUse)
   {
      XSAttributeDeclaration attr = attrUse.getAttrDeclaration();
      QName attrName = new QName(attr.getNamespace(), attr.getName());

      XSSimpleTypeDefinition attrType = attr.getTypeDefinition();
      TypeBinding typeBinding = bindSimpleType(attrType);

      if (trace)
      {
         log.trace("binding attribute " + attrName + ", required=" + attrUse.getRequired());
      }

      AttributeBinding binding = new AttributeBinding(schema, attrName, typeBinding, DefaultHandlers.ATTRIBUTE_HANDLER);
      binding.setRequired(attrUse.getRequired());
      if(attrUse.getConstraintType() == XSConstants.VC_DEFAULT)
      {
         // Associate the default value with the binding
         binding.setDefaultConstraint(attrUse.getConstraintValue());
      }

      if (processAnnotations)
      {
         XSAnnotation an = attr.getAnnotation();
         if(an != null)
         {
            if (trace)
            {
               log.trace(attrName + " attribute annotation");
            }

            XsdAnnotation xsdAn = XsdAnnotation.unmarshal(an.getAnnotationString());
            XsdAppInfo appInfo = xsdAn.getAppInfo();
            if(appInfo != null)
            {
               PropertyMetaData propertyMetaData = appInfo.getPropertyMetaData();
               if(propertyMetaData != null)
               {
                  binding.setPropertyMetaData(propertyMetaData);
               }

               boolean mapEntryKey = appInfo.isMapEntryKey();
               if(mapEntryKey)
               {
                  binding.setMapEntryKey(mapEntryKey);
               }

               boolean mapEntryValue = appInfo.isMapEntryValue();
               if(mapEntryValue)
               {
                  binding.setMapEntryValue(mapEntryValue);
               }
            }
         }
      }


      if (trace)
      {
         String msg = "bound attribute " + attrName;

         if(binding.getPropertyMetaData() != null)
         {
            msg += " property=" +
               binding.getPropertyMetaData().getName() +
               ", collectionType=" + binding.getPropertyMetaData().getCollectionType();
         }
         else if(binding.isMapEntryKey())
         {
            msg += "bound as a key in a map entry";
         }
         else if(binding.isMapEntryValue())
         {
            msg += "bound as a value in a map entry";
         }
         else
         {
            msg += " type=" + attrType.getName();
         }

         if(binding.getDefaultConstraint() != null)
         {
            msg += ", default=" + binding.getDefaultConstraint();
View Full Code Here

               assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
            }
          }
         
          // add assertion facets, from "complexType -> simpleContent -> restriction"
          XSSimpleTypeDefinition simpleTypeDef = complexTypeDef.getSimpleType();
          if (simpleTypeDef != null) {
            XSObjectList complexTypeFacets = simpleTypeDef.getMultiValueFacets();
            for (int i = 0; i < complexTypeFacets.getLength(); i++) {
              XSMultiValueFacet facet = (XSMultiValueFacet) complexTypeFacets.item(i);
              if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
                 Vector simpleContentAsserts = facet.getAsserts();
                 for (int simpleAssertIdx = 0; simpleAssertIdx <
                              simpleContentAsserts.size(); simpleAssertIdx++) {
                    XSAssert simpleContentAssert = (XSAssert)
                                         simpleContentAsserts.get(simpleAssertIdx);
                    assertions.addXSObject(simpleContentAssert);
                 }
              }
            }
          }

          // there could be assertions, to be evaluated on attributes. add these
          // assertions to the list of assertions to be processed.
          for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
              Augmentations attrAugs = attributes.getAugmentations(attrIndx);
              AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
                                                 (Constants.ATTRIBUTE_PSVI);
              XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition)attrPSVI.
                                                        getTypeDefinition();
              if (attrType != null) {
                 XSObjectList facets = attrType.getMultiValueFacets();             
                 for (int i = 0; i < facets.getLength(); i++) {
                    XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
                    if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
                       Vector attrAsserts = facet.getAsserts();
                       for (int j = 0; j < attrAsserts.size(); j++) {
                         XSAssertImpl attrAssert = (XSAssertImpl) attrAsserts.elementAt(j);
                         attrAssert.setAttrName(attributes.getLocalName(attrIndx));
                         attrAssert.setAttrValue(attributes.getValue(attrIndx));
                         assertions.addXSObject(attrAssert);   
                       }                       
                       break;
                    }
                 }
              }
          }
             
          if (assertions.size() > 0) {
              assertObject = assertions;            
              // instantiate the assertions processor
              if (fAssertionProcessor == null) {
                // construct parameter values for the assertion processor
                Map assertProcessorParams = new HashMap();
                assertProcessorParams.put("XPATH2_NS_CONTEXT",
                                     ((XSAssertImpl)assertions.get(0)).
                                     getXPath2NamespaceContext());
                // initialize the assertions processor
                initializeAssertProcessor(assertProcessorParams);
              }
          }
        }
        else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
            // if element's governing type is a "simple type"
            XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) typeDef;
            XSObjectList facets = simpleTypeDef.getMultiValueFacets();
            for (int i = 0; i < facets.getLength(); i++) {
              XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
              if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
                assertObject = facet.getAsserts();
                // instantiate the assertions processor
View Full Code Here

TOP

Related Classes of org.apache.xerces.xs.XSSimpleTypeDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.