int enumIndex = 0;
objName = new QName("member3");
objIdlType = new QName(nestedNamespaceURI, "BasicEnum", nestedPrefix);
type = CorbaUtils.getCorbaType(objIdlType, bindingImpl.getCorbaTypeMaps());
assertTrue(type instanceof Enum);
Enum enumType = (Enum)type;
objTypeCode = CorbaUtils.getTypeCode(orb, objIdlType, bindingImpl.getCorbaTypeMaps());
CorbaEnumHandler member3Obj = new CorbaEnumHandler(objName, objIdlType, objTypeCode, enumType);
assertNotNull(member3Obj);
obj.addMember(member3Obj);
// Create member 4, a Basic Enum
Float floatValue = 123456.678f;
objName = new QName("member4");
objIdlType = CorbaConstants.NT_CORBA_FLOAT;
objTypeCode = CorbaUtils.getTypeCode(orb, objIdlType, bindingImpl.getCorbaTypeMaps());
CorbaPrimitiveHandler member4Obj = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
assertNotNull(member4Obj);
obj.addMember(member4Obj);
// Write to an output stream the way a CORBA application would marshal the data for the nested
// struct.
Buffer buf = new Buffer();
OutputStream oStream = new OutputStream(buf);
oStream.write_string(nestedMember1Value);
oStream.write_boolean(nestedMember2Value.booleanValue());
oStream.write_fixed(fixedValue.movePointRight(2));
oStream.write_long(enumIndex);
oStream.write_float(floatValue.floatValue());
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
reader.read(obj);
// Now that the Object has its values, try and write it to Stax
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
XMLEventWriter evtWriter = null;
try {
evtWriter = outputFactory.createXMLEventWriter(outStream);
} catch (XMLStreamException ex) {
assertTrue(false);
}
assertNotNull(evtWriter);
XMLEventFactory factory = XMLEventFactory.newInstance();
try {
bindingImpl.writeObjectToStax(obj, evtWriter, factory, false);
evtWriter.flush();
} catch (XMLStreamException ex) {
assertTrue(false);
}
byte[] b = outStream.toByteArray();
for (int i = 0; i < b.length; ++i) {
System.out.print((char)b[i]);
}
System.out.println();
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
XMLEventReader evtReader = null;
try {
evtReader = inputFactory.createXMLEventReader(inStream);
} catch (XMLStreamException ex) {
assertTrue(false);
}
assertNotNull(evtReader);
// Now use the Stax data to re-create a new object
CorbaObjectHandler result =
bindingImpl.readObjectFromStax(evtReader,
new QName(nestedNamespaceURI, "NestedStruct", nestedPrefix),
false);
// Verify that the object has the correct values
assertTrue(result instanceof CorbaStructHandler);
CorbaStructHandler nestedStructResult = (CorbaStructHandler)result;
result = nestedStructResult.getMember(0);
assertTrue(result instanceof CorbaStructHandler);
CorbaStructHandler structResult = (CorbaStructHandler)result;
// These are from the struct nested inside our other struct
result = structResult.getMember(0);
assertTrue(result instanceof CorbaPrimitiveHandler);
CorbaPrimitiveHandler structPrimitiveMemberResult = (CorbaPrimitiveHandler)result;
assertTrue(structPrimitiveMemberResult.getValueData().equals(nestedMember1Value.toString()));
result = structResult.getMember(1);
assertTrue(result instanceof CorbaPrimitiveHandler);
structPrimitiveMemberResult = (CorbaPrimitiveHandler)result;
assertTrue(structPrimitiveMemberResult.getValueData().equals(nestedMember2Value.toString()));
// This is the fixed nested inside our struct
result = nestedStructResult.getMember(1);
assertTrue(result instanceof CorbaFixedHandler);
CorbaFixedHandler fixedResult = (CorbaFixedHandler)result;
assertTrue(fixedResult.getValue().equals(fixedValue));
// This is the enum nested inside our struct
result = nestedStructResult.getMember(2);
assertTrue(result instanceof CorbaEnumHandler);
CorbaEnumHandler enumResult = (CorbaEnumHandler)result;
assertTrue(enumResult.getValue().equals(enumType.getEnumerator().get(enumIndex).getValue()));
// This is the primitive nested inside our struct
result = nestedStructResult.getMember(3);
assertTrue(result instanceof CorbaPrimitiveHandler);
CorbaPrimitiveHandler primitiveResult = (CorbaPrimitiveHandler)result;