use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class ServiceGenerator 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()) {
ClassCollector collector = penv.get(ClassCollector.class);
Map<String, JavaServiceClass> serviceClasses = javaModel.getServiceClasses();
if (serviceClasses.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SERVICE", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
for (JavaServiceClass js : serviceClasses.values()) {
if (js.getHandlerChains() != null) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
handlerGen.setJavaInterface(js);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : js.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
js.addAnnotation(annot);
js.addImport("javax.jws.HandlerChain");
}
}
}
Set<String> portNames = new HashSet<>();
for (JavaPort port : js.getPorts()) {
if (!port.getPackageName().equals(js.getPackageName()) && !port.getInterfaceClass().equals(js.getName())) {
js.addImport(port.getFullClassName());
}
portNames.add(port.getInterfaceClass());
}
if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
js.addImport(BindingProvider.class.getName());
js.addImport(Client.class.getName());
}
String url = (String) env.get(ToolConstants.CFG_WSDLURL);
String location = (String) env.get(ToolConstants.CFG_WSDLLOCATION);
if (location == null) {
location = url;
}
String serviceSuperclass = (String) env.get("service.superclass");
String simpleServiceName = serviceSuperclass.substring(serviceSuperclass.lastIndexOf('.') + 1);
for (String s : collector.getGeneratedFileInfo()) {
if (s.equals(js.getPackageName() + "." + simpleServiceName)) {
simpleServiceName = serviceSuperclass;
break;
}
}
clearAttributes();
boolean useGetResource = false;
try {
new URL(location);
} catch (MalformedURLException e) {
useGetResource = true;
}
setAttributes("cxfPortClassnames", portNames.toArray(new String[portNames.size()]));
setAttributes("service", js);
setAttributes("wsdlLocation", location);
setAttributes("useGetResource", useGetResource);
setAttributes("serviceSuperclass", simpleServiceName);
if (!simpleServiceName.equals(serviceSuperclass)) {
js.addImport(serviceSuperclass);
}
setAttributes("wsdlUrl", url);
setCommonAttributes();
String target = (String) env.get("service.target");
setAttributes("serviceTarget", target);
if ("jaxws22".equals(target)) {
setAttributes("jaxws22", true);
}
doWrite(SERVICE_TEMPLATE, parseOutputName(js.getPackageName(), js.getName()));
}
}
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class WSDLToJavaProcessor method process.
public void process() throws ToolException {
super.process();
JavaModel jmodel = wsdlDefinitionToJavaModel(context.get(ServiceInfo.class));
context.setJavaModel(jmodel);
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class WSDLToJavaProcessor method wsdlDefinitionToJavaModel.
private JavaModel wsdlDefinitionToJavaModel(ServiceInfo serviceInfo) throws ToolException {
JavaModel javaModel = null;
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(MODEL_MAP));
if (map == null) {
map = new LinkedHashMap<QName, JavaModel>();
context.put(MODEL_MAP, map);
}
if (map.containsKey(serviceInfo.getName())) {
javaModel = map.get(serviceInfo.getName());
} else {
javaModel = new JavaModel();
map.put(serviceInfo.getName(), javaModel);
}
context.put(JavaModel.class, javaModel);
List<JavaInterface> interfaces = new ArrayList<>();
interfaces.addAll(javaModel.getInterfaces().values());
PortTypeProcessor portTypeProcessor = new PortTypeProcessor(context);
portTypeProcessor.process(serviceInfo);
ServiceProcessor serviceProcessor = new ServiceProcessor(context);
serviceProcessor.process(serviceInfo);
for (JavaInterface intf : javaModel.getInterfaces().values()) {
if (!interfaces.contains(intf)) {
intf.annotate(new WebServiceAnnotator());
intf.annotate(new XmlSeeAlsoAnnotator(context.get(ClassCollector.class)));
intf.annotate(new BindingAnnotator());
}
}
return javaModel;
}
use of org.apache.cxf.tools.common.model.JavaModel in project cxf by apache.
the class JAXWSFrontEndProcessor method process.
@SuppressWarnings("unchecked")
public void process() throws ToolException {
checkJaxwsClass();
List<ServiceInfo> services = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
ServiceInfo serviceInfo = services.get(0);
JavaInterface jinf = JavaFirstUtil.serviceInfo2JavaInf(serviceInfo);
String className = (String) context.get(ToolConstants.IMPL_CLASS);
if (className != null && className.equals(jinf.getFullClassName())) {
jinf.setName(jinf.getName() + SEI_SUFFIX);
}
JavaModel jm = new JavaModel();
jm.addInterface("inf", jinf);
jinf.setJavaModel(jm);
context.put(JavaModel.class, jm);
context.put(ToolConstants.SERVICE_NAME, serviceInfo.getName());
EndpointInfo endpointInfo = serviceInfo.getEndpoints().iterator().next();
context.put(ToolConstants.PORT_NAME, endpointInfo.getName());
generators.add(new JaxwsSEIGenerator());
generators.add(new JaxwsImplGenerator());
generators.add(new JaxwsServerGenerator());
generators.add(new JaxwsClientGenerator());
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 JaxwsClientGenerator 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();
QName service = (QName) env.get(ToolConstants.SERVICE_NAME);
QName port = (QName) env.get(ToolConstants.PORT_NAME);
for (JavaInterface intf : interfaces.values()) {
clearAttributes();
setAttributes("intf", intf);
setAttributes("service", service);
setAttributes("port", port);
setAttributes("address", penv.get(ToolConstants.CFG_ADDRESS));
setAttributes("seiClass", env.get(ToolConstants.SEI_CLASS));
setCommonAttributes();
doWrite(CLIENT_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Client"));
}
}
Aggregations