use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class WSDLToCorbaHelper method processOMGUnion.
private CorbaType processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
QName name;
Union corbaUnion = null;
QName schematypeName = checkPrefix(complex.getQName());
if (schematypeName == null) {
schematypeName = defaultName;
name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
} else {
name = createQNameCorbaNamespace(schematypeName.getLocalPart());
}
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();
XmlSchemaElement discEl = null;
XmlSchemaChoice choice = null;
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 (disctype.getQName().getLocalPart().equals("long") || disctype.getQName().getLocalPart().equals("short")) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if (disctype.getQName().getLocalPart().equals("char")) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if (disctype.getQName().getLocalPart().equals("char")) {
for (int i = 0; i < fields.size(); i++) {
caselist.add(Integer.toString(i));
}
} else if (disctype.getQName().getLocalPart().equals("boolean")) {
if (fields.size() == 2) {
caselist.add("TRUE");
caselist.add("FALSE");
} else if (fields.size() == 1) {
caselist.add("TRUE");
} else {
String msg = "Discriminator Type doesnt match number of Choices in Union:" + name;
LOG.log(Level.WARNING, msg);
}
}
}
WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
return corbaUnion;
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class WSDLToIDLAction method createType.
protected IdlType createType(QName idlType, String[] name, CorbaType corbaType) throws Exception {
if (idlType.getLocalPart().equals("CORBA.Object")) {
return IdlInterface.create(null, "Object");
}
CorbaType corbaTypeImpl = corbaType;
if (corbaTypeImpl == null) {
corbaTypeImpl = getCorbaType(idlType);
}
if (corbaTypeImpl == null) {
String msgStr = "Type " + idlType.getLocalPart() + " not found.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
IdlScopeBase scope = root;
StringBuilder dotScopedName = new StringBuilder("");
for (int i = 0; i < name.length - 1; ++i) {
dotScopedName.append(name[i]);
// name array.
if ("CORBA".equals(dotScopedName.toString()) && name.length == 2 && i == 0 && name[1].equals("Object")) {
break;
}
IdlDefn idlDef = scope.lookup(name[i]);
if (idlDef == null) {
// Before creating module, check to see if a Corba type
// represent this name aleady exists.
// For example if type is a.b.c and we are about to create
// module b, look to see if a.b
// is an interface that needs to be processed
QName qname = new QName(corbaTypeImpl.getType().getNamespaceURI(), dotScopedName.toString());
// Check to see if CORBAType exists. If so, create type for it
// otherwise
// create module for this scope
CorbaType possibleCorbaType = getCorbaType(qname);
if (possibleCorbaType != null) {
idlDef = findType(qname);
}
if (idlDef == null) {
idlDef = IdlModule.create(scope, name[i]);
scope.addToScope(idlDef);
}
}
dotScopedName.append(".");
scope = (IdlScopeBase) idlDef;
}
IdlType result = null;
String local = name[name.length - 1];
if (corbaTypeImpl instanceof Enum) {
result = createEnum((Enum) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Sequence) {
result = createSequence((Sequence) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonsequence) {
result = createAnonSequence((Anonsequence) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Exception) {
result = createIdlException((org.apache.cxf.binding.corba.wsdl.Exception) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Struct) {
result = createStruct((Struct) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Union) {
result = createUnion((Union) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Alias) {
result = createTypedef((Alias) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Array) {
result = createArray((Array) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonarray) {
result = createAnonArray((Anonarray) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Fixed) {
result = createFixed((Fixed) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Anonfixed) {
result = createAnonFixed((Anonfixed) corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Const) {
result = createConst((Const) corbaTypeImpl, scope, local);
} else {
result = checkAnon(corbaTypeImpl, scope, local);
}
if (result == null && corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Object) {
result = createInterface((org.apache.cxf.binding.corba.wsdl.Object) corbaTypeImpl, scope, local);
}
return result;
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class EnumVisitor method visit.
public void visit(AST enumNode) {
// <enum_type> ::= "enum" <identifier> "{" <enumerator> {"," <enumerator>}* "}"
// <enumerator> ::= <identifier>
AST enumNameNode = enumNode.getFirstChild();
Scope enumNameScope = new Scope(getScope(), enumNameNode);
// xmlschema:enum
XmlSchemaSimpleType enumSchemaSimpleType = new XmlSchemaSimpleType(schema, true);
enumSchemaSimpleType.setName(mapper.mapToQName(enumNameScope));
XmlSchemaSimpleTypeRestriction enumSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();
enumSchemaSimpleTypeRestriction.setBaseTypeName(Constants.XSD_STRING);
// XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);
// corba:enum
Enum corbaEnum = new Enum();
corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameScope.toString()));
corbaEnum.setRepositoryID(enumNameScope.toIDLRepositoryID());
corbaEnum.setType(enumSchemaSimpleType.getQName());
AST node = enumNameNode.getNextSibling();
while (node != null) {
// xmlschema:enumeration
XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
enumeration.setValue(node.toString());
enumSchemaSimpleTypeRestriction.getFacets().add(enumeration);
// corba:enumerator
Enumerator enumerator = new Enumerator();
enumerator.setValue(node.toString());
corbaEnum.getEnumerator().add(enumerator);
node = node.getNextSibling();
}
// add corbaType
typeMap.getStructOrExceptionOrUnion().add(corbaEnum);
// REVISIT: are there assignments needed?
setSchemaType(enumSchemaSimpleType);
setCorbaType(corbaEnum);
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class CorbaObjectWriter method writeEnum.
// -- complex types --
public void writeEnum(CorbaEnumHandler enumHandler) throws CorbaBindingException {
Enum enumType = (Enum) enumHandler.getType();
String enumLabel = enumHandler.getValue();
List<Enumerator> enumerators = enumType.getEnumerator();
for (int i = 0; i < enumerators.size(); ++i) {
if (enumerators.get(i).getValue().equals(enumLabel)) {
stream.write_long(i);
return;
}
}
throw new CorbaBindingException("CorbaObjectWriter: unable to find enumeration label");
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class CorbaUnionHandler method createDefaultDiscriminatorLabel.
public String createDefaultDiscriminatorLabel() {
String label = null;
// discriminator from, these are the four cases we must check for.
if (discriminator.getTypeCodeKind().value() == TCKind._tk_boolean) {
// against the first label, if there is one.
if (labels.isEmpty()) {
label = "false";
} else {
boolean boolValue = Boolean.parseBoolean(labels.get(0));
label = String.valueOf(!boolValue);
}
} else if (discriminator.getTypeCodeKind().value() == TCKind._tk_char) {
if (labels.isEmpty()) {
label = String.valueOf('0');
} else {
char charValue = labels.get(0).charAt(0);
while (labels.contains(String.valueOf(charValue))) {
charValue++;
}
label = String.valueOf(charValue);
}
} else if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
// Get the list of possible enumerations in the enumerator and compare these to the
// labels we obtained from the Union definition. In order for the union/enum
// combination to be syntactically correct, there must be one enumeration not included
// as a case for the default case to be valid.
Enum enumType = (Enum) discriminator.getType();
List<Enumerator> enumerators = enumType.getEnumerator();
if (labels.isEmpty()) {
// Any value will do since we only have a default case.
label = enumerators.get(0).getValue();
} else {
String enumLabel = null;
for (Iterator<Enumerator> enumIter = enumerators.iterator(); enumIter.hasNext(); ) {
enumLabel = enumIter.next().getValue();
if (!labels.contains(enumLabel)) {
label = enumLabel;
break;
}
}
}
} else if ((discriminator.getTypeCodeKind().value() == TCKind._tk_short) || (discriminator.getTypeCodeKind().value() == TCKind._tk_ushort)) {
if (labels.isEmpty()) {
label = String.valueOf(Short.MAX_VALUE);
}
for (int i = Short.MAX_VALUE; i >= Short.MIN_VALUE; i--) {
if (!labels.contains(String.valueOf(i))) {
label = String.valueOf(i);
break;
}
}
} else if ((discriminator.getTypeCodeKind().value() == TCKind._tk_long) || (discriminator.getTypeCodeKind().value() == TCKind._tk_ulong)) {
if (labels.isEmpty()) {
label = String.valueOf(Integer.MAX_VALUE);
}
for (int i = Integer.MAX_VALUE; i >= Integer.MIN_VALUE; i--) {
if (!labels.contains(String.valueOf(i))) {
label = String.valueOf(i);
break;
}
}
}
return label;
}
Aggregations