1 package org.apache.beehive.wsm.processor.apt; 2 3 20 21 import java.util.HashSet ; 22 import java.util.Set ; 23 24 import com.sun.mirror.apt.AnnotationProcessorEnvironment; 25 import com.sun.mirror.apt.Messager; 26 27 import com.sun.mirror.declaration.AnnotationTypeDeclaration; 28 import com.sun.mirror.declaration.ClassDeclaration; 29 import com.sun.mirror.declaration.Declaration; 30 import com.sun.mirror.declaration.InterfaceDeclaration; 31 import com.sun.mirror.declaration.TypeDeclaration; 32 33 import javax.jws.WebService; 34 35 import org.apache.beehive.wsm.model.BeehiveWsTypeMetadata; 36 import org.apache.beehive.wsm.model.jsr181.Jsr181ObjectModelStore; 37 import org.apache.beehive.wsm.model.jsr181.Jsr181TypeMetadataImpl; 38 39 40 47 public class WsmAnnotationProcessor extends TwoPhaseAnnotationProcessor { 48 49 private Set <TypeDeclaration> handledDecls = new HashSet <TypeDeclaration>(); 50 private Jsr181ObjectModelStore oms; 51 52 55 public WsmAnnotationProcessor(Set <AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) { 56 super (atds, env); 57 oms = new Jsr181ObjectModelStore(env); 58 } 59 60 65 @Override 66 public void check(Declaration _decl) { 67 68 Messager messager = _env.getMessager(); 69 70 try { 71 72 if (handledDecls.contains(_decl)) { 74 return; 75 } 76 77 if (! (_decl instanceof TypeDeclaration)) { 79 return; 80 } 81 WebService wsAnnotation = _decl.getAnnotation(WebService.class); 82 if (null == wsAnnotation) { 83 messager.printError(_decl.getPosition(), "@WebService annotation missing; unable to process: " + ((TypeDeclaration) _decl).getQualifiedName()); 84 } 85 86 handledDecls.add((TypeDeclaration) _decl); 88 89 if (_decl instanceof ClassDeclaration) { 91 ClassDeclaration classDecl = (ClassDeclaration) _decl; 92 messager.printNotice("processing service implementation bean: " + classDecl.getQualifiedName()); 93 94 BeehiveWsTypeMetadata om = null; 95 String endpointInterface = wsAnnotation.endpointInterface().trim(); 96 97 if (null != endpointInterface && 0 < endpointInterface.length()) { 99 100 om = getEndpointInterfaceObjectModel(endpointInterface); 102 103 om.merge(new MirrorTypeInfo(classDecl, _env)); 105 } 106 107 else { 109 om = new Jsr181TypeMetadataImpl(new MirrorTypeInfo(classDecl, _env)); 110 } 111 112 if (null == om) { 114 return; 115 } 116 117 oms.store(om); 119 } 120 121 else if (_decl instanceof InterfaceDeclaration) { 123 InterfaceDeclaration interfaceDecl = (InterfaceDeclaration) _decl; 124 125 messager.printNotice("processing service endpoint interface: " + interfaceDecl.getQualifiedName()); 126 127 BeehiveWsTypeMetadata om = new Jsr181TypeMetadataImpl(new MirrorTypeInfo(interfaceDecl, _env)); 129 if (null == om) { 130 return; 131 } 132 133 oms.store(om); 135 } 136 137 else { 139 messager.printError(_decl.getPosition(), "found unsupported type of TypeDeclaration:" + _decl.getSimpleName()); 140 } 141 } 142 143 catch (Throwable t) { 145 messager.printError(_decl.getPosition(), t.getMessage()); 146 } 147 } 148 149 152 @Override 153 public void generate(Declaration _decl) { 154 155 } 157 158 private BeehiveWsTypeMetadata getEndpointInterfaceObjectModel(String endpointInterface) { 159 160 BeehiveWsTypeMetadata om = null; 161 162 try { 164 om = Jsr181ObjectModelStore.load(getClass().getClassLoader().getResourceAsStream(Jsr181ObjectModelStore.getLocation(endpointInterface).toString())); 165 } 166 catch (Throwable t) { } 167 168 if (null == om) { 170 try { 171 _env.getMessager().printNotice("-> loading object model for required endpoint interface:" + endpointInterface); 172 check(_env.getTypeDeclaration(endpointInterface)); 173 om = Jsr181ObjectModelStore.load(getClass().getClassLoader().getResourceAsStream(Jsr181ObjectModelStore.getLocation(endpointInterface).toString())); 174 } 175 catch (Throwable t) { } 176 } 177 178 return om; 179 } 180 } 181 | Popular Tags |