use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addGlobalElements.
public void addGlobalElements(Map<QName, ElementDeclaration> additionalElements) {
for (Entry<QName, ElementDeclaration> entry : additionalElements.entrySet()) {
QName next = entry.getKey();
if (next != null) {
ElementDeclaration nextElement = entry.getValue();
if (nextElement.getScopeClass() == GLOBAL.class) {
String namespaceURI = next.getNamespaceURI();
Schema targetSchema = getSchemaForNamespace(namespaceURI);
if (targetSchema == null) {
continue;
}
if (targetSchema.getTopLevelElements().get(next.getLocalPart()) == null) {
Element element = new Element();
element.setName(next.getLocalPart());
element.setNillable(nextElement.isNillable());
JavaClass javaClass = nextElement.getJavaType();
// First check for built in type
QName schemaType = helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
if (schemaType != null) {
element.setType(Constants.SCHEMA_PREFIX + COLON + schemaType.getLocalPart());
} else if (areEquals(javaClass, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass, byte[].class) || areEquals(javaClass, Byte[].class) || areEquals(javaClass, Image.class) || areEquals(javaClass, Source.class) || areEquals(javaClass, JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
schemaType = Constants.BASE_64_BINARY_QNAME;
if (nextElement.getTypeMappingInfo() != null) {
if (nextElement.isXmlAttachmentRef()) {
schemaType = Constants.SWA_REF_QNAME;
}
if (nextElement.getXmlMimeType() != null) {
element.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, nextElement.getXmlMimeType());
}
}
String prefix = getOrGeneratePrefixForNamespace(schemaType.getNamespaceURI(), targetSchema);
element.setType(prefix + COLON + schemaType.getLocalPart());
} else if (areEquals(javaClass, CoreClassConstants.XML_GREGORIAN_CALENDAR)) {
schemaType = Constants.ANY_SIMPLE_TYPE_QNAME;
element.setType(Constants.SCHEMA_PREFIX + COLON + schemaType.getLocalPart());
} else {
TypeInfo type = this.typeInfo.get(javaClass.getQualifiedName());
if (type != null) {
String typeName = null;
if (type.isComplexType()) {
typeName = type.getComplexType().getName();
} else {
typeName = type.getSimpleType().getName();
}
// may need an anonymous complex type
if (typeName == null) {
Schema schema = getSchemaForNamespace(next.getNamespaceURI());
ComplexType cType = createComplexTypeForClass(javaClass, type);
TypeDefParticle particle = null;
if (cType.getComplexContent() != null && cType.getComplexContent().getExtension() != null) {
particle = cType.getComplexContent().getExtension().getTypeDefParticle();
} else {
particle = cType.getTypeDefParticle();
}
addToSchemaType(type, type.getPropertyList(), particle, cType, schema);
targetSchema = schema;
element.setComplexType(cType);
} else {
// check namespace of schemaType
if (type.getClassNamespace().equals(namespaceURI)) {
// no need to prefix here
String prefix = targetSchema.getNamespaceResolver().resolveNamespaceURI(namespaceURI);
if (prefix != null && !(prefix.equals(EMPTY_STRING))) {
element.setType(prefix + COLON + typeName);
} else {
element.setType(typeName);
}
} else {
Schema complexTypeSchema = getSchemaForNamespace(type.getClassNamespace());
String complexTypeSchemaNS = type.getClassNamespace();
if (complexTypeSchemaNS == null) {
complexTypeSchemaNS = EMPTY_STRING;
}
addImportIfRequired(targetSchema, complexTypeSchema, type.getClassNamespace());
String prefix = targetSchema.getNamespaceResolver().resolveNamespaceURI(complexTypeSchemaNS);
if (prefix != null) {
element.setType(prefix + COLON + typeName);
} else {
element.setType(typeName);
}
}
}
}
}
if (nextElement.getSubstitutionHead() != null) {
String subLocal = nextElement.getSubstitutionHead().getLocalPart();
String subNamespace = nextElement.getSubstitutionHead().getNamespaceURI();
String prefix = getPrefixForNamespace(targetSchema, subNamespace);
if (prefix == null || prefix.equals(EMPTY_STRING)) {
element.setSubstitutionGroup(subLocal);
} else {
element.setSubstitutionGroup(prefix + COLON + subLocal);
}
}
targetSchema.addTopLevelElement(element);
SchemaTypeInfo info = this.schemaTypeInfo.get(javaClass.getQualifiedName());
if (info == null) {
// probably for a simple type, not generated
info = new SchemaTypeInfo();
info.setSchemaTypeName(schemaType);
schemaTypeInfo.put(javaClass.getQualifiedName(), info);
}
info.getGlobalElementDeclarations().add(next);
}
}
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addMapToSchema.
/**
* Convenience method for processing a reference property. Required
* schema components will be generated and set accordingly.
*
* @param property the map property to be processed
* @param element schema Element a new complex type will be added to
* @param schema the schema being built
* @param typeInfo the TypeInfo that the given property belongs to
*/
private void addMapToSchema(Property property, Element element, Schema schema, TypeInfo typeInfo) {
ComplexType entryComplexType = new ComplexType();
Sequence entrySequence = new Sequence();
Element keyElement = new Element();
keyElement.setName(Property.DEFAULT_KEY_NAME);
keyElement.setMinOccurs(Occurs.ZERO);
JavaClass keyType = property.getKeyType();
JavaClass valueType = property.getActualValueType();
if (keyType == null) {
keyType = helper.getJavaClass(Object.class);
}
if (valueType == null) {
valueType = helper.getJavaClass(Object.class);
}
String typeName;
QName keySchemaType = getSchemaTypeFor(keyType);
if (keySchemaType != null) {
TypeInfo targetInfo = this.typeInfo.get(keyType.getQualifiedName());
if (targetInfo != null) {
Schema keyElementSchema = this.getSchemaForNamespace(keySchemaType.getNamespaceURI());
// add an import here
addImportIfRequired(schema, keyElementSchema, keySchemaType.getNamespaceURI());
}
String prefix;
if (keySchemaType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, keySchemaType.getNamespaceURI());
}
if (prefix != null && !prefix.equals(EMPTY_STRING)) {
typeName = prefix + COLON + keySchemaType.getLocalPart();
} else {
typeName = keySchemaType.getLocalPart();
}
keyElement.setType(typeName);
}
entrySequence.addElement(keyElement);
Element valueElement = new Element();
valueElement.setName(Property.DEFAULT_VALUE_NAME);
valueElement.setMinOccurs(Occurs.ZERO);
QName valueSchemaType = getSchemaTypeFor(valueType);
if (valueSchemaType != null) {
TypeInfo targetInfo = this.typeInfo.get(valueType.getQualifiedName());
if (targetInfo != null) {
Schema valueElementSchema = this.getSchemaForNamespace(valueSchemaType.getNamespaceURI());
// add an import here
addImportIfRequired(schema, valueElementSchema, valueSchemaType.getNamespaceURI());
}
String prefix;
if (valueSchemaType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, valueSchemaType.getNamespaceURI());
}
if (prefix != null && !prefix.equals(EMPTY_STRING)) {
typeName = prefix + COLON + valueSchemaType.getLocalPart();
} else {
typeName = valueSchemaType.getLocalPart();
}
if (property.getValueGenericType() != null) {
valueElement.setMaxOccurs(Occurs.UNBOUNDED);
}
valueElement.setType(typeName);
}
entrySequence.addElement(valueElement);
entryComplexType.setSequence(entrySequence);
JavaClass descriptorClass = null;
if (null != typeInfo.getDescriptor()) {
descriptorClass = helper.getJavaClass(typeInfo.getDescriptor().getJavaClassName());
}
JavaClass mapValueClass = helper.getJavaClass(MapValue.class);
if (null != descriptorClass && mapValueClass.isAssignableFrom(descriptorClass)) {
element.setComplexType(entryComplexType);
element.setMaxOccurs(Occurs.UNBOUNDED);
} else {
ComplexType complexType = new ComplexType();
Sequence sequence = new Sequence();
complexType.setSequence(sequence);
Element entryElement = new Element();
entryElement.setName(ENTRY);
entryElement.setMinOccurs(Occurs.ZERO);
entryElement.setMaxOccurs(Occurs.UNBOUNDED);
sequence.addElement(entryElement);
entryElement.setComplexType(entryComplexType);
element.setComplexType(complexType);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class WSDLGenerator method createInlineSchema.
/**
* Build the inline schema that will make up the content of the
* {@code <wsdl:types>} section of the WSDL.
*/
@SuppressWarnings("unchecked")
private org.w3c.dom.Element createInlineSchema() {
SchemaModelProject project = new SchemaModelProject();
XMLContext context = new XMLContext(project);
XMLMarshaller marshaller = context.createMarshaller();
XMLDescriptor descriptor = (XMLDescriptor) project.getClassDescriptor(Schema.class);
if (descriptor.getNamespaceResolver() == null) {
descriptor.setNamespaceResolver(new NamespaceResolver());
}
descriptor.getNamespaceResolver().put(NS_TNS_PREFIX, serviceNameSpace);
descriptor.getNamespaceResolver().put(NS_SCHEMA_PREFIX, W3C_XML_SCHEMA_NS_URI);
if (hasAttachments) {
descriptor.getNamespaceResolver().put(WSI_SWAREF_PREFIX, WSI_SWAREF_URI);
}
Schema schema = new Schema();
schema.setTargetNamespace(serviceNameSpace);
schema.setElementFormDefault(true);
Import parent = new Import();
parent.setNamespace(importedSchemaNameSpace);
parent.setSchemaLocation(DBWS_SCHEMA_XML);
schema.getImports().add(parent);
if (hasAttachments) {
Import ref = new Import();
ref.setNamespace(WSI_SWAREF_URI);
// ref.setSchemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd"); // later version
ref.setSchemaLocation(WSI_SWAREF_XSD_FILE);
schema.getImports().add(ref);
}
boolean requireFaultTypeEmptyResponse = false;
for (Operation op : xrServiceModel.getOperationsList()) {
String opName = op.getName();
ComplexType requestType = new ComplexType();
// may need to extract tableNameAlias from operation name - everything after first
// underscore '_' character (for cases where a QueryOperation is not user defined)
// i.e. String tableNameAlias = opName.substring(opName.indexOf('_') + 1);
requestType.setName(opName + REQUEST_SUFFIX + TYPE_SUFFIX);
Sequence requestSequence = null;
if (op.getParameters().size() > 0) {
requestSequence = new Sequence();
for (Parameter p : op.getParameters()) {
Element arg = new Element();
if (p.isOptional()) {
arg.setMinOccurs("0");
}
arg.setName(p.getName());
if (THE_INSTANCE_NAME.equals(p.getName())) {
ComplexType nestedComplexType = new ComplexType();
Sequence nestedSequence = new Sequence();
nestedComplexType.setSequence(nestedSequence);
Element nestedElement = new Element();
nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + p.getType().getLocalPart());
// here we may need to use 'tableNameAlias' instead, i.e.
// nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + tableNameAlias);
nestedSequence.addElement(nestedElement);
arg.setComplexType(nestedComplexType);
} else {
arg.setName(p.getName());
if (p.getType().getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
arg.setType(NS_SCHEMA_PREFIX + ":" + p.getType().getLocalPart());
} else if (p.getType().getNamespaceURI().equals(importedSchemaNameSpace)) {
arg.setType(TARGET_NAMESPACE_PREFIX + ":" + p.getType().getLocalPart());
} else {
arg.setType(p.getType().getLocalPart());
}
}
requestSequence.addElement(arg);
}
requestType.setSequence(requestSequence);
}
schema.addTopLevelComplexTypes(requestType);
Element requestElement = new Element();
requestElement.setName(op.getName());
requestElement.setType(NS_TNS_PREFIX + ":" + requestType.getName());
schema.addTopLevelElement(requestElement);
// build response message based on operation type
if (op instanceof QueryOperation) {
QueryOperation q = (QueryOperation) op;
ComplexType responseType = new ComplexType();
responseType.setName(op.getName() + RESPONSE_SUFFIX + TYPE_SUFFIX);
Sequence responseSequence = new Sequence();
Element result = new Element();
result.setName("result");
if (q.isAttachment()) {
result.setType(WSI_SWAREF_PREFIX + ":" + WSI_SWAREF);
} else if (q.isSimpleXMLFormat() || q.getResultType().equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
ComplexType anyType = new ComplexType();
Sequence anySequence = new Sequence();
anySequence.addAny(new Any());
anyType.setSequence(anySequence);
result.setComplexType(anyType);
} else {
if (q.getResultType().getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
result.setType(NS_SCHEMA_PREFIX + ":" + q.getResultType().getLocalPart());
} else {
ComplexType nestedComplexType = new ComplexType();
Sequence nestedSequence = new Sequence();
nestedComplexType.setSequence(nestedSequence);
Element nestedElement = new Element();
// may need if/else based on if the operation is/isn't user defined, i.e.
// if (!q.isUserDefined()) {
// nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + tableNameAlias);
// } else {
// nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + q.getResultType().getLocalPart());
// }
nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + q.getResultType().getLocalPart());
nestedElement.setMinOccurs("0");
if (q.isCollection()) {
nestedElement.setMaxOccurs("unbounded");
}
nestedSequence.addElement(nestedElement);
result.setComplexType(nestedComplexType);
}
}
responseSequence.addElement(result);
responseType.setSequence(responseSequence);
schema.addTopLevelComplexTypes(responseType);
Element responseElement = new Element();
responseElement.setName(op.getName() + RESPONSE_SUFFIX);
responseElement.setType(NS_TNS_PREFIX + ":" + responseType.getName());
schema.addTopLevelElement(responseElement);
} else {
requireFaultTypeEmptyResponse = true;
}
}
if (requireFaultTypeEmptyResponse) {
// <element name="EmptyResponse">
// <xsd:complexType/>
// </element>
Element emptyResponseElement = new Element();
emptyResponseElement.setName(EMPTY_RESPONSE);
ComplexType emptyResponseComplexType = new ComplexType();
emptyResponseElement.setComplexType(emptyResponseComplexType);
schema.addTopLevelElement(emptyResponseElement);
// <xsd:element name="FaultType">
// <xsd:complexType>
// <xsd:sequence>
// <xsd:element name="faultCode" type="xsd:string"/>
// <xsd:element name="faultString" type="xsd:string"/>
// </xsd:sequence>
// </xsd:complexType>
// </element>
Element elementFaultType = new Element();
elementFaultType.setName(FAULT_SUFFIX + TYPE_SUFFIX);
ComplexType faultComplexType = new ComplexType();
elementFaultType.setComplexType(faultComplexType);
Sequence nestedSequence = new Sequence();
faultComplexType.setSequence(nestedSequence);
Element faultCodeElement = new Element();
faultCodeElement.setName("faultCode");
faultCodeElement.setMinOccurs("1");
faultCodeElement.setType(NS_SCHEMA_PREFIX + ":string");
nestedSequence.addElement(faultCodeElement);
Element faultStringElement = new Element();
faultStringElement.setMinOccurs("1");
faultStringElement.setName("faultString");
faultStringElement.setType(NS_SCHEMA_PREFIX + ":string");
nestedSequence.addElement(faultStringElement);
schema.addTopLevelElement(elementFaultType);
}
return marshaller.objectToXML(schema).getDocumentElement();
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SimpleTableWithNestedSQLTestSuite method validateElementRefType.
@Test
public void validateElementRefType() throws TransformerFactoryConfigurationError, TransformerException {
StringWriter sw = new StringWriter();
StreamSource wsdlStreamSource = new StreamSource(new StringReader(DBWS_WSDL_STREAM.toString()));
Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(MATCH_SCHEMA)));
StreamResult streamResult = new StreamResult(sw);
t.transform(wsdlStreamSource, streamResult);
sw.toString();
SchemaModelProject schemaProject = new SchemaModelProject();
XMLContext xmlContext2 = new XMLContext(schemaProject);
XMLUnmarshaller unmarshaller = xmlContext2.createUnmarshaller();
Schema schema = (Schema) unmarshaller.unmarshal(new StringReader(sw.toString()));
ComplexType findByNameResponseType = schema.getTopLevelComplexTypes().get(FINDBYNAME_RESPONSETYPE);
Element result = findByNameResponseType.getSequence().getElements().get(0);
Element unnamed = result.getComplexType().getSequence().getElements().get(0);
assertTrue("wrong refType for " + FINDBYNAME_RESPONSETYPE, TABLE_ALIAS.equals(unnamed.getRef()));
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method typesExists.
private boolean typesExists(String targetNamespace, String sdoTypeName) {
boolean alreadyProcessed = false;
if ((targetNamespace != null) && (targetNamespace.equals(SDOConstants.SDOJAVA_URL) || targetNamespace.equals(SDOConstants.SDO_URL) || targetNamespace.equals(SDOConstants.SDOXML_URL))) {
alreadyProcessed = true;
} else {
QName qname = new QName(targetNamespace, sdoTypeName);
ComplexType processed = processedComplexTypes.get(qname);
if (processed != null) {
alreadyProcessed = true;
}
}
if (!alreadyProcessed) {
SDOType lookup = (SDOType) aHelperContext.getTypeHelper().getType(targetNamespace, sdoTypeName);
if ((lookup != null) && lookup.isFinalized()) {
if (isReturnAllTypes()) {
QName qname = new QName(targetNamespace, sdoTypeName);
getGeneratedTypes().put(qname, lookup);
}
return true;
} else if (lookup == null) {
QName qname = new QName(targetNamespace, sdoTypeName);
SDOType processed = (SDOType) getGeneratedTypes().get(qname);
if (processed != null && processed.isFinalized()) {
alreadyProcessed = true;
}
}
}
return alreadyProcessed;
}
Aggregations