use of org.apache.cxf.tools.common.Processor in project cxf by apache.
the class JavaToJS method execute.
public void execute(boolean exitOnFinish) {
Processor processor = new JavaToJSProcessor();
try {
super.execute(exitOnFinish);
if (!hasInfoOption()) {
ToolContext env = new ToolContext();
env.setParameters(getParametersMap(new HashSet<>()));
if (env.get(ToolConstants.CFG_OUTPUTDIR) == null) {
env.put(ToolConstants.CFG_OUTPUTDIR, ".");
}
if (isVerboseOn()) {
env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
}
env.put(ToolConstants.CFG_CMD_ARG, getArgument());
validate(env);
processor.setEnvironment(env);
processor.process();
}
} catch (ToolException ex) {
if (ex.getCause() instanceof BadUsageException) {
printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
}
err.println();
err.println("JavaToJS Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} catch (Exception ex) {
err.println();
err.println("JavaToJS Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} finally {
tearDown();
}
}
use of org.apache.cxf.tools.common.Processor in project cxf by apache.
the class JAXWSProfileTest method testLoadPlugins.
@Test
public void testLoadPlugins() {
PluginLoader loader = PluginLoader.getInstance();
assertNotNull(loader);
loader.loadPlugin("/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-plugin.xml");
assertEquals(3, loader.getPlugins().size());
Plugin plugin = null;
for (Plugin p : loader.getPlugins().values()) {
if (p.getName().contains("jaxws")) {
plugin = p;
}
}
assertNotNull(plugin);
assertEquals("tools-jaxws-frontend", plugin.getName());
assertEquals("2.0", plugin.getVersion());
assertEquals("apache cxf", plugin.getProvider());
Map<String, FrontEnd> frontends = loader.getFrontEnds();
assertNotNull(frontends);
assertEquals(3, frontends.size());
FrontEnd frontend = getFrontEnd(frontends, 0);
assertEquals("jaxws", frontend.getName());
assertEquals("org.apache.cxf.tools.wsdlto.frontend.jaxws", frontend.getPackage());
assertEquals("JAXWSProfile", frontend.getProfile());
assertNotNull(frontend.getGenerators());
assertNotNull(frontend.getGenerators().getGenerator());
assertEquals(2, frontend.getGenerators().getGenerator().size());
assertEquals("AntGenerator", getGenerator(frontend, 0).getName());
assertEquals("ImplGenerator", getGenerator(frontend, 1).getName());
FrontEndProfile profile = loader.getFrontEndProfile("jaxws");
assertNotNull(profile);
List<FrontEndGenerator> generators = profile.getGenerators();
assertNotNull(generators);
assertEquals(2, generators.size());
assertTrue(generators.get(0) instanceof AntGenerator);
assertTrue(generators.get(1) instanceof ImplGenerator);
Processor processor = profile.getProcessor();
assertNotNull(processor);
assertTrue(processor instanceof WSDLToJavaProcessor);
AbstractWSDLBuilder builder = profile.getWSDLBuilder();
assertNotNull(builder);
assertTrue(builder instanceof JAXWSDefinitionBuilder);
Class<?> container = profile.getContainerClass();
assertEquals(container, JAXWSContainer.class);
assertEquals("/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml", profile.getToolspec());
}
use of org.apache.cxf.tools.common.Processor in project cxf by apache.
the class WSDLToJavaContainer method processWsdl.
private void processWsdl() {
validate(context);
FrontEndProfile frontend = context.get(FrontEndProfile.class);
if (frontend == null) {
throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG));
}
WSDLConstants.WSDLVersion version = getWSDLVersion();
String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
@SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
if (serviceList == null) {
serviceList = new ArrayList<>();
// Build the ServiceModel from the WSDLModel
if (version == WSDLConstants.WSDLVersion.WSDL11) {
AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
builder.setContext(context);
builder.setBus(getBus());
context.put(Bus.class, getBus());
wsdlURL = URIParserUtil.getAbsoluteURI(wsdlURL);
builder.build(wsdlURL);
builder.customize();
Definition definition = builder.getWSDLModel();
context.put(Definition.class, definition);
builder.validate(definition);
WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
if (context.isVerbose()) {
serviceBuilder.setUnwrapLogLevel(Level.INFO);
}
serviceBuilder.setIgnoreUnknownBindings(true);
String allowRefs = (String) context.get(ToolConstants.CFG_ALLOW_ELEMENT_REFS);
if (!StringUtils.isEmpty(allowRefs) || context.optionSet(ToolConstants.CFG_ALLOW_ELEMENT_REFS)) {
if (allowRefs.length() > 0 && allowRefs.charAt(0) == '=') {
allowRefs = allowRefs.substring(1);
}
if (StringUtils.isEmpty(allowRefs)) {
allowRefs = "true";
}
serviceBuilder.setAllowElementRefs(Boolean.valueOf(allowRefs));
}
String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
if (serviceName != null) {
List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
serviceList.addAll(services);
} else if (definition.getServices().size() > 0) {
serviceList = serviceBuilder.buildServices(definition);
} else {
serviceList = serviceBuilder.buildMockServices(definition);
}
// remove definition from cache so that won't fail when encounter same wsdl file
// name but different wsdl content(CXF-3340)
getBus().getExtension(WSDLManager.class).removeDefinition(definition);
} else {
// TODO: wsdl2.0 support
}
}
context.put(ToolConstants.SERVICE_LIST, serviceList);
Map<String, InterfaceInfo> interfaces = new LinkedHashMap<String, InterfaceInfo>();
ServiceInfo service0 = serviceList.get(0);
SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
context.put(ToolConstants.PORTTYPE_MAP, interfaces);
context.put(ClassCollector.class, createClassCollector());
Processor processor = frontend.getProcessor();
if (processor instanceof ClassNameProcessor) {
processor.setEnvironment(context);
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
((ClassNameProcessor) processor).processClassNames();
context.put(ServiceInfo.class, null);
}
}
if (context.optionSet(ToolConstants.CFG_NO_TYPES)) {
context.remove(ToolConstants.CFG_TYPES);
context.remove(ToolConstants.CFG_ALL);
context.remove(ToolConstants.CFG_COMPILE);
}
generateTypes();
if (context.getErrorListener().getErrorCount() > 0) {
return;
}
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
if (context.basicValidateWSDL()) {
validate(service);
}
if (context.getErrorListener().getErrorCount() == 0) {
// Build the JavaModel from the ServiceModel
processor.setEnvironment(context);
processor.process();
}
}
if (context.getErrorListener().getErrorCount() > 0) {
return;
}
if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
enforceWSDLLocation(context);
}
if (!isSuppressCodeGen()) {
// Generate artifacts
for (FrontEndGenerator generator : frontend.getGenerators()) {
generator.generate(context);
}
}
context.remove(ToolConstants.SERVICE_LIST);
// Build projects: compile classes and copy resources etc.
if (context.optionSet(ToolConstants.CFG_COMPILE)) {
new ClassUtils().compile(context);
}
if (context.isExcludeNamespaceEnabled()) {
try {
removeExcludeFiles();
} catch (IOException e) {
throw new ToolException(e);
}
}
if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
processClientJar(context);
}
}
use of org.apache.cxf.tools.common.Processor in project cxf by apache.
the class JavaToWSContainer method processWSDL.
private void processWSDL(ToolContext env, String ft) {
Processor processor = new JavaToWSDLProcessor();
processor.setEnvironment(env);
processor.process();
if (ft.equals(ToolConstants.JAXWS_FRONTEND)) {
if (env.optionSet(ToolConstants.CFG_SERVER) || env.optionSet(ToolConstants.CFG_CLIENT)) {
processor = new JAXWSFrontEndProcessor();
processor.setEnvironment(env);
processor.process();
}
} else {
processor = new SimpleFrontEndProcessor();
processor.setEnvironment(env);
processor.process();
}
}
Aggregations