Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 269   Methods: 20
NCLOC: 84   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JMSConnection.java 75% 80% 75% 77.6%
coverage coverage
 1    /**
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.config.jms;
 8   
 9    import java.io.Serializable;
 10    import java.util.Collection;
 11    import java.util.Vector;
 12    import java.util.Iterator;
 13   
 14    /**
 15    * This class is the object oriented representation of the
 16    * <code>connection</code> element you can find inside the
 17    * <code>jtr.xml</code> configuration file.<br>
 18    * It is logically mapped to a <code>javax.jms.Connection</code>. A
 19    * <code>JMSConnection</code> holds one or more <code>JMSSession</code>s.
 20    *
 21    * @author Francesco Russo (frusso@dev.java.net)
 22    * @version 4.0
 23    * @since 1.1
 24    */
 25    public class JMSConnection implements Serializable {
 26    /**
 27    * Default constructor.
 28    */
 29  1 public JMSConnection() {
 30  1 sessions = new Vector<JMSSession>();
 31    }
 32   
 33    /**
 34    * Set the type of the connection. It can be <code>queue | topic</code>.
 35    *
 36    * @param type
 37    * One of the following two values: <code>queue | topic</code>
 38    */
 39  6 public void setType(String type) {
 40  6 this.type = type;
 41    }
 42   
 43    /**
 44    * Get the type of the connection. It can be <code>queue | topic</code>.
 45    *
 46    * @return String One of the following two values:
 47    * <code>queue | topic</code>
 48    */
 49  28 public String getType() {
 50  28 return type;
 51    }
 52   
 53    /**
 54    * Set the name of the property of the concrete runner that will hold the
 55    * actual <code>Connection</code> instance.
 56    *
 57    * @param property
 58    * The property
 59    */
 60  6 public void setProperty(String property) {
 61  6 this.property = property;
 62    }
 63   
 64    /**
 65    * Get the name of the property of the concrete runner that will hold the
 66    * actual <code>Connection</code> instance.
 67    *
 68    * @return String The property
 69    */
 70  14 public String getProperty() {
 71  14 return property;
 72    }
 73   
 74    /**
 75    * Set the user name required to establish this
 76    * <code>javax.jms.Connection</code>.
 77    *
 78    * @param name
 79    * The user name
 80    */
 81  0 public void setUserName(String name) {
 82  0 userName = name;
 83    }
 84   
 85    /**
 86    * Get the user name required to establish this
 87    * <code>javax.jms.Connection</code>.
 88    *
 89    * @return String The user name
 90    */
 91  14 public String getUserName() {
 92  14 return userName;
 93    }
 94   
 95    /**
 96    * Set the password required to establish this
 97    * <code>javax.jms.Connection</code>.
 98    *
 99    * @param passw
 100    * The password
 101    */
 102  0 public void setPassword(String passw) {
 103  0 password = passw;
 104    }
 105   
 106    /**
 107    * Get the password required to establish this
 108    * <code>javax.jms.Connection</code>.
 109    *
 110    * @return String The password
 111    */
 112  14 public String getPassword() {
 113  14 return password;
 114    }
 115   
 116    /**
 117    * Set the clientID for the current <code>javax.jms.Connection</code>.
 118    *
 119    * @param cid
 120    * The clientID
 121    */
 122  6 public void setClientId(String cid) {
 123  6 clientId = cid;
 124    }
 125   
 126    /**
 127    * Get the clientID for the current <code>javax.jms.Connection</code>.
 128    *
 129    * @return String The clientID
 130    */
 131  42 public String getClientId() {
 132  42 return clientId;
 133    }
 134   
 135    /**
 136    * Set whether this <code>javax.jms.Connection</code> is shareable or not.
 137    *
 138    * @param val
 139    * boolean
 140    */
 141  6 public void setShared(boolean val) {
 142  6 shared = val;
 143    }
 144   
 145    /**
 146    * Is this <code>javax.jms.Connection</code> shareable?
 147    *
 148    * @return boolean
 149    */
 150  14 public boolean isShared() {
 151  14 return shared;
 152    }
 153   
 154    /**
 155    * Every connection can have multiple sessions. This method adds a session
 156    * to the current connection.
 157    *
 158    * @param session
 159    * The session
 160    */
 161  1 public void addSession(JMSSession session) {
 162  1 sessions.add(session);
 163    }
 164   
 165    /**
 166    * Returns all the configured sessions.
 167    *
 168    * @return Collection A <code>Collection</code> of <code>JMSSession</code>s
 169    */
 170  14 public Collection<JMSSession> getSessions() {
 171  14 return sessions;
 172    }
 173   
 174    /**
 175    * States whether the given <code>JMSConnection</code> is a queue
 176    * connection or not
 177    *
 178    * @param jmsConn
 179    * The <code>JMSConnection</code> to be analized
 180    * @return boolean <code>true</code> iff it is a queue connection
 181    */
 182  28 public static boolean isQueueConnection(JMSConnection jmsConn) {
 183  28 return QUEUE_CONNECTION.equals(jmsConn.getType().trim().toLowerCase());
 184    }
 185   
 186    /**
 187    * States whether the given <code>JMSConnection</code> is a topic
 188    * connection or not
 189    *
 190    * @param jmsConn
 191    * The <code>JMSConnection</code> to be analized
 192    * @return boolean <code>true</code> iff it is a topic connection
 193    */
 194  0 public static boolean isTopicConnection(JMSConnection jmsConn) {
 195  0 return TOPIC_CONNECTION.equals(jmsConn.getType().trim().toLowerCase());
 196    }
 197   
 198    /**
 199    * States whether the given <code>JMSConnection</code> is an XA queue
 200    * connection or not
 201    *
 202    * @param jmsConn
 203    * The <code>JMSConnection</code> to be analized
 204    * @return boolean <code>true</code> iff it is an XA queue connection
 205    */
 206  0 public static boolean isXaQueueConnection(JMSConnection jmsConn) {
 207  0 return XA_QUEUE_CONNECTION.equals(jmsConn.getType().trim().toLowerCase());
 208    }
 209   
 210    /**
 211    * States whether the given <code>JMSConnection</code> is an XA topic
 212    * connection or not
 213    *
 214    * @param jmsConn
 215    * The <code>JMSConnection</code> to be analized
 216    * @return boolean <code>true</code> iff it is an XA topic connection
 217    */
 218  0 public static boolean isXaTopicConnection(JMSConnection jmsConn) {
 219  0 return XA_TOPIC_CONNECTION.equals(jmsConn.getType().trim().toLowerCase());
 220    }
 221   
 222    /**
 223    * @see java.lang.Object#toString()
 224    */
 225  14 public String toString() {
 226  14 String res = "Connection: type " + type + " - bean property " + property + " - user name " + userName + " - password " + password + "\n";
 227  14 if (sessions != null) {
 228  14 Iterator iter = sessions.iterator();
 229  14 while (iter.hasNext()) {
 230  14 res = res + iter.next().toString();
 231    }
 232    }
 233  14 return res;
 234    }
 235   
 236    private String type;
 237   
 238    private String property;
 239   
 240    private String userName;
 241   
 242    private String password;
 243   
 244    private String clientId;
 245   
 246    private boolean shared;
 247   
 248    private Collection<JMSSession> sessions;
 249   
 250    /**
 251    *
 252    */
 253    public final static String QUEUE_CONNECTION = "queue";
 254   
 255    /**
 256    *
 257    */
 258    public final static String TOPIC_CONNECTION = "topic";
 259   
 260    /**
 261    *
 262    */
 263    public final static String XA_QUEUE_CONNECTION = "xaQueue";
 264   
 265    /**
 266    *
 267    */
 268    public final static String XA_TOPIC_CONNECTION = "xaTopic";
 269    }