KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jcr > base > BaseProperty


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jcr.base;
31
32 import com.caucho.util.L10N;
33
34 import javax.jcr.Node;
35 import javax.jcr.Property;
36 import javax.jcr.RepositoryException;
37 import javax.jcr.Value;
38 import javax.jcr.ValueFactory;
39 import javax.jcr.ValueFormatException;
40 import javax.jcr.lock.LockException;
41 import javax.jcr.nodetype.ConstraintViolationException;
42 import javax.jcr.nodetype.PropertyDefinition;
43 import javax.jcr.version.VersionException;
44 import java.io.InputStream JavaDoc;
45 import java.util.Calendar JavaDoc;
46
47 /**
48  * Represents a property item in the repository.
49  */

50 public class BaseProperty extends BaseItem implements Property {
51   private static final L10N L = new L10N(BaseProperty.class);
52
53   private ValueFactory _factory = BaseValueFactory.FACTORY;
54   
55   private Value _value; // set to some null
56

57   protected BaseProperty(Value value)
58   {
59     _value = value;
60   }
61   
62   /**
63    * Sets the property value.
64    */

65   public void setValue(Value value)
66     throws ValueFormatException,
67        VersionException,
68        LockException,
69        ConstraintViolationException,
70        RepositoryException
71   {
72     _value = value;
73   }
74   
75   /**
76    * Sets the property value to a value array.
77    */

78   public void setValue(Value[] values)
79     throws ValueFormatException,
80        VersionException,
81        LockException,
82        ConstraintViolationException,
83        RepositoryException
84   {
85     throw new UnsupportedOperationException JavaDoc(getClass().getName());
86   }
87   
88   /**
89    * Sets the property value to a string.
90    */

91   public void setValue(String JavaDoc value)
92     throws ValueFormatException,
93        VersionException,
94        LockException,
95        ConstraintViolationException,
96        RepositoryException
97   {
98     setValue(_factory.createValue(value));
99   }
100   
101   /**
102    * Sets the property value to a string array.
103    */

104   public void setValue(String JavaDoc[] values)
105     throws ValueFormatException,
106        VersionException,
107        LockException,
108        ConstraintViolationException,
109        RepositoryException
110   {
111     throw new UnsupportedOperationException JavaDoc();
112   }
113   
114   /**
115    * Sets the property value to a binary chunk.
116    */

117   public void setValue(InputStream JavaDoc value)
118     throws ValueFormatException,
119        VersionException,
120        LockException,
121        ConstraintViolationException,
122        RepositoryException
123   {
124     setValue(_factory.createValue(value));
125   }
126   
127   /**
128    * Sets the property value to a long.
129    */

130   public void setValue(long value)
131     throws ValueFormatException,
132        VersionException,
133        LockException,
134        ConstraintViolationException,
135        RepositoryException
136   {
137     setValue(_factory.createValue(value));
138   }
139   
140   /**
141    * Sets the property value to a double.
142    */

143   public void setValue(double value)
144     throws ValueFormatException,
145        VersionException,
146        LockException,
147        ConstraintViolationException,
148        RepositoryException
149   {
150     setValue(_factory.createValue(value));
151   }
152   
153   /**
154    * Sets the property value to a date.
155    */

156   public void setValue(Calendar JavaDoc value)
157     throws ValueFormatException,
158        VersionException,
159        LockException,
160        ConstraintViolationException,
161        RepositoryException
162   {
163     setValue(_factory.createValue(value));
164   }
165   
166   /**
167    * Sets the property value to a boolean.
168    */

169   public void setValue(boolean value)
170     throws ValueFormatException,
171        VersionException,
172        LockException,
173        ConstraintViolationException,
174        RepositoryException
175   {
176     setValue(_factory.createValue(value));
177   }
178   
179   /**
180    * Sets the property value to a node reference.
181    */

182   public void setValue(Node value)
183     throws ValueFormatException,
184        VersionException,
185        LockException,
186        ConstraintViolationException,
187        RepositoryException
188   {
189     setValue(_factory.createValue(value));
190   }
191   
192   /**
193    * Returns the property value.
194    */

195   public Value getValue()
196     throws ValueFormatException,
197        RepositoryException
198   {
199     return _value;
200   }
201   
202   /**
203    * Returns the property value as a value array.
204    */

205   public Value[] getValues()
206     throws ValueFormatException,
207        RepositoryException
208   {
209     throw new UnsupportedOperationException JavaDoc(getClass().getName());
210   }
211   
212   /**
213    * Returns the property value as a string.
214    */

215   public String JavaDoc getString()
216     throws ValueFormatException,
217        RepositoryException
218   {
219     return getValue().getString();
220   }
221   
222   /**
223    * Returns the property value as a binary stream.
224    */

225   public InputStream JavaDoc getStream()
226     throws ValueFormatException,
227        RepositoryException
228   {
229     return getValue().getStream();
230   }
231   
232   /**
233    * Returns the property value as a long.
234    */

235   public long getLong()
236     throws ValueFormatException,
237        RepositoryException
238   {
239     return getValue().getLong();
240   }
241   
242   /**
243    * Returns the property value as a double.
244    */

245   public double getDouble()
246     throws ValueFormatException,
247        RepositoryException
248   {
249     return getValue().getDouble();
250   }
251   
252   /**
253    * Returns the property value as a date.
254    */

255   public Calendar JavaDoc getDate()
256     throws ValueFormatException,
257        RepositoryException
258   {
259     return getValue().getDate();
260   }
261   
262   /**
263    * Returns the property value as a boolean.
264    */

265   public boolean getBoolean()
266     throws ValueFormatException,
267        RepositoryException
268   {
269     return getValue().getBoolean();
270   }
271   
272   /**
273    * Returns the property value as a node reference.
274    */

275   public Node getNode()
276     throws ValueFormatException,
277        RepositoryException
278   {
279     throw new UnsupportedOperationException JavaDoc();
280   }
281   
282   /**
283    * Returns the size of the property.
284    */

285   public long getLength()
286     throws ValueFormatException,
287        RepositoryException
288   {
289     return 0;
290   }
291   
292   /**
293    * Returns the size of all the properties.
294    */

295   public long[] getLengths()
296     throws ValueFormatException,
297        RepositoryException
298   {
299     return new long[0];
300   }
301   
302   /**
303    * Returns the property's definition.
304    */

305   public PropertyDefinition getDefinition()
306     throws RepositoryException
307   {
308     throw new UnsupportedOperationException JavaDoc();
309   }
310   
311   /**
312    * Returns the property's base type.
313    */

314   public int getType()
315     throws RepositoryException
316   {
317     return getDefinition().getRequiredType();
318   }
319 }
320
Popular Tags