use of org.apache.cxf.binding.corba.types.CorbaEnumHandler in project cxf by apache.
the class CorbaObjectReader method readEnum.
// -- complex types --
public void readEnum(CorbaObjectHandler obj) throws CorbaBindingException {
int enumIndex = stream.read_long();
Enum enumType = (Enum) obj.getType();
List<Enumerator> enumerators = enumType.getEnumerator();
CorbaEnumHandler enumObj = (CorbaEnumHandler) obj;
enumObj.setValue(enumerators.get(enumIndex).getValue());
}
use of org.apache.cxf.binding.corba.types.CorbaEnumHandler in project cxf by apache.
the class CorbaObjectReader method readUnion.
public void readUnion(CorbaUnionHandler unionHandler) throws CorbaBindingException {
Union unionType = (Union) unionHandler.getType();
List<Unionbranch> branches = unionType.getUnionbranch();
CorbaObjectHandler discriminator = unionHandler.getDiscriminator();
if (!branches.isEmpty()) {
String discLabel = null;
if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
CorbaEnumHandler disc = (CorbaEnumHandler) discriminator;
readEnumDiscriminator(unionHandler, disc);
discLabel = disc.getValue();
} else {
read(discriminator);
discLabel = ((CorbaPrimitiveHandler) discriminator).getDataFromValue();
}
// Now find the label in the union to get the right case
Unionbranch defaultBranch = null;
boolean caseFound = false;
for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
Unionbranch branch = branchIter.next();
if (branch.isSetDefault() && branch.isDefault()) {
defaultBranch = branch;
}
List<CaseType> cases = branch.getCase();
for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
CaseType c = caseIter.next();
if (c.getLabel().equalsIgnoreCase(discLabel)) {
CorbaObjectHandler branchObj = unionHandler.getBranchByName(branch.getName());
this.read(branchObj);
unionHandler.setValue(branch.getName(), branchObj);
caseFound = true;
break;
}
}
if (caseFound) {
break;
}
}
// found the default case.
if (!caseFound && defaultBranch != null) {
CorbaObjectHandler branchObj = unionHandler.getBranchByName(defaultBranch.getName());
this.read(branchObj);
unionHandler.setValue(defaultBranch.getName(), branchObj);
}
}
}
use of org.apache.cxf.binding.corba.types.CorbaEnumHandler 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