View Javadoc

1   /*
2    * Copyright (c) 2003, Andreas Pataki 
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    *
9    * Redistributions of source code must retain the above copyright notice,
10   * this list of conditions and the following disclaimer.
11   * 
12   * Redistributions in binary form must reproduce the above copyright notice,
13   * this list of conditions and the following disclaimer in the documentation
14   * and/or other materials provided with the distribution.
15   * 
16   * Neither the name of the author nor the names of its contributors
17   * may be used to endorse or promote products derived from this software
18   * without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS
21   * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   */
32  
33  package net.sf.tm;
34  
35  import org.apache.commons.lang.builder.EqualsBuilder;
36  import org.apache.commons.lang.builder.HashCodeBuilder;
37  import org.apache.commons.lang.builder.ToStringBuilder;
38  
39  /***
40   * Class holds the status of current state of a web context.  
41   * 
42   * @author Andreas Pataki
43   * @version $Id: WebContext.java,v 1.5 2004/02/10 20:05:38 apataki Exp $
44   */
45  public class WebContext {
46  
47      /***
48       * The path of the context e.g. /something
49       */
50      private String path;
51      /***
52       * The docPath of the context is the path in the filesystem where
53       * the context is installed.
54       */
55      private String docPath;
56      /***
57       * Gives informations of the running status of the context.
58       */
59      private WebContextStatus status = WebContextStatus.STOPPED;
60      /***
61       * Session count 
62       */
63      private int activeSessions;
64  
65      /***
66       * @return The doc path of the context. 
67       */
68      public String getDocPath() {
69          return docPath;
70      }
71  
72      /***
73       * @return The context path
74       */
75      public String getPath() {
76          return path;
77      }
78  
79      /***
80       * @return The status. See the constant definitions in this class for
81       *   the values.
82       */
83      public WebContextStatus getStatus() {
84          return status;
85      }
86  
87      /***
88       * @param string new doc path
89       */
90      public void setDocPath(String string) {
91          docPath = string;
92      }
93  
94      /***
95       * @param string new path
96       */
97      public void setPath(String string) {
98          path = string;
99      }
100 
101     /***
102      * @param i New status. Must be one of the constants defined in this class.
103      */
104     public void setStatus(WebContextStatus i) {
105         status = i;
106     }
107 
108     /***
109       * @return The session count
110       */
111     public int getActiveSessions() {
112         return activeSessions;
113     }
114 
115     /***
116      * @param count Session count
117      */
118     public void setActiveSessions(int count) {
119         activeSessions = count;
120     }
121 
122     /***
123      * Overwritten to ensure that a refreshed context object is the same as the
124      * old one in the tree. Only this way the selection in the 
125      * tree will get preserved.
126      * 
127      * @see java.lang.Object#equals(java.lang.Object)
128      */
129     public boolean equals(Object obj) {
130         if (!(obj instanceof WebContext)) {
131             return false;
132         }
133         WebContext other = (WebContext) obj;
134         return new EqualsBuilder()
135             .append(getDocPath(), other.getDocPath())
136             .append(getPath(), other.getPath())
137             .isEquals();
138     }
139 
140     /***
141      * Overwritten to provide the hash for the same fields used in the
142      * equals method.
143      * 
144      * @see java.lang.Object#hashCode()
145      */
146     public int hashCode() {
147         return new HashCodeBuilder()
148             .append(getDocPath())
149             .append(getPath())
150             .toHashCode();
151     }
152 
153     /***
154      * Overwriten for debuging purposes only.
155      * 
156      * @see java.lang.Object#toString()
157      */
158     public String toString() {
159         return ToStringBuilder.reflectionToString(this);
160     }
161 
162 }