Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/RuntimeCollective/webapps/bean/LabelValue.java


1   /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/bean/LabelValue.java,v 1.6 2003/09/30 15:13:09 joe Exp $
2    * $Revision: 1.6 $
3    * $Date: 2003/09/30 15:13:09 $
4    *
5    * ====================================================================
6    *
7    * Josephine : http://www.runtime-collective.com/josephine/index.html
8    *
9    * Copyright (C) 2003 Runtime Collective
10   * 
11   * This product includes software developed by the
12   * Apache Software Foundation (http://www.apache.org/).
13   *
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2.1 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *
28   */
29  
30  package com.RuntimeCollective.webapps.bean;
31  
32  import java.io.Serializable;
33  
34  import com.RuntimeCollective.webapps.RuntimeParameters;
35  
36  /**
37   * A label value pair. A similar class to this wil be introduced int
38   * Struts 1.1. This class will take it's place until Struts 1.1 is used.
39   *
40   * Use this class when you require a collection that has a different
41   * label to the value. To allow for lazy loading of the Object use the
42   * id constructor.
43   */
44  public class LabelValue implements Serializable {
45  
46      private String iLabel;
47      private Object iValue;
48      private int iValueId;
49  
50      /**
51       * Use this constructor when you want to postpone the actual bean
52       * loading.
53       */
54      public LabelValue(String label, int id) {
55    iLabel = label;
56    iValueId = id;
57      }
58      
59      public LabelValue(String label, Object value) {
60    iLabel = label;
61    iValue = value;
62      }
63      
64      public int getValueId() {
65    return iValueId;
66      }
67      
68      public String getLabel() {
69    return iLabel;
70      }
71  
72      public Object getValue() {
73    if(iValue == null) {
74        iValue = RuntimeParameters.getStore().get(EntityBean.class.getName(), iValueId);
75    }
76    return iValue;
77      }
78      
79      public int hashCode() {
80    return iLabel.hashCode();
81      }
82  
83      public boolean equals(Object o) {
84    try {
85        return ((LabelValue) o).getLabel().equals(iLabel);
86    } catch(Exception ex) {
87        return false;
88    }
89      }
90      
91      public String toString() {
92    return iLabel;
93      }
94      
95  }