You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by rk...@apache.org on 2001/11/28 13:08:11 UTC
cvs commit: xml-axis/java/src/org/apache/axis/wsdlgen Emitter.java Java2Wsdl.java Namespaces.java
rkumar 01/11/28 04:08:11
Modified: java/src/org/apache/axis/wsdlgen Emitter.java Java2Wsdl.java
Namespaces.java
Log:
Another pass at setting up the Java2Wsdl framework -
this batch is primarily namespaces and types related.
Revision Changes Path
1.3 +39 -30 xml-axis/java/src/org/apache/axis/wsdlgen/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdlgen/Emitter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Emitter.java 2001/11/25 18:59:32 1.2
+++ Emitter.java 2001/11/28 12:08:11 1.3
@@ -88,6 +88,7 @@
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Map;
import java.util.StringTokenizer;
/**
@@ -106,13 +107,18 @@
private String serviceName = null;
private String description;
private TypeMappingRegistry reg;
+ private Namespaces namespaces;
private Definition def;
private Document doc;
private String clsName;
private ArrayList encodingList;
- private Namespaces namespaceMap;
+ private Types types;
+ public Emitter () {
+ namespaces = new Namespaces();
+ }
+
/**
* Generates a WSDL document for a given <code>Class</code> and
* a space seperated list of methods at runtime
@@ -193,6 +199,7 @@
*/
public void emit(Class cls, String allowedMethods, String filename) throws Exception {
Document doc = emit(cls, allowedMethods);
+ types.insertTypesFragment(doc);
XMLUtils.PrettyDocumentToStream(doc, new FileOutputStream(new File(filename)));
}
@@ -237,19 +244,18 @@
if (targetNamespace == null)
targetNamespace = Namespaces.makeNamespace(cls.getName());
- namespaceMap = new Namespaces();
- namespaceMap.put(cls.getName(), targetNamespace, "tns");
+ namespaces.put(cls.getName(), targetNamespace, "tns");
+ writeDefinitions();
+ types = new Types(def, reg, namespaces, targetNamespace);
Binding binding = writeBinding();
writePortType(binding);
writeService(binding);
- return doc;
+ return WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
}
private void writeDefinitions() throws Exception {
def = WSDLFactory.newInstance().newDefinition();
- doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
-
def.setTargetNamespace(targetNamespace);
def.addNamespace("tns", targetNamespace);
@@ -292,7 +298,7 @@
service.addPort(port);
}
- private void writePortType(Binding binding) {
+ private void writePortType(Binding binding) throws Exception{
PortType portType = def.createPortType();
portType.setUndefined(false);
@@ -316,7 +322,7 @@
binding.setPortType(portType);
}
- private void writeMessages(Operation oper, Method method) {
+ private void writeMessages(Operation oper, Method method) throws Exception{
Input input = def.createInput();
Message msg = writeRequestMessage(method);
@@ -367,7 +373,7 @@
binding.addBindingOperation(bindingOper);
}
- private Message writeRequestMessage(Method method)
+ private Message writeRequestMessage(Method method) throws Exception
{
Message msg = def.createMessage();
@@ -392,7 +398,7 @@
return msg;
}
- private Message writeResponseMessage(Method method)
+ private Message writeResponseMessage(Method method) throws Exception
{
Message msg = def.createMessage();
@@ -408,31 +414,17 @@
return msg;
}
- private void writePartToMessage(Message msg, String name, Class param)
+ public void writePartToMessage(Message msg, String name, Class param) throws Exception
{
Part part = def.createPart();
- QName qName = reg.getTypeQName(param);
- if (qName == null) {
- qName = new QName("java", param.getName());
- }
- String pref = def.getPrefix(qName.getNamespaceURI());
- if (pref == null) {
- int i = 1;
- while (def.getNamespace("ns" + i) != null) {
- i++;
- }
- def.addNamespace("ns" + i, qName.getNamespaceURI());
+ javax.wsdl.QName typeQName = types.writePartType(param);
+ if (typeQName != null) {
+ part.setTypeName(typeQName);
+ part.setName(name);
}
-
- javax.wsdl.QName typeQName =
- new javax.wsdl.QName(qName.getNamespaceURI(),
- qName.getLocalPart());
-
- part.setTypeName(typeQName);
- part.setName(name);
-
msg.addPart(part);
}
+
/*
* Return a message QName which has not already been defined in the WSDL
*/
@@ -500,6 +492,23 @@
*/
public void setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
+ }
+
+ /**
+ * get the packagename to namespace map
+ * @return <code>Map</code>
+ */
+ public Map getNamespaceMap() {
+ return namespaces;
+ }
+
+ /**
+ * Set the packagename to namespace map with the given map
+ * @param map packagename/namespace <code>Map</code>
+ */
+ public void setNamespaceMap(Map map) {
+ if ((map != null) && (map.isEmpty()))
+ namespaces.putAll(map);
}
/**
1.2 +17 -1 xml-axis/java/src/org/apache/axis/wsdlgen/Java2Wsdl.java
Index: Java2Wsdl.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdlgen/Java2Wsdl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Java2Wsdl.java 2001/11/21 19:24:58 1.1
+++ Java2Wsdl.java 2001/11/28 12:08:11 1.2
@@ -59,6 +59,7 @@
import org.apache.avalon.excalibur.cli.CLOptionDescriptor;
import org.apache.avalon.excalibur.cli.CLUtil;
+import java.util.HashMap;
import java.util.List;
/**
@@ -72,6 +73,7 @@
protected static final int HELP_OPT = 'h';
protected static final int OUTPUT_OPT = 'o';
protected static final int NAMESPACE_OPT = 'n';
+ protected static final int TARGET_NAMESPACE_OPT = 't';
protected static final int LOCATION_OPT = 'l';
protected static final int CLASSDIR_OPT = 'c';
protected static final int ALLOWED_METHODS_OPT = 'm';
@@ -92,8 +94,12 @@
"print this message and exit"),
new CLOptionDescriptor("namespace",
CLOptionDescriptor.ARGUMENT_OPTIONAL,
- NAMESPACE_OPT,
+ TARGET_NAMESPACE_OPT,
"target namespace"),
+ new CLOptionDescriptor("PkgtoNS",
+ CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
+ NAMESPACE_OPT,
+ "package=namespace, name value pairs"),
new CLOptionDescriptor("location",
CLOptionDescriptor.ARGUMENT_OPTIONAL,
LOCATION_OPT,
@@ -121,6 +127,7 @@
String classDir = null;
String wsdlFilename = null;
String allowedMethods = null;
+ HashMap namespaceMap = new HashMap();
// Parse the arguments
CLArgsParser parser = new CLArgsParser(args, options);
@@ -169,6 +176,12 @@
break;
case NAMESPACE_OPT:
+ String namespace = option.getArgument(0);
+ String packageName = option.getArgument(1);
+ namespaceMap.put(namespace, packageName);
+ break;
+
+ case TARGET_NAMESPACE_OPT:
emitter.setTargetNamespace(option.getArgument());
break;
@@ -181,6 +194,9 @@
printUsage();
}
+ if (!namespaceMap.isEmpty()) {
+ emitter.setNamespaceMap(namespaceMap);
+ }
emitter.emit(classDir, className, allowedMethods, wsdlFilename);
}
catch (Throwable t) {
1.2 +33 -3 xml-axis/java/src/org/apache/axis/wsdlgen/Namespaces.java
Index: Namespaces.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdlgen/Namespaces.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Namespaces.java 2001/11/25 18:59:16 1.1
+++ Namespaces.java 2001/11/28 12:08:11 1.2
@@ -77,6 +77,21 @@
* Get the namespaace for the given package If there is no entry in the HashMap for
* this namespace, create one.
* @param key String representing packagename
+ * @return the namespace either created or existing
+ */
+ public String getCreate(String key) {
+ Object value = super.get(key);
+ if (value == null) {
+ value = makeNamespace((String) key);
+ put(key, value, null);
+ }
+ return (String) value;
+ }
+
+ /**
+ * Get the namespaace for the given package If there is no entry in the HashMap for
+ * this namespace, create one.
+ * @param key String representing packagename
* @param prefix the prefix to use for the generated namespace
* @return the namespace either created or existing
*/
@@ -101,18 +116,18 @@
public Object put(Object key, Object value, String prefix) {
if (prefix != null)
namespacePrefixMap.put(value, prefix);
+ else
+ getCreatePrefix((String)value);
return super.put(key, value);
}
/**
- * clears existing entries. adds an entry to the packagename/namespace HashMap
+ * adds an entry to the packagename/namespace HashMap
* for each of the entry in the map. In addition, also add an entries in the
* auxillary namespace/prefix HashMap
* @param map packageName/namespace map
*/
public void putAll(Map map) {
- super.clear();
- namespacePrefixMap.clear();
Iterator i = map.keySet().iterator();
while (i.hasNext()) {
Object key = i.next();
@@ -140,6 +155,21 @@
*/
public void putPrefix(String namespace, String prefix) {
namespacePrefixMap.put(namespace, prefix);
+ }
+
+ /**
+ * adds an entry to the namespace / prefix HashMap
+ * for each of the entry in the map.
+ *
+ * @param map packageName/namespace map
+ */
+ public void putAllPrefix(Map map) {
+ Iterator i = namespacePrefixMap.keySet().iterator();
+ while (i.hasNext()) {
+ Object key = i.next();
+ String prefix = (String) map.get(key);
+ put(key, prefix);
+ }
}
/**