public class ServiceUtils {
public static String simpleServiceXMLRequest(ServiceBean serviceInfo)
throws GFacSchemaException {
ServiceMapDocument serviceMapDocument = ServiceMapDocument.Factory
.newInstance();
ServiceMapType serviceMapType = serviceMapDocument.addNewServiceMap();
ServiceType serviceType = serviceMapType.addNewService();
serviceType.setServiceDescription(serviceInfo.getServiceDescription());
QName serviceQName;
if (serviceInfo.getServiceName().startsWith("{")) {
serviceQName = QName.valueOf(serviceInfo.getServiceName().trim());
} else {
serviceQName = new QName(serviceInfo.getObjectNamespace(),
serviceInfo.getServiceName().trim());
}
ServiceName serviceName = serviceType.getServiceName();
if (serviceName == null) {
serviceName = serviceType.addNewServiceName();
;
}
serviceName.setStringValue(serviceQName.getLocalPart());
serviceName.setTargetNamespace(serviceInfo.getObjectNamespace());
PortTypeType pt;
if (serviceMapType.getPortTypeArray() != null
&& serviceMapType.getPortTypeArray().length > 0) {
pt = serviceMapType.getPortTypeArray(0);
} else {
pt = serviceMapType.addNewPortType();
}
// ArrayList<MethodBean> operations = serviceInfo.getOperations();
List<MethodBean> operations = new ArrayList<MethodBean>();
operations.add(serviceInfo.getMethodBean());
for (int i = 0; i < operations.size(); i++) {
MethodBean op = (MethodBean) operations.get(i);
if (op == null) {
throw new GFacSchemaException("Operation can not be Null");
}
MethodType[] methods = pt.getMethodArray();
MethodType method = null;
if (methods != null) {
for (MethodType oldMethod : methods) {
if (op.getMethodName().equals(oldMethod.getMethodName())) {
method = oldMethod;
}
}
}
if (method == null) {
method = pt.addNewMethod();
}
method.setMethodName(op.getMethodName());
method.setMethodDescription(op.getMethodDescription());
ApplicationType appType = method.getApplication();
if (appType == null) {
appType = method.addNewApplication();
}
appType.setParamValuesOnly(true);
ApplicationName appNameType = appType.getApplicationName();
if (appNameType == null) {
appNameType = appType.addNewApplicationName();
}
QName appName = new QName(serviceInfo.getObjectNamespace(),
serviceInfo.getApplicationName());
appNameType.setStringValue(appName.getLocalPart());
appNameType.setTargetNamespace(appName.getNamespaceURI());
appType.setApplicationDescription(op.getMethodDescription());
// Boolean parameters from Service screen
if (op.isStageOutputDataFiles()) {
method.setStageOutputDataFiles(true);
}
if (op.isForceFileStagingToWorkDir()) {
method.setForceFileStagingToWorkDir(true);
}
if (op.isUseLEADNameListFile()) {
appType.setUseLEADNameListFile(true);
}
if (op.isUseLEADNameListPropertiesFile()) {
appType.setUseLEADNameListPropertiesFile(true);
}
InputParameterType[] inputs = method.getInputParameterArray();
HashMap<String, InputParameterType> inputMap = new HashMap<String, InputParameterType>();
if (inputs != null) {
for (InputParameterType inputParameterType : inputs) {
inputMap.put(inputParameterType.getParameterName(),
inputParameterType);
}
}
OutputParameterType[] outputs = method.getOutputParameterArray();
HashMap<String, OutputParameterType> outputMap = new HashMap<String, OutputParameterType>();
if (inputs != null) {
for (OutputParameterType outputParameterType : outputs) {
outputMap.put(outputParameterType.getParameterName(),
outputParameterType);
}
}
ArrayList<ParamObject> inputparams = op.getInputParms();
for (int y = 0; y < inputparams.size(); y++) {
ParamObject param = (ParamObject) inputparams.get(y);
InputParameterType inputParm = inputMap.get(param.getName());
if (inputParm == null) {
inputParm = method.addNewInputParameter();
}
inputParm.setParameterName(param.getName());
inputParm.setParameterDescription(param.getDesc());
InputDataType.Enum type = InputDataType.Enum.forString(param
.getType());
inputParm.setParameterType(type);
}
ArrayList<ParamObject> outputparams = op.getOutputParms();
for (int y = 0; y < outputparams.size(); y++) {
ParamObject param = (ParamObject) outputparams.get(y);
OutputParameterType outputParm = outputMap.get(param.getName());
if (outputParm == null) {
outputParm = method.addNewOutputParameter();
}
outputParm.setParameterName(param.getName());
outputParm.setParameterDescription(param.getDesc());
OutputDataType.Enum type = OutputDataType.Enum.forString(param
.getType());
outputParm.setParameterType(type);
}
}
if (serviceInfo.getNotAfterInactiveMinutes() != 0) {
if (serviceMapType.getLifeTime() == null) {
serviceMapType.addNewLifeTime().setNotAfterInactiveMinutes(
serviceInfo.getNotAfterInactiveMinutes());
} else {
serviceMapType.getLifeTime().setNotAfterInactiveMinutes(
serviceInfo.getNotAfterInactiveMinutes());
}
}
SchemaValidator validator = new SchemaValidator(serviceMapType);
validator.validate();
return serviceMapDocument.xmlText();
}