use of org.apache.cxf.binding.corba.wsdl.BindingType in project cxf by apache.
the class WSDLToCorbaBindingTest method testArrayMapping.
@Test
public void testArrayMapping() throws Exception {
try {
String fileName = getClass().getResource("/wsdl/array.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("X");
Definition model = generator.generateCORBABinding();
QName bName = new QName("http://schemas.apache.org/idl/anon.idl", "XCORBABinding", "tns");
Binding binding = model.getBinding(bName);
assertNotNull(binding);
assertEquals("XCORBABinding", binding.getQName().getLocalPart());
assertEquals("X", binding.getPortType().getQName().getLocalPart());
assertEquals(1, binding.getExtensibilityElements().size());
assertEquals(1, binding.getBindingOperations().size());
for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
if (extElement.getElementType().getLocalPart().equals("binding")) {
BindingType bindingType = (BindingType) extElement;
assertEquals(bindingType.getRepositoryID(), "IDL:X:1.0");
}
}
Iterator<?> j = binding.getBindingOperations().iterator();
while (j.hasNext()) {
BindingOperation bindingOperation = (BindingOperation) j.next();
assertEquals(1, bindingOperation.getExtensibilityElements().size());
assertEquals(bindingOperation.getBindingInput().getName(), "op_a");
assertEquals(bindingOperation.getBindingOutput().getName(), "op_aResponse");
for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
if (extElement.getElementType().getLocalPart().equals("operation")) {
OperationType corbaOpType = (OperationType) extElement;
assertEquals(corbaOpType.getName(), "op_a");
assertEquals(1, corbaOpType.getParam().size());
assertNotNull(corbaOpType.getReturn());
ParamType paramtype = corbaOpType.getParam().get(0);
assertEquals(paramtype.getName(), "part1");
QName idltype = new QName("http://schemas.apache.org/idl/anon.idl/corba/typemap/", "ArrayType", "ns1");
assertEquals(paramtype.getIdltype(), idltype);
assertEquals(paramtype.getMode().toString(), "IN");
}
}
}
// See if an IDL is able to produce from this CORBA Binding.
WSDLToIDLAction idlgen = new WSDLToIDLAction();
idlgen.setBindingName("XCORBABinding");
idlgen.setOutputFile("array.idl");
idlgen.generateIDL(model);
File f = new File("array.idl");
assertTrue("array.idl should be generated", f.exists());
} finally {
new File("array.idl").deleteOnExit();
}
}
use of org.apache.cxf.binding.corba.wsdl.BindingType in project cxf by apache.
the class WSDLToCorbaBindingTest method testMultipartCORBABindingGeneration.
@Test
public void testMultipartCORBABindingGeneration() throws Exception {
String fileName = getClass().getResource("/wsdl/multipart.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("Test.MultiPart");
Definition model = generator.generateCORBABinding();
QName bName = new QName("http://schemas.apache.org/tests", "Test.MultiPartCORBABinding", "tns");
Binding binding = model.getBinding(bName);
assertNotNull(binding);
assertEquals("Test.MultiPartCORBABinding", binding.getQName().getLocalPart());
assertEquals("Test.MultiPart", binding.getPortType().getQName().getLocalPart());
assertEquals(1, binding.getExtensibilityElements().size());
assertEquals(32, binding.getBindingOperations().size());
List<ExtensibilityElement> extElements = getExtensibilityElements(binding);
ExtensibilityElement extElement = extElements.get(0);
if (extElement.getElementType().getLocalPart().equals("binding")) {
BindingType bindingType = (BindingType) extElement;
assertEquals(bindingType.getRepositoryID(), "IDL:Test/MultiPart:1.0");
}
getStringAttributeTest(binding);
getTestIdTest(binding);
setTestIdTest(binding);
testVoidTest(binding);
testPrimitiveTypeTest(binding, "test_short", CorbaConstants.NT_CORBA_SHORT);
testPrimitiveTypeTest(binding, "test_long", CorbaConstants.NT_CORBA_LONG);
testPrimitiveTypeTest(binding, "test_longlong", CorbaConstants.NT_CORBA_LONGLONG);
testPrimitiveTypeTest(binding, "test_ushort", CorbaConstants.NT_CORBA_USHORT);
testPrimitiveTypeTest(binding, "test_ulong", CorbaConstants.NT_CORBA_ULONG);
testPrimitiveTypeTest(binding, "test_ulonglong", CorbaConstants.NT_CORBA_ULONGLONG);
testPrimitiveTypeTest(binding, "test_float", CorbaConstants.NT_CORBA_FLOAT);
testPrimitiveTypeTest(binding, "test_double", CorbaConstants.NT_CORBA_DOUBLE);
testPrimitiveTypeTest(binding, "test_octet", CorbaConstants.NT_CORBA_OCTET);
testPrimitiveTypeTest(binding, "test_boolean", CorbaConstants.NT_CORBA_BOOLEAN);
testPrimitiveTypeTest(binding, "test_char", CorbaConstants.NT_CORBA_CHAR);
testPrimitiveTypeTest(binding, "test_integer", CorbaConstants.NT_CORBA_LONGLONG);
testPrimitiveTypeTest(binding, "test_nonNegativeInteger", CorbaConstants.NT_CORBA_ULONGLONG);
testPrimitiveTypeTest(binding, "test_positiveInteger", CorbaConstants.NT_CORBA_ULONGLONG);
testPrimitiveTypeTest(binding, "test_negativeInteger", CorbaConstants.NT_CORBA_LONGLONG);
testPrimitiveTypeTest(binding, "test_normalizedString", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_token", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_language", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_Name", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_NCName", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_ID", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_anyURI", CorbaConstants.NT_CORBA_STRING);
testPrimitiveTypeTest(binding, "test_nick_name", CorbaConstants.NT_CORBA_STRING);
}
use of org.apache.cxf.binding.corba.wsdl.BindingType in project cxf by apache.
the class PortTypeVisitor method createBinding.
public Binding createBinding(String scopedPortTypeName) {
StringBuilder bname = new StringBuilder(scopedPortTypeName + "CORBABinding");
QName bqname = new QName(rootDefinition.getTargetNamespace(), bname.toString());
int count = 0;
while (queryBinding(bqname)) {
bname.append(count);
bqname = new QName(rootDefinition.getTargetNamespace(), bname.toString());
}
Binding binding = rootDefinition.createBinding();
binding.setPortType(portType);
binding.setQName(bqname);
try {
BindingType bindingType = (BindingType) extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
String pragmaPrefix = (this.getWsdlVisitor().getPragmaPrefix() != null && this.getWsdlVisitor().getPragmaPrefix().length() > 0) ? this.getWsdlVisitor().getPragmaPrefix() + "/" : "";
bindingType.setRepositoryID(CorbaConstants.REPO_STRING + pragmaPrefix + scopedPortTypeName.replace('.', '/') + CorbaConstants.IDL_VERSION);
binding.addExtensibilityElement((ExtensibilityElement) bindingType);
} catch (WSDLException ex) {
throw new RuntimeException(ex);
}
binding.setUndefined(false);
rootDefinition.addBinding(binding);
return binding;
}
use of org.apache.cxf.binding.corba.wsdl.BindingType in project cxf by apache.
the class WSDLToIDLAction method generateIDL.
public void generateIDL(Definition definition) throws Exception {
if (definition == null) {
typeProcessor.parseWSDL(wsdlFileName);
def = typeProcessor.getWSDLDefinition();
} else {
def = definition;
}
if (printWriter == null) {
printWriter = createPrintWriter(outputFile);
}
if (!isGenerateAllBindings()) {
Binding binding = findBinding(def);
if (binding == null) {
String msgStr = "Binding " + bindingName + " doesn't exists in WSDL.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
generateIDL(def, binding);
} else {
// generate idl for all bindings in the file.
// each idl file will have the name of the binding.
Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
if (bindings.isEmpty()) {
String msgStr = "No bindings exists within this WSDL.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
List<QName> portTypes = new ArrayList<>();
for (Binding binding : bindings) {
List<?> ext = binding.getExtensibilityElements();
if (!(ext.get(0) instanceof BindingType)) {
continue;
}
if (portTypes.contains(binding.getPortType().getQName())) {
continue;
}
portTypes.add(binding.getPortType().getQName());
generateIDL(def, binding);
root = IdlRoot.create();
}
}
printWriter.close();
}
use of org.apache.cxf.binding.corba.wsdl.BindingType in project cxf by apache.
the class PortTypeVisitor method visitInterfaceInheritanceSpec.
private AST visitInterfaceInheritanceSpec(AST interfaceInheritanceSpecNode, Binding binding, Scope childScope) {
// <interface_inheritance_spec> ::= ":" <interface_name> { "," <interface_name> }*
AST interfaceNameNode = interfaceInheritanceSpecNode.getFirstChild();
BindingType corbaBinding = findCorbaBinding(binding);
List<Scope> inheritedScopes = new ArrayList<>();
while (interfaceNameNode != null) {
// check for porttypes in current & parent scopes
Scope interfaceScope = null;
PortType intf = null;
if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
intf = findPortType(interfaceScope);
}
Scope currentScope = getScope();
while (intf == null && currentScope != currentScope.getParent()) {
if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
interfaceScope = ScopedNameVisitor.getFullyScopedName(currentScope, interfaceNameNode);
} else {
interfaceScope = new Scope(currentScope, interfaceNameNode.toString());
}
intf = findPortType(interfaceScope);
currentScope = currentScope.getParent();
}
if (intf == null) {
if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
} else {
interfaceScope = new Scope(new Scope(), interfaceNameNode);
}
intf = findPortType(interfaceScope);
}
if (intf == null) {
throw new RuntimeException("[InterfaceVisitor] Unknown Interface: " + interfaceNameNode.toString());
}
Scope defnScope = interfaceScope.getParent();
Definition defn = manager.getWSDLDefinition(mapper.map(defnScope));
inheritedScopes.add(interfaceScope);
if (defn != null && !defn.getTargetNamespace().equals(definition.getTargetNamespace())) {
String key = defnScope.toString("_");
String fileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + key;
manager.addWSDLDefinitionImport(definition, defn, key, fileName);
}
Binding inheritedBinding = findBinding(intf);
BindingType inheritedCorbaBinding = findCorbaBinding(inheritedBinding);
corbaBinding.getBases().add(inheritedCorbaBinding.getRepositoryID());
// add all the operations of the inherited port type.
for (Operation op : CastUtils.cast(intf.getOperations(), Operation.class)) {
// check to see all the inherited namespaces are added.
String inputNS = op.getInput().getMessage().getQName().getNamespaceURI();
manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(inputNS), inputNS);
// Make sure we import the wsdl for the input namespace
if (definition.getImports().get(inputNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(inputNS)) {
manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(inputNS), mapper.mapNSToPrefix(inputNS), manager.getImportedWSDLDefinitionFile(inputNS));
}
if (op.getOutput() != null) {
String outputNS = op.getOutput().getMessage().getQName().getNamespaceURI();
manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(outputNS), outputNS);
// Make sure we import the wsdl for the output namespace
if (definition.getImports().get(outputNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(outputNS)) {
manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(outputNS), mapper.mapNSToPrefix(outputNS), manager.getImportedWSDLDefinitionFile(outputNS));
}
}
for (Iterator<Fault> faults = CastUtils.cast(op.getFaults().values().iterator()); faults.hasNext(); ) {
String faultNS = faults.next().getMessage().getQName().getNamespaceURI();
manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(faultNS), faultNS);
// Make sure we import the wsdl for the fault namespace
if (definition.getImports().get(faultNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(faultNS)) {
manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(faultNS), mapper.mapNSToPrefix(faultNS), manager.getImportedWSDLDefinitionFile(faultNS));
}
}
portType.addOperation(op);
}
// add all the binding extensions of the inherited corba binding
for (Iterator<BindingOperation> it = CastUtils.cast(inheritedBinding.getBindingOperations().iterator()); it.hasNext(); ) {
binding.addBindingOperation(it.next());
}
interfaceNameNode = interfaceNameNode.getNextSibling();
}
if ((!inheritedScopes.isEmpty()) && (wsdlVisitor.getInheritedScopeMap() != null)) {
wsdlVisitor.getInheritedScopeMap().put(childScope, inheritedScopes);
}
return interfaceInheritanceSpecNode.getNextSibling();
}
Aggregations