Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwayner committed Jan 25, 2011
0 parents commit 8dc7c3b
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .classpath
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>
17 changes: 17 additions & 0 deletions .project
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 added lib/qname.jar
Binary file not shown.
Binary file added lib/resolver.jar
Binary file not shown.
Binary file added lib/serializer.jar
Binary file not shown.
Binary file added lib/velocity-1.7-dep.jar
Binary file not shown.
Binary file added lib/wsdl4j.jar
Binary file not shown.
Binary file added lib/xercesImpl.jar
Binary file not shown.
Binary file added lib/xercesSamples.jar
Binary file not shown.
Binary file added lib/xml-apis.jar
Binary file not shown.
40 changes: 40 additions & 0 deletions src/com/johnwayner/android/simplesoap/ComplexType.java
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();
}
}
60 changes: 60 additions & 0 deletions src/com/johnwayner/android/simplesoap/Field.java
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;
}
}
}
23 changes: 23 additions & 0 deletions src/com/johnwayner/android/simplesoap/MyWriter.java
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();
}
}

}
127 changes: 127 additions & 0 deletions src/com/johnwayner/android/simplesoap/SimpleSoap.java
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 src/com/johnwayner/android/simplesoap/templates/ComplexType.vm
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
}
3 changes: 3 additions & 0 deletions src/com/johnwayner/android/simplesoap/velocity.config
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

0 comments on commit 8dc7c3b

Please sign in to comment.