use of org.apache.ws.commons.schema.XmlSchemaAny in project tdi-studio-se by Talend.
the class ComponentBuilder method buildParameterFromCollection.
private void buildParameterFromCollection(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter, int ioOrRecursion) {
// XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaParticle;
// XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaSequence.getItems();
int count = xmlSchemaObjectCollection.getCount();
for (int j = 0; j < count; j++) {
XmlSchemaObject xmlSchemaObject = xmlSchemaObjectCollection.getItem(j);
if (xmlSchemaObject instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaObject;
XmlSchemaObjectCollection items = xmlSchemaGroupBase.getItems();
if (items != null) {
buildParameterFromCollection(items, parameter, ioOrRecursion);
}
} else if (xmlSchemaObject instanceof XmlSchemaAny) {
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName("_content_");
parameterSon.setParent(parameter);
parameter.getParameterInfos().add(parameterSon);
} else if (xmlSchemaObject instanceof XmlSchemaElement) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObject;
String elementName = xmlSchemaElement.getName();
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName(elementName);
parameterSon.setParent(parameter);
if (((XmlSchemaElement) xmlSchemaObject).getQName() != null) {
parameterSon.setNameSpace(((XmlSchemaElement) xmlSchemaObject).getQName().getNamespaceURI());
}
Long min = xmlSchemaElement.getMinOccurs();
Long max = xmlSchemaElement.getMaxOccurs();
if (max - min > 1) {
parameterSon.setArraySize(-1);
parameterSon.setIndex("*");
}
parameter.getParameterInfos().add(parameterSon);
Boolean isHave = false;
if (!parametersName.isEmpty() && parameterSon.getName() != null) {
for (int p = 0; p < parametersName.size(); p++) {
if (parameterSon.getName().equals(parametersName.get(p))) {
isHave = true;
}
}
}
// }
if (xmlSchemaElement.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String elementTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (elementTypeName != null && elementTypeName.equals("anyType")) {
parameterSon.setName(xmlSchemaElement.getName() + ":anyType");
}
parameterSon.setType(elementTypeName);
parameterSon.setNameSpace(xmlSchemaElement.getQName().getNamespaceURI());
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaType() != null) {
if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
XmlSchemaObjectCollection childCollection = xmlSchemaGroupBase.getItems();
if (childCollection != null && !isHave) {
buildParameterFromCollection(childCollection, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null && !isHave) {
parameter.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterSon, ioOrRecursion);
}
}
} else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
String typeName = xmlSchemaSimpleType.getName();
if (typeName != null && typeName.equals("anyType")) {
ParameterInfo pSon = new ParameterInfo();
pSon.setName("anyType");
pSon.setParent(parameter);
parameter.getParameterInfos().add(pSon);
}
parameter.setType(typeName);
}
} else if (xmlSchemaElement.getRefName() != null) {
String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buildParameterFromElements(elementTypeName, parameterSon, ioOrRecursion);
}
}
} else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObject;
String elementName = xmlSchemaAttribute.getName();
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName(elementName);
parameterSon.setParent(parameter);
parameter.getParameterInfos().add(parameterSon);
Boolean isHave = false;
if (!parametersName.isEmpty() && parameterSon.getName() != null) {
for (int p = 0; p < parametersName.size(); p++) {
if (parameterSon.getName().equals(parametersName.get(p))) {
isHave = true;
}
}
}
if (xmlSchemaAttribute.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
String elementTypeNamespace = xmlSchemaAttribute.getSchemaTypeName().getNamespaceURI();
parameterSon.setType(elementTypeName);
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaAttribute.getRefName() != null) {
String refName = xmlSchemaAttribute.getRefName().getLocalPart();
parameterSon.setType(refName);
if (!isHave) {
buildParameterFromElements(refName, parameterSon, ioOrRecursion);
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project hale by halestudio.
the class XmlSchemaReader method createPropertiesFromParticle.
/**
* Extracts attribute definitions from a {@link XmlSchemaParticle}.
*
* @param declaringGroup the definition of the declaring group
* @param particle the particle
* @param schemaLocation the schema location
* @param schemaNamespace the schema namespace
* @param forceGroup force creating a group (e.g. if the parent is a choice)
*/
private void createPropertiesFromParticle(DefinitionGroup declaringGroup, XmlSchemaParticle particle, String schemaLocation, String schemaNamespace, boolean forceGroup) {
// particle:
if (particle instanceof XmlSchemaSequence) {
// <sequence>
XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
// once will result in no group if not forced)
if (forceGroup || sequence.getMinOccurs() != 1 || sequence.getMaxOccurs() != 1) {
// create a sequence group
QName sequenceName = createGroupName(declaringGroup, "sequence");
DefaultGroupPropertyDefinition sequenceGroup = new DefaultGroupPropertyDefinition(sequenceName, declaringGroup, false);
// set cardinality
long max = (sequence.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (sequence.getMaxOccurs());
sequenceGroup.setConstraint(Cardinality.get(sequence.getMinOccurs(), max));
// set choice constraint (no choice)
sequenceGroup.setConstraint(ChoiceFlag.DISABLED);
// set metadata
setMetadata(sequenceGroup, sequence, schemaLocation);
// use group as parent
declaringGroup = sequenceGroup;
}
for (int j = 0; j < sequence.getItems().getCount(); j++) {
XmlSchemaObject object = sequence.getItems().getItem(j);
if (object instanceof XmlSchemaElement) {
// <element>
createPropertyFromElement((XmlSchemaElement) object, declaringGroup, schemaLocation, schemaNamespace);
// </element>
} else if (object instanceof XmlSchemaParticle) {
// contained particles, e.g. a choice
// content doesn't need to be grouped, it can be decided in
// the method
createPropertiesFromParticle(declaringGroup, (XmlSchemaParticle) object, schemaLocation, schemaNamespace, false);
}
}
// </sequence>
} else if (particle instanceof XmlSchemaChoice) {
// <choice>
XmlSchemaChoice choice = (XmlSchemaChoice) particle;
// create a choice group
QName choiceName = createGroupName(declaringGroup, "choice");
DefaultGroupPropertyDefinition choiceGroup = new DefaultGroupPropertyDefinition(choiceName, declaringGroup, // no flatten allowed
false);
// because of choice
// set custom display name
choiceGroup.setConstraint(DISPLAYNAME_CHOICE);
// set cardinality
long max = (choice.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (choice.getMaxOccurs());
choiceGroup.setConstraint(Cardinality.get(choice.getMinOccurs(), max));
// set choice constraint
choiceGroup.setConstraint(ChoiceFlag.ENABLED);
// set metadata
setMetadata(choiceGroup, choice, schemaLocation);
// create properties with choiceGroup as parent
for (int j = 0; j < choice.getItems().getCount(); j++) {
XmlSchemaObject object = choice.getItems().getItem(j);
if (object instanceof XmlSchemaElement) {
// <element>
createPropertyFromElement((XmlSchemaElement) object, choiceGroup, schemaLocation, schemaNamespace);
} else if (object instanceof XmlSchemaParticle) {
// contained particles, e.g. a choice or sequence
// inside a choice they must form a group
createPropertiesFromParticle(choiceGroup, (XmlSchemaParticle) object, schemaLocation, schemaNamespace, true);
}
}
// </choice>
} else if (particle instanceof XmlSchemaGroupRef) {
// <group ref="..." />
XmlSchemaGroupRef groupRef = (XmlSchemaGroupRef) particle;
QName groupName = groupRef.getRefName();
long max = (groupRef.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (groupRef.getMaxOccurs());
long min = groupRef.getMinOccurs();
/*
* Only allow flatten if group is not forced and appears exactly
* once
*/
XmlGroupReferenceProperty property = new XmlGroupReferenceProperty(groupName, declaringGroup, index, groupName, !forceGroup && min == 1 && max == 1);
// set cardinality constraint
property.setConstraint(Cardinality.get(min, max));
// set metadata
setMetadata(property, groupRef, schemaLocation);
} else if (particle instanceof XmlSchemaAny) {
// XXX ignore for now
reporter.info(new IOMessageImpl("Particle that allows any element is not supported.", null, particle.getLineNumber(), particle.getLinePosition()));
} else {
reporter.error(new IOMessageImpl("Unrecognized particle: " + particle.getClass().getSimpleName(), null, particle.getLineNumber(), particle.getLinePosition()));
}
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project cxf by apache.
the class BeanType method writeSchema.
@Override
public void writeSchema(XmlSchema root) {
BeanTypeInfo inf = getTypeInfo();
XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
complex.setName(getSchemaType().getLocalPart());
AegisType sooperType = getSuperType();
/*
* See Java Virtual Machine specification:
* http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
*/
if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) && !inf.getTypeClass().isInterface()) {
complex.setAbstract(true);
}
XmlSchemaSequence sequence = new XmlSchemaSequence();
/*
* Decide if we're going to extend another type. If we are going to defer, then make sure that we
* extend the type for our superclass.
*/
boolean isExtension = inf.isExtension();
if (isExtension && sooperType != null) {
// if sooperType is null, things are confused.
XmlSchemaComplexContent content = new XmlSchemaComplexContent();
complex.setContentModel(content);
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
content.setContent(extension);
extension.setBaseTypeName(sooperType.getSchemaType());
extension.setParticle(sequence);
} else {
complex.setParticle(sequence);
}
boolean needXmime = false;
boolean needUtilityTypes = false;
// Write out schema for elements
for (QName name : inf.getElements()) {
if (isInheritedProperty(inf, name)) {
continue;
}
XmlSchemaElement element = new XmlSchemaElement(root, false);
element.setName(name.getLocalPart());
sequence.getItems().add(element);
AegisType type = getType(inf, name);
if (type.isFlatArray()) {
// ok, we need some tricks here
element.setMinOccurs(type.getMinOccurs());
element.setMaxOccurs(type.getMaxOccurs());
// for now, assume ArrayType. Look at lists or more general solutions later.
ArrayType aType = (ArrayType) type;
type = aType.getComponentType();
element.setNillable(type.isNillable());
} else {
if (AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
}
}
writeTypeReference(name, element, type, root);
needXmime |= type.usesXmime();
needUtilityTypes |= type.usesUtilityTypes();
}
if (needXmime) {
addXmimeToSchema(root);
}
if (needUtilityTypes) {
AegisContext.addUtilityTypesToSchema(root);
}
/**
* if future proof then add <xsd:any/> element
*/
if (inf.isExtensibleElements()) {
XmlSchemaAny any = new XmlSchemaAny();
any.setMinOccurs(0);
any.setMaxOccurs(Long.MAX_VALUE);
sequence.getItems().add(any);
}
// Write out schema for attributes
for (QName name : inf.getAttributes()) {
if (isInheritedProperty(inf, name)) {
continue;
}
XmlSchemaAttribute attribute = new XmlSchemaAttribute(root, false);
complex.getAttributes().add(attribute);
attribute.setName(name.getLocalPart());
AegisType type = getType(inf, name);
attribute.setSchemaTypeName(type.getSchemaType());
String ns = name.getNamespaceURI();
if (!ns.equals(root.getTargetNamespace())) {
XmlSchemaUtils.addImportIfNeeded(root, ns);
}
}
/**
* If extensible attributes then add <xsd:anyAttribute/>
*/
if (inf.isExtensibleAttributes()) {
complex.setAnyAttribute(new XmlSchemaAnyAttribute());
}
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project cxf by apache.
the class JavascriptUtils method getObjectParticle.
/**
* If the object is an element or an any, return the particle. If it's not a particle, or it's a group,
* throw. We're not ready for groups yet.
* @param object
*/
public static XmlSchemaParticle getObjectParticle(XmlSchemaObject object, QName contextName, XmlSchema currentSchema) {
if (!(object instanceof XmlSchemaParticle)) {
unsupportedConstruct("NON_PARTICLE_CHILD", object.getClass().getSimpleName(), contextName, object);
}
if (object instanceof XmlSchemaGroupRef) {
QName groupName = ((XmlSchemaGroupRef) object).getRefName();
XmlSchemaGroup group = currentSchema.getGroupByName(groupName);
if (group == null) {
unsupportedConstruct("MISSING_GROUP", groupName.toString(), contextName, null);
}
XmlSchemaParticle groupParticle = group.getParticle();
if (!(groupParticle instanceof XmlSchemaSequence)) {
unsupportedConstruct("GROUP_REF_UNSUPPORTED_TYPE", groupParticle.getClass().getSimpleName(), contextName, groupParticle);
}
return groupParticle;
}
if (!(object instanceof XmlSchemaElement) && !(object instanceof XmlSchemaAny) && !(object instanceof XmlSchemaChoice) && !(object instanceof XmlSchemaSequence)) {
unsupportedConstruct("GROUP_CHILD", object.getClass().getSimpleName(), contextName, object);
}
return (XmlSchemaParticle) object;
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project cxf by apache.
the class SchemaJavascriptBuilder method deserializeAny.
private void deserializeAny(XmlSchemaComplexType type, ParticleInfo itemInfo, ParticleInfo nextItem) {
XmlSchemaAny any = (XmlSchemaAny) itemInfo.getParticle();
boolean array = XmlSchemaUtils.isParticleArray(any);
boolean optional = XmlSchemaUtils.isParticleOptional(any);
if (array) {
utils.appendLine("var anyObject = [];");
} else {
utils.appendLine("var anyObject = null;");
}
String anyNamespaceSpec = any.getNamespace();
// we aren't dealing with any-after-any.
XmlSchemaElement nextElement = null;
if (nextItem != null) {
nextElement = (XmlSchemaElement) nextItem.getParticle();
}
String matchType;
String namespaceList = "[]";
if (anyNamespaceSpec == null || "##any".equals(anyNamespaceSpec) || "".equals(anyNamespaceSpec)) {
matchType = "org_apache_cxf_any_ns_matcher.ANY";
} else if ("##other".equals(anyNamespaceSpec)) {
matchType = "org_apache_cxf_any_ns_matcher.OTHER";
} else if ("##local".equals(anyNamespaceSpec)) {
matchType = "org_apache_cxf_any_ns_matcher.LOCAL";
} else {
matchType = "org_apache_cxf_any_ns_matcher.LISTED";
namespaceList = buildNamespaceList(anyNamespaceSpec);
}
String nextLocalPartConstant = "null";
if (nextElement != null) {
nextLocalPartConstant = "'" + nextElement.getQName().getLocalPart() + "'";
}
utils.appendLine("var matcher = new org_apache_cxf_any_ns_matcher(" + matchType + ", '" + xmlSchema.getTargetNamespace() + "'" + ", " + namespaceList + ", " + nextLocalPartConstant + ");");
if (array) {
utils.appendLine("var anyNeeded = " + any.getMinOccurs() + ";");
utils.appendLine("var anyAllowed = " + any.getMaxOccurs() + ";");
} else if (optional) {
utils.appendLine("var anyNeeded = 0;");
utils.appendLine("var anyAllowed = 1;");
} else {
utils.appendLine("var anyNeeded = 1;");
utils.appendLine("var anyAllowed = 1;");
}
utils.startWhile("anyNeeded > 0 || anyAllowed > 0");
utils.appendLine("var anyURI;");
utils.appendLine("var anyLocalPart;");
utils.appendLine("var anyMatched = false;");
utils.startIf("curElement");
utils.appendLine("anyURI = cxfjsutils.getElementNamespaceURI(curElement);");
utils.appendLine("anyLocalPart = cxfjsutils.getNodeLocalName(curElement);");
utils.appendLine("var anyQName = '{' + anyURI + '}' + anyLocalPart;");
utils.appendLine("cxfjsutils.trace('any match: ' + anyQName);");
utils.appendLine("anyMatched = matcher.match(anyURI, anyLocalPart)");
utils.appendLine("cxfjsutils.trace(' --> ' + anyMatched);");
// curElement != null
utils.endBlock();
// if match
utils.startIf("anyMatched");
utils.appendLine("anyDeserializer = " + "cxfjsutils.interfaceObject.globalElementDeserializers[anyQName];");
utils.appendLine("cxfjsutils.trace(' deserializer: ' + anyDeserializer);");
// if complex/serializer function
utils.startIf("anyDeserializer");
utils.appendLine("var anyValue = anyDeserializer(cxfjsutils, curElement);");
// else complex/serializer function
utils.appendElse();
// TODO: for simple types we really need a dictionary of the simple type qnames.
utils.appendLine("var anyValue = curElement.nodeValue;");
// complex/serializer function
utils.endBlock();
if (array) {
utils.appendLine("anyObject.push(anyValue);");
} else {
utils.appendLine("anyObject = anyValue;");
}
utils.appendLine("anyNeeded--;");
utils.appendLine("anyAllowed--;");
// if we consumed the element, we advance.
utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
// match
utils.appendElse();
// non-matching case
utils.startIf("anyNeeded > 0");
utils.appendLine("throw 'not enough ws:any elements';");
// else non-match
utils.appendElse();
utils.appendLine("break;");
// non-match+required
utils.endBlock();
// match/non-match.
utils.endBlock();
// while
utils.endBlock();
utils.appendLine("var anyHolder = new org_apache_cxf_any_holder(anyURI, anyLocalPart, anyValue);");
utils.appendLine("newobject.setAny(anyHolder);");
}
Aggregations