use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class AntGenerator 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()) {
if (javaModel.getServiceClasses().isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_ANT", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
Map<String, String> clientClassNamesMap = new HashMap<>();
Map<String, String> serverClassNamesMap = new HashMap<>();
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
int index = 1;
for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
for (JavaPort jp : js.getPorts()) {
String interfaceName = jp.getInterfaceClass();
JavaInterface intf = interfaces.get(interfaceName);
if (intf == null) {
interfaceName = jp.getPortType();
intf = interfaces.get(interfaceName);
}
String clientClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
String serverClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
String clientTargetName = interfaceName + "Client";
boolean collison = false;
if (clientClassNamesMap.keySet().contains(clientTargetName)) {
clientTargetName = clientTargetName + index;
collison = true;
}
String serverTargetName = interfaceName + "Server";
if (serverClassNamesMap.keySet().contains(serverTargetName)) {
serverTargetName = serverTargetName + index;
collison = true;
}
if (collison) {
index++;
}
clientClassNamesMap.put(clientTargetName, clientClassName);
serverClassNamesMap.put(serverTargetName, serverClassName);
}
}
clearAttributes();
setAttributes("clientClassNamesMap", clientClassNamesMap);
setAttributes("serverClassNamesMap", serverClassNamesMap);
setAttributes("wsdlLocation", javaModel.getLocation());
setCommonAttributes();
doWrite(ANT_TEMPLATE, parseOutputName(null, "build", ".xml"));
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class ClientGenerator 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()) {
if (javaModel.getServiceClasses().isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_CLIENT", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
for (JavaPort jp : js.getPorts()) {
String interfaceName = jp.getInterfaceClass();
JavaInterface intf = interfaces.get(interfaceName);
if (intf == null) {
interfaceName = jp.getPortType();
intf = interfaces.get(interfaceName);
}
String clientClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
clientClassName = mapClassName(intf.getPackageName(), clientClassName, penv);
clearAttributes();
setAttributes("clientClassName", clientClassName);
setAttributes("intf", intf);
setAttributes("service", js);
setAttributes("port", jp);
setCommonAttributes();
doWrite(CLT_TEMPLATE, parseOutputName(intf.getPackageName(), clientClassName));
}
}
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class ImplGenerator 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, JavaInterface> interfaces = javaModel.getInterfaces();
Map<String, JavaServiceClass> services = javaModel.getServiceClasses();
JavaServiceClass service = null;
if (!services.values().isEmpty()) {
for (JavaServiceClass javaservice : services.values()) {
service = javaservice;
for (JavaPort jport : javaservice.getPorts()) {
JavaInterface intf = interfaces.get(jport.getInterfaceClass());
outputImpl(intf, service, jport.getPortName(), penv);
}
}
} else {
for (Map.Entry<String, JavaInterface> entry : interfaces.entrySet()) {
outputImpl(entry.getValue(), null, "", penv);
}
}
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class SEIGenerator 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, JavaInterface> interfaces = javaModel.getInterfaces();
if (interfaces.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
continue;
}
for (JavaInterface intf : interfaces.values()) {
if (hasHandlerConfig(intf)) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
// REVISIT: find a better way to handle Handler gen, should not
// pass JavaInterface around.
handlerGen.setJavaInterface(intf);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : intf.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
intf.addAnnotation(annot);
intf.addImport("javax.jws.HandlerChain");
}
}
}
if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
JAnnotation ann = new JAnnotation(DataBinding.class);
JAnnotationElement el = new JAnnotationElement(null, penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS), true);
ann.addElement(el);
intf.addAnnotation(ann);
}
clearAttributes();
setAttributes("intf", intf);
String seiSc = "";
for (String s : intf.getSuperInterfaces()) {
if (!seiSc.isEmpty()) {
seiSc += ", ";
} else {
seiSc = "extends ";
}
seiSc += s;
}
if (!StringUtils.isEmpty(seiSc)) {
seiSc += " ";
}
setAttributes("seiSuperinterfaceString", seiSc);
setCommonAttributes();
doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));
}
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class ServerGenerator 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()) {
String address = "CHANGE_ME";
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
if (javaModel.getServiceClasses().isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SRV", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
for (JavaPort jp : js.getPorts()) {
String interfaceName = jp.getInterfaceClass();
JavaInterface intf = interfaces.get(interfaceName);
if (intf == null) {
interfaceName = jp.getPortType();
intf = interfaces.get(interfaceName);
}
address = StringUtils.isEmpty(jp.getBindingAdress()) ? address : jp.getBindingAdress();
String serverClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
serverClassName = mapClassName(intf.getPackageName(), serverClassName, penv);
clearAttributes();
setAttributes("serverClassName", serverClassName);
setAttributes("intf", intf);
String name = getImplName(jp.getPortName(), js.getServiceName(), intf, penv);
setAttributes("impl", name);
setAttributes("address", address);
setCommonAttributes();
doWrite(SRV_TEMPLATE, parseOutputName(intf.getPackageName(), serverClassName));
}
}
}
}
Aggregations