KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > api > jms > MantaDestination


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Nimo 23-MAR-2004.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 package org.mr.api.jms;
47
48 import javax.jms.Destination JavaDoc;
49 import javax.jms.JMSException JavaDoc;
50 import javax.naming.NamingException JavaDoc;
51 import javax.naming.Reference JavaDoc;
52 import javax.naming.Referenceable JavaDoc;
53 import javax.naming.StringRefAddr JavaDoc;
54
55 import org.mr.core.util.byteable.Byteable;
56 import org.mr.core.util.byteable.ByteableInputStream;
57 import org.mr.core.util.byteable.ByteableOutputStream;
58 import org.mr.core.util.byteable.ByteableRegistry;
59
60 import java.io.IOException JavaDoc;
61 import java.io.Serializable JavaDoc;
62
63 /**
64  * @author Nimo 23-MAR-2004
65  *
66  * A Destination object encapsulates a provider-specific address. The JMS API does not define a
67  * standard address syntax. Although a standard address syntax was considered, it was decided
68  * that the differences in address semantics between existing message-oriented middleware (MOM)
69  * products were too wide to bridge with a single syntax. Since Destination is an administered
70  * object, it may contain provider-specific configuration information in addition to its address.
71  * The JMS API also supports a client's use of provider-specific address names.
72  * Destination objects support concurrent use.
73  * A Destination object is a JMS administered object.
74  * JMS administered objects are objects containing configuration information that are created by an
75  * administrator and later used by JMS clients. They make it practical to administer the JMS API in
76  * the enterprise. Although the interfaces for administered objects do not explicitly depend on the
77  * Java Naming and Directory Interface (JNDI) API, the JMS API establishes the convention that JMS
78  * clients find administered objects by looking them up in a JNDI namespace.
79  * An administrator can place an administered object anywhere in a namespace. The JMS API does not
80  * define a naming policy.
81  * It is expected that JMS providers will provide the tools an administrator needs to create and
82  * configure administered objects in a JNDI namespace. JMS provider implementations of administered
83  * objects should implement the javax.naming.Referenceable and java.io.Serializable interfaces so that
84  * they can be stored in all JNDI naming contexts. In addition, it is recommended that these
85  * implementations follow the JavaBeansTM design patterns.
86  *
87  * This strategy provides several benefits:
88  *
89  * It hides provider-specific details from JMS clients.
90  * It abstracts JMS administrative information into objects in the Java programming language
91  * ("Java objects") that are easily organized and administered from a common management console.
92  * Since there will be JNDI providers for all popular naming services, JMS providers can deliver
93  * one implementation of administered objects that will run everywhere. An administered object
94  * should not hold on to any remote resources. Its lookup should not use remote resources other
95  * than those used by the JNDI API itself. Clients should think of administered objects as local
96  * Java objects. Looking them up should not have any hidden side effects or use surprising amounts
97  * of local resources
98  *
99  */

100
101 public class MantaDestination implements Destination JavaDoc, Byteable, Referenceable JavaDoc, Serializable JavaDoc {
102
103    /**
104      * generated <code>serialVersionUID</code>
105      */

106     private static final long serialVersionUID = 6875502999461250235L;
107     //The name of the destination that this object refers to.
108
String JavaDoc destinationName;
109     
110     /**
111      * Constructors for the destination object
112      */

113     public MantaDestination() {
114     }
115     public MantaDestination(String JavaDoc s) {
116         this.destinationName = s;
117     }
118     public MantaDestination(Destination JavaDoc d) {
119         this.destinationName = d.toString();
120     }
121     
122     public void setPhysicalName(String JavaDoc name) throws JMSException JavaDoc {
123         destinationName = name;
124     }
125     
126     public String JavaDoc getPhysicalName() {
127         return destinationName;
128     }
129     
130     public String JavaDoc toString() {
131         return destinationName;
132     }
133     
134     //Byteable methods-------------------
135
final static String JavaDoc objName = "MantaDest";
136      public String JavaDoc getByteableName() {
137         
138         return objName;
139     }
140
141     public void toBytes(ByteableOutputStream out) throws IOException JavaDoc {
142         
143         out.writeUTF(destinationName);
144         out.flush();
145         
146     }
147
148     public Byteable createInstance(ByteableInputStream in) throws IOException JavaDoc {
149     
150         MantaDestination cd = new MantaDestination();
151         cd.destinationName = in.readUTF();
152         return cd;
153     }
154
155     public void registerToByteableRegistry() {
156         ByteableRegistry.registerByteableFactory(getByteableName() , this);
157         
158     }
159     
160     public static void register() throws JMSException JavaDoc{
161         MantaDestination instance = new MantaDestination();
162         instance.registerToByteableRegistry();
163     }
164    
165     /**
166      * A destination may be looked up from a JNDI. Therefore it must
167      * implement the Referencable interface and have this method inside it.
168      *
169      */

170     public Reference JavaDoc getReference() throws NamingException JavaDoc {
171       
172       return new Reference JavaDoc (
173          getClass().getName(),
174          new StringRefAddr JavaDoc("name",this.destinationName),
175          MantaDestinationFactory.class.getName(),
176          null
177       );
178       
179    }
180 }
181
Popular Tags