KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment;
24
25 import java.util.Set JavaDoc;
26
27 import com.sun.enterprise.deployment.types.MessageDestinationReference;
28 import com.sun.enterprise.util.LocalStringManagerImpl;
29
30
31 /**
32  * An object representing the use of a message destination in a
33  * J2EE component.
34  *
35  * @author Kenneth Saks
36  *
37 */

38
39 public class MessageDestinationReferenceDescriptor extends EnvironmentProperty
40     implements MessageDestinationReference {
41
42     // Usage types
43
public static final String JavaDoc CONSUMES = "Consumes";
44     public static final String JavaDoc PRODUCES = "Produces";
45     public static final String JavaDoc CONSUMES_PRODUCES = "ConsumesProduces";
46     
47     private static LocalStringManagerImpl localStrings =
48         new LocalStringManagerImpl(MessageDestinationReferenceDescriptor.class);
49     
50     private BundleDescriptor referringBundle;
51
52     private String JavaDoc usage;
53
54     private String JavaDoc destinationType;
55
56     // JNDI name of physical destination
57
private String JavaDoc jndiName;
58
59     // Holds information about the destination to which we are linked.
60
private MessageDestinationReferencerImpl referencer;
61     
62     /**
63     * copy constructor
64     */

65     public MessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor other) {
66     super(other);
67     referringBundle = other.referringBundle; // copy as-is
68
usage = other.usage; // immutable String
69
destinationType = other.destinationType; // immutable String
70
referencer = new MessageDestinationReferencerImpl(other.referencer);
71     }
72
73     /**
74      * Construct an message destination reference
75      * with the given name and descriptor of the reference.
76      *
77      * @param name the message-destination-ref name as used in
78      * the referencing component
79      * @param optional description
80      */

81     public MessageDestinationReferenceDescriptor(String JavaDoc name, String JavaDoc desc) {
82     super(name, "", desc);
83         referencer = new MessageDestinationReferencerImpl(this);
84     }
85     
86     /**
87     * Constructs a reference in the extrernal state.
88     */

89     
90     public MessageDestinationReferenceDescriptor() {
91         referencer = new MessageDestinationReferencerImpl(this);
92     }
93     
94     /**
95      * @return the usage type of the message destination reference
96      * (Consumes, Produces, ConsumesProduces)
97      */

98     public String JavaDoc getUsage() {
99         return usage;
100     }
101
102     /**
103      * @param usage the usage type of the message destination reference
104      * (Consumes, Produces, ConsumesProduces)
105      */

106     public void setUsage(String JavaDoc destUsage) {
107         usage = destUsage;
108     }
109
110     public String JavaDoc getDestinationType() {
111         return destinationType;
112     }
113
114     public void setDestinationType(String JavaDoc type) {
115         destinationType = type;
116     }
117
118     public String JavaDoc getJndiName() {
119         return (jndiName != null && ! jndiName.equals("")) ?
120             jndiName : mappedName;
121     }
122
123     public void setJndiName(String JavaDoc physicalDestinationName) {
124         jndiName = physicalDestinationName;
125     }
126
127     public String JavaDoc getInjectResourceType() {
128         return getDestinationType();
129     }
130
131     public void setInjectResourceType(String JavaDoc resourceType) {
132         setDestinationType(resourceType);
133     }
134
135     /**
136      * Set the referring bundle, i.e. the bundle within which this
137      * message destination reference is declared.
138      */

139     public void setReferringBundleDescriptor(BundleDescriptor referringBundle)
140     {
141     this.referringBundle = referringBundle;
142     }
143
144     /**
145      * Get the referring bundle, i.e. the bundle within which this
146      * message destination reference is declared.
147      */

148     public BundleDescriptor getReferringBundleDescriptor()
149     {
150     return referringBundle;
151     }
152
153     //
154
// Implementations of MessageDestinationReferencer methods.
155
//
156

157     public boolean isLinkedToMessageDestination() {
158         return referencer.isLinkedToMessageDestination();
159     }
160     
161     /**
162      * @return the name of the message destination to which I refer
163      */

164     public String JavaDoc getMessageDestinationLinkName() {
165         return referencer.getMessageDestinationLinkName();
166     }
167
168     /**
169      * Sets the name of the message destination to which I refer.
170      */

171     public void setMessageDestinationLinkName(String JavaDoc linkName) {
172         referencer.setMessageDestinationLinkName(linkName);
173     }
174
175     public MessageDestinationDescriptor setMessageDestinationLinkName
176         (String JavaDoc linkName, boolean resolveLink) {
177         return referencer.setMessageDestinationLinkName(linkName, resolveLink);
178     }
179
180     public MessageDestinationDescriptor resolveLinkName() {
181         return referencer.resolveLinkName();
182     }
183         
184     public boolean ownedByMessageDestinationRef() {
185         return true;
186     }
187
188     /**
189      * Get the descriptor for the message destination reference owner.
190      */

191     public MessageDestinationReferenceDescriptor getMessageDestinationRefOwner
192         () {
193         return this;
194     }
195
196     /**
197      * True if the owner is a message-driven bean.
198      */

199     public boolean ownedByMessageBean() {
200         return false;
201     }
202
203     /**
204      * Get the descriptor for the message-driven bean owner.
205      */

206     public EjbMessageBeanDescriptor getMessageBeanOwner() {
207         return null;
208     }
209
210     /**
211      * @return the message destination to which I refer. Can be NULL.
212     */

213     public MessageDestinationDescriptor getMessageDestination() {
214         return referencer.getMessageDestination();
215     }
216
217     /**
218      * @param messageDestiation the message destination to which I refer.
219      */

220     public void setMessageDestination(MessageDestinationDescriptor newMsgDest) {
221         referencer.setMessageDestination(newMsgDest);
222     }
223
224     /** returns a formatted string representing me.
225     */

226     
227     public void print(StringBuffer JavaDoc toStringBuffer) {
228         if (isLinkedToMessageDestination()) {
229         toStringBuffer.append("Resolved Message-Destination-Ref ").append(getName()).append(
230                 "points to logical message destination ").append(getMessageDestination().getName());
231     } else {
232         toStringBuffer.append("Unresolved Message-Destination-Ref ").append(getName()).append(
233                 "@").append(getType()).append("@").append(usage);
234     }
235     }
236     
237     /* Equality on name. */
238     public boolean equals(Object JavaDoc object) {
239     if (object instanceof MessageDestinationReference) {
240         MessageDestinationReference reference =
241                 (MessageDestinationReference) object;
242         return reference.getName().equals(this.getName());
243     }
244     return false;
245     }
246 }
247
Popular Tags