use of org.apache.cxf.binding.corba.types.CorbaUnionHandler in project cxf by apache.
the class CorbaObjectReader method initializeCorbaObjectHandler.
private CorbaObjectHandler initializeCorbaObjectHandler(CorbaObjectHandler template) {
Constructor<?> templateConstructor = template.getClass().getDeclaredConstructors()[0];
Object[] params = new Object[4];
// of a sequence and needs to have the name "item" in order
if (template.isRecursive()) {
// Revisit: Is this always the case?
params[0] = new QName("item");
} else {
params[0] = template.getName();
}
params[1] = template.getIdlType();
params[2] = template.getTypeCode();
params[3] = template.getType();
CorbaObjectHandler handler = null;
try {
handler = (CorbaObjectHandler) templateConstructor.newInstance(params);
// the template object.
if (template instanceof CorbaAnyHandler) {
((CorbaAnyHandler) handler).setTypeMap(((CorbaAnyHandler) template).getTypeMap());
}
} catch (java.lang.Exception ex) {
throw new CorbaBindingException("Unable to instantiate sequence element", ex);
}
if (template instanceof CorbaSequenceHandler) {
CorbaSequenceHandler templateSeq = (CorbaSequenceHandler) template;
((CorbaSequenceHandler) handler).setTemplateElement(templateSeq.getTemplateElement());
} else if (template instanceof CorbaStructHandler) {
CorbaStructHandler templateStruct = (CorbaStructHandler) template;
CorbaStructHandler struct = (CorbaStructHandler) handler;
struct.setRecursive(template.isRecursive());
List<CorbaObjectHandler> members = templateStruct.getMembers();
for (int i = 0; i < members.size(); i++) {
CorbaObjectHandler member = initializeCorbaObjectHandler(members.get(i));
struct.addMember(member);
}
} else if (template instanceof CorbaArrayHandler) {
CorbaArrayHandler templateArray = (CorbaArrayHandler) template;
CorbaArrayHandler array = (CorbaArrayHandler) handler;
List<CorbaObjectHandler> elements = templateArray.getElements();
for (int i = 0; i < elements.size(); i++) {
CorbaObjectHandler element = initializeCorbaObjectHandler(elements.get(i));
array.addElement(element);
}
} else if (template instanceof CorbaUnionHandler) {
CorbaUnionHandler templateUnion = (CorbaUnionHandler) template;
CorbaUnionHandler union = (CorbaUnionHandler) handler;
union.setRecursive(template.isRecursive());
union.setDiscriminator(initializeCorbaObjectHandler(templateUnion.getDiscriminator()));
List<CorbaObjectHandler> cases = templateUnion.getCases();
for (int i = 0; i < cases.size(); i++) {
union.addCase(initializeCorbaObjectHandler(cases.get(i)));
}
}
return handler;
}
use of org.apache.cxf.binding.corba.types.CorbaUnionHandler in project cxf by apache.
the class CorbaObjectWriter method writeUnion.
public void writeUnion(CorbaObjectHandler obj) throws CorbaBindingException {
Union unionType = (Union) obj.getType();
List<Unionbranch> branches = unionType.getUnionbranch();
if (!branches.isEmpty()) {
CorbaObjectHandler discriminator = ((CorbaUnionHandler) obj).getDiscriminator();
this.write(discriminator);
CorbaObjectHandler unionValue = ((CorbaUnionHandler) obj).getValue();
if (unionValue != null) {
this.write(unionValue);
}
}
}
Aggregations