com.webcohesion.enunciate.modules.jaxws.model.ResponseWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enunciate-jaxws Show documentation
Show all versions of enunciate-jaxws Show documentation
Model processing for JAX-WS API.
/**
* Copyright © 2006-2016 Web Cohesion ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.webcohesion.enunciate.modules.jaxws.model;
import com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement;
import com.webcohesion.enunciate.modules.jaxb.model.ImplicitRootElement;
import javax.lang.model.type.TypeKind;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
* A response wrapper for a web method in document/literal wrapped style.
*
* @author Ryan Heaton
*/
public class ResponseWrapper implements WebMessage, WebMessagePart, ImplicitRootElement {
private WebMethod webMethod;
/**
* @param webMethod The web method to wrap.
*/
public ResponseWrapper(WebMethod webMethod) {
this.webMethod = webMethod;
}
/**
* Get the web method to which this response is associated.
*
* @return The web method to which this response is associated.
*/
public WebMethod getWebMethod() {
return webMethod;
}
/**
* The name of the JAXWS response bean.
*
* @return The name of the JAXWS response bean.
*/
public String getResponseBeanName() {
String capitalizedName = this.webMethod.getSimpleName().toString();
capitalizedName = Character.toString(capitalizedName.charAt(0)).toUpperCase() + capitalizedName.substring(1);
String responseBeanName = this.webMethod.getDeclaringEndpointInterface().getPackage().getQualifiedName() + ".jaxws." + capitalizedName + "Response";
javax.xml.ws.ResponseWrapper annotation = webMethod.getAnnotation(javax.xml.ws.ResponseWrapper.class);
if ((annotation != null) && (annotation.className() != null) && (!"".equals(annotation.className()))) {
responseBeanName = annotation.className();
}
return responseBeanName;
}
/**
* The local name of the output.
*
* @return The local name of the output.
*/
public String getElementName() {
String name = webMethod.getOperationName() + "Response";
javax.xml.ws.ResponseWrapper annotation = webMethod.getAnnotation(javax.xml.ws.ResponseWrapper.class);
if ((annotation != null) && (annotation.localName() != null) && (!"".equals(annotation.localName()))) {
name = annotation.localName();
}
return name;
}
// Inherited.
public String getTargetNamespace() {
return getElementNamespace();
}
/**
* The local namespace of the output.
*
* @return The local namespace of the output.
*/
public String getElementNamespace() {
String namespace = webMethod.getDeclaringEndpointInterface().getTargetNamespace();
javax.xml.ws.ResponseWrapper annotation = webMethod.getAnnotation(javax.xml.ws.ResponseWrapper.class);
if ((annotation != null) && (annotation.targetNamespace() != null) && (!"".equals(annotation.targetNamespace()))) {
namespace = annotation.targetNamespace();
}
return namespace;
}
/**
* Documentation explaining this is a response wrapper for its method.
*
* @return Documentation explaining this is a response wrapper for its method.
*/
public String getElementDocs() {
String docs = "doc/lit response wrapper for operation \"" + webMethod.getOperationName() + "\".";
String methodDocs = webMethod.getJavaDoc().toString();
if (methodDocs.trim().length() > 0) {
docs += " (" + methodDocs.trim() + ")";
}
return docs;
}
/**
* @return {@link ParticleType#ELEMENT}
*/
public ParticleType getParticleType() {
return ParticleType.ELEMENT;
}
/**
* The qname of the response element.
*
* @return The qname of the response element.
*/
public QName getParticleQName() {
return new QName(getElementNamespace(), getElementName());
}
/**
* @return true.
*/
public boolean isImplicitSchemaElement() {
return true;
}
/**
* The schema type for a response wrapper is always anonymous.
*
* @return null
*/
public QName getTypeQName() {
return null;
}
/**
* The collection of output parameters for this response.
*
* @return The collection of output parameters for this response.
*/
public Collection getChildElements() {
Collection childElements = new ArrayList();
if (webMethod.getReturnType().getKind() != TypeKind.VOID) {
WebResult webResult = webMethod.getWebResult();
if (!webResult.isHeader()) {
childElements.add(webResult);
}
}
for (WebParam webParam : webMethod.getWebParameters()) {
if (webParam.isOutput() && !webParam.isHeader()) {
childElements.add(webParam);
}
}
return childElements;
}
/**
* There's only one part to a doc/lit response wrapper.
*
* @return this.
*/
public Collection getParts() {
return new ArrayList(Arrays.asList(this));
}
/**
* @return false
*/
public boolean isInput() {
return false;
}
/**
* @return true
*/
public boolean isOutput() {
return true;
}
/**
* @return false
*/
public boolean isHeader() {
return false;
}
/**
* @return false
*/
public boolean isFault() {
return false;
}
/**
* The simple name of the method appended with "Response".
*
* @return The simple name of the method appended with "Response".
*/
public String getMessageName() {
return webMethod.getDeclaringEndpointInterface().getSimpleName() + "." + webMethod.getSimpleName() + "Response";
}
/**
* Documentation explaining this is a response message for its method.
*
* @return Documentation explaining this is a response message for its method.
*/
public String getMessageDocs() {
String docs = "response message for operation \"" + webMethod.getOperationName() + "\".";
String methodDocs = webMethod.getJavaDoc().toString();
if (methodDocs.trim().length() > 0) {
docs += " (" + methodDocs.trim() + ")";
}
return docs;
}
/**
* @return null
*/
public String getPartDocs() {
return null;
}
/**
* The simple name of the method appended with "Response".
*
* @return The simple name of the method appended with "Response".
*/
public String getPartName() {
return "parameters";
}
}