use of org.apache.cxf.binding.corba.wsdl.Enumerator 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 {
for (Iterator<Enumerator> enumIter = enumerators.iterator(); enumIter.hasNext(); ) {
String 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;
}
use of org.apache.cxf.binding.corba.wsdl.Enumerator in project cxf by apache.
the class WSDLToIDLAction method createEnum.
private IdlType createEnum(Enum e, IdlScopeBase scope, String local) {
IdlEnum enum1 = IdlEnum.create(scope, local);
Iterator<Enumerator> it = e.getEnumerator().iterator();
while (it.hasNext()) {
// Enumerators are created in the same scope
// as the enum, according to IDL grammar rules.
String n = it.next().getValue();
IdlEnumerator enumerator = IdlEnumerator.create(scope, n);
scope.addToScope(enumerator);
enum1.addEnumerator(enumerator);
}
scope.addToScope(enum1);
return enum1;
}
use of org.apache.cxf.binding.corba.wsdl.Enumerator 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);
}
Aggregations