use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class JaxwsServerGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
JavaModel javaModel = env.get(JavaModel.class);
if (passthrough()) {
return;
}
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
for (JavaInterface intf : interfaces.values()) {
clearAttributes();
setAttributes("intf", intf);
setAttributes("address", penv.get(ToolConstants.CFG_ADDRESS));
setAttributes("implClass", env.get(ToolConstants.IMPL_CLASS));
setCommonAttributes();
doWrite(SERVER_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Server"));
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class SimpleFrontEndProcessor method process.
@SuppressWarnings("unchecked")
public void process() throws ToolException {
List<ServiceInfo> services = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
ServiceInfo serviceInfo = services.get(0);
JavaInterface jinf = JavaFirstUtil.serviceInfo2JavaInf(serviceInfo);
JavaModel jm = new JavaModel();
jm.addInterface("inf", jinf);
jinf.setJavaModel(jm);
context.put(JavaModel.class, jm);
generators.add(new SimpleSEIGenerator());
generators.add(new SimpleImplGenerator());
generators.add(new SimpleServerGenerator());
generators.add(new SimpleClientGenerator());
generators.add(new AntGenerator());
for (AbstractGenerator generator : generators) {
generator.generate(context);
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class SimpleImplGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
JavaModel javaModel = env.get(JavaModel.class);
if (passthrough()) {
return;
}
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
for (JavaInterface intf : interfaces.values()) {
clearAttributes();
setAttributes("intf", intf);
setAttributes("seiClass", env.get(ToolConstants.SEI_CLASS));
setCommonAttributes();
doWrite(IMPL_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Impl"));
env.put(ToolConstants.IMPL_CLASS, intf.getFullClassName() + "Impl");
}
}
use of org.apache.cxf.tools.common.model.JavaModel 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.JavaModel 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) {
String fName = null;
String fNamespace = null;
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