KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > indirection > ValueHolder


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.indirection;
23
24 import java.io.Serializable JavaDoc;
25
26 /**
27  * <p>
28  * <b>Purpose</b>: Act as a place holder for a variable that required a value holder interface.
29  * This class should be used to initialze an objects attributes that are using indirection is their mappings.
30  */

31 public class ValueHolder implements ValueHolderInterface, Cloneable JavaDoc, Serializable JavaDoc {
32
33     /**
34      * Stores the wrapped object.
35      */

36     protected Object JavaDoc value;
37
38     /**
39      * PUBLIC:
40      * Initialize the holder.
41      */

42     public ValueHolder() {
43         super();
44     }
45
46     /**
47      * PUBLIC:
48      * Initialize the holder with an object.
49      */

50     public ValueHolder(Object JavaDoc value) {
51         this.value = value;
52     }
53
54     /**
55      * INTERNAL:
56      */

57     public Object JavaDoc clone() {
58         try {
59             return super.clone();
60         } catch (CloneNotSupportedException JavaDoc exception) {
61             ;
62         }
63
64         return null;
65     }
66
67     /**
68      * PUBLIC:
69      * Return the wrapped object.
70      */

71     public synchronized Object JavaDoc getValue() {
72         return value;
73     }
74
75     /**
76      * PUBLIC:
77      * Return a boolean indicating whether the
78      * wrapped object has been set or not.
79      */

80     public boolean isInstantiated() {
81         // Always return true since we consider
82
// null to be a valid wrapped object.
83
return true;
84     }
85
86     /**
87      * PUBLIC:
88      * Set the wrapped object.
89      */

90     public void setValue(Object JavaDoc value) {
91         this.value = value;
92     }
93
94     /**
95      * INTERNAL:
96      */

97     public String JavaDoc toString() {
98         if (getValue() == null) {
99             return "{" + null + "}";
100         }
101         return "{" + getValue().toString() + "}";
102     }
103 }
104
Popular Tags