use of javax.wsdl.Binding in project cxf by apache.
the class IDLToWSDLProcessor method parseIDL.
public void parseIDL(AST idlTree) throws Exception {
if (env.isVerbose()) {
System.out.println(idlTree.toStringTree());
}
// target namespace
String tns = (String) env.get(ToolCorbaConstants.CFG_TNS);
if (tns == null) {
tns = CorbaConstants.WSDL_NS_URI + idl;
}
// XmlSchema namespace
String schemans = (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE);
// corba typemap namespace
String corbatypemaptns = (String) env.get(ToolCorbaConstants.CFG_CORBATYPEMAP_NAMESPACE);
outputDir = ".";
try {
WSDLASTVisitor visitor = new WSDLASTVisitor(tns, schemans, corbatypemaptns, preprocessor.getPragmaPrefix());
visitor.getManager().setIgnoreImports(ignoreImports);
if (env.optionSet(ToolConstants.CFG_OUTPUTDIR)) {
outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
}
visitor.setOutputDir(outputDir);
Definition def = visitor.getDefinition();
if (env.optionSet(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE)) {
visitor.setSequenceOctetType((String) env.get(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE));
}
if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE)) {
// visitor.getDefinition()
def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX, (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE));
}
if (env.optionSet(ToolCorbaConstants.CFG_BOUNDEDSTRINGS)) {
visitor.setBoundedStringOverride(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_MODULETONS)) {
String mapping = (String) env.get(ToolCorbaConstants.CFG_MODULETONS);
// parse the mapping & set a map of module to namespace mapping in the visitor
visitor.setModuleToNSMapping(getModuleToNSMapping(mapping));
}
if (env.optionSet(ToolCorbaConstants.CFG_QUALIFIED)) {
visitor.setQualified(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_POLYMORPHIC_FACTORIES)) {
visitor.setSupportPolymorphicFactories(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA)) {
visitor.setSchemaGenerated(true);
// generate default namespace for schema if -T is used alone.
if (env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE) == null) {
visitor.updateSchemaNamespace(def.getTargetNamespace() + "-types");
def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX, def.getTargetNamespace() + "-types");
}
}
if (env.optionSet(ToolCorbaConstants.CFG_EXCLUDEMODULES)) {
String modules = (String) env.get(ToolCorbaConstants.CFG_EXCLUDEMODULES);
// parse the mapping & set a map of module to namespace mapping in the visitor
visitor.setExcludedModules(getExcludedModules(modules));
}
visitor.visit(idlTree);
cleanUpTypeMap(visitor.getTypeMap());
Binding[] bindings = visitor.getCorbaBindings();
generateCORBAService(def, bindings, visitor.getModuleToNSMapper().isDefaultMapping());
writeDefinitions(visitor);
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
}
}
use of javax.wsdl.Binding in project cxf by apache.
the class PortTypeVisitor method visitInterface.
// Visits a fully declared interface
private void visitInterface(AST identifierNode) {
try {
String interfaceName = identifierNode.toString();
Scope interfaceScope = new Scope(getScope(), interfaceName);
portType = definition.createPortType();
String portTypeName = interfaceScope.toString();
XmlSchema newSchema = schema;
if (!mapper.isDefaultMapping()) {
portTypeName = interfaceScope.tail();
// add a schema based on the interface
String tns = mapper.map(interfaceScope);
newSchema = manager.createXmlSchemaForDefinition(definition, tns, schemas);
definition.addNamespace(interfaceScope.toString("_"), tns);
}
String tns = definition.getTargetNamespace();
portType.setQName(new QName(tns, portTypeName));
definition.addPortType(portType);
portType.setUndefined(false);
Binding binding = createBinding(interfaceScope.toString());
AST specNode = identifierNode.getNextSibling();
if (specNode.getType() == IDLTokenTypes.LCURLY) {
specNode = specNode.getNextSibling();
}
AST exportNode;
if (specNode.getType() == IDLTokenTypes.RCURLY) {
exportNode = specNode.getNextSibling();
} else if (specNode.getType() == IDLTokenTypes.COLON) {
exportNode = visitInterfaceInheritanceSpec(specNode, binding, interfaceScope);
exportNode = exportNode.getNextSibling();
} else {
exportNode = specNode;
}
while (exportNode != null && exportNode.getType() != IDLTokenTypes.RCURLY) {
if (TypeDclVisitor.accept(exportNode)) {
TypeDclVisitor visitor = new TypeDclVisitor(interfaceScope, definition, newSchema, wsdlVisitor);
visitor.visit(exportNode);
} else if (ConstVisitor.accept(exportNode)) {
ConstVisitor visitor = new ConstVisitor(interfaceScope, definition, newSchema, wsdlVisitor);
visitor.visit(exportNode);
} else if (ExceptionVisitor.accept(exportNode)) {
ExceptionVisitor visitor = new ExceptionVisitor(interfaceScope, definition, newSchema, wsdlVisitor);
visitor.visit(exportNode);
} else if (AttributeVisitor.accept(exportNode)) {
AttributeVisitor attributeVisitor = new AttributeVisitor(interfaceScope, definition, newSchema, wsdlVisitor, portType, binding);
attributeVisitor.visit(exportNode);
} else if (OperationVisitor.accept(interfaceScope, definition, newSchema, exportNode, wsdlVisitor)) {
OperationVisitor visitor = new OperationVisitor(interfaceScope, definition, newSchema, wsdlVisitor, portType, binding);
visitor.visit(exportNode);
} else {
throw new RuntimeException("[InterfaceVisitor] Invalid IDL: unknown element " + exportNode.toString());
}
exportNode = exportNode.getNextSibling();
}
// Once we've finished declaring the interface, we should make sure it has been removed
// from the list of scopedNames so that we indicate that is no longer simply forward
// declared.
Scope scopedName = new Scope(getScope(), identifierNode);
scopedNames.remove(scopedName);
if (wsdlVisitor.getDeferredActions() != null) {
handleDeferredActions(wsdlVisitor.getDeferredActions(), scopedName, identifierNode);
}
if (!mapper.isDefaultMapping()) {
manager.deferAttachSchemaToWSDL(definition, newSchema, false);
// manager.attachSchemaToWSDL(definition, newSchema, false);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of javax.wsdl.Binding 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();
}
use of javax.wsdl.Binding in project cxf by apache.
the class UniqueBodyPartsValidator method isValid.
public boolean isValid() {
Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
for (Binding binding : bindings) {
uniqueBodyPartsMap = new HashMap<>();
List<BindingOperation> ops = CastUtils.cast(binding.getBindingOperations());
for (BindingOperation op : ops) {
Operation operation = op.getOperation();
if (operation != null && operation.getInput() != null) {
Message inMessage = operation.getInput().getMessage();
BindingInput bin = op.getBindingInput();
Set<String> headers = new HashSet<>();
if (bin != null) {
List<ExtensibilityElement> lst = CastUtils.cast(bin.getExtensibilityElements());
for (ExtensibilityElement ext : lst) {
if (!(ext instanceof SOAPHeader)) {
continue;
}
SOAPHeader header = (SOAPHeader) ext;
if (!header.getMessage().equals(inMessage.getQName())) {
continue;
}
headers.add(header.getPart());
}
}
if (inMessage != null && !isUniqueBodyPart(operation.getName(), inMessage, headers, binding.getQName())) {
return false;
}
}
}
}
return true;
}
use of javax.wsdl.Binding in project cxf by apache.
the class WSDLRefValidator method getBindings.
private Map<QName, XNode> getBindings(Service service) {
Map<QName, XNode> bindings = new HashMap<>();
if (service.getPorts().values().isEmpty()) {
throw new ToolException("Service " + service.getQName() + " does not contain any usable ports");
}
Collection<Port> ports = CastUtils.cast(service.getPorts().values());
for (Port port : ports) {
Binding binding = port.getBinding();
bindings.put(binding.getQName(), getXNode(service, port));
if (WSDLConstants.NS_WSDL11.equals(binding.getQName().getNamespaceURI())) {
throw new ToolException("Binding " + binding.getQName().getLocalPart() + " namespace set improperly.");
}
}
return bindings;
}
Aggregations