-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8dc7c3b
Showing
16 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry excluding="config/|velocitytemplates/" kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="lib" path="lib/velocity-1.7-dep.jar"/> | ||
<classpathentry kind="lib" path="lib/qname.jar"/> | ||
<classpathentry kind="lib" path="lib/wsdl4j.jar" sourcepath="/home/johnwayner/.m2/repository/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2-sources.jar"/> | ||
<classpathentry kind="lib" path="lib/xercesImpl.jar"/> | ||
<classpathentry kind="lib" path="lib/resolver.jar"/> | ||
<classpathentry kind="lib" path="lib/serializer.jar"/> | ||
<classpathentry kind="lib" path="lib/xercesSamples.jar"/> | ||
<classpathentry kind="lib" path="lib/xml-apis.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>android-simplesoap</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.johnwayner.android.simplesoap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ComplexType { | ||
public String name; | ||
public List<Field> fields = new ArrayList<Field>(); | ||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
|
||
public List<Field> getFields() { | ||
return fields; | ||
} | ||
|
||
|
||
public void setFields(List<Field> fields) { | ||
this.fields = fields; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(name); | ||
sb.append("\n"); | ||
for(Field f : fields) { | ||
sb.append("\t").append(f).append("\n"); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.johnwayner.android.simplesoap; | ||
|
||
public class Field { | ||
public String name; | ||
public String type; | ||
public boolean isList; | ||
public Field(String name, String type, boolean isList) { | ||
super(); | ||
this.name = name; | ||
this.type = type; | ||
this.isList = isList; | ||
} | ||
|
||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
|
||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
|
||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
|
||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
|
||
|
||
public boolean isList() { | ||
return isList; | ||
} | ||
|
||
|
||
|
||
public void setList(boolean isList) { | ||
this.isList = isList; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public String toString() { | ||
if(isList) { | ||
return "List<" + type + "> " + name; | ||
} else { | ||
return type + " " + name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.johnwayner.android.simplesoap; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import javax.wsdl.Definition; | ||
import javax.wsdl.WSDLException; | ||
|
||
import com.ibm.wsdl.xml.WSDLWriterImpl; | ||
|
||
public class MyWriter extends WSDLWriterImpl { | ||
|
||
public void writeTypes(Definition def) { | ||
PrintWriter pw = new PrintWriter(System.out); | ||
|
||
try { | ||
printTypes(def.getTypes(), def, pw); | ||
} catch (WSDLException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.johnwayner.android.simplesoap; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import javax.wsdl.Definition; | ||
import javax.wsdl.Types; | ||
import javax.wsdl.extensions.schema.Schema; | ||
import javax.wsdl.factory.WSDLFactory; | ||
import javax.wsdl.xml.WSDLReader; | ||
import javax.wsdl.xml.WSDLWriter; | ||
|
||
import org.apache.velocity.Template; | ||
import org.apache.velocity.VelocityContext; | ||
import org.apache.velocity.app.Velocity; | ||
import org.w3c.dom.NamedNodeMap; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class SimpleSoap { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
try { | ||
WSDLFactory wsdlFactory = WSDLFactory.newInstance(); | ||
WSDLReader wsdlReader = wsdlFactory.newWSDLReader(); | ||
WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter(); | ||
|
||
Definition def = wsdlReader.readWSDL(null, "/media/Data/dev/UnitedRoadsShipperAndroid/soap_stuff/service.wsdl"); | ||
|
||
Types types = def.getTypes(); | ||
List<Schema> elems = types.getExtensibilityElements(); | ||
|
||
List<ComplexType> outputTypes = new ArrayList<ComplexType>(); | ||
|
||
for(Schema elem : elems) { | ||
NodeList complexTypes = elem.getElement().getChildNodes(); | ||
for(int i=0; i<complexTypes.getLength(); i++) { | ||
Node type = complexTypes.item(i); | ||
if("s:element".equals(type.getNodeName())) { | ||
ComplexType ctype = new ComplexType(); | ||
outputTypes.add(ctype); | ||
ctype.name = type.getAttributes().getNamedItem("name").getNodeValue(); | ||
Node seq = type.getChildNodes().item(1).getChildNodes().item(1); | ||
if("s:sequence".equals(seq.getNodeName())) { | ||
NodeList fields = seq.getChildNodes(); | ||
for(int f=0; f<fields.getLength(); f++) { | ||
if("s:element".equals(fields.item(f).getNodeName())) { | ||
NamedNodeMap attrs = fields.item(f).getAttributes(); | ||
ctype.fields.add( | ||
new Field( | ||
attrs.getNamedItem("name").getNodeValue(), | ||
wsdlType2JavaType(attrs.getNamedItem("type").getNodeValue()), | ||
!attrs.getNamedItem("maxOccurs").getNodeValue().equals("1"))); | ||
} | ||
} | ||
} | ||
} | ||
if("s:complexType".equals(type.getNodeName())) { | ||
ComplexType ctype = new ComplexType(); | ||
outputTypes.add(ctype); | ||
ctype.name = type.getAttributes().getNamedItem("name").getNodeValue(); | ||
Node seq = type.getChildNodes().item(1); | ||
if("s:sequence".equals(seq.getNodeName())) { | ||
NodeList fields = seq.getChildNodes(); | ||
for(int f=0; f<fields.getLength(); f++) { | ||
if("s:element".equals(fields.item(f).getNodeName())) { | ||
NamedNodeMap attrs = fields.item(f).getAttributes(); | ||
ctype.fields.add( | ||
new Field( | ||
attrs.getNamedItem("name").getNodeValue(), | ||
wsdlType2JavaType(attrs.getNamedItem("type").getNodeValue()), | ||
!attrs.getNamedItem("maxOccurs").getNodeValue().equals("1"))); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Properties prop = new Properties(); | ||
prop.load(SimpleSoap.class.getResourceAsStream("/com/johnwayner/android/simplesoap/velocity.config")); | ||
Velocity.init(prop); | ||
|
||
VelocityContext context = new VelocityContext(); | ||
Template complexTypeTemplate = Velocity.getTemplate("com/johnwayner/android/simplesoap/templates/ComplexType.vm"); | ||
for(ComplexType type : outputTypes) { | ||
context.put("type", type); | ||
context.put("package", "com.unitedroads.android.shipper.soap.simple.types"); | ||
File output = new File("/media/Data/dev/UnitedRoadsShipperAndroid/UnitedRoadsShipperAndroid/src/com/unitedroads/android/shipper/soap/simple/types/" + type.name + ".java"); | ||
System.out.println("output: " + output.getAbsolutePath()); | ||
FileWriter fw = new FileWriter(output); | ||
complexTypeTemplate.merge(context, fw); | ||
fw.close(); | ||
} | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static final Map<String, String> wsdlTypes2JavaTypes = new HashMap<String, String>(); | ||
static { | ||
wsdlTypes2JavaTypes.put("s:string", "String"); | ||
wsdlTypes2JavaTypes.put("s:boolean", "Boolean"); | ||
wsdlTypes2JavaTypes.put("s:int", "Integer"); | ||
wsdlTypes2JavaTypes.put("s:double", "Double"); | ||
wsdlTypes2JavaTypes.put("s:date", "Date"); | ||
} | ||
public static String wsdlType2JavaType(String wsdlType) { | ||
if(wsdlTypes2JavaTypes.containsKey(wsdlType)) { | ||
return wsdlTypes2JavaTypes.get(wsdlType); | ||
} else { | ||
if(wsdlType.startsWith("tns:")) { | ||
return wsdlType.substring(4); | ||
} | ||
} | ||
|
||
throw new RuntimeException("Unmapped type: " + wsdlType); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/com/johnwayner/android/simplesoap/templates/ComplexType.vm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package $package; | ||
|
||
import java.util.List; | ||
import java.util.Date; | ||
import org.simpleframework.xml.Element; | ||
import org.simpleframework.xml.ElementList; | ||
|
||
public class $type.name { | ||
#foreach( $field in $type.fields ) | ||
#if ($field.isList()) | ||
@ElementList(inline=true) | ||
#else | ||
@Element | ||
#end | ||
$field.toString(); | ||
#end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource.loader = cp | ||
cp.loader.description = Classpath loader | ||
cp.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader |