001: package com.bm.ejb3metadata.annotations.analyzer;
002:
003: import org.ejb3unit.asm.Type;
004:
005: import com.bm.ejb3metadata.annotations.impl.JAnnotationResource;
006: import com.bm.ejb3metadata.annotations.metadata.interfaces.IAnnotationResource;
007:
008: /**
009: * This class manages the handling of @{@link javax.annotation.Resource}
010: * annotation.
011: * @param <T> An implementation of IAnnotationResource interface.
012: * @author Daniel Wiese
013: */
014: public class JavaxAnnotationResourceVisitor<T extends IAnnotationResource>
015: extends AbsAnnotationVisitor<T> implements AnnotationType {
016:
017: /**
018: * Name attribute of the annotation.
019: */
020: private static final String NAME = "name";
021:
022: /**
023: * Class with type attribute of the annotation.
024: */
025: private static final String CLASS_TYPE = "type";
026:
027: /**
028: * Atuthentication type attribute of the annotation.
029: */
030: private static final String AUTHENTICATION_TYPE = "authenticationType";
031:
032: /**
033: * Shareable attribute of the annotation.
034: */
035: private static final String SHAREABLE = "shareable";
036:
037: /**
038: * Description of the annotation.
039: */
040: private static final String DESCRIPTION = "description";
041:
042: /**
043: * Mapped name attribute of the annotation.
044: */
045: private static final String MAPPED_NAME = "mappedName";
046:
047: /**
048: * Type of annotation.
049: */
050: public static final String TYPE = "Ljavax/annotation/Resource;";
051:
052: /**
053: * Internal object used representing @{@link javax.annotation.Resource}
054: * annotation.
055: */
056: private JAnnotationResource jAnnotationResource = null;
057:
058: /**
059: * Constructor.
060: * @param annotationMetadata linked to a class or method metadata
061: */
062: public JavaxAnnotationResourceVisitor(final T annotationMetadata) {
063: super (annotationMetadata);
064: jAnnotationResource = new JAnnotationResource();
065: }
066:
067: /**
068: * Visits a primitive value of the annotation.<br>
069: * @param name the value name.
070: * @param value the actual value, whose type must be {@link Byte},
071: * {@link Boolean}, {@link Character}, {@link Short},
072: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
073: * {@link String} or {@link org.ejb3unit.asm.Type}.
074: */
075: @Override
076: public void visit(final String name, final Object value) {
077: if (name.equals(NAME)) {
078: jAnnotationResource.setName((String) value);
079: } else if (name.equals(CLASS_TYPE)) {
080: Type type = (Type) value;
081: jAnnotationResource.setType(type.getClassName());
082: } else if (name.equals(SHAREABLE)) {
083: jAnnotationResource.setShareable(((Boolean) value)
084: .booleanValue());
085: } else if (name.equals(DESCRIPTION)) {
086: jAnnotationResource.setDescription((String) value);
087: } else if (name.equals(MAPPED_NAME)) {
088: jAnnotationResource.setMappedName((String) value);
089: }
090: }
091:
092: /**
093: * Visits an enumeration value of the annotation.
094: * @param name the value name.
095: * @param desc the class descriptor of the enumeration class.
096: * @param value the actual enumeration value.
097: */
098: @Override
099: public void visitEnum(final String name, final String desc,
100: final String value) {
101: if (name.equals(AUTHENTICATION_TYPE)) {
102: /**
103: if (CONTAINER.name().equals(value)) {
104: jAnnotationResource.setAuthenticationType(CONTAINER);
105: } else if (APPLICATION.name().equals(value)) {
106: jAnnotationResource.setAuthenticationType(APPLICATION);
107: }
108: **/
109: }
110: }
111:
112: /**
113: * Visits the end of the annotation. <br>
114: * Creates the object and store it.
115: */
116: @Override
117: public void visitEnd() {
118: // add object
119: getAnnotationMetadata().setJAnnotationResource(
120: jAnnotationResource);
121: }
122:
123: /**
124: * @return type of the annotation (its description)
125: */
126: public String getType() {
127: return TYPE;
128: }
129:
130: /**
131: * @return Internal object used representing @{@link javax.annotation.Resource}
132: * annotation.
133: */
134: protected JAnnotationResource getJAnnotationResource() {
135: return jAnnotationResource;
136: }
137:
138: /**
139: * Sets the jAnnotationResource object.
140: * @param jAnnotationResource the object which replaced the previous one.
141: */
142: protected void setJAnnotationResource(
143: final JAnnotationResource jAnnotationResource) {
144: this.jAnnotationResource = jAnnotationResource;
145: }
146:
147: }
|