changed folder name
This commit is contained in:
parent
4503531ec9
commit
80c6a52c69
73 changed files with 0 additions and 0 deletions
112
src/zutil/net/ws/WSInterface.java
Normal file
112
src/zutil/net/ws/WSInterface.java
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
/**
|
||||
*
|
||||
* Specifies web service parameter names and other things.
|
||||
* Example:
|
||||
* <pre>
|
||||
* private static class Test implements WSInterface{
|
||||
* public Test(){}
|
||||
*
|
||||
* @WSDocumentation("blabla")
|
||||
* @WSDLParamDocumentation("olle = an variable?")
|
||||
* public void pubZ(
|
||||
* @WSParamName("olle") int lol)
|
||||
* throws Exception{
|
||||
* ....
|
||||
* }
|
||||
*
|
||||
* @WSReturnName("param")
|
||||
* public String pubA(
|
||||
* @WSParamName(value="lol", optional=true) String lol)
|
||||
* throws Exception{
|
||||
* ....
|
||||
* }
|
||||
*
|
||||
* @WSDisabled()
|
||||
* public void privaZ(....){
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* </pre>
|
||||
* @author Ziver
|
||||
*/
|
||||
public interface WSInterface {
|
||||
/**
|
||||
* Annotation that assigns a name to an parameters
|
||||
* in an method.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface WSParamName {
|
||||
String value();
|
||||
boolean optional() default false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation that assigns a name to the return value
|
||||
* in an method.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface WSReturnName {
|
||||
String value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables publication of the given method
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface WSDisabled { }
|
||||
|
||||
/**
|
||||
* Method or Parameter comments for the WSDL.
|
||||
* These comments are put in the message part of the WSDL
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface WSDocumentation{
|
||||
String value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter comments for the WSDL.
|
||||
* These comments are put in the message part of the WSDL
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface WSParamDocumentation{
|
||||
String value();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used in the header.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface WSHeader { }
|
||||
|
||||
/**
|
||||
* Specifies the name space for the method.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface WSNamespace {
|
||||
String value();
|
||||
}
|
||||
}
|
||||
175
src/zutil/net/ws/WSMethodDef.java
Normal file
175
src/zutil/net/ws/WSMethodDef.java
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import zutil.net.ws.WSInterface.WSDocumentation;
|
||||
|
||||
// TODO: Header parameters
|
||||
public class WSMethodDef {
|
||||
/** A list of input parameters **/
|
||||
private ArrayList<WSParameterDef> inputs;
|
||||
/** A List of return parameters of the method **/
|
||||
private ArrayList<WSParameterDef> outputs;
|
||||
/** A List of exceptions that this method throws **/
|
||||
private ArrayList<Class<?>> exceptions;
|
||||
/** The real method that this class represent, can be null if its a remote method **/
|
||||
private Method method;
|
||||
/** Documentation of the method **/
|
||||
private String doc;
|
||||
/** The published name of the method **/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param me is a method in a class that implements WSInterface
|
||||
*/
|
||||
public WSMethodDef(Method me) {
|
||||
if(!WSInterface.class.isAssignableFrom(me.getDeclaringClass()) )
|
||||
throw new ClassCastException("Declaring class does not implement WSInterface!");
|
||||
method = me;
|
||||
inputs = new ArrayList<WSParameterDef>();
|
||||
outputs = new ArrayList<WSParameterDef>();
|
||||
exceptions = new ArrayList<Class<?>>();
|
||||
name = method.getName();
|
||||
|
||||
//***** Documentation
|
||||
WSDocumentation tmpDoc = method.getAnnotation(WSInterface.WSDocumentation.class);
|
||||
if(tmpDoc != null){
|
||||
doc = tmpDoc.value();
|
||||
}
|
||||
//***** Exceptions
|
||||
for( Class<?> exc : method.getExceptionTypes() ){
|
||||
exceptions.add( exc );
|
||||
}
|
||||
//********* Get the input parameter names **********
|
||||
Annotation[][] paramAnnotation = method.getParameterAnnotations();
|
||||
|
||||
for(int i=0; i<paramAnnotation.length ;i++){
|
||||
WSParameterDef param = new WSParameterDef();
|
||||
for(Annotation annotation : paramAnnotation[i]){
|
||||
if(annotation instanceof WSInterface.WSParamName){
|
||||
WSInterface.WSParamName paramName = (WSInterface.WSParamName) annotation;
|
||||
param.name = paramName.value();
|
||||
param.optional = paramName.optional();
|
||||
}
|
||||
}
|
||||
// if no name was found then use default
|
||||
if(param.name == null)
|
||||
param.name = "args"+i;
|
||||
|
||||
inputs.add( param );
|
||||
}
|
||||
|
||||
//******** The return parameter name ************
|
||||
WSInterface.WSReturnName returnName = method.getAnnotation(WSInterface.WSReturnName.class);
|
||||
if( WSReturnValueList.class.isAssignableFrom( method.getReturnType() ) ){
|
||||
Class<?> retClass = method.getReturnType();
|
||||
Field[] fields = retClass.getFields();
|
||||
for(int i=0; i<fields.length ;i++){
|
||||
WSParameterDef ret_param = new WSParameterDef();
|
||||
WSReturnValueList.WSValueName retValName = fields[i]
|
||||
.getAnnotation( WSReturnValueList.WSValueName.class );
|
||||
if(retValName != null) ret_param.name = retValName.value();
|
||||
else ret_param.name = fields[i].getName();
|
||||
ret_param.paramClass = fields[i].getType();
|
||||
outputs.add( ret_param );
|
||||
}
|
||||
}
|
||||
else{
|
||||
WSParameterDef ret_param = new WSParameterDef();
|
||||
if(returnName != null) ret_param.name = returnName.value();
|
||||
else ret_param.name = "return";
|
||||
ret_param.paramClass = method.getReturnType();
|
||||
outputs.add( ret_param );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the published name of the method
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of exceptions this method throws
|
||||
*/
|
||||
public int exceptionCount(){
|
||||
return exceptions.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of exceptions this method throws
|
||||
*/
|
||||
public List<Class<?>> getExceptions(){
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of parameters for this method
|
||||
*/
|
||||
public int inputCount(){
|
||||
return inputs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of input parameters
|
||||
*/
|
||||
public List<WSParameterDef> getInputs(){
|
||||
return inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of parameters for this method
|
||||
*/
|
||||
public int outputCount(){
|
||||
return outputs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of input parameters
|
||||
*/
|
||||
public List<WSParameterDef> getOutputs(){
|
||||
return outputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Documentation of the method if one exists or else null
|
||||
*/
|
||||
public String getDocumentation(){
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
boolean first = true;
|
||||
tmp.append(name).append("(");
|
||||
for(WSParameterDef param : inputs){
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
tmp.append(" ,");
|
||||
tmp.append(param.paramClass.getSimpleName());
|
||||
tmp.append(" ");
|
||||
tmp.append(param.name);
|
||||
}
|
||||
tmp.append(") => ");
|
||||
first = true;
|
||||
for(WSParameterDef param : outputs){
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
tmp.append(" ,");
|
||||
tmp.append(param.paramClass.getSimpleName());
|
||||
tmp.append(" ");
|
||||
tmp.append(param.name);
|
||||
}
|
||||
return tmp.toString();
|
||||
}
|
||||
}
|
||||
56
src/zutil/net/ws/WSObject.java
Normal file
56
src/zutil/net/ws/WSObject.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This class is used as an return Object for a web service.
|
||||
* If an class implements this interface then it can return
|
||||
* multiple values through the SOAPInterface. Example:
|
||||
* <pre>
|
||||
* private static class TestObject implements WSObject{
|
||||
* @SOAPFieldName("name")
|
||||
* public String name;
|
||||
* @SOAPFieldName("lastname")
|
||||
* public String lastname;
|
||||
*
|
||||
* public TestObject(String n, String l){
|
||||
* name = n;
|
||||
* lastname = l;
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public interface WSObject{
|
||||
/**
|
||||
* Specifies the name of a field.
|
||||
* The fields that are available in the service should
|
||||
* be declared public.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface WSFieldName {
|
||||
String value();
|
||||
boolean optional() default false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This generates an documentation tag in the
|
||||
* WSDL for the object type
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
/*
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface WSDLDocumentation {
|
||||
String value();
|
||||
}*/
|
||||
}
|
||||
43
src/zutil/net/ws/WSParameterDef.java
Normal file
43
src/zutil/net/ws/WSParameterDef.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
public class WSParameterDef{
|
||||
/** The class type of the parameter **/
|
||||
protected Class<?> paramClass;
|
||||
/** The web service name of the parameter **/
|
||||
protected String name;
|
||||
/** Developer documentation **/
|
||||
protected String doc;
|
||||
/** If this parameter is optional **/
|
||||
protected boolean optional;
|
||||
/** Is it an header parameter **/
|
||||
//boolean header;
|
||||
|
||||
|
||||
public Class<?> getParamClass() {
|
||||
return paramClass;
|
||||
}
|
||||
protected void setParamClass(Class<?> paramClass) {
|
||||
this.paramClass = paramClass;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDoc() {
|
||||
return doc;
|
||||
}
|
||||
protected void setDoc(String doc) {
|
||||
this.doc = doc;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
protected void setOptional(boolean optional) {
|
||||
this.optional = optional;
|
||||
}
|
||||
}
|
||||
57
src/zutil/net/ws/WSReturnValueList.java
Normal file
57
src/zutil/net/ws/WSReturnValueList.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* This interface is for returning multiple object.
|
||||
* All the public fields in the class that implements
|
||||
* this class will be set as return values. And the
|
||||
* implementing class will be transparent.
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public class WSReturnValueList {
|
||||
|
||||
/**
|
||||
* Method comments for the WSDL.
|
||||
* These comments are put in the operation part of the WSDL
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface WSDLDocumentation{
|
||||
String value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables publication of the given field.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
/*@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SOAPDisabledValue { }*/
|
||||
|
||||
/**
|
||||
* Annotation that assigns a name to the return value
|
||||
* to the field.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface WSValueName {
|
||||
String value();
|
||||
}
|
||||
|
||||
|
||||
public Object getValue(Field field) throws IllegalArgumentException, IllegalAccessException{
|
||||
return field.get(this);
|
||||
}
|
||||
}
|
||||
|
||||
66
src/zutil/net/ws/WebServiceDef.java
Normal file
66
src/zutil/net/ws/WebServiceDef.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package zutil.net.ws;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.wsdl.WSDLException;
|
||||
|
||||
public class WebServiceDef {
|
||||
/** A map of methods in this Service **/
|
||||
private HashMap<String,WSMethodDef> methods;
|
||||
/** URL of the Service **/
|
||||
//private String url;
|
||||
/** Namespace of the service **/
|
||||
//private String namespace;
|
||||
/** Name of the web service **/
|
||||
private String name;
|
||||
/** This is the WSInterface class **/
|
||||
private Class<? extends WSInterface> intf;
|
||||
|
||||
|
||||
public WebServiceDef(Class<? extends WSInterface> intf) throws WSDLException{
|
||||
this.intf = intf;
|
||||
methods = new HashMap<String,WSMethodDef>();
|
||||
name = intf.getSimpleName();
|
||||
|
||||
for(Method m : intf.getDeclaredMethods()){
|
||||
// check for public methods
|
||||
if((m.getModifiers() & Modifier.PUBLIC) > 0 &&
|
||||
!m.isAnnotationPresent(WSInterface.WSDisabled.class)){
|
||||
WSMethodDef method = new WSMethodDef(m);
|
||||
methods.put(method.getName(), method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class that defines this web service
|
||||
*/
|
||||
public Class<? extends WSInterface> getWSClass(){
|
||||
return intf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the Service (usually the class name of the WSInterface)
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a Set of all the method names
|
||||
*/
|
||||
public Set<String> getMethodNames(){
|
||||
return methods.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the methods
|
||||
*/
|
||||
public Collection<WSMethodDef> getMethods(){
|
||||
return methods.values();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue