use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SOAPResponseWriter method initialize.
@SuppressWarnings("unchecked")
public void initialize() {
SOAPResponseClassLoader loader = new SOAPResponseClassLoader(Thread.currentThread().getContextClassLoader());
NamespaceResolver nr = new NamespaceResolver();
nr.put(SERVICE_NAMESPACE_PREFIX, dbwsAdapter.getExtendedSchema().getTargetNamespace());
for (Operation op : dbwsAdapter.getOperationsList()) {
String className = op.getName() + "_Response";
Class<?> opClass = loader.buildClass(className);
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setDefaultRootElement(SERVICE_NAMESPACE_PREFIX + ":" + op.getName() + "Response");
descriptor.setNamespaceResolver(nr);
descriptor.setJavaClass(opClass);
if (op instanceof QueryOperation) {
QueryOperation queryOperation = (QueryOperation) op;
if (queryOperation.isSimpleXMLFormat()) {
XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
mapping.setUseXMLRoot(true);
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
descriptor.addMapping(mapping);
mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
} else if (queryOperation.isAttachment()) {
Attachment attachment = queryOperation.getResult().getAttachment();
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
} else {
QName type = queryOperation.getResult().getType();
String localElement = type.getLocalPart();
// look for top-level complex types
Set<Map.Entry<String, ComplexType>> entrySet = dbwsAdapter.getSchema().getTopLevelComplexTypes().entrySet();
for (Map.Entry<String, ComplexType> me : entrySet) {
if (me.getValue().getName().equals(type.getLocalPart())) {
localElement = me.getKey();
break;
}
}
XMLDescriptor typeDescriptor = dbwsAdapter.getDescriptorsByQName().get(type);
if (typeDescriptor != null) {
if (queryOperation.isCollection()) {
XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping();
mapping.setAttributeName("result");
mapping.setReferenceClass(typeDescriptor.getJavaClass());
mapping.useCollectionClass(ArrayList.class);
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
descriptor.addMapping(mapping);
mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
} else {
XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
mapping.setAttributeName("result");
mapping.setReferenceClass(typeDescriptor.getJavaClass());
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
descriptor.addMapping(mapping);
mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
}
} else {
if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
descriptor.addMapping(mapping);
} else if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, BASE_64_BINARY))) {
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
mapping.setShouldInlineBinaryData(true);
((XMLField) mapping.getField()).setSchemaType(type);
descriptor.addMapping(mapping);
} else {
XMLDirectMapping mapping = new XMLDirectMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/text()");
descriptor.addMapping(mapping);
}
}
}
}
dbwsAdapter.getOXSession().getProject().addDescriptor(descriptor);
((DatabaseSessionImpl) dbwsAdapter.getOXSession()).initializeDescriptorIfSessionAlive(descriptor);
dbwsAdapter.getXMLContext().storeXMLDescriptorByQName(descriptor);
resultDescriptors.put(op.getName(), descriptor);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLCompositeMapping.
/**
* Process a given XML composite mapping - either an XMLCompositeObjectMapping, or an
* XMLCompositeCollectionMapping. For XMLCompositeDirectCollectionMappings the
* processXMLCompositeDirectCollectionMapping method should be used.
*/
protected void processXMLCompositeMapping(CompositeObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean collection) {
Field xmlField = (Field) mapping.getField();
String refClassName = mapping.getReferenceClassName();
Descriptor refDesc = getDescriptorByName(refClassName, descriptors);
if (refDesc == null) {
throw DescriptorException.descriptorIsMissing(refClassName, (DatabaseMapping) mapping);
}
XPathFragment frag = xmlField.getXPathFragment();
seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
frag = getTargetXPathFragment(frag);
Element element = buildElement(frag, null, Occurs.ZERO, (collection ? Occurs.UNBOUNDED : null));
ComplexType ctype = null;
// if the reference descriptor's schema context is null we need to generate an anonymous complex type
if (refDesc.getSchemaReference() == null) {
ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
} else {
element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
if (frag.getNamespaceURI() != null) {
// may need to add a global element
element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, ctype, refDesc);
} else if (ctype != null) {
// set an anonymous complex type
element.setComplexType(ctype);
}
boolean isNillable = false;
if (!collection) {
isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
} else {
isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
}
element.setNillable(isNillable);
if (xmlField.isRequired()) {
element.setMinOccurs("1");
}
seq.addElement(element);
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method createGlobalElement.
/**
* Create a global element. An import is added if necessary. This method
* will typically be called when processing an XPath and a prefixed path
* element is encountered the requires an element ref.
*
* @param frag XPathFragment which wil lbe used to create the global element
* @param workingSchema current schema
* @param fragSchema frag's schema
* @param isChoice indicates if we need to construct a choice
* @param isUnbounded maxOccurs setting for choice
* @param prop property which owns the xml-path
* @param shouldSetType if this is the last fragment in the xml-path and not an 'any', we should set the type
*/
public Element createGlobalElement(XPathFragment frag, Schema workingSchema, Schema fragSchema, boolean isChoice, boolean isUnbounded, Property prop, boolean shouldSetType) {
Element gElement = new Element();
gElement.setName(frag.getLocalName());
if (shouldSetType) {
gElement.setType(getQualifiedTypeName(prop, fragSchema));
} else {
ComplexType gCType = new ComplexType();
TypeDefParticle particle;
if (isChoice) {
particle = new Choice();
if (isUnbounded) {
particle.setMaxOccurs(Occurs.UNBOUNDED);
}
} else {
particle = new Sequence();
}
gCType.setTypeDefParticle(particle);
gElement.setComplexType(gCType);
}
fragSchema.addTopLevelElement(gElement);
addImportIfRequired(workingSchema, fragSchema, frag.getNamespaceURI());
return gElement;
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addSchemaComponents.
public void addSchemaComponents(JavaClass myClass) {
// first check for type
String myClassName = myClass.getQualifiedName();
Element rootElement = null;
TypeInfo info = typeInfo.get(myClassName);
if (info.isTransient() || info.getClassNamespace().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
return;
}
SchemaTypeInfo schemaTypeInfo = new SchemaTypeInfo();
schemaTypeInfo.setSchemaTypeName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
this.schemaTypeInfo.put(myClass.getQualifiedName(), schemaTypeInfo);
NamespaceInfo namespaceInfo = this.packageToPackageInfoMappings.get(myClass.getPackageName()).getNamespaceInfo();
if (namespaceInfo.getLocation() != null && !namespaceInfo.getLocation().equals(GENERATE)) {
return;
}
Schema schema = getSchemaForNamespace(info.getClassNamespace(), myClass.getPackageName());
info.setSchema(schema);
String typeName = info.getSchemaTypeName();
String pfx = EMPTY_STRING;
Property valueField = null;
if (info.isSetXmlRootElement()) {
// Create the root element and add it to the schema
org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement xmlRE = info.getXmlRootElement();
rootElement = new Element();
String elementName = xmlRE.getName();
if (elementName.equals(XMLProcessor.DEFAULT) || elementName.equals(EMPTY_STRING)) {
try {
elementName = info.getXmlNameTransformer().transformRootElementName(myClassName);
} catch (Exception ex) {
throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(myClassName, info.getXmlNameTransformer().getClass().getName(), ex);
}
}
rootElement.setName(elementName);
String rootNamespace = xmlRE.getNamespace();
if (rootNamespace.equals(XMLProcessor.DEFAULT)) {
Schema rootElementSchema = getSchemaForNamespace(namespaceInfo.getNamespace());
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(namespaceInfo.getNamespace(), rootNamespace));
rootNamespace = namespaceInfo.getNamespace();
} else {
Schema rootElementSchema = getSchemaForNamespace(rootNamespace);
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(rootNamespace, elementName));
}
// handle root-level imports/includes [schema = the type's schema]
Schema rootSchema = getSchemaForNamespace(rootNamespace);
addImportIfRequired(rootSchema, schema, schema.getTargetNamespace());
// setup a prefix, if necessary
if (rootSchema != null && !info.getClassNamespace().equals(EMPTY_STRING)) {
pfx = getOrGeneratePrefixForNamespace(info.getClassNamespace(), rootSchema);
pfx += COLON;
}
}
if (CompilerHelper.isSimpleType(info)) {
SimpleType type = new SimpleType();
// simple type case, we just need the name and namespace info
if (typeName.equals(EMPTY_STRING)) {
// A root elem or locally defined whenever used
if (rootElement != null) {
rootElement.setSimpleType(type);
}
} else {
type.setName(typeName);
schema.addTopLevelSimpleTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
// Figure out schema type and set it as Restriction
QName restrictionType = null;
Restriction restriction = new Restriction();
if (info.isEnumerationType()) {
restrictionType = ((EnumTypeInfo) info).getRestrictionBase();
restriction.setEnumerationFacets(this.getEnumerationFacetsFor((EnumTypeInfo) info));
String prefix = null;
if (restrictionType.getNamespaceURI() != null && !EMPTY_STRING.equals(restrictionType.getNamespaceURI())) {
if (javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(restrictionType.getNamespaceURI())) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, restrictionType.getNamespaceURI());
}
}
String extensionTypeName = restrictionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
restriction.setBaseType(extensionTypeName);
type.setRestriction(restriction);
} else {
valueField = info.getXmlValueProperty();
JavaClass javaType = valueField.getActualType();
QName baseType = getSchemaTypeFor(javaType);
String prefix = null;
if (baseType.getNamespaceURI() != null && !baseType.getNamespaceURI().equals(EMPTY_STRING)) {
if (baseType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, baseType.getNamespaceURI());
}
}
String baseTypeName = baseType.getLocalPart();
if (prefix != null) {
baseTypeName = prefix + COLON + baseTypeName;
}
if (valueField.isXmlList() || (valueField.getGenericType() != null)) {
// generate a list instead of a restriction
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
list.setItemType(baseTypeName);
type.setList(list);
} else {
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
// TODO: This assignment seems like a bug, probably this should be "baseTypeName" ?
baseType = new QName(schemaType.namespace(), schemaType.name());
}
restriction.setBaseType(baseTypeName);
type.setRestriction(restriction);
}
}
info.setSimpleType(type);
} else if ((valueField = this.getXmlValueFieldForSimpleContent(info)) != null) {
ComplexType type = new ComplexType();
SimpleContent content = new SimpleContent();
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
} else {
type.setName(typeName);
schema.addTopLevelComplexTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
QName extensionType = getSchemaTypeFor(valueField.getType());
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
extensionType = new QName(schemaType.namespace(), schemaType.name());
}
String prefix = null;
if (extensionType.getNamespaceURI() != null && !extensionType.getNamespaceURI().equals(EMPTY_STRING)) {
if (extensionType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, extensionType.getNamespaceURI());
}
}
String extensionTypeName = extensionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
Extension extension = new Extension();
extension.setBaseType(extensionTypeName);
content.setExtension(extension);
type.setSimpleContent(content);
info.setComplexType(type);
} else {
ComplexType type = createComplexTypeForClass(myClass, info);
TypeDefParticle compositor = null;
if (type.getComplexContent() != null && type.getComplexContent().getExtension() != null) {
compositor = type.getComplexContent().getExtension().getTypeDefParticle();
} else {
compositor = type.getTypeDefParticle();
}
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
info.setCompositor(compositor);
} else {
type.setName(typeName);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
schema.addTopLevelComplexTypes(type);
info.setComplexType(type);
info.setCompositor(compositor);
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addXmlJoinNodesToSchema.
/**
* Convenience method that processes the XmlJoinNodes for a given Property and adds the
* appropriate components to the schema.
*
* @param property the Property contianing one or more XmlJoinNode entries
* @param compositor the sequence/choice/all that will be added to
* @param schema the schema currently being built
* @param type the complex type currently being built
*/
private void addXmlJoinNodesToSchema(Property property, TypeDefParticle compositor, Schema schema, ComplexType type) {
for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
// create the XPathFragment(s) for the path
Field<XMLConversionManager, NamespaceResolver> xfld = new XMLField(xmlJoinNode.getXmlPath());
xfld.setNamespaceResolver(schema.getNamespaceResolver());
xfld.initialize();
// build the schema components for the xml-path
AddToSchemaResult asr = buildSchemaComponentsForXPath(xfld.getXPathFragment(), new AddToSchemaResult(compositor, schema), false, property);
// process the last fragment
TypeDefParticle currentParticle = asr.particle;
Schema currentSchema = asr.schema;
if (currentParticle.getOwner() instanceof ComplexType) {
type = ((ComplexType) currentParticle.getOwner());
}
// get a QName for the last part of the xpath - this will be used as the
// attribute/element name, and also to figure out if a ref is required
QName schemaName;
XPathFragment frag = xfld.getLastXPathFragment();
boolean isAttribute = xmlJoinNode.getXmlPath().contains(ATT);
// for non-attributes, the last fragment may be 'text()'
if (!isAttribute) {
if (frag.nameIsText()) {
frag = xfld.getXPathFragment();
while (frag.getNextFragment() != null && !frag.getNextFragment().nameIsText()) {
frag = frag.getNextFragment();
}
}
}
schemaName = new QName(frag.getNamespaceURI(), frag.getLocalName());
// handle Element/Attribute
if (isAttribute) {
addAttributeToSchema(buildAttribute(schemaName, Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE), schemaName, currentSchema, type);
} else {
addElementToSchema(buildElement(schemaName.getLocalPart(), Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE, currentParticle instanceof All), schemaName.getNamespaceURI(), false, currentParticle, currentSchema, null);
}
}
}
Aggregations