use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.
the class JAXBDataBinding method addedToClassCollector.
private boolean addedToClassCollector(String packageName) {
ClassCollector classCollector = context.get(ClassCollector.class);
Collection<String> files = classCollector.getGeneratedFileInfo();
for (String file : files) {
int dotIndex = file.lastIndexOf(".");
String sub = dotIndex <= 0 ? "" : file.substring(0, dotIndex - 1);
if (sub.equals(packageName)) {
return true;
}
}
return false;
}
use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.
the class XmlSeeAlsoAnnotatorTest method testAddXmlSeeAlsoAnnotation.
@Test
public void testAddXmlSeeAlsoAnnotation() throws Exception {
JavaInterface intf = new JavaInterface();
assertFalse(intf.getImports().hasNext());
ClassCollector collector = new ClassCollector();
collector.getTypesPackages().add(ObjectFactory.class.getPackage().getName());
intf.annotate(new XmlSeeAlsoAnnotator(collector));
Iterator<String> iter = intf.getImports();
assertEquals("javax.xml.bind.annotation.XmlSeeAlso", iter.next());
assertEquals("@XmlSeeAlso({" + ObjectFactory.class.getName() + ".class})", intf.getAnnotations().iterator().next().toString());
}
use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.
the class JAXRSContainer method processWadl.
private void processWadl() {
File outDir = new File((String) context.get(WadlToolConstants.CFG_OUTPUTDIR));
String wadlURL = getAbsoluteWadlURL();
String authentication = (String) context.get(WadlToolConstants.CFG_AUTHENTICATION);
String wadl = readWadl(wadlURL, authentication);
SourceGenerator sg = new SourceGenerator();
sg.setBus(getBus());
boolean generateImpl = context.optionSet(WadlToolConstants.CFG_IMPL);
sg.setGenerateImplementation(generateImpl);
if (generateImpl) {
sg.setGenerateInterfaces(context.optionSet(WadlToolConstants.CFG_INTERFACE));
}
sg.setPackageName((String) context.get(WadlToolConstants.CFG_PACKAGENAME));
sg.setResourceName((String) context.get(WadlToolConstants.CFG_RESOURCENAME));
sg.setEncoding((String) context.get(WadlToolConstants.CFG_ENCODING));
sg.setAuthentication(authentication);
String wadlNs = (String) context.get(WadlToolConstants.CFG_WADL_NAMESPACE);
if (wadlNs != null) {
sg.setWadlNamespace(wadlNs);
}
sg.setJaxbClassNameSuffix((String) context.get(WadlToolConstants.CFG_JAXB_CLASS_NAME_SUFFIX));
sg.setSupportMultipleXmlReps(context.optionSet(WadlToolConstants.CFG_MULTIPLE_XML_REPS));
sg.setSupportBeanValidation(context.optionSet(WadlToolConstants.CFG_BEAN_VALIDATION));
sg.setCreateJavaDocs(context.optionSet(WadlToolConstants.CFG_CREATE_JAVA_DOCS));
// set the base path
sg.setWadlPath(wadlURL);
CustomizationParser parser = new CustomizationParser(context);
parser.parse(context);
List<InputSource> bindingFiles = parser.getJaxbBindings();
sg.setBindingFiles(bindingFiles);
sg.setCompilerArgs(parser.getCompilerArgs());
List<InputSource> schemaPackageFiles = parser.getSchemaPackageFiles();
sg.setSchemaPackageFiles(schemaPackageFiles);
sg.setSchemaPackageMap(context.getNamespacePackageMap());
sg.setJavaTypeMap(DEFAULT_JAVA_TYPE_MAP);
sg.setSchemaTypeMap(getSchemaTypeMap());
sg.setMediaTypeMap(getMediaTypeMap());
sg.setSuspendedAsyncMethods(getSuspendedAsyncMethods());
sg.setResponseMethods(getResponseMethods());
sg.setOnewayMethods(getOnewayMethods());
sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
sg.setValidateWadl(context.optionSet(WadlToolConstants.CFG_VALIDATE_WADL));
boolean inheritResourceParams = context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS);
sg.setInheritResourceParams(inheritResourceParams);
if (inheritResourceParams) {
sg.setInheritResourceParamsFirst(isInheritResourceParamsFirst());
}
sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
boolean noVoidForEmptyResponses = context.optionSet(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES);
if (noVoidForEmptyResponses) {
sg.setUseVoidForEmptyResponses(false);
}
sg.setGenerateResponseIfHeadersSet(context.optionSet(WadlToolConstants.CFG_GENERATE_RESPONSE_IF_HEADERS_SET));
// generate
String codeType = context.optionSet(WadlToolConstants.CFG_TYPES) ? SourceGenerator.CODE_TYPE_GRAMMAR : SourceGenerator.CODE_TYPE_PROXY;
sg.generateSource(wadl, outDir, codeType);
// compile
if (context.optionSet(WadlToolConstants.CFG_COMPILE)) {
ClassCollector collector = createClassCollector();
List<String> generatedServiceClasses = sg.getGeneratedServiceClasses();
for (String className : generatedServiceClasses) {
int index = className.lastIndexOf(".");
collector.addServiceClassName(className.substring(0, index), className.substring(index + 1), className);
}
List<String> generatedTypeClasses = sg.getGeneratedTypeClasses();
for (String className : generatedTypeClasses) {
int index = className.lastIndexOf(".");
collector.addTypesClassName(className.substring(0, index), className.substring(index + 1), className);
}
context.put(ClassCollector.class, collector);
new ClassUtils().compile(context);
}
}
use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.
the class AbstractCXFToolContainer method createClassCollector.
protected ClassCollector createClassCollector() {
ClassCollector collector = new ClassCollector();
String[] reserved = (String[]) context.get(ToolConstants.CFG_RESERVE_NAME);
if (reserved != null) {
for (String r : reserved) {
collector.reserveClass(r);
}
}
return collector;
}
Aggregations