use of org.eclipse.persistence.internal.oxm.schema.model.All in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addToSchemaType.
public void addToSchemaType(TypeInfo ownerTypeInfo, java.util.List<Property> properties, TypeDefParticle compositor, ComplexType type, Schema workingSchema) {
// If there are no properties we don't want a sequence/choice or all tag written out
if (properties.size() == 0) {
type.setAll(null);
type.setSequence(null);
type.setChoice(null);
ownerTypeInfo.setCompositor(null);
return;
}
boolean extAnyAdded = false;
// generate schema components for each property
for (Property next : properties) {
if (next == null) {
continue;
}
Schema currentSchema = workingSchema;
TypeDefParticle parentCompositor = compositor;
boolean isChoice = (parentCompositor instanceof Choice);
ComplexType parentType = type;
// ignore transient and inverse reference/non-writeable properties
if (!next.isTransient() && !(next.isInverseReference() && !next.isWriteableInverseReference())) {
// handle xml extensions
if (next.isVirtual()) {
boolean extSchemaAny = false;
if (ownerTypeInfo.getXmlVirtualAccessMethods().getSchema() != null) {
extSchemaAny = ownerTypeInfo.getXmlVirtualAccessMethods().getSchema().equals(XmlVirtualAccessMethodsSchema.ANY);
}
if (extSchemaAny && !next.isAttribute()) {
if (!extAnyAdded) {
addAnyToSchema(next, compositor, true, Constants.ANY_NAMESPACE_ANY);
extAnyAdded = true;
continue;
} else {
// any already added
continue;
}
} else {
// proceed, adding the schema element as usual
}
}
// handle transformers
if (next.isSetXmlTransformation() && next.getXmlTransformation().isSetXmlWriteTransformers()) {
addTransformerToSchema(next, ownerTypeInfo, compositor, type, workingSchema);
continue;
}
// handle XmlJoinNodes
if (next.isSetXmlJoinNodes()) {
addXmlJoinNodesToSchema(next, parentCompositor, currentSchema, parentType);
continue;
}
// deal with xml-path case
if (next.getXmlPath() != null) {
// create schema components based on the XmlPath
AddToSchemaResult xpr = addXPathToSchema(next, parentCompositor, currentSchema, isChoice, type);
// if the returned object or schema component is null there is nothing to do
if (xpr == null || ((parentCompositor = xpr.particle) == null && xpr.simpleContentType == null)) {
continue;
}
// now process the property as per usual, adding to the created schema component
if (xpr.schema == null) {
// no need to generate the attribute in the target schema
continue;
}
currentSchema = xpr.schema;
if (parentCompositor == null) {
parentType = xpr.simpleContentType;
} else if (parentCompositor.getOwner() instanceof ComplexType) {
parentType = ((ComplexType) parentCompositor.getOwner());
}
// deal with the XmlElementWrapper case
} else if (!isChoice && !next.isMap() && next.isSetXmlElementWrapper()) {
AddToSchemaResult asr = addXmlElementWrapperToSchema(next, currentSchema, compositor);
// if returned object is null there is nothing to do
if (asr == null) {
continue;
}
// the returned object contains ComplexType and TypeDefParticles to use
parentType = asr.type;
parentCompositor = asr.particle;
}
// handle mixed content
if (next.isMixedContent()) {
parentType.setMixed(true);
}
// handle attribute
if (next.isAttribute() && !next.isAnyAttribute()) {
addAttributeToSchema(buildAttribute(next, currentSchema), next.getSchemaName(), currentSchema, parentType);
// handle any attribute
} else if (next.isAnyAttribute()) {
addAnyAttributeToSchema(parentType);
// handle choice
} else if (next.isChoice()) {
addChoiceToSchema(next, ownerTypeInfo, parentType, parentCompositor, currentSchema);
// handle reference
} else if (next.isReference()) {
addReferenceToSchema(next, currentSchema, parentCompositor);
// handle any
} else if (next.isAny() || next.getVariableAttributeName() != null) {
addAnyToSchema(next, parentCompositor);
// add an element
} else if (!(ownerTypeInfo.getXmlValueProperty() != null && ownerTypeInfo.getXmlValueProperty() == next)) {
Element element = buildElement(next, parentCompositor instanceof All, currentSchema, ownerTypeInfo);
addElementToSchema(element, next.getSchemaName().getNamespaceURI(), next.isPositional(), parentCompositor, currentSchema, ownerTypeInfo.getJavaClass().getPackageName());
}
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.All in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method createComplexTypeForClass.
private ComplexType createComplexTypeForClass(JavaClass myClass, TypeInfo info) {
Schema schema = getSchemaForNamespace(info.getClassNamespace());
ComplexType type = new ComplexType();
JavaClass superClass = CompilerHelper.getNextMappedSuperClass(myClass, this.typeInfo, this.helper);
// Handle abstract class
if (myClass.isAbstract()) {
type.setAbstractValue(true);
}
Extension extension = null;
if (superClass != null) {
TypeInfo parentTypeInfo = this.typeInfo.get(superClass.getQualifiedName());
if (parentTypeInfo != null) {
extension = new Extension();
// may need to qualify the type
String parentPrefix = getPrefixForNamespace(schema, parentTypeInfo.getClassNamespace());
if (parentPrefix != null) {
extension.setBaseType(parentPrefix + COLON + parentTypeInfo.getSchemaTypeName());
} else {
extension.setBaseType(parentTypeInfo.getSchemaTypeName());
}
if (parentTypeInfo.getXmlValueProperty() != null) {
SimpleContent content = new SimpleContent();
content.setExtension(extension);
type.setSimpleContent(content);
return type;
} else {
ComplexContent content = new ComplexContent();
content.setExtension(extension);
type.setComplexContent(content);
}
}
}
TypeDefParticle compositor = null;
String[] propOrder = null;
if (info.isSetPropOrder()) {
propOrder = info.getPropOrder();
}
if (propOrder != null && propOrder.length == 0) {
// requires the extension case to use sequences
if (info.hasElementRefs()) {
// generate a sequence to satisfy TCK
compositor = new Sequence();
if (extension != null) {
extension.setSequence((Sequence) compositor);
} else {
type.setSequence((Sequence) compositor);
}
} else if (extension != null) {
compositor = new All();
extension.setAll((All) compositor);
} else {
compositor = new All();
type.setAll((All) compositor);
}
} else {
// generate a sequence to satisfy TCK
compositor = new Sequence();
if (extension != null) {
extension.setSequence((Sequence) compositor);
} else {
type.setSequence((Sequence) compositor);
}
}
return type;
}
use of org.eclipse.persistence.internal.oxm.schema.model.All 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