use of com.sun.xml.ws.model.WrapperParameter in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method sortMethodParameters.
/**
* Sorts the parameters for the method by their position
* @param method the {@link JavaMethod} used to sort the parameters
* @return the sorted {@link List} of parameters
*/
protected List<ParameterImpl> sortMethodParameters(JavaMethodImpl method) {
Set<ParameterImpl> paramSet = new HashSet<>();
List<ParameterImpl> sortedParams = new ArrayList<>();
if (isRpcLit(method)) {
for (ParameterImpl param : method.getRequestParameters()) {
if (param instanceof WrapperParameter) {
paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
} else {
paramSet.add(param);
}
}
for (ParameterImpl param : method.getResponseParameters()) {
if (param instanceof WrapperParameter) {
paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
} else {
paramSet.add(param);
}
}
} else {
paramSet.addAll(method.getRequestParameters());
paramSet.addAll(method.getResponseParameters());
}
Iterator<ParameterImpl> params = paramSet.iterator();
if (paramSet.isEmpty())
return sortedParams;
ParameterImpl param = params.next();
sortedParams.add(param);
ParameterImpl sortedParam;
int pos;
for (int i = 1; i < paramSet.size(); i++) {
param = params.next();
for (pos = 0; pos < i; pos++) {
sortedParam = sortedParams.get(pos);
if (param.getIndex() == sortedParam.getIndex() && param instanceof WrapperParameter)
break;
if (param.getIndex() < sortedParam.getIndex()) {
break;
}
}
sortedParams.add(pos, param);
}
return sortedParams;
}
use of com.sun.xml.ws.model.WrapperParameter in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generateBindingOperation.
protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
BindingOperationType operation = binding.operation().name(method.getOperationName());
extension.addBindingOperationExtension(operation, method);
String targetNamespace = model.getTargetNamespace();
QName requestMessage = new QName(targetNamespace, method.getOperationName());
List<ParameterImpl> bodyParams = new ArrayList<>();
List<ParameterImpl> headerParams = new ArrayList<>();
splitParameters(bodyParams, headerParams, method.getRequestParameters());
SOAPBinding soapBinding = method.getBinding();
operation.soapOperation().soapAction(soapBinding.getSOAPAction());
// input
TypedXmlWriter input = operation.input();
extension.addBindingOperationInputExtension(input, method);
BodyType body = input._element(Body.class);
boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
if (soapBinding.getUse() == Use.LITERAL) {
body.use(LITERAL);
if (headerParams.size() > 0) {
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().next();
if (isRpc) {
StringBuilder parts = new StringBuilder();
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0)
parts.append(' ');
parts.append(parameter.getPartName());
}
body.parts(parts.toString());
} else {
body.parts(param.getPartName());
}
} else {
body.parts("");
}
generateSOAPHeaders(input, headerParams, requestMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
} else {
// TODO localize this
throw new WebServiceException("encoded use is not supported");
}
if (method.getMEP() != MEP.ONE_WAY) {
// output
bodyParams.clear();
headerParams.clear();
splitParameters(bodyParams, headerParams, method.getResponseParameters());
TypedXmlWriter output = operation.output();
extension.addBindingOperationOutputExtension(output, method);
body = output._element(Body.class);
body.use(LITERAL);
if (headerParams.size() > 0) {
StringBuilder parts = new StringBuilder();
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
if (param != null) {
if (isRpc) {
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0) {
parts.append(" ");
}
parts.append(parameter.getPartName());
}
} else {
parts = new StringBuilder(param.getPartName());
}
}
}
body.parts(parts.toString());
QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
generateSOAPHeaders(output, headerParams, responseMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
}
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
Fault fault = operation.fault().name(exception.getMessageName());
extension.addBindingOperationFaultExtension(fault, method, exception);
SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
soapFault.use(LITERAL);
}
}
use of com.sun.xml.ws.model.WrapperParameter in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generateSOAPMessages.
/**
* Generates messages for a SOAPBinding
* @param method The {@link JavaMethod} to generate messages for
* @param binding The {@link com.sun.xml.ws.api.model.soap.SOAPBinding} to add the generated messages to
*/
protected void generateSOAPMessages(JavaMethodImpl method, com.sun.xml.ws.api.model.soap.SOAPBinding binding) {
boolean isDoclit = binding.isDocLit();
// Message message = portDefinitions.message().name(method.getOperation().getName().getLocalPart());
Message message = portDefinitions.message().name(method.getRequestMessageName());
extension.addInputMessageExtension(message, method);
com.sun.xml.ws.wsdl.writer.document.Part part;
BindingContext jaxbContext = model.getBindingContext();
boolean unwrappable = true;
for (ParameterImpl param : method.getRequestParameters()) {
if (isDoclit) {
if (isHeaderParameter(param))
unwrappable = false;
part = message.part().name(param.getPartName());
part.element(param.getName());
} else {
if (param.isWrapperStyle()) {
for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
part = message.part().name(childParam.getPartName());
part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
}
} else {
part = message.part().name(param.getPartName());
part.element(param.getName());
}
}
}
if (method.getMEP() != MEP.ONE_WAY) {
message = portDefinitions.message().name(method.getResponseMessageName());
extension.addOutputMessageExtension(message, method);
for (ParameterImpl param : method.getResponseParameters()) {
if (isDoclit) {
part = message.part().name(param.getPartName());
part.element(param.getName());
} else {
if (param.isWrapperStyle()) {
for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
part = message.part().name(childParam.getPartName());
part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
}
} else {
part = message.part().name(param.getPartName());
part.element(param.getName());
}
}
}
}
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
QName tagName = exception.getDetailType().tagName;
String messageName = exception.getMessageName();
QName messageQName = new QName(model.getTargetNamespace(), messageName);
if (processedExceptions.contains(messageQName))
continue;
message = portDefinitions.message().name(messageName);
extension.addFaultMessageExtension(message, method, exception);
// tagName.getLocalPart());
part = message.part().name("fault");
part.element(tagName);
processedExceptions.add(messageQName);
}
}
use of com.sun.xml.ws.model.WrapperParameter in project metro-jax-ws by eclipse-ee4j.
the class TieHandler method createResponseMessageBuilder.
/**
* prepare objects for creating response {@link Message}
*/
private EndpointResponseMessageBuilder createResponseMessageBuilder(List<MessageFiller> fillers) {
EndpointResponseMessageBuilder tmpBodyBuilder = null;
List<ParameterImpl> rp = javaMethodModel.getResponseParameters();
for (ParameterImpl param : rp) {
ValueGetter getter = ValueGetter.get(param);
switch(param.getOutBinding().kind) {
case BODY:
if (param.isWrapperStyle()) {
if (param.getParent().getBinding().isRpcLit()) {
tmpBodyBuilder = new EndpointResponseMessageBuilder.RpcLit((WrapperParameter) param, soapVersion);
} else {
tmpBodyBuilder = new EndpointResponseMessageBuilder.DocLit((WrapperParameter) param, soapVersion);
}
} else {
tmpBodyBuilder = new EndpointResponseMessageBuilder.Bare(param, soapVersion);
}
break;
case HEADER:
fillers.add(new MessageFiller.Header(param.getIndex(), param.getXMLBridge(), getter));
break;
case ATTACHMENT:
fillers.add(MessageFiller.AttachmentFiller.createAttachmentFiller(param, getter));
break;
case UNBOUND:
break;
default:
// impossible
throw new AssertionError();
}
}
if (tmpBodyBuilder == null) {
// no parameter binds to body. we create an empty message
switch(soapVersion) {
case SOAP_11:
tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP11;
break;
case SOAP_12:
tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP12;
break;
default:
throw new AssertionError();
}
}
return tmpBodyBuilder;
}
use of com.sun.xml.ws.model.WrapperParameter in project metro-jax-ws by eclipse-ee4j.
the class JAXBContextFactory method newContext.
@Override
protected BindingContext newContext(BindingInfo bi) {
Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
Map<String, Object> properties = new HashMap<>();
Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
// chen workaround for document-literal wrapper - new feature on eclipselink API requested
for (TypeInfo tinfo : map.keySet()) {
WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
if (wp != null) {
Class<?> wrpCls = (Class) tinfo.type;
Element javaAttributes = null;
for (ParameterImpl p : wp.getWrapperChildren()) {
Element xmlelem = findXmlElement(p.getTypeInfo().properties());
if (xmlelem != null) {
if (javaAttributes == null) {
javaAttributes = javaAttributes(wrpCls, extMapping);
}
xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
String fieldName = getFieldName(p, wrpCls);
xmlelem.setAttribute("java-attribute", fieldName);
javaAttributes.appendChild(xmlelem);
}
}
if (wrpCls.getPackage() != null)
wrpCls.getPackage().getName();
}
}
// Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
// if (src != null){
// TransformerFactory tf = TransformerFactory.newInstance();
// try {
// Transformer t = tf.newTransformer();
// java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
// StreamResult sax = new StreamResult(bo);
// t.transform(src, sax);
// System.out.println(new String(bo.toByteArray()));
// } catch (TransformerConfigurationException e) {
// e.printStackTrace();
// throw new WebServiceException(e.getMessage(), e);
// } catch (TransformerException e) {
// e.printStackTrace();
// throw new WebServiceException(e.getMessage(), e);
// }
// }
HashSet<Type> typeSet = new HashSet<>();
HashSet<TypeMappingInfo> typeList = new HashSet<>();
for (TypeMappingInfo tmi : map.values()) {
typeList.add(tmi);
typeSet.add(tmi.getType());
}
for (Class<?> clss : bi.contentClasses()) {
if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
typeSet.add(clss);
TypeMappingInfo tmi = new TypeMappingInfo();
tmi.setType(clss);
typeList.add(tmi);
}
}
TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
if (extMapping != null) {
properties.put(OXM_XML_OVERRIDE, extMapping);
}
if (bi.getDefaultNamespace() != null) {
properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
}
try {
org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
} catch (JAXBException e) {
throw new DatabindingException(e.getMessage(), e);
}
}
Aggregations