use of com.sun.tools.ws.processor.model.java.JavaParameter in project metro-jax-ws by eclipse-ee4j.
the class SeiGenerator method write.
private void write(Port port) {
JavaInterface intf = port.getJavaInterface();
String className = Names.customJavaTypeClassName(intf);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls;
try {
cls = getClass(className, ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
QName portTypeName = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
Locator loc = null;
if (portTypeName != null) {
PortType pt = port.portTypes.get(portTypeName);
if (pt != null) {
loc = pt.getLocator();
}
}
receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
return;
}
// so skip it.
if (!cls.methods().isEmpty()) {
return;
}
// write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
String ptDoc = intf.getJavaDoc();
if (ptDoc != null) {
comment.add(ptDoc);
comment.add("\n\n");
}
comment.addAll(getJAXWSClassComment());
// @WebService
JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
writeWebServiceAnnotation(port, webServiceAnn);
// @HandlerChain
writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options);
// @SOAPBinding
writeSOAPBinding(port, cls);
// @XmlSeeAlso
if (options.target.isLaterThan(Options.Target.V2_1)) {
writeXmlSeeAlso(cls);
}
for (Operation operation : port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
// @WebMethod
JMethod m;
JDocComment methodDoc;
String methodJavaDoc = operation.getJavaDoc();
if (method.getReturnType().getName().equals("void")) {
m = cls.method(JMod.PUBLIC, void.class, method.getName());
methodDoc = m.javadoc();
} else {
JAXBTypeAndAnnotation retType = method.getReturnType().getType();
m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
retType.annotate(m);
methodDoc = m.javadoc();
JCommentPart ret = methodDoc.addReturn();
ret.add("returns " + retType.getName());
}
if (methodJavaDoc != null) {
methodDoc.add(methodJavaDoc);
}
writeWebMethod(operation, m);
JClass holder = cm.ref(Holder.class);
for (JavaParameter parameter : method.getParametersList()) {
JVar var;
JAXBTypeAndAnnotation paramType = parameter.getType().getType();
if (parameter.isHolder()) {
var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
} else {
var = m.param(paramType.getType(), parameter.getName());
}
// annotate parameter with JAXB annotations
paramType.annotate(var);
methodDoc.addParam(var);
JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class));
writeWebParam(operation, parameter, paramAnn);
}
com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
for (Fault fault : operation.getFaultsSet()) {
m._throws(fault.getExceptionClass());
methodDoc.addThrows(fault.getExceptionClass());
wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
}
// It should be the last thing to invoke after JMethod is built completely
extension.writeMethodAnnotations(wsdlOp, m);
}
}
use of com.sun.tools.ws.processor.model.java.JavaParameter in project metro-jax-ws by eclipse-ee4j.
the class SeiGenerator method writeWebParam.
private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) {
Parameter param = javaParameter.getParameter();
Request req = operation.getRequest();
Response res = operation.getResponse();
boolean header = isHeaderParam(param, req) || (res != null && isHeaderParam(param, res));
String name;
boolean isWrapped = operation.isWrapped();
if ((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) {
name = param.getBlock().getName().getLocalPart();
} else {
name = param.getName();
}
paramAnno.param("name", name);
String ns = null;
if (isDocStyle) {
// its bare nsuri
ns = param.getBlock().getName().getNamespaceURI();
if (isWrapped) {
ns = param.getType().getName().getNamespaceURI();
}
} else if (header) {
ns = param.getBlock().getName().getNamespaceURI();
}
if (ns != null || (isDocStyle && isWrapped)) {
paramAnno.param("targetNamespace", ns);
}
if (header) {
paramAnno.param("header", true);
}
if (param.isINOUT()) {
paramAnno.param("mode", jakarta.jws.WebParam.Mode.INOUT);
} else if ((res != null) && (isMessageParam(param, res) || isHeaderParam(param, res) || isAttachmentParam(param, res) || isUnboundParam(param, res) || param.isOUT())) {
paramAnno.param("mode", jakarta.jws.WebParam.Mode.OUT);
}
// doclit wrapped could have additional headers
if (!(isDocStyle && isWrapped) || header) {
paramAnno.param("partName", javaParameter.getParameter().getName());
}
}
use of com.sun.tools.ws.processor.model.java.JavaParameter in project metro-jax-ws by eclipse-ee4j.
the class JwsImplGenerator method visit.
@Override
public void visit(Service service) {
QName serviceName = service.getName();
// process the ordered service only if it is defined
if (options.implServiceName != null && !equalsNSOptional(options.implServiceName, serviceName))
return;
for (Port port : service.getPorts()) {
if (port.isProvider()) {
// Not generating for Provider based endpoint
continue;
}
// Generate the impl class name according to
// Xpath(/definitions/service/port[@name]);
QName portName = port.getName();
// process the ordered port only if it is defined
if (options.implPortName != null && !equalsNSOptional(options.implPortName, portName))
continue;
String simpleClassName = serviceName.getLocalPart() + "_" + portName.getLocalPart() + "Impl";
String className = makePackageQualified(simpleClassName);
implFiles.add(className);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls = null;
try {
cls = getClass(className, ClassType.CLASS);
} catch (JClassAlreadyExistsException e) {
log("Class " + className + " generates failed. JClassAlreadyExistsException[" + className + "].");
return;
}
// Each serviceImpl will implements one port interface
JavaInterface portIntf = port.getJavaInterface();
String portClassName = Names.customJavaTypeClassName(portIntf);
JDefinedClass portCls = null;
try {
portCls = getClass(portClassName, ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
log("Class " + className + " generates failed. JClassAlreadyExistsException[" + portClassName + "].");
return;
}
cls._implements(portCls);
// create a default constructor
cls.constructor(JMod.PUBLIC);
// write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
if (service.getJavaDoc() != null) {
comment.add(service.getJavaDoc());
comment.add("\n\n");
}
comment.addAll(getJAXWSClassComment());
// @WebService
JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
writeWebServiceAnnotation(service, port, webServiceAnn);
// @BindingType
JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
writeBindingTypeAnnotation(port, bindingTypeAnn);
// extra annotation
for (GeneratorExtension f : findService(GeneratorExtension.class)) {
f.writeWebServiceAnnotation(model, cm, cls, port);
}
// WebMethods
for (Operation operation : port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
// @WebMethod
JMethod m;
JDocComment methodDoc;
String methodJavaDoc = operation.getJavaDoc();
if (method.getReturnType().getName().equals("void")) {
m = cls.method(JMod.PUBLIC, void.class, method.getName());
methodDoc = m.javadoc();
} else {
JAXBTypeAndAnnotation retType = method.getReturnType().getType();
m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
retType.annotate(m);
methodDoc = m.javadoc();
JCommentPart ret = methodDoc.addReturn();
ret.add("returns " + retType.getName());
}
if (methodJavaDoc != null)
methodDoc.add(methodJavaDoc);
JClass holder = cm.ref(Holder.class);
for (JavaParameter parameter : method.getParametersList()) {
JVar var;
JAXBTypeAndAnnotation paramType = parameter.getType().getType();
if (parameter.isHolder()) {
var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
} else {
var = m.param(paramType.getType(), parameter.getName());
}
methodDoc.addParam(var);
}
com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
for (Fault fault : operation.getFaultsSet()) {
m._throws(fault.getExceptionClass());
methodDoc.addThrows(fault.getExceptionClass());
wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
}
m.body().block().directStatement("//replace with your impl here");
m.body().block().directStatement(getReturnString(method.getReturnType().getName()));
}
}
}
Aggregations