use of org.apache.cxf.javascript.NamespacePrefixAccumulator in project cxf by apache.
the class AttributeTest method setupClientAndRhino.
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
testUtilities.setBus(getBean(Bus.class, "cxf"));
testUtilities.initializeRhino();
testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
client = clientProxyFactory.getClientFactoryBean().create();
serviceInfos = client.getEndpoint().getService().getServiceInfos();
// there can only be one.
assertEquals(1, serviceInfos.size());
ServiceInfo serviceInfo = serviceInfos.get(0);
schemata = serviceInfo.getSchemas();
nameManager = BasicNameManager.newNameManager(serviceInfo);
NamespacePrefixAccumulator prefixAccumulator = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
for (SchemaInfo schema : schemata) {
SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixAccumulator, nameManager);
String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
assertNotNull(allThatJavascript);
testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
}
}
use of org.apache.cxf.javascript.NamespacePrefixAccumulator in project cxf by apache.
the class WSDLToJavaScriptProcessor method process.
public void process() throws ToolException {
super.process();
ServiceInfo serviceInfo = context.get(ServiceInfo.class);
File jsFile = getOutputFile(serviceInfo.getName().getLocalPart() + ".js");
BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
Map<String, String> nsPrefixMap = CastUtils.cast(context.get(ToolConstants.CFG_JSPREFIXMAP, Map.class), String.class, String.class);
if (nsPrefixMap != null) {
for (Map.Entry<String, String> prefixEntry : nsPrefixMap.entrySet()) {
prefixManager.collect(prefixEntry.getValue(), prefixEntry.getKey());
}
}
BufferedWriter writer = null;
try {
OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
JavascriptGetInterceptor.writeUtilsToResponseStream(WSDLToJavaScriptProcessor.class, outputStream);
}
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF8);
writer = new BufferedWriter(outputStreamWriter);
XmlSchemaCollection collection = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection();
SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
String jsForSchemas = jsBuilder.generateCodeForSchemaCollection(collection);
writer.append(jsForSchemas);
ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager);
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
writer.append(serviceJavascript);
} catch (FileNotFoundException e) {
throw new ToolException(e);
} catch (IOException e) {
throw new ToolException(e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
throw new ToolException(e);
}
}
}
use of org.apache.cxf.javascript.NamespacePrefixAccumulator in project cxf by apache.
the class SerializationTest method setupClientAndRhino.
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
testUtilities.setBus(getBean(Bus.class, "cxf"));
testUtilities.initializeRhino();
testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
client = clientProxyFactory.getClientFactoryBean().create();
serviceInfos = client.getEndpoint().getService().getServiceInfos();
// there can only be one.
assertEquals(1, serviceInfos.size());
ServiceInfo serviceInfo = serviceInfos.get(0);
schemata = serviceInfo.getSchemas();
nameManager = BasicNameManager.newNameManager(serviceInfo);
NamespacePrefixAccumulator prefixAccumulator = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
for (SchemaInfo schema : schemata) {
SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixAccumulator, nameManager);
String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
assertNotNull(allThatJavascript);
testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
}
}
use of org.apache.cxf.javascript.NamespacePrefixAccumulator in project cxf by apache.
the class JavaToJSProcessor method process.
public void process() throws ToolException {
String oldClassPath = System.getProperty(JAVA_CLASS_PATH);
LOG.log(Level.INFO, "OLD_CP", oldClassPath);
if (context.get(ToolConstants.CFG_CLASSPATH) != null) {
String newCp = (String) context.get(ToolConstants.CFG_CLASSPATH);
System.setProperty(JAVA_CLASS_PATH, newCp + File.pathSeparator + oldClassPath);
LOG.log(Level.INFO, "NEW_CP", newCp);
}
// check for command line specification of data binding.
ServiceBuilder builder = getServiceBuilder();
ServiceInfo serviceInfo = builder.createService();
File jsFile = getOutputFile(builder.getOutputFile(), serviceInfo.getName().getLocalPart() + ".js");
BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
BufferedWriter writer = null;
try {
OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
JavascriptGetInterceptor.writeUtilsToResponseStream(JavaToJSProcessor.class, outputStream);
}
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF8);
writer = new BufferedWriter(outputStreamWriter);
for (SchemaInfo schema : schemata) {
SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
String allThatJavascript = jsBuilder.generateCodeForSchema(schema.getSchema());
writer.append(allThatJavascript);
}
ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager);
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
writer.append(serviceJavascript);
} catch (FileNotFoundException e) {
throw new ToolException(e);
} catch (IOException e) {
throw new ToolException(e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
throw new ToolException(e);
}
}
}
System.setProperty(JAVA_CLASS_PATH, oldClassPath);
LOG.log(Level.INFO, "RESUME_CP", oldClassPath);
}
Aggregations