use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class WSDLRefValidator method validatePartType.
private boolean validatePartType(String namespace, String name, boolean isElement) {
boolean partvalid = false;
if (namespace.equals(WSDLConstants.NS_SCHEMA_XSD)) {
if (isElement) {
XmlSchemaElement schemaEle = schemaCollection.getElementByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
partvalid = schemaEle != null ? true : false;
} else {
if ("anyType".equals(name)) {
return true;
}
XmlSchemaType schemaType = schemaCollection.getTypeByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
partvalid = schemaType != null ? true : false;
}
} else {
if (isElement) {
if (schemaCollection.getElementByQName(new QName(namespace, name)) != null) {
partvalid = true;
}
} else {
if (schemaCollection.getTypeByQName(new QName(namespace, name)) != null) {
partvalid = true;
}
}
}
return partvalid;
}
use of org.apache.ws.commons.schema.XmlSchemaElement 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.XmlSchemaElement 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.XmlSchemaElement in project cxf by apache.
the class WSDLToCorbaHelper method processLiteralArray.
private CorbaType processLiteralArray(XmlSchemaComplexType complex, QName defaultName, boolean anonymous) throws Exception {
// NEED TO DO
QName name;
QName typeName = null;
QName schematypeName = checkPrefix(complex.getQName());
if (schematypeName == null) {
schematypeName = defaultName;
name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
schematypeName = checkPrefix(schematypeName);
name = checkPrefix(name);
} else {
name = createQNameCorbaNamespace(schematypeName.getLocalPart());
name = checkPrefix(name);
}
CorbaType arrayType = null;
XmlSchemaElement arrayEl = null;
QName elName = null;
if (complex.getParticle() instanceof XmlSchemaSequence) {
XmlSchemaSequence seq = (XmlSchemaSequence) complex.getParticle();
Iterator<XmlSchemaSequenceMember> iterator = seq.getItems().iterator();
Iterator<XmlSchemaSequenceMember> iter = seq.getItems().iterator();
while (iterator.hasNext()) {
if (iter.next() instanceof XmlSchemaElement) {
arrayEl = (XmlSchemaElement) iterator.next();
elName = arrayEl.getQName();
XmlSchemaType atype = arrayEl.getSchemaType();
if (elName == null) {
elName = arrayEl.getRef().getTargetQName();
/*
* TODO: why are we looking up an element name with findSchemaType?
*/
atype = findSchemaType(elName);
}
String uri = defaultName.getNamespaceURI();
if (complex.getQName() != null) {
uri = complex.getQName().getNamespaceURI();
}
if (elName.getNamespaceURI().isEmpty()) {
elName = new QName(uri, elName.getLocalPart());
}
QName arrayTypeName = elName;
if (anonymous) {
arrayTypeName = new QName(elName.getNamespaceURI(), defaultName.getLocalPart() + "." + elName.getLocalPart());
}
arrayType = convertSchemaToCorbaType(atype, arrayTypeName, atype, null, true);
boolean isQualified = getElementQualification(arrayEl, uri);
if (isQualified) {
arrayType.setQualified(isQualified);
} else {
elName = new QName("", elName.getLocalPart());
}
typeName = arrayType.getQName();
}
}
}
Long maxOccurs = null;
Long minOccurs = null;
if (arrayEl != null) {
if (arrayEl.isNillable()) {
QName nilunionname = createQNameTargetNamespace(arrayType.getQName().getLocalPart() + "_nil");
boolean isQualified = arrayType.isSetQualified() && arrayType.isQualified();
arrayType = createNillableUnion(nilunionname, elName, arrayType.getQName(), isQualified);
typeName = createQNameCorbaNamespace(arrayType.getQName().getLocalPart());
if (arrayType != null && !isDuplicate(arrayType)) {
typeMappingType.getStructOrExceptionOrUnion().add(arrayType);
}
}
maxOccurs = arrayEl.getMaxOccurs();
minOccurs = arrayEl.getMinOccurs();
}
return createArray(name, schematypeName, checkPrefix(typeName), elName, maxOccurs, minOccurs, anonymous);
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class WSDLToCorbaHelper method findTypeInSchema.
private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
XmlSchemaType schemaType = null;
if (xmlSchema.getElementByName(typeName) != null) {
XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
schemaType = schemaElement.getSchemaType();
} else if (xmlSchema.getTypeByName(typeName) != null) {
schemaType = xmlSchema.getTypeByName(typeName);
}
if (schemaType != null) {
return schemaType;
}
for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
if (!(extSchema instanceof XmlSchemaImport)) {
schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
if (schemaType != null) {
return schemaType;
}
}
}
return null;
}
Aggregations