KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jcr > ReferenceValue


1 /*
2  * $Id: ReferenceValue.java,v 1.2 2004/07/24 00:16:21 benjmestrallet Exp $
3  *
4  * Copyright 2002-2004 Day Management AG, Switzerland.
5  *
6  * Licensed under the Day RI License, Version 2.0 (the "License"),
7  * as a reference implementation of the following specification:
8  *
9  * Content Repository API for Java Technology, revision 0.12
10  * <http://www.jcp.org/en/jsr/detail?id=170>
11  *
12  * You may not use this file except in compliance with the License.
13  * You may obtain a copy of the License files at
14  *
15  * http://www.day.com/content/en/licenses/day-ri-license-2.0
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */

24 package javax.jcr;
25
26 import java.util.Calendar JavaDoc;
27
28 /**
29  * A <code>ReferenceValue</code> provides an implementation
30  * of the <code>Value</code> interface representing a Reference value
31  * (i.e. a UUID of an existing node).
32  *
33  * @author Stefan Guggisberg
34  */

35 public class ReferenceValue extends BaseValue {
36
37   public static final int TYPE = PropertyType.REFERENCE;
38
39   private final String JavaDoc uuid;
40
41   /**
42    * Constructs a <code>ReferenceValue</code> object representing a UUID of
43    * an existing node.
44    *
45    * @param target the node to be referenced
46    * @throws IllegalArgumentException If <code>target</code> is nonreferenceable.
47    * @throws RepositoryException If another error occurs.
48    */

49   public ReferenceValue(Node target) throws RepositoryException {
50     super(TYPE);
51     try {
52       this.uuid = target.getUUID();
53     } catch (UnsupportedRepositoryOperationException ure) {
54       throw new IllegalArgumentException JavaDoc("target is nonreferenceable.");
55     }
56   }
57
58   /**
59    * Constructs a <code>ReferenceValue</code> object representing a UUID of
60    * an existing node.
61    *
62    * @param uuid the UUID of the referenced node
63    */

64   public ReferenceValue(String JavaDoc uuid) {
65     super(TYPE);
66     // @todo validate uuid format
67
this.uuid = uuid;
68   }
69
70   /**
71    * Indicates whether some other object is "equal to" this one.
72    * <p/>
73    * The result is <code>true</code> if and only if the argument is not
74    * <code>null</code> and is a <code>ReferenceValue</code> object that
75    * represents the same value as this object.
76    *
77    * @param obj the reference object with which to compare.
78    * @return <code>true</code> if this object is the same as the obj
79    * argument; <code>false</code> otherwise.
80    */

81   public boolean equals(Object JavaDoc obj) {
82     if (this == obj) {
83       return true;
84     }
85     if (obj instanceof ReferenceValue) {
86       ReferenceValue other = (ReferenceValue) obj;
87       if (uuid == other.uuid) {
88         return true;
89       } else if (uuid != null && other.uuid != null) {
90         return uuid.equals(other.uuid);
91       }
92     }
93     return false;
94   }
95
96   //----------------------------------------------------------------< Value >
97
/**
98    * @see Value#getDate
99    */

100   public Calendar JavaDoc getDate() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
101     setValueConsumed();
102
103     throw new ValueFormatException("conversion to date failed: inconvertible types");
104   }
105
106   /**
107    * @see Value#getLong
108    */

109   public long getLong() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
110     setValueConsumed();
111
112     throw new ValueFormatException("conversion to long failed: inconvertible types");
113   }
114
115   /**
116    * @see Value#getBoolean
117    */

118   public boolean getBoolean() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
119     setValueConsumed();
120
121     throw new ValueFormatException("conversion to boolean failed: inconvertible types");
122   }
123
124   /**
125    * @see Value#getDouble
126    */

127   public double getDouble() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
128     setValueConsumed();
129
130     throw new ValueFormatException("conversion to double failed: inconvertible types");
131   }
132
133   /**
134    * @see Value#getString
135    */

136   public String JavaDoc getString() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
137     setValueConsumed();
138
139     if (uuid != null) {
140       return uuid;
141     } else {
142       throw new ValueFormatException("empty value");
143     }
144   }
145 }
146
Popular Tags