*
* Build service endpoint interface model, also build fault model if any.
*
*/
public WSCodeGenModel buildSEIModel() {
WSCodeGenModel cgModel = new WSCodeGenModel();
for (Service service : wsModel.getServices()) {
for (Port port : service.getPorts()) {
if (port.isProvider()) {
continue; // Not generating for Provider based endpoint
}
SEIInfo seiInfo = new SEIInfo();
JavaInterface intf = port.getJavaInterface();
// fqn class name
String className = intf.getName();
// If the interface has already been defined, just skip it.
if (interfaceClassNames.contains(className)) {
continue;
}
interfaceClassNames.add(className);
// package name of this interface
String packageName = ClassNameUtil.getPackageName(className);
seiInfo.setPackageName(packageName);
// simple class name
// String simpleName = intf.getSimpleName();
String simpleName = ClassNameUtil.stripQualifier(className);
seiInfo.setName(simpleName);
// java doc of this interface
String ptDoc = intf.getJavaDoc();
seiInfo.setDocComment(ptDoc);
// @WebService
seiInfo.setWebServiceAnnotation(getWebServiceAnnotation(port));
// @SOAPBinding
seiInfo.setSoapBindingAnnotation(getSOAPBindingAnnotation(port));
for (Operation operation: port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
MethodInfo methodInfo = new MethodInfo();
// method name
methodInfo.setName(method.getName());
// method doc comment
String methodJavaDoc = operation.getJavaDoc();
if (methodJavaDoc == null) {
methodJavaDoc = "public method";
}
// method return type
String returnTypeName;
if(method.getReturnType().getName().equals("void")){
returnTypeName = "void";
} else {
returnTypeName = method.getReturnType().getType()
.getName();
}
if (this.isWrapped(operation)) { // wrapped response
Response response = operation.getResponse();
Block resBlock = response.getBodyBlocks().next();
returnTypeName = resBlock.getType().getJavaType().getName();
}
TypeInfo returnType = new TypeInfo();
returnType.setFullName(returnTypeName);
returnType.setName(ClassNameUtil
.stripQualifier(returnTypeName));
methodInfo.setReturnType(returnType);
methodInfo.setWebMethodAnnotation(getWebMethodAnnotation(operation, method.getName()));
methodInfo.setWebResultAnnotation(getWebResultAnnotation(operation));
methodInfo.setSoapBindingAnnotation(getSOAPBindingAnnotation(operation));
if (this.isWrapped(operation)) { // wrapped request parameter
Block reqBlock = operation.getRequest().getBodyBlocks().next();
String parameterTypeName = reqBlock.getType().getJavaType().getName();
ParameterInfo paramInfo = new ParameterInfo();
paramInfo.setName("request");
// param type
TypeInfo paramType = new TypeInfo();
paramType.setFullName(parameterTypeName);
paramType.setName(ClassNameUtil
.stripQualifier(parameterTypeName));
paramInfo.setType(paramType);
// add this param in method definition
methodInfo.getParameters().add(paramInfo);
} else {
for (JavaParameter parameter : method.getParametersList()) {
ParameterInfo paramInfo = new ParameterInfo();
// param name
paramInfo.setName(parameter.getName());
// param type
TypeInfo paramType = new TypeInfo();
paramType.setFullName(parameter.getType().getName());
paramType.setName(ClassNameUtil
.stripQualifier(parameter.getType().getName()));
paramInfo.setType(paramType);
// @WebParam
paramInfo.setWebParamAnnotation(getWebParamAnnotation(operation, parameter));
// add this param in method definition
methodInfo.getParameters().add(paramInfo);
//methodJavaDoc += NEW_LINE + "@param " + parameter.getName();
}
}
// Fault
for(Fault fault : operation.getFaultsSet()) {
String faultClassName = Names.customExceptionClassName(fault);
FaultInfo faultInfo = null;
if (faults.containsKey(faultClassName)) {
faultInfo = faults.get(faultClassName);
} else {
faultInfo = getFaultInfo(fault);
// also put the fault model into the codegen model
cgModel.getFaults().add(faultInfo);
faults.put(faultClassName, faultInfo);
}
methodInfo.getThrows().add(faultInfo);
}
methodInfo.setDocComment(methodJavaDoc);
seiInfo.getMethods().add(methodInfo);
}
// add this endpoint interface in the codegen
// model
cgModel.getServiceEndpointInterfaces().add(seiInfo);
}
}
return cgModel;
}