KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > system > MQUrl


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.connectors.system;
25
26 import java.util.logging.Logger JavaDoc;
27 import com.sun.logging.LogDomains;
28 import com.sun.enterprise.util.i18n.StringManager;
29
30
31 /**
32  * Represents one of the MQ address list elements.
33  *
34  * @author Binod P.G
35  */

36 public class MQUrl {
37
38     static Logger JavaDoc logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
39     private String JavaDoc host = null;
40     private String JavaDoc port = null;
41     private String JavaDoc scheme = "mq";
42     private String JavaDoc service = "";
43     private String JavaDoc id = null;
44
45     /**
46      * Constructs the MQUrl with the id. Id is actually
47      * the name of JmsHost element in the domain.xml.
48      *
49      * @param id Logical name of the MQUrl
50      */

51     public MQUrl(String JavaDoc id) {
52         this.id = id;
53     }
54
55     /**
56      * Sets the host name of the Url.
57      *
58      * @param host Host Name of the Url.
59      */

60     public void setHost(String JavaDoc host) {
61         this.host = host;
62     }
63
64     /**
65      * Sets the port number of the Url.
66      *
67      * @param port Port number of the Url.
68      */

69     public void setPort(String JavaDoc port) {
70         this.port = port;
71     }
72
73     /**
74      * Sets the Scheme of MQ connection for this Url.
75      * Eg> mq, mtcp, mqssl ...
76      *
77      * @param scheme scheme of the connection.
78      */

79     public void setScheme(String JavaDoc scheme) {
80         this.scheme = scheme;
81     }
82
83     /**
84      * Sets the type of service offered by MQ broker.
85      * Eg> jms, jmsssl etc.
86      *
87      * @param service Name of service.
88      */

89     public void setService(String JavaDoc service) {
90         this.service = service;
91     }
92
93     /**
94      * String representation of the Url.
95      * i.e> scheme://host:port/service
96      * Eg> mq://javasoft12:7676/jmsssl
97      *
98      * @returns String representation of Url.
99      */

100     public String JavaDoc toString() {
101         if ( host.equals("")) {
102             return "";
103         }
104
105         if ( port.equals("") && service.equals("")) {
106            return scheme + "://" + host;
107         }
108
109         if (service.equals("")) {
110            return scheme + "://" + host + ":" + port + "/";
111         }
112
113         return scheme + "://" + host + ":" + port + "/" + service;
114     }
115
116     /**
117      * Two MQUrls are identified by their id (name).
118      *
119      * @param obj another MQUrl object.
120      * @returns a boolean indicating whether MQUrls are equal.
121      */

122     public boolean equals(Object JavaDoc obj) {
123         if (obj instanceof MQUrl) {
124             return this.id.equals(((MQUrl)obj).id);
125         } else {
126             return false;
127         }
128     }
129
130     /**
131      * Hashcode of MQurl is the same as the Hashcode of its name.
132      *
133      * @return hashcode of MQUrl
134      */

135     public int hashCode() {
136         return id.hashCode();
137     }
138 }
139
Popular Tags