KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > InjectionTarget


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment;
25
26 import java.lang.reflect.Field JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28 import com.sun.enterprise.util.TypeUtil;
29
30 /**
31  * This class holds information about an injection target like the class name
32  * of the injected target, and field/method information used for injection.
33  *
34  * @author Jerome Dochez
35  */

36 public class InjectionTarget {
37     
38     private String JavaDoc className=null;
39     private String JavaDoc targetName=null;
40     private String JavaDoc fieldName=null;
41     private String JavaDoc methodName=null;
42     
43     // runtime info, not persisted
44
private Field JavaDoc field=null;
45     private Method JavaDoc method=null;
46     
47     public boolean isFieldInjectable() {
48         return fieldName!=null;
49     }
50
51     public boolean isMethodInjectable() {
52         return methodName!=null;
53     }
54     
55     public String JavaDoc getClassName() {
56         return className;
57     }
58     
59     public void setClassName(String JavaDoc className) {
60         this.className = className;
61     }
62     
63    /**
64      * This is the form used by the .xml injection-group elements to
65      * represent the target of injection. It either represents the
66      * javabeans property name of the injection method or the name
67      * of the injected field. This value is set on the descriptor
68      * during .xml processing and converted into the appropriate
69      * field/method name during validation.
70      */

71
72     public String JavaDoc getTargetName() {
73         return targetName;
74     }
75     
76     public void setTargetName(String JavaDoc targetName) {
77         this.targetName = targetName;
78     }
79
80     public String JavaDoc getFieldName() {
81         return fieldName;
82     }
83     
84     public void setFieldName(String JavaDoc fieldName) {
85         this.fieldName = fieldName;
86         this.targetName = fieldName;
87     }
88
89     /*
90      * runtime cached information for faster lookup
91      */

92     public Field JavaDoc getField() {
93         return field;
94     }
95     public void setField(Field JavaDoc field) {
96         this.field = field;
97     }
98
99     /**
100      * Inject method name is the actual java method name of the setter method,
101      * not the bean property name. E.g., for @Resource void setFoo(Bar b)
102      * it would be "setFoo", not the property name "foo".
103      */

104     public String JavaDoc getMethodName() {
105         return methodName;
106     }
107     public void setMethodName(String JavaDoc methodName) {
108         this.methodName = methodName;
109         // Method name follows java beans setter syntax
110
this.targetName = TypeUtil.setterMethodToPropertyName(methodName);
111 ;
112     }
113
114     // runtime cached information
115
public Method JavaDoc getMethod() {
116         return method;
117     }
118     public void setMethod(Method JavaDoc method) {
119         this.method = method;
120     }
121
122     public boolean equals(Object JavaDoc o) {
123         if (!(o instanceof InjectionTarget)) {
124             return false;
125         } else {
126             InjectionTarget injTarget = (InjectionTarget)o;
127             return equals(className, injTarget.className) &&
128                    equals(targetName, injTarget.targetName) &&
129                    equals(fieldName, injTarget.fieldName) &&
130                    equals(methodName, injTarget.methodName);
131         }
132     }
133
134     private boolean equals(String JavaDoc s1, String JavaDoc s2) {
135         return (s1 != null && s1.equals(s2) || s1 == null && s2 == null);
136     }
137 }
138
Popular Tags