[jboss-dev-forums] [Design of POJO Server] - Re: Diff behavior with diff AnnotatedMetaDataDeployer
alesj
do-not-reply at jboss.com
Wed Jul 30 14:32:28 EDT 2008
Opt:
| public class OptAnnotationMetaDataDeployer extends AnnotationMetaDataDeployer
| {
| public OptAnnotationMetaDataDeployer()
| {
| super();
| setInput(AnnotationEnvironment.class);
| }
|
| protected void processMetaData(VFSDeploymentUnit unit, WebMetaData webMetaData, ApplicationClientMetaData clientMetaData, List<VirtualFile> classpath) throws Exception
| {
| AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
| if(webMetaData != null)
| {
| processJBossWebMetaData(unit, finder);
| }
| else
| {
| if (clientMetaData != null)
| {
| processJBossClientMetaData(unit, finder);
| }
| else
| {
| String mainClassName = getMainClassName(unit);
| if (mainClassName != null)
| {
| processJBossClientMetaData(unit, finder);
| }
| else
| {
| processJBossMetaData(unit, finder);
| }
| }
| }
| }
|
| /**
| * Process jboss web meta data.
| *
| * @param unit the deployment unit
| * @param finder the finder
| */
| protected void processJBossWebMetaData(VFSDeploymentUnit unit, AnnotationFinder<AnnotatedElement> finder)
| {
| Web25MetaDataCreator creator = new Web25MetaDataCreator(finder);
| Collection<Class<?>> classes = getClasses(unit, creator);
| WebMetaData annotationMetaData = creator.create(classes);
| if(annotationMetaData != null)
| unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME, annotationMetaData, WebMetaData.class);
| }
|
| /**
| * Process jboss app client meta data.
| *
| * @param unit the deployment unit
| * @param finder the finder
| */
| protected void processJBossClientMetaData(VFSDeploymentUnit unit, AnnotationFinder<AnnotatedElement> finder)
| {
| ApplicationClient5MetaDataCreator creator = new ApplicationClient5MetaDataCreator(finder);
| Collection<Class<?>> classes = getClasses(unit, creator);
| ApplicationClientMetaData annotationMetaData = creator.create(classes);
| if(annotationMetaData != null)
| unit.addAttachment(CLIENT_ANNOTATED_ATTACHMENT_NAME, annotationMetaData, ApplicationClientMetaData.class);
| }
|
| /**
| * Process jboss meta data.
| *
| * @param unit the deployment unit
| * @param finder the finder
| */
| protected void processJBossMetaData(VFSDeploymentUnit unit, AnnotationFinder<AnnotatedElement> finder)
| {
| // Create the metadata model from the annotations
| JBoss50Creator creator = new JBoss50Creator(finder);
| Collection<Class<?>> classes = getClasses(unit, creator);
| JBossMetaData annotationMetaData = creator.create(classes);
| if(annotationMetaData != null)
| unit.addAttachment(EJB_ANNOTATED_ATTACHMENT_NAME, annotationMetaData, JBossMetaData.class);
| }
|
| /**
| * Get the classes for creator to process.
| *
| * @param unit the deployment unit
| * @param creator the creator
| * @return classes to process
| */
| @SuppressWarnings("unchecked")
| protected Collection<Class<?>> getClasses(VFSDeploymentUnit unit, AbstractCreator creator)
| {
| boolean trace = log.isTraceEnabled();
|
| AnnotationEnvironment env = unit.getAttachment(AnnotationEnvironment.class);
| if (env == null)
| {
| if (trace)
| log.trace("Cannot scan classes, missing AnnotationEnvironment as attachment: " + unit.getName());
|
| return Collections.emptySet();
| }
|
| String creatorInfo = creator.toString();
| AnnotationContext context = creator.getAnnotationContext();
| Set<Class<?>> classes = new HashSet<Class<?>>();
|
| Collection<Class<? extends Annotation>> typeAnnotations = context.getTypeAnnotations();
| if (trace)
| log.trace("Creator: " + creatorInfo + ", type annotations: " + typeAnnotations);
| for(Class<? extends Annotation> annotation : typeAnnotations)
| {
| Class<Annotation> annotationClass = (Class<Annotation>)annotation;
| Set<Element<Annotation, Class<?>>> elements = env.classIsAnnotatedWith(annotationClass);
| for(Element<Annotation, Class<?>> elt : elements)
| classes.add(elt.getOwner());
| }
|
| Collection<Class<? extends Annotation>> methodAnnotations = context.getMethodAnnotations();
| if (trace)
| log.trace("Creator: " + creatorInfo + ", method annotations: " + methodAnnotations);
| for(Class<? extends Annotation> annotation : methodAnnotations)
| {
| Class<Annotation> annotationClass = (Class<Annotation>)annotation;
| Set<Element<Annotation, Method>> elements = env.classHasMethodAnnotatedWith(annotationClass);
| for(Element<Annotation, Method> elt : elements)
| classes.add(elt.getOwner());
| }
|
| Collection<Class<? extends Annotation>> fieldAnnotations = context.getFieldAnnotations();
| if (trace)
| log.trace("Creator: " + creatorInfo + ", field annotations: " + fieldAnnotations);
| for(Class<? extends Annotation> annotation : fieldAnnotations)
| {
| Class<Annotation> annotationClass = (Class<Annotation>)annotation;
| Set<Element<Annotation, Field>> elements = env.classHasFieldAnnotatedWith(annotationClass);
| for(Element<Annotation, Field> elt : elements)
| classes.add(elt.getOwner());
| }
|
| if (trace)
| log.trace("Annotated classes [" + unit.getName() + ", " + creatorInfo + "]: " + classes);
|
| return classes;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4167717#4167717
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4167717
More information about the jboss-dev-forums
mailing list