1 46 package org.mr.api.jms; 47 48 import org.mr.MantaAgent; 49 import org.xml.sax.SAXException ; 50 import org.xml.sax.InputSource ; 51 import org.w3c.dom.Document ; 52 import org.w3c.dom.Element ; 53 54 55 import javax.jms.*; 56 import javax.naming.NamingException ; 57 import javax.naming.Reference ; 58 import javax.naming.Referenceable ; 59 import javax.naming.StringRefAddr ; 60 import javax.xml.parsers.ParserConfigurationException ; 61 import javax.xml.parsers.DocumentBuilderFactory ; 62 import javax.xml.parsers.DocumentBuilder ; 63 64 import java.util.Vector ; 65 import java.io.Serializable ; 66 import java.io.StringReader ; 67 import java.io.IOException ; 68 69 127 public class MantaConnectionFactory implements Serializable , Referenceable , 128 ConnectionFactory { 129 132 private static final long serialVersionUID = -3363600666809978286L; 133 String name; 134 135 141 public MantaConnectionFactory() { 142 this(MantaConnection.JMS_AGENT_NAME); 143 } 144 public MantaConnectionFactory(String s) { 145 this.name = s; 146 } 147 148 163 public Connection createConnection() throws JMSException{ 164 165 return createConnection("unknown","unknown"); 166 } 168 188 public Connection createConnection(String userName, String password) throws JMSException{ 189 190 MantaConnection cc = new MantaConnection(this,userName,password); 191 addNewConnection(cc); 192 return cc; 193 } 195 196 197 201 void addNewConnection (Connection connection) { 202 createdConnections.addElement(connection); 203 } 204 205 209 void removeConnection (Connection connection) { 210 createdConnections.removeElement(connection); 211 } 212 213 public String toString() 214 { 215 return name; 216 } 217 218 222 MantaAgent getChannel() 223 { 224 MantaAgent agent = MantaAgent.getInstance(); 225 agent.init(); 226 return agent; 227 } 228 229 230 234 public Reference getReference() throws NamingException { 235 236 return new Reference ( 237 getClass().getName(), 238 new StringRefAddr ("name",this.name), 239 MantaConnectionFactoryFactory.class.getName(), 240 null 241 ); 242 } 243 244 246 247 248 Vector createdConnections = new Vector (); 250 251 252 259 public void setConfiguration(Element element){ 260 MantaAgent.setConfiguration(element); 261 } 262 263 273 public void setConfiguration(String strConfiguration) throws ParserConfigurationException , SAXException , IOException { 274 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 275 factory.setIgnoringElementContentWhitespace(true); 276 DocumentBuilder xmlBuilder= factory.newDocumentBuilder(); 277 Document xmlDoc = xmlBuilder.parse(new InputSource (new StringReader (strConfiguration))); 278 Element configurationElement = xmlDoc.getDocumentElement(); 279 MantaAgent.setConfiguration(configurationElement); 280 } 281 } 282 | Popular Tags |