use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class OperationProcessor method addCallbackMethod.
private void addCallbackMethod(JavaMethod method) throws ToolException {
JavaMethod callbackMethod = new JavaMethod(method.getInterface());
callbackMethod.setAsync(true);
callbackMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
callbackMethod.setStyle(method.getStyle());
callbackMethod.setWrapperStyle(method.isWrapperStyle());
callbackMethod.setSoapAction(method.getSoapAction());
callbackMethod.setOperationName(method.getOperationName());
JavaReturn future = new JavaReturn();
future.setClassName("Future<?>");
callbackMethod.setReturn(future);
// REVISIT: test the operation name in the annotation
callbackMethod.annotate(new WebMethodAnnotator());
callbackMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
callbackMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
callbackMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
String asyncCname = null;
for (JavaParameter param : method.getParameters()) {
if (convertOutToAsync) {
if (param.isHolder()) {
if (param.isINOUT()) {
JavaParameter p2 = new JavaParameter();
p2.setName(param.getName());
p2.setClassName(param.getHolderName());
p2.setStyle(JavaType.Style.IN);
callbackMethod.addParameter(p2);
for (String s : param.getAnnotationTags()) {
JAnnotation ann = param.getAnnotation(s);
p2.addAnnotation(s, ann);
}
} else if (!param.isHeader() && asyncCname == null) {
asyncCname = param.getClassName();
}
} else {
callbackMethod.addParameter(param);
}
} else {
callbackMethod.addParameter(param);
}
}
JavaParameter asyncHandler = new JavaParameter();
asyncHandler.setName("asyncHandler");
asyncHandler.setCallback(true);
asyncHandler.setClassName(getAsyncClassName(method, "AsyncHandler", asyncCname));
asyncHandler.setStyle(JavaType.Style.IN);
callbackMethod.addParameter(asyncHandler);
JAnnotation asyncHandlerAnnotation = new JAnnotation(WebParam.class);
asyncHandlerAnnotation.addElement(new JAnnotationElement("name", "asyncHandler"));
asyncHandlerAnnotation.addElement(new JAnnotationElement("targetNamespace", ""));
asyncHandler.addAnnotation("WebParam", asyncHandlerAnnotation);
method.getInterface().addImport("javax.jws.WebParam");
method.getInterface().addMethod(callbackMethod);
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class ParameterProcessor method processInput.
private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
if (requireOutOfBandHeader()) {
try {
Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory");
} catch (Exception e) {
LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString());
}
}
JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class);
for (MessagePartInfo part : inputMessage.getMessageParts()) {
if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) {
continue;
}
JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN);
if (mBinding != null && mBinding.getJaxwsParas() != null) {
for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
if (part.getName().getLocalPart().equals(jwp.getPart())) {
param.setName(jwp.getName());
}
}
}
addParameter(part, method, param);
}
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class ParameterProcessor method getParameterFromQName.
private JavaParameter getParameterFromQName(QName wrapperElement, QName item, JavaType.Style style, MessagePartInfo part) {
String fullJavaName = "";
fullJavaName = this.dataBinding.getWrappedElementType(wrapperElement, item);
String targetNamespace = item.getNamespaceURI();
String jpname = ProcessorUtil.mangleNameToVariableName(item.getLocalPart());
JavaParameter parameter = new JavaParameter(jpname, fullJavaName, targetNamespace);
parameter.setStyle(style);
parameter.setQName(item);
parameter.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriterForWrappedElement(part, context, item));
if (style == JavaType.Style.OUT || style == JavaType.Style.INOUT) {
parameter.setHolder(true);
parameter.setHolderName(javax.xml.ws.Holder.class.getName());
String holderClass = fullJavaName;
if (JAXBUtils.holderClass(fullJavaName) != null) {
holderClass = JAXBUtils.holderClass(fullJavaName).getName();
}
parameter.setClassName(holderClass);
}
return parameter;
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class ParameterProcessorTest method testAddParameter.
@Test
public void testAddParameter() throws Exception {
ParameterProcessor processor = new ParameterProcessor(new ToolContext());
JavaMethod method = new JavaMethod();
JavaParameter p1 = new JavaParameter("request", String.class.getName(), null);
p1.setStyle(JavaType.Style.IN);
processor.addParameter(null, method, p1);
JavaParameter p2 = new JavaParameter("request", String.class.getName(), null);
p2.setStyle(JavaType.Style.OUT);
processor.addParameter(null, method, p2);
assertEquals(1, method.getParameters().size());
assertEquals(JavaType.Style.INOUT, method.getParameters().get(0).getStyle());
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class WebParamAnnotatorTest method setUp.
@Before
public void setUp() {
method = new JavaMethod();
parameter = new JavaParameter();
parameter.setMethod(method);
}
Aggregations