use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.
the class CorbaObjectWriterTest method testWriteSequence.
@Test
public void testWriteSequence() {
String[] data = { "one", "one", "two", "three", "five", "eight", "thirteen", "twenty-one" };
// create an sequence of strings
QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
QName seqIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "sequence", CorbaConstants.NP_WSDL_CORBA);
Sequence seqType = new Sequence();
seqType.setBound(data.length);
seqType.setElemtype(stringIdlType);
// name and respoitory ID of the sequence are not needed for this test
// build the object holder for a sequence.
TypeCode seqTC = orb.create_sequence_tc(data.length, orb.get_primitive_tc(TCKind.tk_string));
CorbaSequenceHandler obj = new CorbaSequenceHandler(new QName("Seq"), seqIdlType, seqTC, seqType);
for (int i = 0; i < data.length; ++i) {
CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), stringIdlType, orb.get_primitive_tc(TCKind.tk_string), null);
nestedObj.setValueFromData(data[i]);
obj.addElement(nestedObj);
}
OutputStream oStream = orb.create_output_stream();
CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
writer.writeSequence(obj);
InputStream iStream = oStream.create_input_stream();
int length = iStream.read_long();
for (int i = 0; i < length; ++i) {
String val = iStream.read_string();
assertTrue(val.equals(data[i]));
}
}
use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.
the class CorbaSequenceHandlerTest method testCorbaSequenceHandler.
@Test
public void testCorbaSequenceHandler() {
objName = new QName("object");
objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "sequenceType", CorbaConstants.NP_WSDL_CORBA);
objTypeCode = orb.create_sequence_tc(5, orb.get_primitive_tc(TCKind.tk_long));
Sequence sequenceType = new Sequence();
sequenceType.setName("sequenceType");
sequenceType.setElemtype(CorbaConstants.NT_CORBA_LONG);
sequenceType.setBound(5);
sequenceType.setRepositoryID("IDL:SequenceType:1.0");
obj = new CorbaSequenceHandler(objName, objIdlType, objTypeCode, sequenceType);
assertNotNull(obj);
int[] sequenceData = { 2, 4, 6, 8, 10 };
for (int i = 0; i < sequenceData.length; ++i) {
QName elName = new QName("item");
QName elIdlType = CorbaConstants.NT_CORBA_LONG;
TypeCode elTC = orb.get_primitive_tc(TCKind.tk_long);
CorbaPrimitiveHandler el = new CorbaPrimitiveHandler(elName, elIdlType, elTC, null);
el.setValue(Integer.valueOf(sequenceData[i]));
obj.addElement(el);
}
QName nameResult = obj.getName();
assertNotNull(nameResult);
assertTrue(objName.equals(nameResult));
QName idlTypeResult = obj.getIdlType();
assertNotNull(idlTypeResult);
assertTrue(idlTypeResult.equals(objIdlType));
TypeCode tcResult = obj.getTypeCode();
assertNotNull(tcResult);
assertTrue(tcResult.kind().value() == objTypeCode.kind().value());
Object objDefResult = obj.getType();
assertNotNull(objDefResult);
assertTrue(objDefResult instanceof Sequence);
int countResult = obj.getNumberOfElements();
for (int i = 0; i < countResult; ++i) {
CorbaObjectHandler elResult = obj.getElement(i);
assertNotNull(elResult);
}
}
use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.
the class WSDLTypes method mapToSequence.
public static CorbaType mapToSequence(QName name, QName schematypeName, QName arrayType, QName elName, int bound, boolean anonymous) {
CorbaType corbaTypeImpl = null;
// schematypeName = checkPrefix(schematypeName);
if (!anonymous) {
// Create a Sequence
Sequence corbaSeq = new Sequence();
corbaSeq.setName(name.getLocalPart());
corbaSeq.setQName(name);
corbaSeq.setType(schematypeName);
corbaSeq.setElemtype(arrayType);
corbaSeq.setElemname(elName);
corbaSeq.setBound(bound);
corbaSeq.setRepositoryID(WSDLToCorbaHelper.REPO_STRING + name.getLocalPart().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION);
corbaTypeImpl = corbaSeq;
} else {
// Create a Anonymous Sequence
Anonsequence corbaSeq = new Anonsequence();
corbaSeq.setName(name.getLocalPart());
corbaSeq.setQName(name);
corbaSeq.setType(schematypeName);
corbaSeq.setElemtype(arrayType);
corbaSeq.setElemname(elName);
corbaSeq.setBound(bound);
corbaTypeImpl = corbaSeq;
}
return corbaTypeImpl;
}
use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.
the class WSDLToCorbaBindingTest method assertMixedArraysMappingDifficultSequences.
/**
* @param typeMap
*/
private void assertMixedArraysMappingDifficultSequences(CorbaTypeMap typeMap) {
String corbaTm = "http://schemas.apache.org/idl/anon.idl/corba/typemap/";
// p9 is unwrapped, so there's "MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequenceArray" type
// registered and "MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence" as type of the element
// which is Struct
Sequence p9 = (Sequence) typeMap.getType("MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequenceArray");
assertEquals(new QName("", "p9-anonymous-unwrapped-non-primitive-sequence"), p9.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence"), p9.getElemtype());
assertFalse(p9.isQualified());
assertFalse(p9.isWrapped());
Struct p9item = (Struct) typeMap.getType("MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence");
assertEquals(1, p9item.getMember().size());
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p9item.getMember().get(0).getIdltype());
assertEquals("item", p9item.getMember().get(0).getName());
Sequence p9q = (Sequence) typeMap.getType("MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence-qArray");
assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p9-anonymous-unwrapped-non-primitive-sequence-q"), p9q.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence-q"), p9q.getElemtype());
assertTrue(p9q.isQualified());
assertFalse(p9q.isWrapped());
Struct p9qitem = (Struct) typeMap.getType("MixedArrayType.p9-anonymous-unwrapped-non-primitive-sequence-q");
assertEquals(1, p9qitem.getMember().size());
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p9qitem.getMember().get(0).getIdltype());
assertEquals("item", p9qitem.getMember().get(0).getName());
// p10 is wrapped, so there's no "MixedArrayType.p10-anonymous-wrapped-non-primitive-sequenceArray"
Anonsequence p10 = (Anonsequence) typeMap.getType("MixedArrayType.p10-anonymous-wrapped-non-primitive-sequenceType");
assertEquals(new QName("", "item"), p10.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p10-anonymous-wrapped-non-primitive-sequence.item"), p10.getElemtype());
assertFalse(p10.isQualified());
assertTrue(p10.isWrapped());
Struct p10item = (Struct) typeMap.getType("MixedArrayType.p10-anonymous-wrapped-non-primitive-sequence.item");
assertEquals(p10item.getMember().size(), 1);
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p10item.getMember().get(0).getIdltype());
assertEquals("item", p10item.getMember().get(0).getName());
assertFalse(p10item.getMember().get(0).isSetQualified());
Anonsequence p10q = (Anonsequence) typeMap.getType("MixedArrayType.p10-anonymous-wrapped-non-primitive-sequence-qType");
assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "item"), p10q.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p10-anonymous-wrapped-non-primitive-sequence-q.item"), p10q.getElemtype());
assertTrue(p10q.isQualified());
assertTrue(p10q.isWrapped());
Struct p10qitem = (Struct) typeMap.getType("MixedArrayType.p10-anonymous-wrapped-non-primitive-sequence-q.item");
assertEquals(p10qitem.getMember().size(), 1);
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p10qitem.getMember().get(0).getIdltype());
assertEquals("item", p10qitem.getMember().get(0).getName());
assertTrue(p10qitem.getMember().get(0).isQualified());
}
use of org.apache.cxf.binding.corba.wsdl.Sequence in project cxf by apache.
the class DeclaratorVisitor method visitNewTypes.
private void visitNewTypes(Scope newScope) {
CorbaType nextCorbaType = null;
XmlSchemaType nextSchemaType = null;
CorbaType oldCorbaType = getCorbaType();
QName newQname = new QName(getCorbaType().getQName().getNamespaceURI(), newScope.toString());
if (oldCorbaType instanceof Alias) {
// Alias
//
Alias oldAlias = (Alias) oldCorbaType;
Alias alias = new Alias();
alias.setQName(newQname);
alias.setBasetype(oldAlias.getBasetype());
alias.setType(oldAlias.getType());
alias.setRepositoryID(newScope.toIDLRepositoryID());
nextCorbaType = alias;
} else if (oldCorbaType instanceof Sequence) {
// Sequence
//
nextSchemaType = duplicateXmlSchemaComplexType(newScope);
Sequence oldSequence = (Sequence) oldCorbaType;
Sequence newSequence = new Sequence();
newSequence.setQName(newQname);
newSequence.setType(nextSchemaType.getQName());
newSequence.setElemtype(oldSequence.getElemtype());
newSequence.setElemname(oldSequence.getElemname());
newSequence.setBound(oldSequence.getBound());
newSequence.setRepositoryID(newScope.toIDLRepositoryID());
nextCorbaType = newSequence;
} else if (oldCorbaType instanceof Fixed) {
// Fixed
//
nextSchemaType = duplicateXmlSchemaSimpleType(newScope);
Fixed oldFixed = (Fixed) getCorbaType();
Fixed newFixed = new Fixed();
newFixed.setQName(newQname);
newFixed.setDigits(oldFixed.getDigits());
newFixed.setScale(oldFixed.getScale());
newFixed.setType(oldFixed.getType());
newFixed.setRepositoryID(newScope.toIDLRepositoryID());
nextCorbaType = newFixed;
} else {
System.err.println("[DeclaratorVisitor: Unexpected CORBA type error!]");
System.exit(1);
}
if (nextCorbaType != null) {
typeMap.getStructOrExceptionOrUnion().add(nextCorbaType);
}
}
Aggregations