/** * Read an XSDSchema instance and create the node hierarchy under the given root node. * * @param schema the schema object; may not be null * @param encoding the encoding for the XSD; may be null if the encoding is not specified * @param contentSize the size of the XML Schema Document content; may not be negative * @param rootNode the root node that will be populated with the XML Schema Document information * @throws Exception if there is a probelm reading the XSD content */ protected void process(XSDSchema schema, String encoding, long contentSize, Node rootNode) throws Exception { assert schema != null; logger.debug("Target namespace: '{0}'", schema.getTargetNamespace()); rootNode.setProperty(SrampLexicon.CONTENT_TYPE, MimeTypeConstants.APPLICATION_XML); if (encoding != null) { rootNode.setProperty(SrampLexicon.CONTENT_ENCODING, encoding); } rootNode.setProperty(SrampLexicon.CONTENT_SIZE, contentSize); // Parse the annotations first to aggregate them all into a single 'sramp:description' property // ... @SuppressWarnings("unchecked") List<XSDAnnotation> annotations = schema.getAnnotations(); processAnnotations(annotations, rootNode); processNonSchemaAttributes(schema, rootNode); // Parse the objects ... for (EObject obj : schema.eContents()) { if (obj instanceof XSDSimpleTypeDefinition) { processSimpleTypeDefinition((XSDSimpleTypeDefinition) obj, rootNode); } else if (obj instanceof XSDComplexTypeDefinition) { processComplexTypeDefinition((XSDComplexTypeDefinition) obj, rootNode); } else if (obj instanceof XSDElementDeclaration) { processElementDeclaration((XSDElementDeclaration) obj, rootNode); } else if (obj instanceof XSDAttributeDeclaration) { processAttributeDeclaration((XSDAttributeDeclaration) obj, rootNode, false); } else if (obj instanceof XSDImport) { processImport((XSDImport) obj, rootNode); } else if (obj instanceof XSDInclude) { processInclude((XSDInclude) obj, rootNode); } else if (obj instanceof XSDRedefine) { processRedefine((XSDRedefine) obj, rootNode); } else if (obj instanceof XSDAttributeGroupDefinition) { processAttributeGroupDefinition((XSDAttributeGroupDefinition) obj, rootNode); } else if (obj instanceof XSDAnnotation) { // already processed above ... } } // Resolve any outstanding, unresolved references ... resolveReferences(); }
/** * Add external resources referenced by the specified XSD resource to the resultant list * * @param eResource the resource to process for references * @param recurse if true, the result will include all direct and indirect dependent resources * otherwise only the direct dependencies are returned. * @param includeExternal If true, external resource references will be included in the resulant * array, otherwise they will be excluded from the result. * @param result the resultant list to add to */ protected void addExternallyReferencedResourcesForXsd( final XSDResourceImpl eResource, final boolean recurse, final boolean includeExternal, final List result, final Set unresolvedResourceURIs) { if (eResource != null) { // Resolve all schema directives (import/include/redefine) Set visitedXsdResources = new HashSet(); resolveSchemaDirectives(eResource, recurse, visitedXsdResources, unresolvedResourceURIs); // Add the resource referenced through the directive to the overall result XSDSchema schema = eResource.getSchema(); for (final Iterator i = schema.eContents().iterator(); i.hasNext(); ) { EObject eObj = (EObject) i.next(); if (eObj instanceof XSDSchemaDirective) { XSDSchema resolvedSchema = ((XSDSchemaDirective) eObj).getResolvedSchema(); Resource rsrc = (resolvedSchema != null ? resolvedSchema.eResource() : null); if (rsrc != null && !result.contains(rsrc)) { if (!includeExternal && isExternalResource(rsrc)) { continue; } result.add(rsrc); if (recurse) { addExternallyReferencedResources( rsrc, recurse, includeExternal, result, unresolvedResourceURIs); } } } } // Ensure that the schema for schema resource (e.g. "http://www.w3.org/2001/XMLSchema") is // added to the result; if (includeExternal) { Resource rsrc = schema.getSchemaForSchema().eResource(); if (rsrc != null && !result.contains(rsrc)) { result.add(rsrc); } } } }