KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > bussinessproxy > meta > EJBTargetMetaDef


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7  http://www.apache.org/licenses/LICENSE-2.0
8
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package com.jdon.bussinessproxy.meta;
17
18 /**
19  * EJB2 Service META definition
20  *
21  */

22
23 public class EJBTargetMetaDef extends DistributedTargetMetaDef {
24
25     private boolean isLocal = true;
26     
27     private String JavaDoc home;
28
29     private String JavaDoc remote;
30
31     private String JavaDoc local;
32
33     /**
34      * remote EJB
35      */

36     public EJBTargetMetaDef(String JavaDoc name, String JavaDoc p_jndiName,
37             String JavaDoc p_homeClassName, String JavaDoc p_remoteClassName) {
38         super(name, p_jndiName);
39         this.home = p_homeClassName;
40         this.remote = p_remoteClassName;
41         this.isLocal = false;
42     }
43
44     /**
45      * local EJB
46      */

47     public EJBTargetMetaDef(String JavaDoc name, String JavaDoc p_jndiName,
48             String JavaDoc p_localClassName) {
49         super(name, p_jndiName);
50         this.local = p_localClassName;
51     }
52     
53     public boolean isEJB() {
54         return true;
55     }
56
57     public boolean isLocal() {
58         return isLocal;
59     }
60
61     public Class JavaDoc getHomeClass() {
62         try {
63             return Class.forName(home);
64         } catch (ClassNotFoundException JavaDoc ex) {
65             throw new RuntimeException JavaDoc("Unable to load the class : " + home);
66         }
67     }
68
69     public Class JavaDoc getRemoteClass() {
70         try {
71             return Class.forName(remote);
72         } catch (ClassNotFoundException JavaDoc ex) {
73             throw new RuntimeException JavaDoc("Unable to load the class : " + remote);
74         }
75     }
76
77     public String JavaDoc getClassName() {
78         if (isLocal)
79             return getLocalName();
80         else
81             return getRemoteName();
82
83     }
84
85     public String JavaDoc getLocalName() {
86         return local;
87     }
88
89     public String JavaDoc getRemoteName() {
90         return remote;
91     }
92
93     public String JavaDoc getHomeName() {
94         return home;
95     }
96
97     public boolean equals(Object JavaDoc obj) {
98         if (obj instanceof EJBTargetMetaDef) {
99             EJBTargetMetaDef definition = (EJBTargetMetaDef) obj;
100             if (isLocal) {
101                 if (!(definition.getLocalName().equals(local))
102                         || !(definition.getJndiName().equals(jndiName)))
103                     return false;
104
105             } else {
106                 if (!(definition.getHomeName().equals(home))
107                         || !(definition.getJndiName().equals(jndiName))
108                         || !(definition.getRemoteName().equals(remote)))
109                     return false;
110             }
111             return true;
112         }
113         return false;
114     }
115
116     public String JavaDoc toString() {
117         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("EJB");
118         buffer.append(jndiName);
119         buffer.append("Home/Local class :");
120         if (isLocal)
121             buffer.append(local);
122         else
123             buffer.append(home);
124
125         return buffer.toString();
126     }
127
128     public int hashCode() {
129         return jndiName.hashCode();
130     }
131
132     /**
133      * @return Returns the name.
134      */

135     public String JavaDoc getName() {
136         return name;
137     }
138
139     /**
140      * @param name
141      * The name to set.
142      */

143     public void setName(String JavaDoc name) {
144         this.name = name;
145     }
146
147     /**
148      * jndiName作为EJB的key
149      * @return String
150      */

151     public String JavaDoc getCacheKey() {
152         return jndiName;
153     }
154
155 }
156
Popular Tags