use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class WrapperBeanFieldAnnotator method annotate.
public void annotate(final JavaAnnotatable field) {
final JavaField jField;
if (field instanceof JavaField) {
jField = (JavaField) field;
} else {
throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
}
String rawName = jField.getRawName();
boolean hasEl = false;
for (Annotation ann : jField.getJaxbAnnotaions()) {
if (ann instanceof XmlMimeType) {
JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
jField.addAnnotation(mimeAnno);
} else if (ann instanceof XmlJavaTypeAdapter) {
JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlAttachmentRef) {
JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlList) {
JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlElement) {
hasEl = true;
XmlElement el = (XmlElement) ann;
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
if (!StringUtils.isEmpty(el.namespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
}
if (el.nillable()) {
xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
}
if (el.required()) {
xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
}
if (!StringUtils.isEmpty(el.defaultValue())) {
xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
if (!hasEl) {
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class WrapperBeanAnnotatorTest method testAnnotate.
@Test
public void testAnnotate() {
String pkgName = "org.apache.cxf.tools.fortest.withannotation.doc.jaxws";
WrapperBeanClass clz = new WrapperBeanClass();
clz.setFullClassName(pkgName + ".SayHi");
clz.setElementName(new QName("http://doc.withannotation.fortest.tools.cxf.apache.org/", "sayHi"));
clz.annotate(new WrapperBeanAnnotator());
List<JAnnotation> annotations = clz.getAnnotations();
String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
JAnnotation rootElementAnnotation = annotations.get(0);
assertEquals("@XmlRootElement(name = \"sayHi\", " + "namespace = \"" + expectedNamespace + "\")", rootElementAnnotation.toString());
JAnnotation xmlTypeAnnotation = annotations.get(2);
assertEquals("@XmlType(name = \"sayHi\", " + "namespace = \"" + expectedNamespace + "\")", xmlTypeAnnotation.toString());
JAnnotation accessorTypeAnnotation = annotations.get(1);
assertEquals("@XmlAccessorType(XmlAccessType.FIELD)", accessorTypeAnnotation.toString());
WrapperBeanClass resWrapperClass = new WrapperBeanClass();
resWrapperClass.setFullClassName(pkgName + ".SayHiResponse");
resWrapperClass.setElementName(new QName(expectedNamespace, "sayHiResponse"));
resWrapperClass.annotate(new WrapperBeanAnnotator());
annotations = resWrapperClass.getAnnotations();
rootElementAnnotation = annotations.get(0);
assertEquals("@XmlRootElement(name = \"sayHiResponse\", " + "namespace = \"" + expectedNamespace + "\")", rootElementAnnotation.toString());
accessorTypeAnnotation = annotations.get(1);
assertEquals("@XmlAccessorType(XmlAccessType.FIELD)", accessorTypeAnnotation.toString());
xmlTypeAnnotation = annotations.get(2);
assertEquals("@XmlType(name = \"sayHiResponse\", " + "namespace = \"" + expectedNamespace + "\")", xmlTypeAnnotation.toString());
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class HandlerConfigGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Element e = this.intf.getHandlerChains();
List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(e, ToolConstants.HANDLER_CHAINS_URI, ToolConstants.HANDLER_CHAIN);
if (!elemList.isEmpty()) {
String fName = ProcessorUtil.getHandlerConfigFileName(this.intf.getName());
handlerChainAnnotation = new JAnnotation(HandlerChain.class);
handlerChainAnnotation.addElement(new JAnnotationElement("name", HANDLER_CHAIN_NAME));
handlerChainAnnotation.addElement(new JAnnotationElement("file", fName + ".xml"));
generateHandlerChainFile(e, parseOutputName(this.intf.getPackageName(), fName, ".xml"));
}
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class SEIGenerator 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()) {
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
if (interfaces.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
continue;
}
for (JavaInterface intf : interfaces.values()) {
if (hasHandlerConfig(intf)) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
// REVISIT: find a better way to handle Handler gen, should not
// pass JavaInterface around.
handlerGen.setJavaInterface(intf);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : intf.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
intf.addAnnotation(annot);
intf.addImport("javax.jws.HandlerChain");
}
}
}
if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
JAnnotation ann = new JAnnotation(DataBinding.class);
JAnnotationElement el = new JAnnotationElement(null, penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS), true);
ann.addElement(el);
intf.addAnnotation(ann);
}
clearAttributes();
setAttributes("intf", intf);
String seiSc = "";
for (String s : intf.getSuperInterfaces()) {
if (!seiSc.isEmpty()) {
seiSc += ", ";
} else {
seiSc = "extends ";
}
seiSc += s;
}
if (!StringUtils.isEmpty(seiSc)) {
seiSc += " ";
}
setAttributes("seiSuperinterfaceString", seiSc);
setCommonAttributes();
doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));
}
}
}
use of org.apache.cxf.tools.common.model.JAnnotation in project cxf by apache.
the class ServiceGenerator 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()) {
ClassCollector collector = penv.get(ClassCollector.class);
Map<String, JavaServiceClass> serviceClasses = javaModel.getServiceClasses();
if (serviceClasses.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SERVICE", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
for (JavaServiceClass js : serviceClasses.values()) {
if (js.getHandlerChains() != null) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
handlerGen.setJavaInterface(js);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : js.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
js.addAnnotation(annot);
js.addImport("javax.jws.HandlerChain");
}
}
}
Set<String> portNames = new HashSet<>();
for (JavaPort port : js.getPorts()) {
if (!port.getPackageName().equals(js.getPackageName()) && !port.getInterfaceClass().equals(js.getName())) {
js.addImport(port.getFullClassName());
}
portNames.add(port.getInterfaceClass());
}
if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
js.addImport(BindingProvider.class.getName());
js.addImport(Client.class.getName());
}
String url = (String) env.get(ToolConstants.CFG_WSDLURL);
String location = (String) env.get(ToolConstants.CFG_WSDLLOCATION);
if (location == null) {
location = url;
}
String serviceSuperclass = (String) env.get("service.superclass");
String simpleServiceName = serviceSuperclass.substring(serviceSuperclass.lastIndexOf('.') + 1);
for (String s : collector.getGeneratedFileInfo()) {
if (s.equals(js.getPackageName() + "." + simpleServiceName)) {
simpleServiceName = serviceSuperclass;
break;
}
}
clearAttributes();
boolean useGetResource = false;
try {
new URL(location);
} catch (MalformedURLException e) {
useGetResource = true;
}
setAttributes("cxfPortClassnames", portNames.toArray(new String[0]));
setAttributes("service", js);
setAttributes("wsdlLocation", location);
setAttributes("useGetResource", useGetResource);
setAttributes("serviceSuperclass", simpleServiceName);
if (!simpleServiceName.equals(serviceSuperclass)) {
js.addImport(serviceSuperclass);
}
setAttributes("wsdlUrl", url);
setCommonAttributes();
String target = (String) env.get("service.target");
setAttributes("serviceTarget", target);
if ("jaxws22".equals(target)) {
setAttributes("jaxws22", true);
}
doWrite(SERVICE_TEMPLATE, parseOutputName(js.getPackageName(), js.getName()));
}
}
}
Aggregations