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());
}
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;
}
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);
}
}
}
}
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);
}
}
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();
}
Aggregations