Search in sources :

Example 11 with Namespace

use of org.eclipse.persistence.internal.oxm.Namespace in project eclipselink by eclipse-ee4j.

the class GenerateSchemaTestCases method outputSchema.

/**
 * For debugging - write the given schema to System out.
 */
protected void outputSchema(Schema generatedSchema) {
    Project p = new SchemaModelProject();
    Vector namespaces = generatedSchema.getNamespaceResolver().getNamespaces();
    for (int i = 0; i < namespaces.size(); i++) {
        Namespace next = (Namespace) namespaces.get(i);
        ((XMLDescriptor) p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
    }
    XMLContext context = new XMLContext(p);
    XMLMarshaller marshaller = context.createMarshaller();
    StringWriter generatedSchemaWriter = new StringWriter();
    marshaller.marshal(generatedSchema, generatedSchemaWriter);
    System.out.println(generatedSchemaWriter.toString());
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) StringWriter(java.io.StringWriter) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) Vector(java.util.Vector) Namespace(org.eclipse.persistence.internal.oxm.Namespace)

Example 12 with Namespace

use of org.eclipse.persistence.internal.oxm.Namespace in project eclipselink by eclipse-ee4j.

the class GenerateSchemaTestCases method getDocument.

/**
 * Return a Document for a given EclipseLink schema model Schema.
 *
 * @see Document
 */
protected Document getDocument(Schema schema) {
    Document document = parser.newDocument();
    Project p = new SchemaModelProject();
    for (Iterator<Namespace> nameIt = schema.getNamespaceResolver().getNamespaces().iterator(); nameIt.hasNext(); ) {
        Namespace next = nameIt.next();
        ((XMLDescriptor) p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
    }
    XMLContext context = new XMLContext(p);
    XMLMarshaller marshaller = context.createMarshaller();
    marshaller.marshal(schema, document);
    return document;
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) Document(org.w3c.dom.Document) Namespace(org.eclipse.persistence.internal.oxm.Namespace)

Example 13 with Namespace

use of org.eclipse.persistence.internal.oxm.Namespace in project eclipselink by eclipse-ee4j.

the class SDOType method setupInheritance.

public void setupInheritance(SDOType parentType) {
    if (parentType == null) {
        // root of inheritance
        addClassIndicator(getXmlDescriptor(), getImplClass(), true);
    } else {
        if ((parentType.getURI() != null) && (!parentType.getURI().equals(SDOConstants.SDO_URL))) {
            // set parent descriptor indicator if necessary
            if (!parentType.getXmlDescriptor().hasInheritance()) {
                addClassIndicator(parentType.getXmlDescriptor(), parentType.getImplClass(), false);
            }
            XMLDescriptor parentDescriptor = (XMLDescriptor) parentType.getXmlDescriptor().getInheritancePolicy().getRootParentDescriptor();
            NamespaceResolver parentNR = parentDescriptor.getNonNullNamespaceResolver();
            if (parentNR != null) {
                for (int i = 0; i < parentNR.getNamespaces().size(); i++) {
                    Namespace nextNamespace = parentNR.getNamespaces().get(i);
                    if ((!nextNamespace.getPrefix().equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) && (!nextNamespace.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOXML_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDO_URL))) {
                        getXmlDescriptor().getNonNullNamespaceResolver().put(nextNamespace.getPrefix(), nextNamespace.getNamespaceURI());
                    }
                }
            }
            if (getInstanceClassName() != null) {
                String indicator = getName();
                String prefix = parentDescriptor.getNamespaceResolver().resolveNamespaceURI(getURI());
                if (prefix == null) {
                    prefix = getXmlDescriptor().getNamespaceResolver().resolveNamespaceURI(getURI());
                    if (prefix != null) {
                        parentDescriptor.getNamespaceResolver().put(prefix, getURI());
                    }
                }
                if (prefix != null) {
                    indicator = prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + indicator;
                }
                Class<?> implClass = getImplClass();
                parentDescriptor.getInheritancePolicy().addClassIndicator(implClass, indicator);
                parentDescriptor.getInheritancePolicy().setShouldReadSubclasses(true);
                Class<?> parentClass = parentType.getImplClass();
                getXmlDescriptor().getInheritancePolicy().setParentClass(parentClass);
                getXmlDescriptor().getInheritancePolicy().setParentDescriptor(parentType.getXmlDescriptor());
                parentType.getXmlDescriptor().getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
                getXmlDescriptor().getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
            }
        }
    }
    // now setup inheritance for any subtypes
    if (isBaseType()) {
        for (int i = 0; i < subTypes.size(); i++) {
            SDOType nextSubType = (SDOType) subTypes.get(i);
            if (!nextSubType.isDataType() && nextSubType.isSubType()) {
                nextSubType.setupInheritance(this);
            }
        }
    }
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Namespace(org.eclipse.persistence.internal.oxm.Namespace)

Example 14 with Namespace

use of org.eclipse.persistence.internal.oxm.Namespace in project eclipselink by eclipse-ee4j.

the class SDOType method initializeNamespaces.

/**
 * INTERNAL:
 * Get the XMLDescriptor associated with this Type or generate a new one.
 */
public void initializeNamespaces(List namespaceResolvers) {
    if (!isDataType()) {
        NamespaceResolver nr = new NamespaceResolver();
        // copy namespaces between resolvers for well known and SDO namespaces
        if (namespaceResolvers != null) {
            for (int i = 0; i < namespaceResolvers.size(); i++) {
                NamespaceResolver nextNR = (NamespaceResolver) namespaceResolvers.get(i);
                if (nextNR != null) {
                    for (int j = 0, size = nextNR.getNamespaces().size(); j < size; j++) {
                        Namespace nextNamespace = nextNR.getNamespaces().get(j);
                        if ((!nextNamespace.getPrefix().equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) && (!nextNamespace.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOXML_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDO_URL))) {
                            String newPrefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).addNamespace(nextNamespace.getPrefix(), nextNamespace.getNamespaceURI());
                            nr.put(newPrefix, nextNamespace.getNamespaceURI());
                        }
                    }
                }
            }
        }
        xmlDescriptor.setNamespaceResolver(nr);
        if (getURI() != null) {
            String prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(getURI());
            xmlDescriptor.getNamespaceResolver().put(prefix, getURI());
        }
        xmlDescriptor.getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Namespace(org.eclipse.persistence.internal.oxm.Namespace)

Example 15 with Namespace

use of org.eclipse.persistence.internal.oxm.Namespace in project eclipselink by eclipse-ee4j.

the class SDOSchemaGenerator method generate.

/**
 * <p>Method to generate an XSD. Note the following:<ul>
 * <li> All types must have same URI
 * <li> Referenced types in same URI will also be generated in schema
 * <li> Includes will never be generated
 * <li> Imports will be generated for referenced types in other URIs
 * </ul>
 * @param types The list of commonj.sdo.Type objects to generate the XSD from
 * @param aNamespaceToSchemaLocation map of namespaces to schemaLocations
 * used for getting the value of the schemaLocation attribute of generated imports and includes
 * @return String The generated XSD.
 */
public String generate(List types, Map<String, String> aNamespaceToSchemaLocation) {
    if ((types == null) || (types.size() == 0)) {
        throw new IllegalArgumentException("No Schema was generated from null or empty list of types.");
    }
    String uri = null;
    namespaceToSchemaLocation = aNamespaceToSchemaLocation;
    Type firstType = (Type) types.get(0);
    if (firstType == null) {
        throw new IllegalArgumentException("No Schema was generated from a list of types containing null elements");
    } else {
        uri = firstType.getURI();
    }
    allTypes = types;
    generateSchema(uri, types);
    // Now we have a built schema model
    Project p = new SchemaModelProject();
    Vector<Namespace> namespaces = generatedSchema.getNamespaceResolver().getNamespaces();
    for (int i = 0; i < namespaces.size(); i++) {
        Namespace next = namespaces.get(i);
        ((XMLDescriptor) p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
    }
    XMLLogin login = new XMLLogin();
    login.setDatasourcePlatform(new DOMPlatform());
    p.setDatasourceLogin(login);
    XMLContext context = new XMLContext(p);
    XMLMarshaller marshaller = context.createMarshaller();
    StringWriter generatedSchemaWriter = new StringWriter();
    marshaller.marshal(generatedSchema, generatedSchemaWriter);
    return generatedSchemaWriter.toString();
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Namespace(org.eclipse.persistence.internal.oxm.Namespace) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) StringWriter(java.io.StringWriter)

Aggregations

Namespace (org.eclipse.persistence.internal.oxm.Namespace)15 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)6 XMLContext (org.eclipse.persistence.oxm.XMLContext)6 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)6 Project (org.eclipse.persistence.sessions.Project)6 StringWriter (java.io.StringWriter)4 Vector (java.util.Vector)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)3 Type (commonj.sdo.Type)2 DataObject (commonj.sdo.DataObject)1 XmlAccessorType (jakarta.xml.bind.annotation.XmlAccessorType)1 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 XmlMimeType (jakarta.xml.bind.annotation.XmlMimeType)1 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1 XmlType (jakarta.xml.bind.annotation.XmlType)1 XmlJavaTypeAdapter (jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1