use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class RequestWrapper method buildFields.
protected List<JavaField> buildFields(final Method method, final MessageInfo message) {
List<JavaField> fields = new ArrayList<>();
final Type[] paramClasses = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
for (MessagePartInfo mpi : message.getMessageParts()) {
int idx = mpi.getIndex();
String name = mpi.getName().getLocalPart();
Type t = paramClasses[idx];
String type = getTypeString(t);
JavaField field = new JavaField(name, type, "");
if (paramAnnotations != null && paramAnnotations.length == paramClasses.length) {
WebParam wParam = getWebParamAnnotation(paramAnnotations[idx]);
if (wParam != null && !StringUtils.isEmpty(wParam.targetNamespace())) {
field.setTargetNamespace(wParam.targetNamespace());
} else {
field.setTargetNamespace("");
}
}
List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx);
field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[0]));
fields.add(field);
}
return fields;
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class Wrapper method buildWrapperBeanClass.
public WrapperBeanClass buildWrapperBeanClass() {
WrapperBeanClass jClass = getJavaClass();
List<JavaField> fields = buildFields();
for (JavaField field : fields) {
field.setOwner(jClass);
field.annotate(new WrapperBeanFieldAnnotator());
jClass.addField(field);
jClass.appendGetter(field);
jClass.appendSetter(field);
}
jClass.annotate(new WrapperBeanAnnotator());
return jClass;
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class FaultGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
for (JavaModel javaModel : map.values()) {
Map<String, JavaExceptionClass> exceptionClasses = javaModel.getExceptionClasses();
for (Entry<String, JavaExceptionClass> entry : exceptionClasses.entrySet()) {
JavaExceptionClass expClz = entry.getValue();
clearAttributes();
if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
String faultSerialVersionUID = penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
setAttributes("faultSerialVersionUID", faultSerialVersionUID);
if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
} else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateTimestampSUID());
} else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
// nothing
setAttributes("suid", "");
} else {
// do a quick Parse to make sure it looks like a Long
try {
Long.parseLong(faultSerialVersionUID);
} catch (NumberFormatException nfe) {
throw new ToolException(nfe);
}
setAttributes("suid", faultSerialVersionUID);
}
} else {
setAttributes("suid", "");
}
setAttributes("expClass", expClz);
String exceptionSuperclass;
if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
} else {
exceptionSuperclass = "java.lang.Exception";
}
String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
String exceptionSuperclassString = simpleName;
for (JavaField jf : expClz.getFields()) {
String jfClassName = jf.getClassName();
if (jfClassName.substring(jfClassName.lastIndexOf('.') + 1).equals(simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
}
ClassCollector collector = penv.get(ClassCollector.class);
for (String pkg : collector.getTypesPackages()) {
if (collector.containTypesClass(pkg, simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
}
if (expClz.getName().equals(exceptionSuperclassString)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("exceptionSuperclass", exceptionSuperclassString);
if (!exceptionSuperclass.startsWith("java.lang.") && !exceptionSuperclassString.equals(exceptionSuperclass)) {
expClz.addImport(exceptionSuperclass);
}
setCommonAttributes();
doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(), expClz.getName()));
}
}
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class FaultProcessor method processFault.
private void processFault(JavaMethod method, FaultInfo faultMessage) throws ToolException {
JavaModel model = method.getInterface().getJavaModel();
String name = NameUtil.mangleNameToClassName(faultMessage.getName().getLocalPart());
String namespace = faultMessage.getName().getNamespaceURI();
String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
if (namespace.equals(method.getInterface().getNamespace())) {
packageName = method.getInterface().getPackageName();
}
JAXWSBinding jaxwsBinding = faultMessage.getExtensor(JAXWSBinding.class);
if (jaxwsBinding != null) {
if (jaxwsBinding.getPackage() != null) {
packageName = jaxwsBinding.getPackage();
}
if (jaxwsBinding.getJaxwsClass() != null && jaxwsBinding.getJaxwsClass().getClassName() != null) {
name = jaxwsBinding.getJaxwsClass().getClassName();
if (name.contains(".")) {
packageName = name.substring(0, name.lastIndexOf('.'));
name = name.substring(name.lastIndexOf('.') + 1);
}
}
}
while (isNameCollision(packageName, name)) {
name = name + "_Exception";
}
String fullClassName = packageName + "." + name;
collector.addExceptionClassName(packageName, name, fullClassName);
boolean samePackage = method.getInterface().getPackageName().equals(packageName);
method.addException(new JavaException(faultMessage.getName().getLocalPart(), samePackage ? name : fullClassName, namespace));
List<MessagePartInfo> faultParts = faultMessage.getMessageParts();
JavaExceptionClass expClass = new JavaExceptionClass(model);
expClass.setName(name);
expClass.setNamespace(namespace);
expClass.setPackageName(packageName);
for (MessagePartInfo part : faultParts) {
final String fName;
String fNamespace;
if (part.getElementQName() != null) {
fNamespace = part.getElementQName().getNamespaceURI();
// fNamespace = part.getConcreteName().getNamespaceURI();
fName = part.getConcreteName().getLocalPart();
} else {
fNamespace = part.getTypeQName().getNamespaceURI();
fName = part.getConcreteName().getLocalPart();
}
if (StringUtils.isEmpty(fNamespace)) {
fNamespace = namespace;
}
String fType = ProcessorUtil.getType(part, context, false);
// REVISIT - custom JAXB package names
String fPackageName = method.getInterface().getPackageName();
JavaField fField = new JavaField(fName, fType, fNamespace);
fField.setQName(ProcessorUtil.getElementName(part));
if (!method.getInterface().getPackageName().equals(fPackageName)) {
fField.setClassName(ProcessorUtil.getFullClzName(part, context, false));
}
if (!fType.equals(ProcessorUtil.resolvePartType(part))) {
fField.setClassName(ProcessorUtil.getType(part, context, true));
}
expClass.addField(fField);
}
model.addExceptionClass(packageName + "." + name, expClass);
expClass.setClassJavaDoc(faultMessage.getDocumentation());
}
Aggregations