use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class JAXWSBindingParser method queryXPathNode.
private Node queryXPathNode(Node target, String expression) {
NodeList nlst;
try {
ContextImpl contextImpl = new ContextImpl(target);
XPathFactory xpathFactory = XPathFactory.newInstance();
try {
xpathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
} catch (javax.xml.xpath.XPathFactoryConfigurationException ex) {
// ignore
}
XPath xpath = xpathFactory.newXPath();
xpath.setNamespaceContext(contextImpl);
nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
Message msg = new Message("XPATH_ERROR", LOG, new Object[] { expression });
throw new ToolException(msg, e);
}
if (nlst.getLength() != 1) {
Message msg = new Message("ERROR_TARGETNODE_WITH_XPATH", LOG, new Object[] { expression });
throw new ToolException(msg);
}
Node rnode = nlst.item(0);
if (!(rnode instanceof Element)) {
return null;
}
return rnode;
}
use of org.apache.cxf.common.i18n.Message 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.common.i18n.Message 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));
}
}
}
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class AbstractGenerator method parseOutputName.
protected Writer parseOutputName(String packageName, String filename, String ext) throws ToolException {
if (wantToKeep() && isCollision(packageName, filename, ext)) {
Message msg = new Message("SKIP_GEN", LOG, packageName + '.' + filename + ext);
LOG.log(Level.INFO, msg.toString());
return null;
}
FileWriterUtil fw = new FileWriterUtil(getOutputDir(), env.get(OutputStreamCreator.class));
final Writer writer;
try {
if (".java".equals(ext)) {
writer = fw.getWriter(packageName, filename + ext, (String) getEnvironment().get(ToolConstants.CFG_ENCODING));
} else {
writer = fw.getWriter(packageName, filename + ext);
}
} catch (IOException ioe) {
Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, packageName + '.' + filename + ext);
throw new ToolException(msg, ioe);
}
return writer;
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class CustomizationParser method getTargetNode.
public Element getTargetNode(String uri) {
if (uri == null) {
return null;
}
if (uri.equals(wsdlURL) && wsdlNode != null) {
return wsdlNode;
}
Document doc = null;
try (URIResolver resolver = new URIResolver(uri)) {
if (!resolver.isResolved()) {
return null;
}
XMLStreamReader reader = null;
try {
// NOPMD
reader = StaxUtils.createXMLStreamReader(uri, resolver.getInputStream());
doc = StaxUtils.read(reader, true);
} catch (Exception e) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { uri });
throw new ToolException(msg, e);
} finally {
try {
StaxUtils.close(reader);
} catch (XMLStreamException e) {
// ignore
}
}
} catch (IOException e1) {
return null;
}
try {
doc.setDocumentURI(uri);
} catch (Exception ex) {
// ignore - probably not DOM level 3
}
if (doc != null) {
return doc.getDocumentElement();
}
return null;
}
Aggregations