use of org.apache.ws.commons.schema.XmlSchemaChoice in project cxf by apache.
the class WSDLToCorbaHelper method processOMGUnion.
private CorbaType processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
QName name;
QName schematypeName = checkPrefix(complex.getQName());
if (schematypeName == null) {
schematypeName = defaultName;
name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
} else {
name = createQNameCorbaNamespace(schematypeName.getLocalPart());
}
Union corbaUnion = new Union();
corbaUnion.setName(name.getLocalPart());
corbaUnion.setQName(name);
String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
corbaUnion.setRepositoryID(id);
corbaUnion.setType(schematypeName);
XmlSchemaSequence stype = (XmlSchemaSequence) complex.getParticle();
Iterator<XmlSchemaSequenceMember> it = stype.getItems().iterator();
XmlSchemaParticle st1 = (XmlSchemaParticle) it.next();
XmlSchemaParticle st2 = (XmlSchemaParticle) it.next();
final XmlSchemaElement discEl;
final XmlSchemaChoice choice;
if (st1 instanceof XmlSchemaElement) {
discEl = (XmlSchemaElement) st1;
choice = (XmlSchemaChoice) st2;
} else {
discEl = (XmlSchemaElement) st2;
choice = (XmlSchemaChoice) st1;
}
CorbaType disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl.getSchemaType(), null, false);
corbaUnion.setDiscriminator(disctype.getQName());
List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
List<String> caselist = new ArrayList<>();
if (disctype instanceof Enum) {
Enum corbaenum = (Enum) disctype;
Iterator<Enumerator> iterator = corbaenum.getEnumerator().iterator();
while (iterator.hasNext()) {
Enumerator enumerator = iterator.next();
caselist.add(enumerator.getValue());
}
} else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
if ("long".equals(disctype.getQName().getLocalPart()) || "short".equals(disctype.getQName().getLocalPart())) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if ("char".equals(disctype.getQName().getLocalPart())) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if ("boolean".equals(disctype.getQName().getLocalPart())) {
if (fields.size() == 2) {
caselist.add("TRUE");
caselist.add("FALSE");
} else if (fields.size() == 1) {
caselist.add("TRUE");
} else {
String msg = "Discriminator Type does not match number of Choices in Union:" + name;
LOG.log(Level.WARNING, msg);
}
}
}
WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
return corbaUnion;
}
use of org.apache.ws.commons.schema.XmlSchemaChoice in project cxf by apache.
the class WSDLToCorbaHelper method processContainerAsMembers.
protected List<MemberType> processContainerAsMembers(XmlSchemaParticle particle, QName defaultName, QName schemaTypeName) throws Exception {
List<MemberType> members = new ArrayList<>();
final Iterator<? extends XmlSchemaObjectBase> iterL;
if (particle instanceof XmlSchemaSequence) {
XmlSchemaSequence scontainer = (XmlSchemaSequence) particle;
iterL = scontainer.getItems().iterator();
} else if (particle instanceof XmlSchemaChoice) {
XmlSchemaChoice scontainer = (XmlSchemaChoice) particle;
iterL = scontainer.getItems().iterator();
} else if (particle instanceof XmlSchemaAll) {
XmlSchemaAll acontainer = (XmlSchemaAll) particle;
iterL = acontainer.getItems().iterator();
} else {
LOG.warning("Unknown particle type " + particle.getClass().getName());
iterL = new ArrayList<XmlSchemaObjectBase>().iterator();
}
while (iterL.hasNext()) {
XmlSchemaParticle container = (XmlSchemaParticle) iterL.next();
if (container instanceof XmlSchemaSequence) {
XmlSchemaSequence sequence = (XmlSchemaSequence) container;
CorbaType memberType = processSequenceType(sequence, defaultName, schemaTypeName);
QName typeName = memberType.getQName();
if (memberType instanceof Struct && !isDuplicate(memberType)) {
typeMappingType.getStructOrExceptionOrUnion().add(memberType);
}
MemberType member = new MemberType();
member.setName(memberType.getName() + "_f");
member.setIdltype(typeName);
member.setAnonschematype(true);
if (memberType.isSetQualified() && memberType.isQualified()) {
member.setQualified(true);
}
members.add(member);
} else if (container instanceof XmlSchemaChoice) {
XmlSchemaChoice choice = (XmlSchemaChoice) container;
MemberType member = processChoiceMember(choice, defaultName, schemaTypeName);
member.setAnonschematype(true);
members.add(member);
} else if (container instanceof XmlSchemaAll) {
XmlSchemaAll all = (XmlSchemaAll) container;
MemberType member = processAllMember(all, defaultName, schemaTypeName);
member.setAnonschematype(true);
members.add(member);
} else if (container instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) container;
CorbaType corbatype = processLocalElement(defaultName, element, schemaTypeName.getNamespaceURI());
QName elName = element.getQName();
if (elName == null) {
elName = element.getRef().getTargetQName();
}
if (corbatype != null) {
MemberType member;
String memberName = elName.getLocalPart();
member = new MemberType();
member.setName(memberName);
member.setIdltype(corbatype.getQName());
if (corbatype.isSetQualified() && corbatype.isQualified()) {
member.setQualified(true);
}
members.add(member);
} else {
LOG.log(Level.WARNING, "Unsupported Element Found in CORBA Binding Generation:" + elName);
}
}
}
return members;
}
use of org.apache.ws.commons.schema.XmlSchemaChoice in project cxf by apache.
the class WSDLTypes method isOMGUnion.
public static boolean isOMGUnion(XmlSchemaComplexType type) {
boolean isUnion = false;
if (type.getParticle() instanceof XmlSchemaSequence && type.getAttributes().isEmpty()) {
XmlSchemaSequence stype = (XmlSchemaSequence) type.getParticle();
if (stype.getItems().size() == 2) {
XmlSchemaParticle st1 = (XmlSchemaParticle) stype.getItems().get(0);
XmlSchemaParticle st2 = (XmlSchemaParticle) stype.getItems().get(1);
XmlSchemaElement discEl = null;
if (st1 instanceof XmlSchemaChoice && st2 instanceof XmlSchemaElement) {
isUnion = true;
discEl = (XmlSchemaElement) st2;
} else if (st2 instanceof XmlSchemaChoice && st1 instanceof XmlSchemaElement) {
isUnion = true;
discEl = (XmlSchemaElement) st1;
}
if (isUnion && !"discriminator".equals(discEl.getQName().getLocalPart())) {
isUnion = false;
}
}
}
return isUnion;
}
use of org.apache.ws.commons.schema.XmlSchemaChoice in project cxf by apache.
the class UnionVisitor method visitDeclaredUnion.
public void visitDeclaredUnion(AST identifierNode) {
Scope unionScope = new Scope(getScope(), identifierNode);
AST discriminatorNode = identifierNode.getNextSibling();
AST caseNode = discriminatorNode.getNextSibling();
// xmlschema:union
XmlSchemaComplexType unionSchemaComplexType = new XmlSchemaComplexType(schema, true);
unionSchemaComplexType.setName(mapper.mapToQName(unionScope));
// REVISIT
// TEMPORARILY
// using TypesVisitor to visit <const_type>
// it should be visited by a SwitchTypeSpecVisitor
TypesVisitor visitor = new TypesVisitor(getScope(), definition, schema, wsdlVisitor, null);
visitor.visit(discriminatorNode);
CorbaType ctype = visitor.getCorbaType();
Scope fullyQualifiedName = visitor.getFullyQualifiedName();
XmlSchemaChoice choice = new XmlSchemaChoice();
choice.setMinOccurs(1);
choice.setMaxOccurs(1);
unionSchemaComplexType.setParticle(choice);
// corba:union
Union corbaUnion = new Union();
corbaUnion.setQName(new QName(typeMap.getTargetNamespace(), unionScope.toString()));
corbaUnion.setRepositoryID(unionScope.toIDLRepositoryID());
corbaUnion.setType(unionSchemaComplexType.getQName());
if (ctype != null) {
corbaUnion.setDiscriminator(ctype.getQName());
} else {
// Discriminator type is forward declared.
UnionDeferredAction unionDiscriminatorAction = new UnionDeferredAction(corbaUnion);
wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionDiscriminatorAction);
}
boolean recursiveAdd = addRecursiveScopedName(identifierNode);
processCaseNodes(caseNode, unionScope, choice, corbaUnion);
if (recursiveAdd) {
removeRecursiveScopedName(identifierNode);
}
// add corbaType
typeMap.getStructOrExceptionOrUnion().add(corbaUnion);
// REVISIT: are these assignments needed?
setSchemaType(unionSchemaComplexType);
setCorbaType(corbaUnion);
// Need to check if the union was forward declared
processForwardUnionActions(unionScope);
// Once we've finished declaring the union, we should make sure it has been removed from
// the list of scopedNames so that we indicate that is no longer simply forward declared.
scopedNames.remove(unionScope);
}
use of org.apache.ws.commons.schema.XmlSchemaChoice in project tomee by apache.
the class CommonsSchemaInfoBuilder method getNestedElements.
private static List<XmlSchemaElement> getNestedElements(XmlSchemaComplexType complexType) {
List<XmlSchemaElement> elements = new ArrayList<>();
XmlSchemaParticle particle = complexType.getParticle();
if (particle instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) particle;
elements.add(element);
} else if (particle instanceof XmlSchemaGroupBase && !(particle instanceof XmlSchemaChoice)) {
XmlSchemaGroupBase groupBase = (XmlSchemaGroupBase) particle;
for (Iterator iterator = groupBase.getItems().getIterator(); iterator.hasNext(); ) {
XmlSchemaParticle child = (XmlSchemaParticle) iterator.next();
if (child instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) child;
elements.add(element);
}
}
} else {
// ignore all other types... you can have these other types, but JAX-RPC doesn't support them
}
return elements;
}
Aggregations