1 46 package org.mr.api.jms; 47 48 import javax.jms.Destination ; 49 import javax.jms.JMSException ; 50 import javax.naming.NamingException ; 51 import javax.naming.Reference ; 52 import javax.naming.Referenceable ; 53 import javax.naming.StringRefAddr ; 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 ; 61 import java.io.Serializable ; 62 63 100 101 public class MantaDestination implements Destination , Byteable, Referenceable , Serializable { 102 103 106 private static final long serialVersionUID = 6875502999461250235L; 107 String destinationName; 109 110 113 public MantaDestination() { 114 } 115 public MantaDestination(String s) { 116 this.destinationName = s; 117 } 118 public MantaDestination(Destination d) { 119 this.destinationName = d.toString(); 120 } 121 122 public void setPhysicalName(String name) throws JMSException { 123 destinationName = name; 124 } 125 126 public String getPhysicalName() { 127 return destinationName; 128 } 129 130 public String toString() { 131 return destinationName; 132 } 133 134 final static String objName = "MantaDest"; 136 public String getByteableName() { 137 138 return objName; 139 } 140 141 public void toBytes(ByteableOutputStream out) throws IOException { 142 143 out.writeUTF(destinationName); 144 out.flush(); 145 146 } 147 148 public Byteable createInstance(ByteableInputStream in) throws IOException { 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 { 161 MantaDestination instance = new MantaDestination(); 162 instance.registerToByteableRegistry(); 163 } 164 165 170 public Reference getReference() throws NamingException { 171 172 return new Reference ( 173 getClass().getName(), 174 new StringRefAddr ("name",this.destinationName), 175 MantaDestinationFactory.class.getName(), 176 null 177 ); 178 179 } 180 } 181 | Popular Tags |