private void appendTypes(StringBuilder buffer, XSModel xsmodel) { XSNamedMap xsmap = xsmodel.getComponents(XSConstants.TYPE_DEFINITION); int len = xsmap != null ? xsmap.getLength() : 0; for (int i = 0; i < len; i++) { XSTypeDefinition xstype = (XSTypeDefinition)xsmap.item(i); if (Constants.NS_SCHEMA_XSD.equals(xstype.getNamespace())) continue; buffer.append(this.write(xstype)); } }
public Set<XSElementDeclaration> getSubstitutions( XSElementDeclaration substitutee ) { Set<XSElementDeclaration> substitutions = new HashSet<XSElementDeclaration>(); XSNamedMap elementDeclMap = schema.getComponents( XSConstants.ELEMENT_DECLARATION ); for ( int i = 0; i < elementDeclMap.getLength(); i++ ) { XSElementDecl elementDecl = (XSElementDecl) elementDeclMap.item( i ); if ( isSubstitutable( elementDecl.getSubstitutionGroupAffiliation(), substitutee ) ) { substitutions.add( elementDecl ); } } return substitutions; }
private static QName getQName(XSModel xsModel, String root) { String namespace = null; XSNamedMap m1 = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION); if (m1 != null) { for (int i = 0; i < m1.getLength(); i++) { XSObject o = m1.item(i); if (root.equals(o.getName())) { namespace = o.getNamespace(); } } } return new QName(namespace, root); }
private void appendGlobalElements(StringBuilder buffer, XSModel xsmodel) { XSNamedMap xsmap = xsmodel.getComponents(XSConstants.ELEMENT_DECLARATION); int len = xsmap != null ? xsmap.getLength() : 0; for (int i = 0; i < len; i++) { XSElementDeclaration xsel = (XSElementDeclaration)xsmap.item(i); if (Constants.NS_SCHEMA_XSD.equals(xsel.getNamespace())) continue; buffer.append(this.write(xsel)); } }
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); XSModel xsModel = schemaLoader.loadURI(xsdResource.getURL().getPath()); ((XSComplexTypeDecl) xsModel.getComponents(XSTypeDefinition.COMPLEX_TYPE).itemByName(xsdName, "typeName")).getAttrGrp().getAttributeUses();
private void init() { // build lookup map to avoid usage of XSModel#getElementDeclaration(...) -- sometimes returns null for element // declarations that definitely exist (observed for XPlanGML 4.0 schemas with ADE) XSNamedMap elDecls = xsModel.getComponents( XSConstants.ELEMENT_DECLARATION ); for ( int i = 0; i < elDecls.getLength(); i++ ) { XSElementDeclaration elDecl = (XSElementDeclaration) elDecls.item( i ); QName name = new QName( elDecl.getNamespace(), elDecl.getName() ); nameToElDecl.put( name, elDecl ); } XSNamedMap typeDefs = xsModel.getComponents( XSConstants.TYPE_DEFINITION ); for ( int i = 0; i < typeDefs.getLength(); i++ ) { XSTypeDefinition typeDef = (XSTypeDefinition) typeDefs.item( i ); QName name = new QName( typeDef.getNamespace(), typeDef.getName() ); nameToTypeDef.put( name, typeDef ); } }
throw new OdaException( Messages.getString( "ui.invalidXSDFile" ) ); return xsModel.getComponents( XSConstants.ELEMENT_DECLARATION );
public Schema createSchema(XSModel model) { schemas.clear(); Map<Source, Schema> schemas = new LinkedHashMap<>(); XSNamedMap rootEls = model.getComponents(XSConstants.ELEMENT_DECLARATION); for (int i = 0; i < rootEls.getLength(); i++) { XSElementDeclaration el = (XSElementDeclaration) rootEls.item(i); XSTypeDefinition type = el.getTypeDefinition(); debug("Processing root element " + el.getName() + "{" + el.getNamespace() + "}"); Schema schema = createTypeSchema(type, false, false); schemas.put(new Source(el.getName()), schema); } if (schemas.size() == 0) throw new ConverterException("No root element declaration"); if (schemas.size() == 1) return schemas.values().iterator().next(); return createRootRecordSchema(schemas); }
public XSNamedMap parseXMLSchema( URL url ) throws Exception { if( log.isLoggable( Level.FINE ) ) log.fine( "Parsing XML Schema " + url ); // Use Xerces DOM Implementation System.setProperty( DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl " ); // Get DOM Implementation Registry DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // Get DOM Implementation using DOM Registry DOMImplementationLS ls = (DOMImplementationLS) registry.getDOMImplementation( "LS" ); // create input LSInput input = ls.createLSInput(); input.setCharacterStream( new InputStreamReader( url.openStream() ) ); // Get XS Implementation XSImplementation impl = (XSImplementation) registry.getDOMImplementation( "XS-Loader" ); // Load XMLSchema XSLoader schemaLoader = impl.createXSLoader( null ); XSModel schema = schemaLoader.load( input ); // Get simple type definitions XSNamedMap map = schema.getComponents( XSTypeDefinition.SIMPLE_TYPE ); return map; }
public static List<XSComplexTypeDefinition> getSubTypes(XSModel xsModel, XSComplexTypeDefinition complexType) { List<XSComplexTypeDefinition> subTypes = new ArrayList<>(); XSNamedMap namedMap = xsModel.getComponents(XSConstants.TYPE_DEFINITION); XSObject anyType = namedMap.itemByName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anyType"); for (int i = 0; i < namedMap.getLength(); i++) { XSObject item = namedMap.item(i); if (item instanceof XSComplexTypeDefinition) { XSComplexTypeDefinition complexItem = (XSComplexTypeDefinition) item; if (!complexItem.getAbstract()) { do { complexItem = (XSComplexTypeDefinition) complexItem.getBaseType(); } while (complexItem != anyType && complexItem != complexType); if (complexItem == complexType) { subTypes.add((XSComplexTypeDefinition) item); } } } } return subTypes; }
public boolean validateFeatures() { boolean allFeaturesValid = true; XSNamedMap globalElements = this.model.getComponents((short) 2); for (int i = 0; i < globalElements.getLength(); i++) { XSElementDeclaration element = (XSElementDeclaration) globalElements .item(i); if ((isFeature(element)) && (!validateFeature(element))) { allFeaturesValid = false; } } return allFeaturesValid; }
/** * Builds the anonymous type mapping. This is intended to be called lazily. */ public void build() { XSModel model = JBossXSModel.this; anonymousTypeMap = new HashMap<String, XSTypeDefinition>(); 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(); }
public Collection getFeatureNames() { if (this.featureNames == null) { this.featureNames = new ArrayList(); XSNamedMap globalElements = this.model.getComponents((short) 2); for (int i = 0; i < globalElements.getLength(); i++) { XSElementDeclaration element = (XSElementDeclaration) globalElements .item(i); String namespaceUri = element.getNamespace(); String localName = element.getName(); if ((isFeature(element)) && (!element.getAbstract())) { this.featureNames.add(new QName(namespaceUri, localName)); } } } return this.featureNames; }
public Collection getGeometryNames() { if (this.geometryNames == null) { this.geometryNames = new ArrayList(); XSNamedMap globalElements = this.model.getComponents((short) 2); for (int i = 0; i < globalElements.getLength(); i++) { XSElementDeclaration element = (XSElementDeclaration) globalElements .item(i); String namespaceUri = element.getNamespace(); String localName = element.getName(); if ((isGeometry(element)) && (!element.getAbstract())) { this.geometryNames.add(new QName(namespaceUri, localName)); } } } return this.geometryNames; }
@SuppressWarnings("rawtypes") private List<Path> processModel(XSModel schema) throws BagriException { XSNamedMap elts = schema.getComponents(XSConstants.ELEMENT_DECLARATION);
/** * This method extracts types and names of messages, which have complex types */ private void analyzeType(QName aTypeName, List<Param> aParams) throws XNIException { if (schemaModel == null) { return; } XSNamedMap components = schemaModel.getComponents(XSTypeDefinition.COMPLEX_TYPE); for (int i = 0; i < components.getLength() - 1; i++) { XSObject item = components.item(i); // iterate over complex types till the requested type is found and then extract the // particles from this complex type if (matches(item, aTypeName)) { XSComplexTypeDecl newComplexTypeElem = (XSComplexTypeDecl) item; analyzeComplexType(aParams, newComplexTypeElem, initialRecDepth); break; // There can only be one item matching the qName, so we can bail out } } }
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);
xsMap = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION); for (int i = 0; i < xsMap.getLength(); i ++) xsMap = xsModel.getComponents(XSConstants.TYPE_DEFINITION); for (int i = 0; i < xsMap.getLength(); i ++) xsMap = xsModel.getComponents(XSConstants.MODEL_GROUP_DEFINITION); for (int i = 0; i < xsMap.getLength(); i ++)
XSNamedMap elementDecls = schemaModel.getComponents(XSConstants.ELEMENT_DECLARATION);
private void addTopLevelComponents(QName nameTest) { // get the annotations() components XSObjectList annotations = xsModel.getAnnotations(); for (int i = 0, n = annotations.size(); i < n; ++i) { addComponent(annotations.item(i), nameTest, result); } final short[] SCHEMA_COMPONENTS = new short[] { XSConstants.ELEMENT_DECLARATION, XSConstants.TYPE_DEFINITION, XSConstants.ATTRIBUTE_DECLARATION, XSConstants.ATTRIBUTE_GROUP, XSConstants.MODEL_GROUP_DEFINITION, XSConstants.NOTATION_DECLARATION, // XSConstants.IDENTITY_CONSTRAINT // TODO: return empty. we don't support IDC at top level }; XSNamedMap map; for (int i = 0; i < SCHEMA_COMPONENTS.length; ++i) { map = xsModel.getComponents(SCHEMA_COMPONENTS[i]); if (!map.isEmpty()) { for (int j = 0, n =map.size(); j < n; ++j) { addComponent(map.item(i), nameTest, result); } } } } // getTopLevelComponents()