use of org.apache.cxf.tools.common.model.JavaClass in project cxf by apache.
the class BeanGenerator method generateAndCompile.
public void generateAndCompile(Collection<JavaClass> wrapperClasses, File dir) {
VelocityGenerator generator = new VelocityGenerator(false);
generator.setBaseDir(dir.toString());
List<File> generatedFiles = new ArrayList<>();
try {
for (JavaClass wrapperClass : wrapperClasses) {
generator.setCommonAttributes();
generator.setAttributes("bean", wrapperClass);
File file = generator.parseOutputName(wrapperClass.getPackageName(), wrapperClass.getName());
generatedFiles.add(file);
generator.doWrite(TEMPLATE, new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, (String) getToolContext().get(ToolConstants.CFG_ENCODING)));
generator.clearAttributes();
}
// compile the classes
Compiler compiler = (Compiler) getToolContext().get(ToolConstants.COMPILER);
if (compiler == null) {
compiler = new Compiler();
}
compiler.setOutputDir(compileToDir);
List<String> files = new ArrayList<>(generatedFiles.size());
for (File file : generatedFiles) {
files.add(file.getAbsolutePath());
}
compiler.compileFiles(files.toArray(new String[0]));
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.cxf.tools.common.model.JavaClass in project cxf by apache.
the class BeanGenerator method generate.
public File generate(final File sourcedir) {
File dir = getOutputBase();
if (dir == null) {
dir = sourcedir;
}
if (dir == null) {
dir = new File("./");
}
Collection<JavaClass> wrapperClasses = generateBeanClasses(getServiceModel());
if (!wrapperClasses.isEmpty()) {
generateAndCompile(wrapperClasses, dir);
}
return dir;
}
use of org.apache.cxf.tools.common.model.JavaClass in project cxf by apache.
the class RequestWrapperTest method testNoAnnotationNoClass.
@Test
public void testNoAnnotationNoClass() throws Exception {
String pkgName = "org.apache.cxf.tools.fortest.classnoanno.docwrapped";
Class<?> testingClass = Class.forName(pkgName + ".Stock");
OperationInfo opInfo = getOperation(testingClass, "getPrice");
Wrapper wrapper = new RequestWrapper();
wrapper.setOperationInfo(opInfo);
assertTrue(wrapper.isWrapperAbsent());
assertTrue(wrapper.isToDifferentPackage());
assertFalse(wrapper.isWrapperBeanClassNotExist());
assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName());
assertEquals("GetPrice", wrapper.getJavaClass().getName());
JavaClass jClass = wrapper.buildWrapperBeanClass();
assertNotNull(jClass);
List<JavaField> jFields = jClass.getFields();
assertEquals(1, jFields.size());
assertEquals("arg0", jFields.get(0).getName());
assertEquals("java.lang.String", jFields.get(0).getClassName());
List<JavaMethod> jMethods = jClass.getMethods();
assertEquals(2, jMethods.size());
JavaMethod jMethod = jMethods.get(0);
assertEquals("getArg0", jMethod.getName());
assertTrue(jMethod.getParameterListWithoutAnnotation().isEmpty());
jMethod = jMethods.get(1);
assertEquals("setArg0", jMethod.getName());
assertEquals(1, jMethod.getParameterListWithoutAnnotation().size());
assertEquals("java.lang.String newArg0", jMethod.getParameterListWithoutAnnotation().get(0));
}
use of org.apache.cxf.tools.common.model.JavaClass in project cxf by apache.
the class WrapperTest method testGetWrapperBeanClassFromQName.
@Test
public void testGetWrapperBeanClassFromQName() {
QName qname = new QName("http://cxf.apache.org", "sayHi");
Wrapper wrapper = new Wrapper();
wrapper.setName(qname);
JavaClass jClass = wrapper.getWrapperBeanClass(qname);
assertEquals("org.apache.cxf", jClass.getPackageName());
assertEquals("SayHi", jClass.getName());
assertEquals("http://cxf.apache.org", jClass.getNamespace());
}
use of org.apache.cxf.tools.common.model.JavaClass in project cxf by apache.
the class WrapperBeanFieldAnnotatorTest method testAnnotate.
@Test
public void testAnnotate() {
JavaClass clz = new JavaClass();
clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHi");
JavaField reqField = new JavaField("array", "String[]", "http://doc.withannotation.fortest.tools.cxf.apache.org/");
reqField.setOwner(clz);
List<JAnnotation> annotation = reqField.getAnnotations();
assertEquals(0, annotation.size());
reqField.annotate(new WrapperBeanFieldAnnotator());
annotation = reqField.getAnnotations();
String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
assertEquals("@XmlElement(name = \"array\", namespace = \"" + expectedNamespace + "\")", annotation.get(0).toString());
clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
JavaField resField = new JavaField("return", "String[]", "http://doc.withannotation.fortest.tools.cxf.apache.org/");
resField.setOwner(clz);
resField.annotate(new WrapperBeanFieldAnnotator());
annotation = resField.getAnnotations();
assertEquals("@XmlElement(name = \"return\", namespace = \"" + expectedNamespace + "\")", annotation.get(0).toString());
}
Aggregations