use of com.sun.tools.xjc.api.TypeAndAnnotation in project metro-jax-ws by eclipse-ee4j.
the class ModelerUtils method createRpcLitParameters.
public static List<Parameter> createRpcLitParameters(Message message, Block block, S2JJAXBModel jaxbModel, ErrorReceiverFilter errReceiver) {
RpcLitStructure rpcStruct = (RpcLitStructure) block.getType();
List<Parameter> parameters = new ArrayList<>();
for (MessagePart part : message.getParts()) {
if (!ModelerUtils.isBoundToSOAPBody(part))
continue;
QName name = part.getDescriptor();
TypeAndAnnotation typeAndAnn = jaxbModel.getJavaType(name);
if (typeAndAnn == null) {
String msgQName = "{" + message.getDefining().getTargetNamespaceURI() + "}" + message.getName();
errReceiver.error(part.getLocator(), ModelerMessages.WSDLMODELER_RPCLIT_UNKOWNSCHEMATYPE(name.toString(), part.getName(), msgQName));
throw new AbortException();
}
String type = typeAndAnn.getTypeClass().fullName();
type = ClassNameInfo.getGenericClass(type);
RpcLitMember param = new RpcLitMember(new QName("", part.getName()), type);
JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAndAnn));
param.setJavaType(javaType);
rpcStruct.addRpcLitMember(param);
Parameter parameter = ModelerUtils.createParameter(part.getName(), param, block);
parameter.setEmbedded(true);
parameters.add(parameter);
}
return parameters;
}
use of com.sun.tools.xjc.api.TypeAndAnnotation in project metro-jax-ws by eclipse-ee4j.
the class WSDLModeler method getDoclitParameters.
private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
if (parameterList.isEmpty()) {
return new ArrayList<>();
}
List<Parameter> params = new ArrayList<>();
Message inMsg = getInputMessage();
Message outMsg = getOutputMessage();
boolean unwrappable = isUnwrappable();
List<Parameter> outParams = null;
int pIndex = 0;
for (MessagePart part : parameterList) {
QName reqBodyName = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block block = new Block(reqBodyName, jaxbType, part);
if (unwrappable) {
// So build body and header blocks and set to request and response
JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
block = new Block(reqBodyName, jaxbStructType, part);
if (ModelerUtils.isBoundToSOAPBody(part)) {
if (part.isIN()) {
req.addBodyBlock(block);
} else if (part.isOUT()) {
res.addBodyBlock(block);
} else if (part.isINOUT()) {
req.addBodyBlock(block);
res.addBodyBlock(block);
}
} else if (ModelerUtils.isUnbound(part)) {
if (part.isIN()) {
req.addUnboundBlock(block);
} else if (part.isOUT()) {
res.addUnboundBlock(block);
} else if (part.isINOUT()) {
req.addUnboundBlock(block);
res.addUnboundBlock(block);
}
}
if (part.isIN() || part.isINOUT()) {
params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
int index = 0;
Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
for (Parameter param : params) {
param.setParameterIndex(index++);
param.setMode(mode);
setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
}
} else if (part.isOUT()) {
outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
for (Parameter param : outParams) {
param.setMode(Mode.OUT);
setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
}
}
} else {
if (ModelerUtils.isBoundToSOAPBody(part)) {
if (part.isIN()) {
req.addBodyBlock(block);
} else if (part.isOUT()) {
res.addBodyBlock(block);
} else if (part.isINOUT()) {
req.addBodyBlock(block);
res.addBodyBlock(block);
}
} else if (ModelerUtils.isBoundToSOAPHeader(part)) {
if (part.isIN()) {
req.addHeaderBlock(block);
} else if (part.isOUT()) {
res.addHeaderBlock(block);
} else if (part.isINOUT()) {
req.addHeaderBlock(block);
res.addHeaderBlock(block);
}
} else if (ModelerUtils.isBoundToMimeContent(part)) {
List<MIMEContent> mimeContents;
if (part.isIN()) {
mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
req.addAttachmentBlock(block);
} else if (part.isOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
res.addAttachmentBlock(block);
} else if (part.isINOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
req.addAttachmentBlock(block);
res.addAttachmentBlock(block);
mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
JAXBType outJaxbType = getAttachmentType(mimeContents, part);
String inType = jaxbType.getJavaType().getType().getName();
String outType = outJaxbType.getJavaType().getType().getName();
TypeAndAnnotation inTa = jaxbType.getJavaType().getType().getTypeAnn();
TypeAndAnnotation outTa = outJaxbType.getJavaType().getType().getTypeAnn();
if ((((inTa != null) && (outTa != null) && inTa.equals(outTa))) && !inType.equals(outType)) {
String javaType = "jakarta.activation.DataHandler";
// S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
// JCodeModel cm = jaxbModel.generateCode(null, errReceiver);
JType jt = options.getCodeModel().ref(javaType);
JAXBTypeAndAnnotation jaxbTa = jaxbType.getJavaType().getType();
jaxbTa.setType(jt);
}
}
} else if (ModelerUtils.isUnbound(part)) {
if (part.isIN()) {
req.addUnboundBlock(block);
} else if (part.isOUT()) {
res.addUnboundBlock(block);
} else if (part.isINOUT()) {
req.addUnboundBlock(block);
res.addUnboundBlock(block);
}
}
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
param.setMode(part.getMode());
if (part.isReturn()) {
param.setParameterIndex(-1);
} else {
param.setParameterIndex(pIndex++);
}
if (part.isIN()) {
setCustomizedParameterName(info.bindingOperation, inMsg, part, param, false);
} else if (outMsg != null) {
setCustomizedParameterName(info.bindingOperation, outMsg, part, param, false);
}
params.add(param);
}
}
if (unwrappable && (outParams != null)) {
int index = params.size();
for (Parameter param : outParams) {
if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
param.setParameterIndex(-1);
} else {
Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
if ((inParam != null) && inParam.isIN()) {
QName inElementName = inParam.getType().getName();
QName outElementName = param.getType().getName();
String inJavaType = inParam.getTypeName();
String outJavaType = param.getTypeName();
TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
QName outRawTypeName = ModelerUtils.getRawTypeName(param);
if (inElementName.getLocalPart().equals(outElementName.getLocalPart()) && inJavaType.equals(outJavaType) && (inTa == null || outTa == null || inTa.equals(outTa)) && (inRawTypeName == null || outRawTypeName == null || inRawTypeName.equals(outRawTypeName))) {
inParam.setMode(Mode.INOUT);
continue;
}
}
if (outParams.size() == 1) {
param.setParameterIndex(-1);
} else {
param.setParameterIndex(index++);
}
}
params.add(param);
}
}
return params;
}
use of com.sun.tools.xjc.api.TypeAndAnnotation in project metro-jax-ws by eclipse-ee4j.
the class WSDLModeler method getAttachmentType.
private JAXBType getAttachmentType(List<MIMEContent> mimeContents, MessagePart part) {
if (!enableMimeContent()) {
return getJAXBType(part);
}
String javaType;
List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
if (mimeTypes.size() > 1) {
javaType = "jakarta.activation.DataHandler";
} else {
javaType = getJavaTypeForMimeType(mimeTypes.get(0));
}
S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
JType jt = options.getCodeModel().ref(javaType);
QName desc = part.getDescriptor();
TypeAndAnnotation typeAnno = null;
if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
typeAnno = jaxbModel.getJavaType(desc);
desc = new QName("", part.getName());
} else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
if (typeAnno == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part.getDescriptor(), part.getName()));
}
for (String mimeType : mimeTypes) {
if ((!mimeType.equals("text/xml") && !mimeType.equals("application/xml"))) {
// According to AP 1.0,
// RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
// global element declaration (via the element attribute of the wsdl:part
// element) then the value of the type attribute of a mime:content element
// that binds that part MUST be a content type suitable for carrying an
// XML serialization.
// should we throw warning?
// type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
warning(part, ModelerMessages.MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(part.getName(), mimeType));
}
}
}
if (typeAnno == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part.getName()));
}
return new JAXBType(desc, new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno, jt)), null, getJAXBModelBuilder().getJAXBModel());
}
use of com.sun.tools.xjc.api.TypeAndAnnotation in project metro-jax-ws by eclipse-ee4j.
the class WSDLModeler method getJAXBType.
/**
* @return Returns a JAXBType object
*/
private JAXBType getJAXBType(MessagePart part) {
JAXBType type;
QName name = part.getDescriptor();
if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
type = getJAXBModelBuilder().getJAXBType(name);
if (type == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
}
} else {
S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
if (typeAnno == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
}
JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno));
type = new JAXBType(new QName("", part.getName()), javaType);
}
return type;
}
Aggregations