/* * gvNIX is an open source tool for rapid application development (RAD). * Copyright (C) 2010 Generalitat Valenciana * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ package org.gvnix.service.roo.addon.addon.ws.export; import com.github.antlrjavaparser.api.body.BodyDeclaration; import com.github.antlrjavaparser.api.body.ClassOrInterfaceDeclaration; import com.github.antlrjavaparser.api.body.ConstructorDeclaration; import com.github.antlrjavaparser.api.body.EnumDeclaration; import com.github.antlrjavaparser.api.body.FieldDeclaration; import com.github.antlrjavaparser.api.body.MethodDeclaration; import com.github.antlrjavaparser.api.body.TypeDeclaration; import com.github.antlrjavaparser.api.body.VariableDeclarator; import com.github.antlrjavaparser.api.expr.AnnotationExpr; import com.github.antlrjavaparser.api.expr.ArrayInitializerExpr; import com.github.antlrjavaparser.api.expr.Expression; import com.github.antlrjavaparser.api.expr.MemberValuePair; import com.github.antlrjavaparser.api.expr.NormalAnnotationExpr; import com.github.antlrjavaparser.api.expr.StringLiteralExpr; import com.github.antlrjavaparser.api.type.ClassOrInterfaceType; import com.github.antlrjavaparser.api.type.ReferenceType; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.logging.Logger; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; import org.gvnix.service.roo.addon.addon.ws.WSCompilationUnit; import org.gvnix.service.roo.addon.annotations.GvNIXWebFault; import org.gvnix.service.roo.addon.annotations.GvNIXWebMethod; import org.gvnix.service.roo.addon.annotations.GvNIXWebParam; import org.gvnix.service.roo.addon.annotations.GvNIXXmlElementField; import org.springframework.roo.classpath.antlrjavaparser.details.JavaParserConstructorMetadataBuilder; import org.springframework.roo.classpath.antlrjavaparser.details.JavaParserFieldMetadataBuilder; import org.springframework.roo.classpath.antlrjavaparser.details.JavaParserMethodMetadataBuilder; import org.springframework.roo.classpath.details.ConstructorMetadata; import org.springframework.roo.classpath.details.ConstructorMetadataBuilder; import org.springframework.roo.classpath.details.FieldMetadata; import org.springframework.roo.classpath.details.FieldMetadataBuilder; import org.springframework.roo.classpath.details.MemberFindingUtils; import org.springframework.roo.classpath.details.MethodMetadata; import org.springframework.roo.classpath.details.MethodMetadataBuilder; import org.springframework.roo.classpath.details.annotations.AnnotatedJavaType; import org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue; import org.springframework.roo.classpath.details.annotations.AnnotationMetadata; import org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder; import org.springframework.roo.classpath.details.annotations.ArrayAttributeValue; import org.springframework.roo.classpath.details.annotations.BooleanAttributeValue; import org.springframework.roo.classpath.details.annotations.ClassAttributeValue; import org.springframework.roo.classpath.details.annotations.EnumAttributeValue; import org.springframework.roo.classpath.details.annotations.StringAttributeValue; import org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder; import org.springframework.roo.model.EnumDetails; import org.springframework.roo.model.JavaSymbolName; import org.springframework.roo.model.JavaType; import org.springframework.roo.project.LogicalPath; import org.springframework.roo.project.Path; import org.springframework.roo.project.ProjectOperations; /** * Create sources related to generated by wsdl2java maven plugin. * <p> * This listener is monitoring target folder * {@link WSExportWsdlImpl#GENERATED_CXF_SOURCES_DIR} files and include this * files for generation into project sources folder. On listener activation, the * files for generation are reset. * </p> * <p> * Project target files are generated by wsdl2java maven plugin executed by * {@link WSExportWsdlOperations#exportWsdl(String)}. * </p> * * @author <a href="http://www.disid.com">DISID Corporation S.L.</a> made for <a * href="http://www.dgti.gva.es">General Directorate for Information * Technologies (DGTI)</a> */ @Component @Service public class WSExportWsdlImpl implements WsExportWsdl { private static final String FOLDER_SEPARATOR = "/"; private String genSourcesDir; protected static Logger logger = Logger.getLogger(WSExportWsdlImpl.class .getName()); @Reference private ProjectOperations projectOperations; /** * {@inheritDoc} */ public String getGenSourcesDir() { if (genSourcesDir != null) { return genSourcesDir; } genSourcesDir = projectOperations.getPathResolver().getIdentifier( LogicalPath.getInstance(Path.ROOT, ""), GENERATED_CXF_SOURCES_DIR); return genSourcesDir; } /** * {@inheritDoc} */ public void loadFaultFieldDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, List<FieldMetadata> fieldMetadataList, BodyDeclaration bodyDeclaration) { FieldMetadata fieldMetadata; FieldDeclaration fieldDeclaration; fieldDeclaration = (FieldDeclaration) bodyDeclaration; for (VariableDeclarator var : fieldDeclaration.getVariables()) { fieldMetadata = JavaParserFieldMetadataBuilder.getInstance( declaredByMetadataId, fieldDeclaration, var, compilationUnitServices, new HashSet<JavaSymbolName>()) .build(); fieldMetadataList.add(fieldMetadata); } } /** * {@inheritDoc} */ public void loadFaultConstructorDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, List<ConstructorMetadata> constructorMetadataList, BodyDeclaration bodyDeclaration) { ConstructorMetadata constructorMetadata; ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) bodyDeclaration; constructorMetadata = JavaParserConstructorMetadataBuilder.getInstance( declaredByMetadataId, constructorDeclaration, compilationUnitServices, new HashSet<JavaSymbolName>()).build(); ConstructorMetadataBuilder constructorMetadataBuilder = new ConstructorMetadataBuilder( declaredByMetadataId, constructorMetadata); constructorMetadata = constructorMetadataBuilder.build(); constructorMetadataList.add(constructorMetadata); } /** * {@inheritDoc} */ public void loadFaultMethodDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, List<MethodMetadata> methodMetadataList, MethodDeclaration methodDeclaration) { MethodMetadata tmpMethodMetadata; tmpMethodMetadata = JavaParserMethodMetadataBuilder.getInstance( declaredByMetadataId, methodDeclaration, compilationUnitServices, new HashSet<JavaSymbolName>()).build(); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine(tmpMethodMetadata.getBody()); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( declaredByMetadataId, tmpMethodMetadata.getModifier(), tmpMethodMetadata.getMethodName(), tmpMethodMetadata.getReturnType(), tmpMethodMetadata.getParameterTypes(), tmpMethodMetadata.getParameterNames(), bodyBuilder); for (AnnotationMetadata annotationMetadata : tmpMethodMetadata .getAnnotations()) { methodMetadataBuilder.addAnnotation(annotationMetadata); } for (JavaType myJavaType : tmpMethodMetadata.getThrowsTypes()) { methodMetadataBuilder.addThrowsType(myJavaType); } methodMetadataList.add(methodMetadataBuilder.build()); } /** * {@inheritDoc} */ public AnnotationMetadata getGvNIXWebFaultAnnotation( ClassOrInterfaceDeclaration classOrInterfaceDeclaration, JavaType exceptionType) { AnnotationMetadata gvNIXWFAMetadata; List<AnnotationAttributeValue<?>> gvNIXWFAAttr = new ArrayList<AnnotationAttributeValue<?>>(); // @WebFault(name = "faultDetail", targetNamespace = // "http://apache.org/hello_world_soap_http/types") List<AnnotationExpr> annotationExprList = classOrInterfaceDeclaration .getAnnotations(); String faultBeanWebFault = exceptionType.getFullyQualifiedTypeName(); for (AnnotationExpr annotationExpr : annotationExprList) { if (annotationExpr instanceof NormalAnnotationExpr) { NormalAnnotationExpr normalAnnotationExpr = (NormalAnnotationExpr) annotationExpr; StringAttributeValue nameStringAttributeValue; StringAttributeValue targetNamespcStrAttrVal; // Retrieve values. for (MemberValuePair pair : normalAnnotationExpr.getPairs()) { if (pair.getName().contentEquals("name")) { // name nameStringAttributeValue = new StringAttributeValue( new JavaSymbolName("name"), ((StringLiteralExpr) pair.getValue()) .getValue()); gvNIXWFAAttr.add(nameStringAttributeValue); } else if (pair.getName().contentEquals("targetNamespace")) { // targetNamespace targetNamespcStrAttrVal = new StringAttributeValue( new JavaSymbolName("targetNamespace"), ((StringLiteralExpr) pair.getValue()) .getValue()); gvNIXWFAAttr.add(targetNamespcStrAttrVal); } } } } // faultBean gvNIXWFAAttr.add(new StringAttributeValue(new JavaSymbolName( "faultBean"), faultBeanWebFault)); // Create GvNIXWebFault annotation. gvNIXWFAMetadata = new AnnotationMetadataBuilder(new JavaType( GvNIXWebFault.class.getName()), gvNIXWFAAttr).build(); return gvNIXWFAMetadata; } /** * {@inheritDoc} */ public void loadWebServiceFieldDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, List<FieldMetadata> fieldMetadataList, BodyDeclaration bodyDeclaration) { FieldMetadata fieldMetadata; FieldDeclaration tmpFieldDeclaration; FieldDeclaration fieldDeclaration; tmpFieldDeclaration = (FieldDeclaration) bodyDeclaration; fieldDeclaration = new FieldDeclaration( tmpFieldDeclaration.getJavaDoc(), tmpFieldDeclaration.getModifiers(), new ArrayList<AnnotationExpr>(), tmpFieldDeclaration.getType(), tmpFieldDeclaration.getVariables()); for (VariableDeclarator var : fieldDeclaration.getVariables()) { fieldMetadata = JavaParserFieldMetadataBuilder.getInstance( declaredByMetadataId, fieldDeclaration, var, compilationUnitServices, new HashSet<JavaSymbolName>()) .build(); fieldMetadataList.add(fieldMetadata); } } /** * {@inheritDoc} */ public void loadWebServiceMethodDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, ClassOrInterfaceDeclaration implementedInterface, List<MethodMetadata> methodMetadataList, String defaultNamespace, BodyDeclaration bodyDeclaration) { MethodMetadata methodMetadata; MethodMetadata tmpMethodMetadata; MethodDeclaration methodDeclaration; methodDeclaration = (MethodDeclaration) bodyDeclaration; tmpMethodMetadata = JavaParserMethodMetadataBuilder.getInstance( declaredByMetadataId, methodDeclaration, compilationUnitServices, new HashSet<JavaSymbolName>()).build(); // Check method from interface because Web // Service // Annotations are defined there for (BodyDeclaration interfacebodyDeclaration : implementedInterface .getMembers()) { MethodDeclaration interfaceMethodDeclaration; if (interfacebodyDeclaration instanceof MethodDeclaration) { interfaceMethodDeclaration = (MethodDeclaration) interfacebodyDeclaration; if (interfaceMethodDeclaration.getName().contentEquals( methodDeclaration.getName())) { MethodMetadata interfaceTmpMethodMetadata = JavaParserMethodMetadataBuilder .getInstance(declaredByMetadataId, interfaceMethodDeclaration, compilationUnitServices, new HashSet<JavaSymbolName>()).build(); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( declaredByMetadataId, interfaceTmpMethodMetadata.getModifier(), interfaceTmpMethodMetadata.getMethodName(), interfaceTmpMethodMetadata.getReturnType(), interfaceTmpMethodMetadata.getParameterTypes(), interfaceTmpMethodMetadata.getParameterNames(), new InvocableMemberBodyBuilder() .appendFormalLine(tmpMethodMetadata .getBody())); for (AnnotationMetadata annotationMetadata : interfaceTmpMethodMetadata .getAnnotations()) { methodMetadataBuilder.addAnnotation(annotationMetadata); } for (JavaType myJavaType : interfaceTmpMethodMetadata .getThrowsTypes()) { methodMetadataBuilder.addThrowsType(myJavaType); } interfaceTmpMethodMetadata = methodMetadataBuilder.build(); // Web Service method Operation. methodMetadata = getGvNIXWebMethodMetadata( interfaceTmpMethodMetadata, defaultNamespace); methodMetadataList.add(methodMetadata); } } } } /** * Creates MethodMetadata with gvNIX Annotation values to export as Web * Service Operation. TODO to be removed from interface?. This method could * be useless outside this service. * <p> * Set Web Method and Parameters annotations. * </p> * * @param methodMetadata * @param defaultNamespace from Web Service to set where is not defined in * annotations. * @return {@link MethodMetadata} with gvNIX Annotations. */ protected MethodMetadata getGvNIXWebMethodMetadata( MethodMetadata methodMetadata, String defaultNamespace) { MethodMetadata gvNIXMethodMetadata; // Method annotations. List<AnnotationMetadata> gvNIXWMAMdataList = new ArrayList<AnnotationMetadata>(); AnnotationMetadata gvNIXWMAnnMdata = getGvNIXWebMethodAnnotation( methodMetadata, defaultNamespace); Validate.isTrue( gvNIXWMAnnMdata != null, "Generated Web Service method: '" + methodMetadata.getMethodName() + "' is not correctly generated with Web Service annotation values.\nRelaunch the command."); gvNIXWMAMdataList.add(gvNIXWMAnnMdata); // Input Parameters annotations. List<AnnotatedJavaType> annotatedGvNIXWebParameterList = getGvNIXWebParamsAnnotations( methodMetadata, defaultNamespace); Validate.isTrue( gvNIXWMAnnMdata != null, "Generated Web Service method: '" + methodMetadata.getMethodName() + "' is not correctly generated with Web Service annotation values for its parameters.\nRelaunch the command."); // Rebuild method with retrieved parameters. InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine(methodMetadata.getBody()); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( methodMetadata.getDeclaredByMetadataId(), methodMetadata.getModifier(), methodMetadata.getMethodName(), methodMetadata.getReturnType(), annotatedGvNIXWebParameterList, methodMetadata.getParameterNames(), bodyBuilder); for (AnnotationMetadata annotationMetadata : gvNIXWMAMdataList) { methodMetadataBuilder.addAnnotation(annotationMetadata); } for (JavaType javaType : methodMetadata.getThrowsTypes()) { methodMetadataBuilder.addThrowsType(javaType); } gvNIXMethodMetadata = methodMetadataBuilder.build(); return gvNIXMethodMetadata; } /** * Define @GvNIXWebMethod annotation using Web Services annotation attribute * values. TODO to be removed from interface?. This method could be useless * outside this service. * <p> * Returns 'null' if @WebMethod annotation is not defined. * </p> * * @param methodMetadata to check Web Services annotations. * @param defaultNamespace from Web Service to set where is not defined in * annotations. * @return {@link GvNIXWebMethod} with Attributes. */ private AnnotationMetadata getGvNIXWebMethodAnnotation( MethodMetadata methodMetadata, String defaultNamespace) { AnnotationMetadata gvNIXWMAnnMdata = null; AnnotationAttributeValue<?> tmpAttributeValue; List<AnnotationAttributeValue<?>> gvNIXWMAnnAttrVal = new ArrayList<AnnotationAttributeValue<?>>(); List<AnnotationMetadata> methodAnnotations = methodMetadata .getAnnotations(); AnnotationMetadata webMethodAnnotation = MemberFindingUtils .getAnnotationOfType(methodAnnotations, new JavaType( "javax.jws.WebMethod")); if (webMethodAnnotation == null) { return gvNIXWMAnnMdata; } // String operationName(); StringAttributeValue opeNameStringAttrValue; tmpAttributeValue = webMethodAnnotation .getAttribute(new JavaSymbolName("operationName")); if (tmpAttributeValue == null) { opeNameStringAttrValue = new StringAttributeValue( new JavaSymbolName("operationName"), methodMetadata .getMethodName().getSymbolName()); } else { opeNameStringAttrValue = (StringAttributeValue) tmpAttributeValue; } gvNIXWMAnnAttrVal.add(opeNameStringAttrValue); // Check if exists action attribute value. tmpAttributeValue = webMethodAnnotation .getAttribute(new JavaSymbolName("action")); StringAttributeValue actionAttributeValue; if (tmpAttributeValue != null) { actionAttributeValue = new StringAttributeValue(new JavaSymbolName( "action"), ((StringAttributeValue) tmpAttributeValue).getValue()); } else { actionAttributeValue = new StringAttributeValue(new JavaSymbolName( "action"), ""); } gvNIXWMAnnAttrVal.add(actionAttributeValue); // @javax.jws.WebResult AnnotationMetadata webResultAnnotation = MemberFindingUtils .getAnnotationOfType(methodAnnotations, new JavaType( "javax.jws.WebResult")); ClassAttributeValue resultTypeAttributeValue; StringAttributeValue resultNameAttributeValue; StringAttributeValue resultNamespaceAttributeValue = null; BooleanAttributeValue headerAttributeValue = null; StringAttributeValue partNameAttributeValue = null; if (webResultAnnotation == null) { resultTypeAttributeValue = new ClassAttributeValue( new JavaSymbolName("webResultType"), JavaType.VOID_PRIMITIVE); resultNameAttributeValue = new StringAttributeValue( new JavaSymbolName("resultName"), "void"); } else { resultTypeAttributeValue = new ClassAttributeValue( new JavaSymbolName("webResultType"), methodMetadata.getReturnType()); AnnotationAttributeValue<?> nameAttributeValue = webResultAnnotation .getAttribute(new JavaSymbolName("name")); if (nameAttributeValue != null) { resultNameAttributeValue = new StringAttributeValue( new JavaSymbolName("resultName"), ((StringAttributeValue) nameAttributeValue).getValue()); } else { resultNameAttributeValue = new StringAttributeValue( new JavaSymbolName("resultName"), "return"); } AnnotationAttributeValue<?> namespaceAttributeValue = webResultAnnotation .getAttribute(new JavaSymbolName("targetNamespace")); if (namespaceAttributeValue != null) { resultNamespaceAttributeValue = new StringAttributeValue( new JavaSymbolName("resultNamespace"), ((StringAttributeValue) namespaceAttributeValue) .getValue()); } else { resultNamespaceAttributeValue = new StringAttributeValue( new JavaSymbolName("resultNamespace"), defaultNamespace); } // Parameter webResultHeader. headerAttributeValue = (BooleanAttributeValue) webResultAnnotation .getAttribute(new JavaSymbolName("header")); if (headerAttributeValue == null) { headerAttributeValue = new BooleanAttributeValue( new JavaSymbolName("webResultHeader"), false); } else { headerAttributeValue = new BooleanAttributeValue( new JavaSymbolName("webResultHeader"), headerAttributeValue.getValue()); } // Parameter webResultPartName. partNameAttributeValue = (StringAttributeValue) webResultAnnotation .getAttribute(new JavaSymbolName("partName")); if (partNameAttributeValue == null) { partNameAttributeValue = new StringAttributeValue( new JavaSymbolName("webResultPartName"), "parameters"); } else { partNameAttributeValue = new StringAttributeValue( new JavaSymbolName("webResultPartName"), partNameAttributeValue.getValue()); } } gvNIXWMAnnAttrVal.add(resultTypeAttributeValue); gvNIXWMAnnAttrVal.add(resultNameAttributeValue); if (resultNamespaceAttributeValue != null) { gvNIXWMAnnAttrVal.add(resultNamespaceAttributeValue); } if (headerAttributeValue != null) { gvNIXWMAnnAttrVal.add(headerAttributeValue); } if (partNameAttributeValue != null) { gvNIXWMAnnAttrVal.add(partNameAttributeValue); } // @javax.xml.ws.RequestWrapper AnnotationMetadata requestWrapperAnnotation = MemberFindingUtils .getAnnotationOfType(methodAnnotations, new JavaType( "javax.xml.ws.RequestWrapper")); if (requestWrapperAnnotation != null) { StringAttributeValue localNameAttributeValue = (StringAttributeValue) requestWrapperAnnotation .getAttribute(new JavaSymbolName("localName")); StringAttributeValue rqstWrapperNameAttrVal = new StringAttributeValue( new JavaSymbolName("requestWrapperName"), localNameAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(rqstWrapperNameAttrVal); StringAttributeValue targetNamespaceAttributeValue = (StringAttributeValue) requestWrapperAnnotation .getAttribute(new JavaSymbolName("targetNamespace")); StringAttributeValue rqstTarNamespaceAttrVal = new StringAttributeValue( new JavaSymbolName("requestWrapperNamespace"), targetNamespaceAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(rqstTarNamespaceAttrVal); StringAttributeValue classNameAttributeValue = (StringAttributeValue) requestWrapperAnnotation .getAttribute(new JavaSymbolName("className")); StringAttributeValue requestClassNameAttributeValue = new StringAttributeValue( new JavaSymbolName("requestWrapperClassName"), classNameAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(requestClassNameAttributeValue); } // @javax.xml.ws.ResponseWrapper AnnotationMetadata responseWrapperAnnotation = MemberFindingUtils .getAnnotationOfType(methodAnnotations, new JavaType( "javax.xml.ws.ResponseWrapper")); if (responseWrapperAnnotation != null) { StringAttributeValue localNameAttributeValue = (StringAttributeValue) responseWrapperAnnotation .getAttribute(new JavaSymbolName("localName")); StringAttributeValue rspnsWrapperNameAttrVal = new StringAttributeValue( new JavaSymbolName("responseWrapperName"), localNameAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(rspnsWrapperNameAttrVal); StringAttributeValue targetNamespaceAttributeValue = (StringAttributeValue) responseWrapperAnnotation .getAttribute(new JavaSymbolName("targetNamespace")); StringAttributeValue rspnsTarNamespaceAttrVal = new StringAttributeValue( new JavaSymbolName("responseWrapperNamespace"), targetNamespaceAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(rspnsTarNamespaceAttrVal); StringAttributeValue classNameAttributeValue = (StringAttributeValue) responseWrapperAnnotation .getAttribute(new JavaSymbolName("className")); StringAttributeValue rspnsClassNameAttrVal = new StringAttributeValue( new JavaSymbolName("responseWrapperClassName"), classNameAttributeValue.getValue()); gvNIXWMAnnAttrVal.add(rspnsClassNameAttrVal); } // @javax.jws.soap.SOAPBinding AnnotationMetadata sOAPBindingAnnotation = MemberFindingUtils .getAnnotationOfType(methodAnnotations, new JavaType( "javax.jws.soap.SOAPBinding")); if (sOAPBindingAnnotation != null) { EnumAttributeValue sOAPBindingAttributeValue = (EnumAttributeValue) sOAPBindingAnnotation .getAttribute(new JavaSymbolName("parameterStyle")); if (sOAPBindingAttributeValue != null) { gvNIXWMAnnAttrVal .add(new EnumAttributeValue( new JavaSymbolName("parameterStyle"), new EnumDetails( new JavaType( "org.gvnix.service.roo.addon.annotations.GvNIXWebMethod.GvNIXWebMethodParameterStyle"), sOAPBindingAttributeValue.getValue() .getField()))); } } gvNIXWMAnnMdata = new AnnotationMetadataBuilder(new JavaType( GvNIXWebMethod.class.getName()), gvNIXWMAnnAttrVal).build(); return gvNIXWMAnnMdata; } /** * Define @GVNIXWebParam for each input method parameter. * <p> * If there isn't WebParam annotation defined returns null. * </p> * * @param methodMetadata to check for Web Services annotations. * @param defaultNamespace from Web Service to set where is not defined in * annotations. * @return {@link List} of {@link AnnotatedJavaType} for each input method * parameter. */ private List<AnnotatedJavaType> getGvNIXWebParamsAnnotations( MethodMetadata methodMetadata, String defaultNamespace) { List<AnnotatedJavaType> annotatedGvNIXWebParameterList = new ArrayList<AnnotatedJavaType>(); List<AnnotatedJavaType> parameterTypesList = methodMetadata .getParameterTypes(); List<JavaSymbolName> parameterNamesList = methodMetadata .getParameterNames(); if (parameterTypesList.isEmpty() && parameterNamesList.isEmpty()) { return annotatedGvNIXWebParameterList; } AnnotatedJavaType parameterWithAnnotations; List<AnnotationMetadata> parameterAnnotationList; for (AnnotatedJavaType parameterType : parameterTypesList) { parameterAnnotationList = new ArrayList<AnnotationMetadata>(); AnnotationMetadata webParamAnnotationMetadata = MemberFindingUtils .getAnnotationOfType(parameterType.getAnnotations(), new JavaType("javax.jws.WebParam")); if (webParamAnnotationMetadata == null) { // If there is not WebParam annotation defined returns null. return null; } List<AnnotationAttributeValue<?>> gvNIXWParamAttrValList = new ArrayList<AnnotationAttributeValue<?>>(); StringAttributeValue nameWebParamAttributeValue = (StringAttributeValue) webParamAnnotationMetadata .getAttribute(new JavaSymbolName("name")); gvNIXWParamAttrValList.add(nameWebParamAttributeValue); ClassAttributeValue typeClassAttributeValue = new ClassAttributeValue( new JavaSymbolName("type"), parameterType.getJavaType()); gvNIXWParamAttrValList.add(typeClassAttributeValue); // @GvNIXWebParam AnnotationMetadata gvNixWParamAnnMdata = new AnnotationMetadataBuilder( new JavaType(GvNIXWebParam.class.getName()), gvNIXWParamAttrValList).build(); parameterAnnotationList.add(gvNixWParamAnnMdata); // @WebParam parameterAnnotationList.add(webParamAnnotationMetadata); // Add annotation list to parameter. parameterWithAnnotations = new AnnotatedJavaType( parameterType.getJavaType(), parameterAnnotationList); annotatedGvNIXWebParameterList.add(parameterWithAnnotations); } return annotatedGvNIXWebParameterList; } /** * {@inheritDoc} */ public void loadFieldFromType(String id, WSCompilationUnit compUnit, List<FieldMetadata> fields, BodyDeclaration body) { // Fields from Inner Class type defined. FieldDeclaration field = (FieldDeclaration) body; if (field.getType() instanceof ReferenceType) { ReferenceType refType = (ReferenceType) field.getType(); if (refType.getType() instanceof ClassOrInterfaceType) { ClassOrInterfaceType type = (ClassOrInterfaceType) refType .getType(); type.setScope(null); field.setType(type); } } FieldDeclaration fieldDecl = new FieldDeclaration(field.getJavaDoc(), field.getModifiers(), field.getAnnotations(), field.getType(), field.getVariables()); for (VariableDeclarator var : fieldDecl.getVariables()) { // Set var initilize to null beacuse if implements an // interface the class is not well generated. var.setInit(null); fields.add(getGvNIXXmlElementFieldAnnotation(JavaParserFieldMetadataBuilder .getInstance(id, fieldDecl, var, compUnit, new HashSet<JavaSymbolName>()).build())); } } /** * <p> * Convert field with @XmlElement annotation to field with @GvNIXXmlElementField * with its values. * </p> * <p> * Creates {@link FieldMetadata} with @GvNIXXmlElementField annotation even * if not exists @XmlElement. * </p> * TODO to be removed from interface?. This method could be useless outside * this service. * * @param fieldMetadata * @return {@link FieldMetadata} with @GvNIXXmlElementField annotation. */ protected FieldMetadata getGvNIXXmlElementFieldAnnotation( FieldMetadata field) { AnnotationMetadata gvNixXmlElementAnnot; AnnotationMetadata xmlElementAnnot = MemberFindingUtils .getAnnotationOfType(field.getAnnotations(), new JavaType( XmlElement.class.getName())); if (xmlElementAnnot != null) { // Field has XmlElement annotation: create GvNIXXmlElement from it gvNixXmlElementAnnot = getXmlElementFieldAnnotation(xmlElementAnnot); } else { AnnotationMetadata xmlElementRefAnnot = MemberFindingUtils .getAnnotationOfType(field.getAnnotations(), new JavaType( XmlElementRef.class.getName())); if (xmlElementRefAnnot != null) { // Field has XmlElementRef: create GvNIXXmlElement from it gvNixXmlElementAnnot = getXmlElementRefFieldAnnotation(field); } else { // Field no XmlElement, XmlElementRef: create empty // GvNIXXmlElement gvNixXmlElementAnnot = new AnnotationMetadataBuilder( new JavaType(GvNIXXmlElementField.class.getName()), new ArrayList<AnnotationAttributeValue<?>>()).build(); } } List<AnnotationMetadata> annots = new ArrayList<AnnotationMetadata>(); annots.add(gvNixXmlElementAnnot); // Create new Field with GvNIXAnnotation. FieldMetadataBuilder fieldMetadataBuilder = new FieldMetadataBuilder( field.getDeclaredByMetadataId(), field.getModifier(), field.getFieldName(), field.getFieldType(), field.getFieldInitializer()); for (AnnotationMetadata annotationMetadata : annots) { fieldMetadataBuilder.addAnnotation(annotationMetadata); } return fieldMetadataBuilder.build(); } /** * Get GvNIXXmlElement annotation related with XmlElement annotation. * <p> * Creates the GvNIXXmlElement with all attributes defined in XmlElement * annotation. * </p> * * @param annot XmlElement annotation * @return GvNIXXmlElement annotation */ private AnnotationMetadata getXmlElementFieldAnnotation( AnnotationMetadata annot) { List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>(); for (JavaSymbolName attrName : annot.getAttributeNames()) { attrs.add(annot.getAttribute(attrName)); } return new AnnotationMetadataBuilder(new JavaType( GvNIXXmlElementField.class.getName()), attrs).build(); } /** * Get GvNIXXmlElement annotation related with XmlElementRef annotation. * <p> * Only when field is of JAXBElement type, creates the GvNIXXmlElement with * a "type" attribute with the first parameter type value. * </p> * * @param xmlElementAnnotation XmlElementRef annotation * @return GvNIXXmlElement annotation */ private AnnotationMetadata getXmlElementRefFieldAnnotation( FieldMetadata field) { List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>(); JavaType type = field.getFieldType(); List<JavaType> params = type.getParameters(); if (type.getFullyQualifiedTypeName() .equals(JAXBElement.class.getName()) && !params.isEmpty()) { attrs.add(new ClassAttributeValue(new JavaSymbolName("type"), params.get(0))); } return new AnnotationMetadataBuilder(new JavaType( GvNIXXmlElementField.class.getName()), attrs).build(); } /** * {@inheritDoc} */ public String getFilename(String path) { if (path == null) { return null; } int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR); return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path); } /** * {@inheritDoc} */ public void addNameAttr(List<AnnotationAttributeValue<?>> attrs, List<MemberValuePair> pairs) { // Search name attribute in pairs for (MemberValuePair pair : pairs) { if (pair.getName().contentEquals("name")) { // Add name to attributes list attrs.add(new StringAttributeValue(new JavaSymbolName("name"), ((StringLiteralExpr) pair.getValue()).getValue())); return; } } } /** * {@inheritDoc} */ public void addXmlTypeNameAttr(List<AnnotationAttributeValue<?>> attrs, MemberValuePair pair) { if (StringUtils.isNotBlank(pair.getValue().toString())) { attrs.add(new StringAttributeValue( new JavaSymbolName("xmlTypeName"), ((StringLiteralExpr) pair.getValue()).getValue())); } } /** * {@inheritDoc} */ public void addElementListAttr(List<AnnotationAttributeValue<?>> annotAttrs) { List<StringAttributeValue> attrs = new ArrayList<StringAttributeValue>(); attrs.add(new StringAttributeValue(new JavaSymbolName("ignored"), "")); annotAttrs.add(new ArrayAttributeValue<StringAttributeValue>( new JavaSymbolName("elementList"), attrs)); } /** * {@inheritDoc} */ public void addNamespaceAttr(List<AnnotationAttributeValue<?>> attrs, MemberValuePair pair) { attrs.add(new StringAttributeValue(new JavaSymbolName("namespace"), ((StringLiteralExpr) pair.getValue()).getValue())); } /** * {@inheritDoc} */ public void addElementListAttr( List<AnnotationAttributeValue<?>> annotAttrs, MemberValuePair pair) { List<StringAttributeValue> attrs = new ArrayList<StringAttributeValue>(); for (Expression value : ((ArrayInitializerExpr) pair.getValue()) .getValues()) { attrs.add(new StringAttributeValue(new JavaSymbolName("ignored"), ((StringLiteralExpr) value).getValue())); } annotAttrs.add(new ArrayAttributeValue<StringAttributeValue>( new JavaSymbolName("elementList"), attrs)); } /** * {@inheritDoc} */ public void addExportedAttr(List<AnnotationAttributeValue<?>> attrs) { // Exported attr: always true to know when export from WSDL attrs.add(new BooleanAttributeValue(new JavaSymbolName("exported"), true)); } /** * {@inheritDoc} */ public void addEnumElementAttr(TypeDeclaration typeDecl, List<AnnotationAttributeValue<?>> annotAttrs) { // Check if is an Enum class if (typeDecl instanceof EnumDeclaration) { annotAttrs.add(new BooleanAttributeValue(new JavaSymbolName( "enumElement"), true)); } else { annotAttrs.add(new BooleanAttributeValue(new JavaSymbolName( "enumElement"), false)); } } }