/**
*
*/
package test.org.soyatec.parse;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Port;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ElementExtensible;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
import org.apache.ws.commons.schema.XmlSchemaObject;
import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
import org.apache.ws.commons.schema.XmlSchemaObjectTable;
import org.apache.ws.commons.schema.XmlSchemaParticle;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
import org.apache.ws.commons.schema.XmlSchemaType;
import org.w3c.dom.Element;
import com.ibm.wsdl.ServiceImpl;
import com.ibm.wsdl.extensions.schema.SchemaImpl;
/**
* @author muyinfei
*
*/
public class WSDLParser {
// private static Parser wsdlParser = null;
// private static SymbolTable symbolTable = null;
private static Map servicesMap = null;
private static Map serviceEntryMap = null;
/**
* @param args
*/
public static void main(String[] args) {
String wsdlURI = "E:/temp folder/wsdl files/AddressService.wsdl";
try {
useWSDL4JTpParse(wsdlURI);
} catch (WSDLException e1) {
e1.printStackTrace();
}
//wsdlParser = new Parser();
//SchemaBuilder schemaBuilder = new SchemaBuilder();
XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
try {
//wsdlParser.run(wsdlURL);
// WSDLFactory wsdlFactory = WSDLFactory.newInstance();
// WSDLReader reader=wsdlFactory.newWSDLReader();
// Definition def=reader.readWSDL(null, wsdlURL);
/*symbolTable = wsdlParser.getSymbolTable();
serviceEntryMap = getServiceEntryMap(ServiceEntry.class);
servicesMap = getService();
Collection serivices = servicesMap.values();
for (Iterator iterator = serivices.iterator(); iterator.hasNext();) {
Service service = (Service) iterator.next();
//org.apache.axis.client.Service clientService = new org.apache.axis.client.Service(wsdlParser, service.getQName());
String serviceName = service.getQName().getLocalPart();
Map portsMap = service.getPorts();
Collection ports = portsMap.values();
for (Iterator iterator2 = ports.iterator(); iterator2.hasNext();) {
Port port = (Port) iterator2.next();
String portName = port.getName();
BindingEntry bindingEntry = getBindingEntry(serviceName, portName);
String bindingEntryName = bindingEntry.getQName().getLocalPart();
List operations = port.getBinding().getBindingOperations();
for (Iterator iterator3 = operations.iterator(); iterator3
.hasNext();) {
BindingOperation bindingOperation = (BindingOperation) iterator3.next();
Operation operation = bindingOperation.getOperation();
String operationName = operation.getName();
Parameters parameters = bindingEntry.getParameters(operation);
if (parameters != null) {
Vector inputParams = parameters.list;
for (Iterator iterator4 = inputParams.iterator(); iterator4
.hasNext();) {
Parameter inputParam = (Parameter) iterator4.next();
String inputParamName = inputParam.getName();
TypeEntry type = inputParam.getType();
String typeName = type.getName();
if (!type.isSimpleType() && !type.isBaseType()) {
Node node = type.getNode();
Vector containedElements = SchemaUtils.getContainedElementDeclarations(node, symbolTable);
for (Iterator iterator5= containedElements.iterator(); iterator.hasNext();) {
ElementDecl element = (ElementDecl) iterator5.next();
TypeEntry elementType = element.getType();
if (elementType.isSimpleType()) {
} else {
}
System.out.println("element: " + element) ;
}
}
}
Parameter returnParam = parameters.returnParam;
String returnParamName = returnParam.getName();
TypeEntry type = returnParam.getType();
String typeName = type.getName();
if (!type.isSimpleType() && !type.isBaseType()) {
Node node = type.getNode();
Vector containedElements = SchemaUtils.getContainedElementDeclarations(node, symbolTable);
for (Iterator iterator5= containedElements.iterator(); iterator5.hasNext();) {
ElementDecl element = (ElementDecl) iterator5.next();
TypeEntry elementType = element.getType();
if (elementType.isSimpleType()) {
} else {
}
System.out.println("element: " + element) ;
}
}
System.out.println("services:" + serviceEntryMap);
}
}
}
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
/*public static List getServiceInfos() {
List serviceInfos = new ArrayList();
Map servicesMap = getService();
Collection serivices = servicesMap.values();
for (Iterator iterator = serivices.iterator(); iterator.hasNext();) {
Service service = (Service) iterator.next();
ServiceInfo serviceInfo = new ServiceInfo();
String serviceName = service.getQName().getLocalPart();
serviceInfo.setName(serviceName);
List operations = getOperations(service);
serviceInfo.setOperations(operations);
serviceInfos.add(serviceInfo);
}
return serviceInfos;
}
public static List getOperations(Service service) {
List operations = new ArrayList();
String serviceName = service.getQName().getLocalPart();
Map portsMap = service.getPorts();
Collection ports = portsMap.values();
for (Iterator iterator = ports.iterator(); iterator.hasNext();) {
Port port = (Port) iterator.next();
String portName = port.getName();
BindingEntry bindingEntry = getBindingEntry(serviceName, portName);
List bindingOperations = port.getBinding().getBindingOperations();
for (Iterator iterator2 = bindingOperations.iterator(); iterator2.hasNext();) {
BindingOperation bindingOperation = (BindingOperation) iterator2.next();
Operation operation = bindingOperation.getOperation();
String operationName = operation.getName();
OperationInfo operationInfo = new OperationInfo();
Parameters parameters = bindingEntry.getParameters(operation);
if (parameters != null) {
}
}
}
return operations;
}
private static BindingEntry getBindingEntry(String serviceName, String portName) {
ServiceEntry serviceEntry = (ServiceEntry) serviceEntryMap.get(serviceName);
Port port = serviceEntry.getService().getPort(portName);
Binding binding = port.getBinding();
SymbolTable table = wsdlParser.getSymbolTable();
return table.getBindingEntry(binding.getQName());
}
private static Map getServiceEntryMap(Class cls) {
HashMap serviceEntryMap = new HashMap();
HashMap map = wsdlParser.getSymbolTable().getHashMap();
Iterator iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
QName key = (QName) entry.getKey();
Vector v = (Vector) entry.getValue();
int size = v.size();
for (int i = 0; i < size; ++i) {
SymTabEntry symTabEntry = (SymTabEntry) v.elementAt(i);
if (cls.isInstance(symTabEntry)) {
- 1
- 2
- 3
- 4
- 5
- 6
前往页