You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.9 KiB
Java
97 lines
2.9 KiB
Java
package cokr.xit.interfaces.sntris;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Function;
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
import org.apache.axis.constants.Style;
|
|
import org.apache.axis.constants.Use;
|
|
import org.apache.axis.description.ElementDesc;
|
|
import org.apache.axis.description.OperationDesc;
|
|
import org.apache.axis.description.ParameterDesc;
|
|
import org.apache.axis.description.TypeDesc;
|
|
|
|
import cokr.xit.foundation.AbstractComponent;
|
|
|
|
public class Descriptor extends AbstractComponent {
|
|
private String urn;
|
|
|
|
public Descriptor(String urn) {
|
|
this.urn = urn;
|
|
}
|
|
|
|
public QName qname(String name) {
|
|
return qname(urn, name);
|
|
}
|
|
|
|
public QName qname(String urn, String name) {
|
|
return new QName(!isEmpty(urn) ? "urn:" + urn : "", name);
|
|
}
|
|
|
|
private static final List<String> langTypes = List.of("string", "int", "long", "double", "boolean");
|
|
|
|
public QName oftype(String typeName) {
|
|
typeName = typeName.replace("[]", "");
|
|
|
|
return langTypes.contains(typeName.toLowerCase()) ?
|
|
new QName("http://www.w3.org/2001/XMLSchema", typeName) :
|
|
qname(typeName);
|
|
}
|
|
|
|
public TypeDesc type(Class<?> klass, Function<Descriptor, ElementDesc[]> fields) {
|
|
TypeDesc typeDesc = new TypeDesc(klass, true);
|
|
typeDesc.setXmlType(qname(klass.getSimpleName()));
|
|
|
|
if (fields != null)
|
|
for (ElementDesc field: fields.apply(this))
|
|
typeDesc.addFieldDesc(field);
|
|
|
|
return typeDesc;
|
|
}
|
|
|
|
public ElementDesc field(String name, String type, boolean nullable) {
|
|
return field(name, qname(name), type, nullable);
|
|
}
|
|
|
|
public ElementDesc field(String name, QName qname, String type, boolean nullable) {
|
|
ElementDesc elemField = new ElementDesc();
|
|
elemField.setFieldName(name);
|
|
elemField.setXmlName(qname);
|
|
elemField.setXmlType(oftype(type));
|
|
elemField.setNillable(nullable);
|
|
return elemField;
|
|
}
|
|
|
|
public ParameterDesc param(String name, Class<?> klass, boolean nullable) {
|
|
return param(qname(name), klass, nullable);
|
|
}
|
|
|
|
public ParameterDesc param(QName name, Class<?> klass, boolean nullable) {
|
|
String type = klass.getSimpleName();
|
|
if (List.of("String").contains(type))
|
|
type = type.toLowerCase();
|
|
|
|
ParameterDesc param = new ParameterDesc(name, ParameterDesc.IN, oftype(type), klass, false, false);
|
|
param.setNillable(nullable);
|
|
return param;
|
|
}
|
|
|
|
public OperationDesc operation(String name, Class<?> returnType, QName returnName, Function<Descriptor, ParameterDesc[]> params) {
|
|
OperationDesc oper = new OperationDesc();
|
|
oper.setName(name);
|
|
|
|
if (params != null)
|
|
for (ParameterDesc param: params.apply(this))
|
|
oper.addParameter(param);
|
|
|
|
String type = returnType.getSimpleName();
|
|
oper.setReturnType(oftype(type));
|
|
oper.setReturnClass(returnType);
|
|
oper.setReturnQName(returnName);
|
|
oper.setStyle(Style.WRAPPED);
|
|
oper.setUse(Use.LITERAL);
|
|
|
|
return oper;
|
|
}
|
|
} |