use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class CorbaUtils method getComplexTypeCode.
public static TypeCode getComplexTypeCode(ORB orb, QName type, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
TypeCode tc = getAnonTypeCode(orb, type, obj, typeMap, seenTypes);
if (tc == null) {
if (obj instanceof Alias) {
Alias aliasType = (Alias) obj;
tc = orb.create_alias_tc(aliasType.getRepositoryID(), getTypeCodeName(aliasType.getName()), getTypeCode(orb, aliasType.getBasetype(), typeMap, seenTypes));
} else if (obj instanceof Array) {
Array arrayType = (Array) obj;
tc = orb.create_array_tc((int) arrayType.getBound(), getTypeCode(orb, arrayType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Enum) {
Enum enumType = (Enum) obj;
String name = enumType.getName();
List<Enumerator> enums = enumType.getEnumerator();
String[] members = new String[enums.size()];
for (int i = 0; i < members.length; ++i) {
members[i] = enums.get(i).getValue();
}
name = getTypeCodeName(name);
tc = orb.create_enum_tc(enumType.getRepositoryID(), name, members);
} else if (obj instanceof Exception) {
Exception exceptType = (Exception) obj;
List<MemberType> list = exceptType.getMember();
StructMember[] members = new StructMember[list.size()];
for (int i = 0; i < members.length; ++i) {
MemberType member = list.get(i);
members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
}
String name = getTypeCodeName(exceptType.getName());
tc = orb.create_exception_tc(exceptType.getRepositoryID(), name, members);
} else if (obj instanceof Fixed) {
Fixed fixedType = (Fixed) obj;
tc = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
} else if (obj instanceof org.apache.cxf.binding.corba.wsdl.Object) {
org.apache.cxf.binding.corba.wsdl.Object objType = (org.apache.cxf.binding.corba.wsdl.Object) obj;
if (objType.getName().equals("CORBA.Object")) {
tc = orb.create_interface_tc(objType.getRepositoryID(), "Object");
} else {
tc = orb.create_interface_tc(objType.getRepositoryID(), getTypeCodeName(objType.getName()));
}
} else if (obj instanceof Sequence) {
Sequence seqType = (Sequence) obj;
tc = orb.create_sequence_tc((int) seqType.getBound(), getTypeCode(orb, seqType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Struct) {
Struct structType = (Struct) obj;
if (seenTypes.contains(new QName(structType.getName()))) {
tc = orb.create_recursive_tc(structType.getRepositoryID());
} else {
seenTypes.push(new QName(structType.getName()));
List<MemberType> list = structType.getMember();
StructMember[] members = new StructMember[list.size()];
for (int i = 0; i < members.length; ++i) {
MemberType member = list.get(i);
members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
}
String name = getTypeCodeName(structType.getName());
tc = orb.create_struct_tc(structType.getRepositoryID(), name, members);
seenTypes.pop();
}
} else if (obj instanceof Union) {
tc = getUnionTypeCode(orb, obj, typeMap, seenTypes);
}
}
return tc;
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class CorbaUtils method getUnionTypeCode.
public static TypeCode getUnionTypeCode(ORB orb, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
Union unionType = (Union) obj;
if (seenTypes.contains(new QName(unionType.getName()))) {
return orb.create_recursive_tc(unionType.getRepositoryID());
}
seenTypes.push(new QName(unionType.getName()));
TypeCode discTC = getTypeCode(orb, unionType.getDiscriminator(), typeMap, seenTypes);
Map<String, UnionMember> members = new LinkedHashMap<String, UnionMember>();
List<Unionbranch> branches = unionType.getUnionbranch();
for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
Unionbranch branch = branchIter.next();
List<CaseType> cases = branch.getCase();
for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
CaseType cs = caseIter.next();
if (!members.containsKey(cs.getLabel())) {
UnionMember member = new UnionMember();
member.name = branch.getName();
member.type = getTypeCode(orb, branch.getIdltype(), typeMap, seenTypes);
member.label = orb.create_any();
// * enum
switch(discTC.kind().value()) {
case TCKind._tk_short:
member.label.insert_short(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_ushort:
member.label.insert_ushort(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_long:
member.label.insert_long(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_ulong:
member.label.insert_ulong(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_longlong:
member.label.insert_longlong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_ulonglong:
member.label.insert_ulonglong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_char:
member.label.insert_char(cs.getLabel().charAt(0));
break;
case TCKind._tk_boolean:
member.label.insert_boolean(Boolean.parseBoolean(cs.getLabel()));
break;
case TCKind._tk_enum:
org.omg.CORBA.portable.OutputStream out = member.label.create_output_stream();
Enum enumVal = (Enum) getCorbaType(unionType.getDiscriminator(), typeMap);
List<Enumerator> enumerators = enumVal.getEnumerator();
for (int i = 0; i < enumerators.size(); ++i) {
Enumerator e = enumerators.get(i);
if (e.getValue().equals(cs.getLabel())) {
out.write_long(i);
}
}
member.label.read_value(out.create_input_stream(), discTC);
break;
default:
throw new CorbaBindingException("Unsupported discriminator type");
}
// Some orbs are strict on how the case labels are stored for
// each member. So we can't
// simply insert the labels as strings
members.put(cs.getLabel(), member);
}
}
}
seenTypes.pop();
return orb.create_union_tc(unionType.getRepositoryID(), getTypeCodeName(unionType.getName()), discTC, members.values().toArray(new UnionMember[members.size()]));
}
use of org.apache.cxf.binding.corba.wsdl.Enum in project cxf by apache.
the class CorbaObjectReaderTest method testReadEnum.
@Test
public void testReadEnum() {
OutputStream oStream = orb.create_output_stream();
// create the following enum
// enum { RED, GREEN, BLUE };
oStream.write_long(1);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
String[] enums = { "RED", "GREEN", "BLUE" };
Enum enumType = new Enum();
Enumerator enumRed = new Enumerator();
enumRed.setValue(enums[0]);
Enumerator enumGreen = new Enumerator();
enumGreen.setValue(enums[1]);
Enumerator enumBlue = new Enumerator();
enumBlue.setValue(enums[2]);
enumType.getEnumerator().add(enumRed);
enumType.getEnumerator().add(enumGreen);
enumType.getEnumerator().add(enumBlue);
// These values don't matter to the outcome of the test but are needed during construction
QName enumName = new QName("TestEnum");
QName enumIdlType = new QName("corbatm:TestEnum");
TypeCode enumTC = orb.create_enum_tc("IDL:TestEnum:1.0", enumName.getLocalPart(), enums);
CorbaEnumHandler obj = new CorbaEnumHandler(enumName, enumIdlType, enumTC, enumType);
reader.readEnum(obj);
assertTrue(obj.getValue().equals(enums[1]));
}
Aggregations