KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jcr > SoftLinkValue


1 /*
2  * $Id: SoftLinkValue.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>SoftLinkValue</code> provides an implementation
30  * of the <code>Value</code> interface representing a soft link value
31  * (i.e. an absolute or relative repository path).
32  *
33  * @author Stefan Guggisberg
34  */

35 public class SoftLinkValue extends BaseValue {
36
37   public static final int TYPE = PropertyType.SOFTLINK;
38
39   private final String JavaDoc path;
40
41   /**
42    * Constructs a <code>SoftLinkValue</code> object representing an absolute
43    * or relative path.
44    *
45    * @param path the link this <code>SoftLinkValue</code> should represent
46    */

47   public SoftLinkValue(String JavaDoc path) {
48     super(TYPE);
49 // @todo validate path syntax
50
this.path = path;
51   }
52
53   /**
54    * Indicates whether some other object is "equal to" this one.
55    * <p/>
56    * The result is <code>true</code> if and only if the argument is not
57    * <code>null</code> and is a <code>SoftLinkValue</code> object that
58    * represents the same value as this object.
59    *
60    * @param obj the reference object with which to compare.
61    * @return <code>true</code> if this object is the same as the obj
62    * argument; <code>false</code> otherwise.
63    */

64   public boolean equals(Object JavaDoc obj) {
65     if (this == obj) {
66       return true;
67     }
68     if (obj instanceof SoftLinkValue) {
69       SoftLinkValue other = (SoftLinkValue) obj;
70       if (path == other.path) {
71         return true;
72       } else if (path != null && other.path != null) {
73         return path.equals(other.path);
74       }
75     }
76     return false;
77   }
78
79   //----------------------------------------------------------------< Value >
80
/**
81    * @see Value#getDate
82    */

83   public Calendar JavaDoc getDate() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
84     setValueConsumed();
85
86     throw new ValueFormatException("conversion to date failed: inconvertible types");
87   }
88
89   /**
90    * @see Value#getLong
91    */

92   public long getLong() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
93     setValueConsumed();
94
95     throw new ValueFormatException("conversion to long failed: inconvertible types");
96   }
97
98   /**
99    * @see Value#getBoolean
100    */

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

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

119   public String JavaDoc getString() throws ValueFormatException, IllegalStateException JavaDoc, RepositoryException {
120     setValueConsumed();
121
122     if (path != null) {
123       return path;
124     } else {
125       throw new ValueFormatException("empty value");
126     }
127   }
128 }
129
Popular Tags