use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class WrapperClassGenerator method createWrapperClass.
// CHECKSTYLE:OFF
private void createWrapperClass(MessagePartInfo wrapperPart, MessageInfo messageInfo, OperationInfo op, Method method, boolean isRequest, Set<Class<?>> wrapperBeans, JaxWsServiceFactoryBean factory, InterfaceInfo interfaceInfo, boolean qualified) {
ASMHelper.ClassWriter cw = helper.createClassWriter();
if (cw == null) {
LOG.warning(op.getName() + " requires a wrapper bean but problems with" + " ASM has prevented creating one. Operation may not work correctly.");
return;
}
QName wrapperElement = messageInfo.getName();
boolean anonymous = factory.getAnonymousWrapperTypes();
String pkg = getPackageName(method) + ".jaxws_asm" + (anonymous ? "_an" : "");
String className = pkg + "." + StringUtils.capitalize(op.getName().getLocalPart());
if (!isRequest) {
className = className + "Response";
}
String pname = pkg + ".package-info";
Class<?> def = findClass(pname, method.getDeclaringClass());
if (def == null) {
generatePackageInfo(pname, wrapperElement.getNamespaceURI(), method.getDeclaringClass(), method, interfaceInfo, qualified);
}
def = findClass(className, method.getDeclaringClass());
String origClassName = className;
int count = 0;
while (def != null) {
Boolean b = messageInfo.getProperty("parameterized", Boolean.class);
if (b != null && b) {
className = origClassName + (++count);
def = findClass(className, method.getDeclaringClass());
} else {
wrapperPart.setTypeClass(def);
wrapperBeans.add(def);
return;
}
}
String classFileName = StringUtils.periodToSlashes(className);
OpcodesProxy opCodes = helper.getOpCodes();
cw.visit(opCodes.V1_5, opCodes.ACC_PUBLIC + opCodes.ACC_SUPER, classFileName, null, "java/lang/Object", null);
ASMHelper.AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
av0.visit("name", wrapperElement.getLocalPart());
av0.visit("namespace", wrapperElement.getNamespaceURI());
av0.visitEnd();
av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
av0.visitEnd();
av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
if (!anonymous) {
av0.visit("name", wrapperElement.getLocalPart());
av0.visit("namespace", wrapperElement.getNamespaceURI());
} else {
av0.visit("name", "");
}
av0.visitEnd();
// add constructor
ASMHelper.MethodVisitor mv = cw.visitMethod(opCodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
ASMHelper.Label lbegin = helper.createLabel();
mv.visitLabel(lbegin);
mv.visitVarInsn(opCodes.ALOAD, 0);
mv.visitMethodInsn(opCodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(opCodes.RETURN);
ASMHelper.Label lend = helper.createLabel();
mv.visitLabel(lend);
mv.visitLocalVariable("this", "L" + classFileName + ";", null, lbegin, lend, 0);
mv.visitMaxs(0, 0);
mv.visitEnd();
for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
generateMessagePart(cw, mpi, method, classFileName, factory);
}
cw.visitEnd();
Class<?> clz = loadClass(className, method.getDeclaringClass(), cw.toByteArray());
wrapperPart.setTypeClass(clz);
wrapperBeans.add(clz);
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class AegisDatabinding method initializeMessage.
protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container, int partType, Set<AegisType> deps) {
if (container == null) {
return;
}
for (MessagePartInfo part : container.getMessageParts()) {
AegisType type = getParameterType(s, serviceTM, part, partType);
if (part.getXmlSchema() == null) {
// schema hasn't been filled in yet
if (type.isAbstract()) {
part.setTypeQName(type.getSchemaType());
} else {
part.setElementQName(type.getSchemaType());
}
}
Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);
long miValue = -1;
if (type.hasMinOccurs()) {
miValue = type.getMinOccurs();
}
Integer i = AnnotationReader.getMinOccurs(anns);
if (i != null) {
miValue = i;
}
if (miValue > 0) {
part.setProperty("minOccurs", Long.toString(miValue));
}
// However, this if at least allow .aegis.xml files to get control.
if (part.getProperty("nillable") == null) {
boolean isNil = type.isNillable();
Boolean b = AnnotationReader.isNillable(anns);
if (b != null || (miValue != 0 && isNil)) {
part.setProperty("nillable", b == null ? isNil : b);
}
/*
if (miValue == -1 && (b == null ? isNil : b)) {
part.setProperty("minOccurs", "1");
}
*/
}
if (type.hasMaxOccurs()) {
String moValue;
long mo = type.getMaxOccurs();
if (mo != Long.MAX_VALUE) {
moValue = Long.toString(mo);
part.setProperty("maxOccurs", moValue);
}
}
part2Type.put(part, type);
// QName elName = getSuggestedName(service, op, param)
deps.add(type);
type.getTypeMapping().register(type);
addDependencies(deps, type);
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ServiceModelVisitor method visitOperation.
private void visitOperation(OperationInfo o) {
MessageInfo in = o.getInput();
if (in != null) {
begin(in);
for (MessagePartInfo part : in.getMessageParts()) {
begin(part);
end(part);
}
end(in);
}
MessageInfo out = o.getOutput();
if (out != null) {
begin(out);
for (MessagePartInfo part : out.getMessageParts()) {
begin(part);
end(part);
}
end(out);
}
for (FaultInfo f : o.getFaults()) {
begin(f);
for (MessagePartInfo part : f.getMessageParts()) {
begin(part);
end(part);
}
end(f);
}
if (o.isUnwrappedCapable()) {
OperationInfo uop = o.getUnwrappedOperation();
begin(uop);
visitOperation(o.getUnwrappedOperation());
end(uop);
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ParameterProcessor method buildParamModelsWithoutOrdering.
private void buildParamModelsWithoutOrdering(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
boolean wrapped = method.isWrapperStyle();
if (wrapped) {
if (inputMessage != null) {
List<MessagePartInfo> inputParts = inputMessage.getMessageParts();
MessagePartInfo inputPart = !inputParts.isEmpty() ? inputParts.iterator().next() : null;
List<QName> inputWrapElement = null;
if (inputPart != null && inputPart.isElement()) {
inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
}
if (inputWrapElement != null) {
for (QName item : inputWrapElement) {
String fullJavaName = dataBinding.getWrappedElementType(inputPart.getElementQName(), item);
if (StringUtils.isEmpty(fullJavaName)) {
wrapped = false;
break;
}
}
}
}
if (outputMessage != null) {
List<MessagePartInfo> outputParts = outputMessage.getMessageParts();
MessagePartInfo outputPart = !outputParts.isEmpty() ? outputParts.iterator().next() : null;
List<QName> outputWrapElement = null;
if (outputPart != null && outputPart.isElement()) {
outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
}
if (outputWrapElement != null) {
for (QName item : outputWrapElement) {
String fullJavaName = dataBinding.getWrappedElementType(outputPart.getElementQName(), item);
if (StringUtils.isEmpty(fullJavaName)) {
wrapped = false;
break;
}
}
}
}
if (!wrapped) {
// could not map one of the parameters to a java type, need to drop down to bare style
method.setWrapperStyle(false);
}
}
if (inputMessage != null) {
if (method.isWrapperStyle()) {
processWrappedInput(method, inputMessage);
} else {
processInput(method, inputMessage);
}
}
if (outputMessage == null) {
processReturn(method, null);
} else {
if (method.isWrapperStyle()) {
processWrappedOutput(method, inputMessage, outputMessage);
} else {
processOutput(method, inputMessage, outputMessage);
}
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ParameterProcessor method isValidOrdering.
private boolean isValidOrdering(List<String> parameterOrder, MessageInfo inputMessage, MessageInfo outputMessage) {
Iterator<String> params = parameterOrder.iterator();
List<MessagePartInfo> inputParts = inputMessage.getMessageParts();
List<MessagePartInfo> outputParts;
if (outputMessage != null) {
outputParts = outputMessage.getMessageParts();
} else {
outputParts = new ArrayList<>();
}
while (params.hasNext()) {
String param = params.next();
MessagePartInfo inPart = null;
MessagePartInfo outPart = null;
for (MessagePartInfo part : inputParts) {
if (param.equals(part.getName().getLocalPart())) {
inPart = part;
break;
}
}
// check output parts
for (MessagePartInfo part : outputParts) {
if (param.equals(part.getName().getLocalPart())) {
outPart = part;
break;
}
}
if (inPart == null && outPart == null) {
return false;
} else if (inPart != null && outPart != null) {
if (inPart.isElement() != outPart.isElement()) {
return false;
}
if (inPart.isElement() && !inPart.getElementQName().equals(outPart.getElementQName())) {
return false;
} else if (!inPart.isElement() && !inPart.getTypeQName().equals(outPart.getTypeQName())) {
return false;
}
}
}
return true;
}
Aggregations