XSDSchema schema = xsdMainResource.getSchema(); if (schema != null) {
/** * Remove all references to this schema, and all schemas built in the same resource set It is * important to call this method for every dynamic schema created that is not needed anymore, * because references in the static schema's will otherwise keep it alive forever */ public void dispose() { if (schema != null) { ResourceSet rs = schema.eResource().getResourceSet(); for (Resource r : rs.getResources()) { if (r instanceof XSDResourceImpl) { Schemas.dispose(((XSDResourceImpl) r).getSchema()); } } schema = null; } } }
return ((XSDResourceImpl) resolvedResource).getSchema(); } else {
EmfXsdLoadTest.class.getResource(filename).toString()), true); XSDSchema schema = resource.getSchema(); Assert.assertNotNull(schema); SchemaIndex index = null;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.xsd.util.XSDResourceFactoryImpl; import org.eclipse.xsd.util.XSDResourceImpl; import org.eclipse.xsd.XSDSchema; static ResourceSet resourceSet; XSDResourceFactoryImpl rf = new XSDResourceFactoryImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", rf); resourceSet = new ResourceSetImpl(); resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_LOCATION, Boolean.TRUE); XSDResourceImpl rsrc = (XSDResourceImpl)(resourceSet.getResource(uri, true)); XSDSchema sch = rsrc.getSchema();
@Override public EObject getEObject(String uriFragment) { // Do ID-based lookup. // if (!uriFragment.startsWith("/")) { Element theElement = getSchema().getElement(); if (theElement != null) { // Navigate out through the elements. // Element resultElement = theElement.getOwnerDocument().getElementById(uriFragment); List<Element> parents = new ArrayList<Element>(); for (Node parent = resultElement; parent != null; parent = parent.getParentNode()) { if (parent.getNodeType() == Node.ELEMENT_NODE) { parents.add((Element)parent); } } return ((org.eclipse.xsd.impl.XSDSchemaImpl)getSchema()).getBestConcreteComponent(parents); } } return super.getEObject(uriFragment); }
@Override public EObject getEObject(String uriFragment) { // Do ID-based lookup. // if (!uriFragment.startsWith("/")) { Element theElement = getSchema().getElement(); if (theElement != null) { // Navigate out through the elements. // Element resultElement = theElement.getOwnerDocument().getElementById(uriFragment); List<Element> parents = new ArrayList<Element>(); for (Node parent = resultElement; parent != null; parent = parent.getParentNode()) { if (parent.getNodeType() == Node.ELEMENT_NODE) { parents.add((Element)parent); } } return ((org.eclipse.xsd.impl.XSDSchemaImpl)getSchema()).getBestConcreteComponent(parents); } } return super.getEObject(uriFragment); }
final XSDResourceImpl rsrc = new XSDResourceImpl(URI.createFileURI(xsdFileWithPath)); rsrc.load(new HashMap()); final XSDSchema schema = rsrc.getSchema(); for (Object content : schema.getContents()) { if (content instanceof XSDImport) { XSDImport xsdImport = (XSDImport) content; xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), ""); } }
public static final XSDSchema parse(String location, List locators, List resolvers) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File(location).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet.createResource(URI.createURI( ".xsd")); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
public static final XSDSchema parse(String location, List locators, List resolvers) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File(location).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet.createResource(URI.createURI( ".xsd")); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
public static final XSDSchema parse( String location, List locators, List resolvers ) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File( location ).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet .createResource(URI.createURI(".xsd")); // LOGGER.info("About to parse xsd schema: " + uri); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
public static synchronized XSDSchema getSchemaInstance(String namespace) { if (XSDConstants.SCHEMA_INSTANCE_URI_2001.equals(namespace)) { if (xsdSchemaInstance2001 == null) { try { String baseURL = XSDPlugin.INSTANCE.getBaseURL().toString(); getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); getGlobalResourceSet().getLoadOptions().put("XSD_SCHEMA_INSTANCE", XSDConstants.SCHEMA_INSTANCE_URI_2001); Resource schemaInstance2001Resource = getGlobalResourceSet().getResource (URI.createURI(baseURL + "cache/www.w3.org/2001/XMLSchema-instance.xsd"), true); xsdSchemaInstance2001 = ((XSDResourceImpl)schemaInstance2001Resource).getSchema(); } catch (Exception exception) { exception.printStackTrace(); } finally { getGlobalResourceSet().getLoadOptions().remove("XSD_SCHEMA_INSTANCE"); } } return xsdSchemaInstance2001; } return null; }
public static synchronized XSDSchema getSchemaInstance(String namespace) { if (XSDConstants.SCHEMA_INSTANCE_URI_2001.equals(namespace)) { if (xsdSchemaInstance2001 == null) { try { String baseURL = XSDPlugin.INSTANCE.getBaseURL().toString(); getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); getGlobalResourceSet().getLoadOptions().put("XSD_SCHEMA_INSTANCE", XSDConstants.SCHEMA_INSTANCE_URI_2001); Resource schemaInstance2001Resource = getGlobalResourceSet().getResource (URI.createURI(baseURL + "cache/www.w3.org/2001/XMLSchema-instance.xsd"), true); xsdSchemaInstance2001 = ((XSDResourceImpl)schemaInstance2001Resource).getSchema(); } catch (Exception exception) { exception.printStackTrace(); } finally { getGlobalResourceSet().getLoadOptions().remove("XSD_SCHEMA_INSTANCE"); } } return xsdSchemaInstance2001; } return null; }
XSDSchema otherSchema = xsdResource.getSchema(); for (XSDSchemaContent content : otherSchema.getContents())
protected void doSave(Writer writer, Map<?, ?> options) throws IOException { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(writer, document, options); } }
protected void doSave(Writer writer, Map<?, ?> options) throws IOException { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(writer, document, options); } }
@Override protected void doSave(OutputStream os, Map<?, ?> options) throws IOException { if (os instanceof URIConverter.WriteableOutputStream) { doSave(((URIConverter.WriteableOutputStream)os).asWriter(), options); } else { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(os, document, options); } } }
@Override protected void doSave(OutputStream os, Map<?, ?> options) throws IOException { if (os instanceof URIConverter.WriteableOutputStream) { doSave(((URIConverter.WriteableOutputStream)os).asWriter(), options); } else { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(os, document, options); } } }
eSchema = ((XSDResourceImpl)resolvedResource).getSchema();
resolvedSchema = resourceImpl.getSchema(); if (resolvedSchema != null)