KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > jbicommon > descriptor > Consumes


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005-2006 EBM WebSourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id$
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.tools.jbicommon.descriptor;
24
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.commons.lang.builder.EqualsBuilder;
28 import org.apache.commons.lang.builder.HashCodeBuilder;
29 import org.apache.commons.lang.builder.ToStringBuilder;
30
31 /**
32  * The consumes element is used to declare a service consumed by a service unit.
33  * A consumed service must be define with the following required attribute:
34  * <ul>
35  * <li><b>interface-name.</b> This qualified name indicates the type of
36  * service to be consumed.</li>
37  * </ul>
38  * Optionally a fully qualified name of the endpoint the SU will use to consume
39  * the service can be specified. If the service endpoint name is declared, an
40  * optional attribute can be supplied:
41  * <ul>
42  * <li><b>link-type.</b> This attribute is used to indicate the expected use
43  * of this consumer with connection links. The possible values of this
44  * attributes are:</li>
45  * <ul>
46  * <li><b>standard.</b> This is the default value. This indicates that the
47  * provided service endpoint must be routed according to standard normalized
48  * message routing rules.</li>
49  * <li><b>hard.</b>This indicates that the provided service endpoint name must
50  * match a service provider's service endpoint name; indirect connections are
51  * not allowed.</li>
52  * <li><b>soft.</b>This indicates that the provided service endpoint must
53  * <i>not</i> match a service provider's service endpoint name; rather, it must
54  * match an indirect connection name.</li>
55  * </ul>
56  * </ul>
57  *
58  * @version $Rev: 477 $ $Date: 2006-05-29 15:18:07Z $
59  * @since Petals 1.0
60  * @author <a HREF="mailto:rmarins@fossilec.com">Rafael Marins</a>
61  */

62 public class Consumes extends ExtensibleJbiElement {
63
64     /**
65      * Hard Link Type.
66      */

67     public static final String JavaDoc HARD_LINK_TYPE = "hard";
68
69     /**
70      * Soft Link Type.
71      */

72     public static final String JavaDoc SOFT_LINK_TYPE = "soft";
73
74     /**
75      * Standard Link Type.
76      */

77     public static final String JavaDoc STD_LINK_TYPE = "standard";
78
79     /**
80      * Endpoint name to be provided.
81      */

82     private String JavaDoc endpointName;
83
84     /**
85      * Qualified interface name.
86      */

87     private QName JavaDoc interfaceName;
88
89     /**
90      * The optional link type.
91      */

92     private String JavaDoc linkType;
93
94     /**
95      * Service name to be provided.
96      */

97     private QName JavaDoc serviceName;
98
99     /**
100      * Default constructor.
101      */

102     public Consumes() { // NOPMD by gblondelle
103
super();
104     }
105
106     @Override JavaDoc
107     public boolean equals(final Object JavaDoc other) {
108         if (!(other instanceof Consumes)) {
109             return false; // NOPMD by gblondelle
110
}
111         Consumes castOther = (Consumes) other;
112         return new EqualsBuilder().append(endpointName, castOther.endpointName)
113                 .append(interfaceName, castOther.interfaceName).append(
114                         linkType, castOther.linkType).append(serviceName,
115                         castOther.serviceName).isEquals();
116     }
117
118     /**
119      * Returns the optional fully qualified endpoint which the service unit will
120      * use to consume the service.
121      *
122      * @return <code>String</code> the endpoint name.
123      */

124     public String JavaDoc getEndpointName() {
125         return endpointName;
126     }
127
128     /**
129      * Return the qualified name indicating the type of service to be consumed.
130      *
131      * @return <code>QName</code> the interface name.
132      */

133     public QName JavaDoc getInterfaceName() {
134         return interfaceName;
135     }
136
137     /**
138      * Returns the optional link type associated to a fully qualified endpoint
139      * the SU will use to consume the service.
140      *
141      * @return <code>String</code> the link type: <code>"standard"</code>,
142      * <code>"hard"</code> or <code>"soft"</code>.
143      */

144     public String JavaDoc getLinkType() {
145         return linkType;
146     }
147
148     //
149
// Getters and Setters
150
//
151

152     /**
153      * Returns the optional fully qualified service name which the service unit
154      * will use to consume the service.
155      *
156      * @return <code>QName</code> the service name.
157      */

158     public QName JavaDoc getServiceName() {
159         return serviceName;
160     }
161
162     @Override JavaDoc
163     public int hashCode() {
164         return new HashCodeBuilder().append(endpointName).append(interfaceName)
165                 .append(linkType).append(serviceName).toHashCode();
166     }
167
168     /**
169      * Returns <code>true</code> if the hard link type is used.
170      */

171     public boolean isHardLink() {
172         return (hasQualifiedEndpoint())
173                 && (linkType != null && linkType.equals(HARD_LINK_TYPE));
174     }
175
176     /**
177      * Returns <code>true</code> if the soft link type is used.
178      */

179     public boolean isSoftLink() {
180         return (hasQualifiedEndpoint())
181                 && (linkType != null && linkType.equals(SOFT_LINK_TYPE));
182     }
183
184     /**
185      * Returns <code>true</code> if the standard link type is used.
186      */

187     public boolean isStandardLink() {
188         return (hasQualifiedEndpoint())
189                 && (linkType == null || linkType.equals(STD_LINK_TYPE));
190     }
191
192     @Override JavaDoc
193     public String JavaDoc toString() {
194         return new ToStringBuilder(this).append("endpointName", endpointName)
195                 .append("interfaceName", interfaceName).append("linkType",
196                         linkType).append("serviceName", serviceName).toString();
197     }
198
199     /**
200      * Returns <code>true</code> if the optional fully qualified endpoint name
201      * have been specified. Otherwise, returns <code>false</code>.
202      */

203     boolean hasQualifiedEndpoint() {
204         return serviceName != null && endpointName != null;
205     }
206
207     //
208
// implementation methods
209
//
210

211     /**
212      * Set the optional fully qualified endpoint name which the service unit
213      * will consume.
214      *
215      * @param endpointName
216      * the endpoint name.
217      */

218     void setEndpointName(final String JavaDoc endpointName) {
219         this.endpointName = endpointName;
220     }
221
222     /**
223      * Set the interface name indicating the type of service to be consumed.
224      *
225      * @param interfaceName
226      * the interface name.
227      */

228     void setInterfaceName(final QName JavaDoc interfaceName) {
229         this.interfaceName = interfaceName;
230     }
231
232     /**
233      * Set the optional link type.
234      *
235      * @param type
236      * the link type.
237      */

238     void setLinkType(final String JavaDoc type) {
239         this.linkType = type;
240     }
241
242     /**
243      * Set the optional fully qualified service name which the service unit will
244      * consume.
245      *
246      * @param serviceName
247      * the service name.
248      */

249     void setServiceName(final QName JavaDoc serviceName) {
250         this.serviceName = serviceName;
251     }
252 }
253
Popular Tags