Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSNamedMap


        XMLGrammarPreparser parser = new XMLGrammarPreparser();
        parser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
        try {
            XSGrammar xsg = (XSGrammar) parser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, source);
            org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
            XSNamedMap map = xsm.getComponents(XSTypeDefinition.SIMPLE_TYPE);
            int numDefs = map.getLength();
            ArrayList<String> names = new ArrayList<String>(numDefs);
            for (int i = 0; i < numDefs; i++) {
                XSSimpleType xstype = (XSSimpleType) map.item(i);
                // Filter built in types - only needed for 2.6.0
                if ( ! XSD.equals(xstype.getNamespace()) ) {
                    //xstype.derivedFrom()
                    XSDDatatype definedType = new XSDGenericType(xstype, source.getSystemId());
                    tm.registerDatatype(definedType);
View Full Code Here


         ModelGroupBinding groupBinding = schemaBinding.getGroup(groupQName);
         assertNotNull("Group " + groupQName + " exists in the schema binding.", groupBinding);
      }
      */

      XSNamedMap types = xsSchema.getComponents(XSConstants.TYPE_DEFINITION);
      for (int i = 0; i < types.getLength(); ++i)
      {
         XSTypeDefinition xsType = (XSTypeDefinition) types.item(i);
         if (IGNORED_NS.contains(xsType.getNamespace()))
            continue;

         QName typeQName = new QName(xsType.getNamespace(), xsType.getName());
         if(ignoredTypes.contains(typeQName))
            continue;
           
         TypeBinding typeBinding = schemaBinding.getType(typeQName);
         if (typeBinding == null)
         {
            boolean ignoreIfNotFound = false;
            if (xsType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
            {
               ignoreIfNotFound = true;
            }
            else
            {
               XSComplexTypeDefinition xsComplexType = (XSComplexTypeDefinition) xsType;
               if (xsComplexType.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE)
               {
                  XSObjectList attributeUses = xsComplexType.getAttributeUses();
                  if(attributeUses.getLength() == 0)
                  {
                     ignoreIfNotFound = true;
                  }  
                  else if (attributeUses.getLength() == 1)
                  {
                     XSAttributeUse xsAttrUse = (XSAttributeUse) attributeUses.item(0);
                     XSAttributeDeclaration xsAttr = xsAttrUse.getAttrDeclaration();
                     if(xsAttr.getNamespace() == null && "id".equals(xsAttr.getName()))
                        ignoreIfNotFound = true;
                  }
               }
            }
           
            if(!ignoreIfNotFound)
            {
               if(trace)
               {
                  log.trace("SchemaBinding global types: ");
                  for (Iterator<TypeBinding> iter = schemaBinding.getTypes(); iter.hasNext();)
                  {
                     TypeBinding type = iter.next();
                     if(!IGNORED_NS.contains(type.getQName().getNamespaceURI()))
                        log.trace("- " + type.getQName());
                  }
               }
               fail("Type " + typeQName + " defined in schema binding.");
            }
         }
         else
         {
            assertEquivalent(xsType, typeBinding);
         }
      }

      XSNamedMap elements = xsSchema.getComponents(XSConstants.ELEMENT_DECLARATION);
      for (int i = 0; i < elements.getLength(); ++i)
      {
         XSElementDeclaration xsElement = (XSElementDeclaration) elements.item(i);
         if (IGNORED_NS.contains(xsElement.getNamespace()))
            continue;
         QName elementQName = new QName(xsElement.getNamespace(), xsElement.getName());
         ElementBinding elementBinding = schemaBinding.getElement(elementQName);
         assertNotNull("ElementBinding " + elementQName + " exists", elementBinding);
View Full Code Here

        XMLGrammarPreparser parser = new XMLGrammarPreparser();
        parser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
        try {
            XSGrammar xsg = (XSGrammar) parser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, source);
            org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
            XSNamedMap map = xsm.getComponents(XSTypeDefinition.SIMPLE_TYPE);
            int numDefs = map.getLength();
            ArrayList<String> names = new ArrayList<String>(numDefs);
            for (int i = 0; i < numDefs; i++) {
                XSSimpleType xstype = (XSSimpleType) map.item(i);
                // Filter built in types - only needed for 2.6.0
                if ( ! XSD.equals(xstype.getNamespace()) ) {
                    //xstype.derivedFrom()
                    XSDDatatype definedType = new XSDGenericType(xstype, source.getSystemId());
                    tm.registerDatatype(definedType);
View Full Code Here

      String targetNS = grammer.getTargetNamespace();
      nsTagListMap.put(targetNS,new ArrayList());
      List tagList = (List)nsTagListMap.get(targetNS);
//      root = null;
     
      XSNamedMap map = grammer.getComponents(XSConstants.ELEMENT_DECLARATION);
      for(int i=0;i<map.getLength();i++){
        XSElementDeclaration element = (XSElementDeclaration)map.item(i);
        parseXSDElement(tagList,element);
      }
    } catch(Exception ex){
     
    }
View Full Code Here

                page1.getFile().getLocation().makeAbsolute().toFile().getParentFile());
            InputStream in = resolver.getInputStream(getSchemaURI());
            if(in!=null){
              SchemaGrammar grammer = (SchemaGrammar)new XMLSchemaLoader().loadGrammar(
                  new XMLInputSource(null,null,null,in,null));
              XSNamedMap map = grammer.getComponents(XSConstants.ELEMENT_DECLARATION);
              for(int i=0;i<map.getLength();i++){
                XSElementDeclaration element = (XSElementDeclaration)map.item(i);
                comboDocumentRoot.add(element.getName());
              }
            }
          }
        } catch(Exception ex){
View Full Code Here

      if (xsmodel == null)
         return true;
      String targetNS = getTargetNamespace(xsmodel);
      if (targetNS == null)
         throw new WSException("Target Namespace of xsmodel is null");
      XSNamedMap tmap = xsmodel.getComponentsByNamespace(XSConstants.TYPE_DEFINITION, targetNS);
      XSNamedMap emap = xsmodel.getComponentsByNamespace(XSConstants.ELEMENT_DECLARATION, targetNS);

      if (tmap != null && tmap.getLength() > 0)
         return false;
      if (emap != null && emap.getLength() > 0)
         return false;

      return true;
   }
View Full Code Here

   {
      if (xsmodel == null)
         return true;
      if (namespace == null)
         throw new WSException("Target Namespace of xsmodel is null");
      XSNamedMap tmap = xsmodel.getComponentsByNamespace(XSConstants.TYPE_DEFINITION, namespace);
      XSNamedMap emap = xsmodel.getComponentsByNamespace(XSConstants.ELEMENT_DECLARATION, namespace);

      if (tmap != null && tmap.getLength() > 0)
         return false;
      if (emap != null && emap.getLength() > 0)
         return false;

      return true;
   }
View Full Code Here

         anonymousElementMap = new HashMap<String, XSElementDeclaration>();

        
         processed.clear();
        
         XSNamedMap namedMap = model.getComponents(XSConstants.TYPE_DEFINITION);
         for (int i = 0; i < namedMap.getLength(); i++)
         {
            XSTypeDefinition type = (XSTypeDefinition)namedMap.item(i);
            if (type.getTypeCategory() != XSTypeDefinition.COMPLEX_TYPE)
               continue;

            analyzeComplexType((XSComplexTypeDefinition)type, null, type.getNamespace());
         }

         namedMap = model.getComponents(XSConstants.ELEMENT_DECLARATION);
         for (int i = 0; i < namedMap.getLength(); i++)
         {
            XSElementDeclaration element = (XSElementDeclaration)namedMap.item(i);
            analyzeElement(element, null, element.getNamespace(), null, null);
         }
         processed.clear();
      }
View Full Code Here

    */
   public void generateJavaSource(XSModel xsmodel, File dirloc, String packageName)
      throws IOException
   {
      //Now that we have the schema, lets build the types for the schema
      XSNamedMap xsnamedmap = xsmodel.getComponents(XSConstants.TYPE_DEFINITION);
      int len = xsnamedmap != null ? xsnamedmap.getLength() : 0;
      for (int i = 0; i < len; i++)
      {
         XSObject type = xsnamedmap.item(i);
         if (type instanceof XSComplexTypeDefinition)
         {
            XSComplexTypeDefinition ctype = (XSComplexTypeDefinition)type;
            //Ignore xsd:anyType
            String nsuri = type.getNamespace();
            String tname = type.getName();
            if (Constants.NS_SCHEMA_XSD.equals(nsuri) && "anyType".equals(tname)) continue;
            xsdJava.createJavaFile(ctype, dirloc.getPath(), packageName, xsmodel);
         }
         else if (type instanceof XSSimpleTypeDefinition)
         {
            XSSimpleTypeDefinition stype = (XSSimpleTypeDefinition)type;
            //Ignore xsd:anyType
            String nsuri = type.getNamespace();
            String tname = type.getName();
            if (Constants.NS_SCHEMA_XSD.equals(nsuri) && "anyType".equals(tname)) continue;
            xsdJava.createJavaFile(stype, dirloc.getPath(), packageName, xsmodel);
         }
      }

      //Consider Global Element Declarations that may have anonymous complex types
      xsnamedmap = xsmodel.getComponents(XSConstants.ELEMENT_DECLARATION);
      len = xsnamedmap != null ? xsnamedmap.getLength() : 0;
      for (int i = 0; i < len; i++)
      {
         XSElementDeclaration elm = (XSElementDeclaration)xsnamedmap.item(i);
         String elmname = elm.getName();
         XSTypeDefinition elmtype = elm.getTypeDefinition();
         if (elmtype != null && elmtype instanceof XSComplexTypeDefinition)
         {
            XSComplexTypeDefinition ctype = (XSComplexTypeDefinition)elmtype;
View Full Code Here

            // Load the XML Schema
            String uri = file.toURI().toString();
            XSModel xsModel = loader.loadURI(uri);

            // Convert top level complex type definitions to node types
            XSNamedMap map = xsModel.getComponents(XSConstants.TYPE_DEFINITION);
            for (int i = 0; i < map.getLength(); i++) {
                XSTypeDefinition tDef = (XSTypeDefinition) map.item(i);
                checkAndConvert(tDef, null, null);
            }
            //  Convert local (anonymous) complex type defs found in top level element declarations
            map = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);
            for (int i = 0; i < map.getLength(); i++) {
                XSElementDeclaration eDec = (XSElementDeclaration) map.item(i);

                XSTypeDefinition tDef = eDec.getTypeDefinition();
                checkAndConvert(tDef, eDec.getNamespace(), eDec.getName());
            }
        } catch (ClassNotFoundException e) {
View Full Code Here

TOP

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

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.