use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class ServiceProcessor method processMultipart.
public void processMultipart(JavaMethod jm, BindingOperationInfo operation, MIMEMultipartRelated ext, JavaType.Style style) throws ToolException {
List<MIMEPart> mimeParts = CastUtils.cast(ext.getMIMEParts());
for (MIMEPart mPart : mimeParts) {
List<ExtensibilityElement> extns = CastUtils.cast(mPart.getExtensibilityElements());
for (ExtensibilityElement extElement : extns) {
if (extElement instanceof MIMEContent) {
MIMEContent mimeContent = (MIMEContent) extElement;
String mimeJavaType = getJavaTypeForMimeType(mPart);
if (JavaType.Style.IN.equals(style)) {
String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
JavaParameter jp = jm.getParameter(paramName);
if (jp == null) {
Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
throw new ToolException(message);
}
if (!jp.getClassName().equals(mimeJavaType)) {
// jp.setType(mimeJavaType);
jp.setClassName(mimeJavaType);
}
} else if (JavaType.Style.OUT.equals(style)) {
JavaType jp = null;
if (!"void".equals(jm.getReturn().getType()) && mimeContent.getPart().equals(jm.getReturn().getName())) {
jp = jm.getReturn();
jp.setClassName(mimeJavaType);
}
if (jp == null) {
for (JavaParameter para : jm.getParameters()) {
if (mimeContent.getPart().equals(para.getPartName())) {
jp = para;
}
}
if (jp != null) {
((JavaParameter) jp).setClassName(mimeJavaType);
}
}
if (jp == null) {
Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
throw new ToolException(message);
}
}
} else if (extElement instanceof SOAPHeader) {
processSoapHeader(jm, operation, extElement);
}
}
}
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class ServiceProcessor method processParameter.
private void processParameter(JavaMethod jm, BindingOperationInfo operation) throws ToolException {
// process input
List<ExtensibilityElement> inbindings = null;
if (operation.getInput() != null) {
inbindings = operation.getInput().getExtensors(ExtensibilityElement.class);
}
if (inbindings == null) {
inbindings = new ArrayList<>();
}
String use = null;
for (ExtensibilityElement ext : inbindings) {
if (SOAPBindingUtil.isSOAPBody(ext)) {
SoapBody soapBody = SOAPBindingUtil.getSoapBody(ext);
use = soapBody.getUse();
} else if (SOAPBindingUtil.isSOAPHeader(ext)) {
processSoapHeader(jm, operation, ext);
}
if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.IN);
}
}
// process output
if (operation.getOutput() != null) {
List<ExtensibilityElement> outbindings = operation.getOutput().getExtensors(ExtensibilityElement.class);
if (outbindings == null) {
outbindings = new ArrayList<>();
}
for (ExtensibilityElement ext : outbindings) {
if (SOAPBindingUtil.isSOAPHeader(ext)) {
SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
if (isOutOfBandHeader(operation.getOutput(), ext)) {
continue;
}
boolean found = false;
for (JavaParameter parameter : jm.getParameters()) {
if (soapHeader.getPart().equals(parameter.getPartName())) {
setParameterAsHeader(parameter);
found = true;
}
}
if (jm.getReturn().getName() != null && jm.getReturn().getName().equals(soapHeader.getPart())) {
found = true;
}
if (Boolean.valueOf((String) context.get(ToolConstants.CFG_EXTRA_SOAPHEADER)) && !found) {
// Header can't be found in java method parameters, in
// different message
// other than messages used in porttype operation
ParameterProcessor processor = new ParameterProcessor(context);
MessagePartInfo exPart = service.getMessage(soapHeader.getMessage()).getMessagePart(new QName(soapHeader.getMessage().getNamespaceURI(), soapHeader.getPart()));
JavaParameter jp = processor.addParameterFromBinding(jm, exPart, JavaType.Style.OUT);
setParameterAsHeader(jp);
}
}
if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.OUT);
}
}
}
jm.setSoapUse(SOAPBindingUtil.getSoapUse(use));
if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.ENCODED == jm.getSoapUse()) {
System.err.println("** Unsupported RPC-Encoded Style Use **");
}
if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
return;
}
if (javax.jws.soap.SOAPBinding.Style.DOCUMENT == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
return;
}
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class WebParamAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaParameter parameter = null;
if (ja instanceof JavaParameter) {
parameter = (JavaParameter) ja;
} else {
throw new RuntimeException("WebParamAnnotator only annotate the JavaParameter");
}
JavaMethod method = parameter.getMethod();
if (method.hasParameter(parameter.getName())) {
JavaParameter paramInList = method.getParameter(parameter.getName());
if (paramInList.isIN() && parameter.isOUT()) {
parameter.setStyle(JavaType.Style.INOUT);
}
}
JAnnotation webParamAnnotation = new JAnnotation(WebParam.class);
String name = parameter.getName();
String targetNamespace = method.getInterface().getNamespace();
String partName = null;
if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader()) {
targetNamespace = parameter.getTargetNamespace();
if (parameter.getQName() != null) {
name = parameter.getQName().getLocalPart();
}
if (!method.isWrapperStyle()) {
partName = parameter.getPartName();
}
}
if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
name = parameter.getPartName();
partName = parameter.getPartName();
}
if (partName != null) {
webParamAnnotation.addElement(new JAnnotationElement("partName", partName));
}
if (parameter.getStyle() == JavaType.Style.OUT) {
webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.OUT));
} else if (parameter.getStyle() == JavaType.Style.INOUT) {
webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.INOUT));
}
webParamAnnotation.addElement(new JAnnotationElement("name", name));
if (null != targetNamespace && (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader())) {
webParamAnnotation.addElement(new JAnnotationElement("targetNamespace", targetNamespace));
}
for (String importClz : webParamAnnotation.getImports()) {
parameter.getMethod().getInterface().addImport(importClz);
}
if (forceHeader) {
webParamAnnotation.addElement(new JAnnotationElement("header", true, true));
}
parameter.addAnnotation("WebParam", webParamAnnotation);
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class XmlJavaTypeAdapterAnnotator method annotate.
public void annotate(JavaAnnotatable jn) {
JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
if (jn instanceof JavaParameter) {
JavaParameter jp = (JavaParameter) jn;
jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else if (jn instanceof JavaMethod) {
JavaMethod jm = (JavaMethod) jn;
jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else {
throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
}
jf.addImport(XmlJavaTypeAdapter.class.getName());
jf.addImport(adapter.getName());
}
use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.
the class XmlListAnotator method annotate.
public void annotate(JavaAnnotatable jn) {
JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
if (jn instanceof JavaParameter) {
JavaParameter jp = (JavaParameter) jn;
jp.addAnnotation("XmlList", jaxbAnnotation);
} else if (jn instanceof JavaMethod) {
JavaMethod jm = (JavaMethod) jn;
jm.addAnnotation("XmlList", jaxbAnnotation);
} else {
throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
}
jf.addImport(XmlList.class.getName());
}
Aggregations