001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jcr.base;
031:
032: import com.caucho.util.L10N;
033:
034: import javax.jcr.Node;
035: import javax.jcr.Property;
036: import javax.jcr.RepositoryException;
037: import javax.jcr.Value;
038: import javax.jcr.ValueFactory;
039: import javax.jcr.ValueFormatException;
040: import javax.jcr.lock.LockException;
041: import javax.jcr.nodetype.ConstraintViolationException;
042: import javax.jcr.nodetype.PropertyDefinition;
043: import javax.jcr.version.VersionException;
044: import java.io.InputStream;
045: import java.util.Calendar;
046:
047: /**
048: * Represents a property item in the repository.
049: */
050: public class BaseProperty extends BaseItem implements Property {
051: private static final L10N L = new L10N(BaseProperty.class);
052:
053: private ValueFactory _factory = BaseValueFactory.FACTORY;
054:
055: private Value _value; // set to some null
056:
057: protected BaseProperty(Value value) {
058: _value = value;
059: }
060:
061: /**
062: * Sets the property value.
063: */
064: public void setValue(Value value) throws ValueFormatException,
065: VersionException, LockException,
066: ConstraintViolationException, RepositoryException {
067: _value = value;
068: }
069:
070: /**
071: * Sets the property value to a value array.
072: */
073: public void setValue(Value[] values) throws ValueFormatException,
074: VersionException, LockException,
075: ConstraintViolationException, RepositoryException {
076: throw new UnsupportedOperationException(getClass().getName());
077: }
078:
079: /**
080: * Sets the property value to a string.
081: */
082: public void setValue(String value) throws ValueFormatException,
083: VersionException, LockException,
084: ConstraintViolationException, RepositoryException {
085: setValue(_factory.createValue(value));
086: }
087:
088: /**
089: * Sets the property value to a string array.
090: */
091: public void setValue(String[] values) throws ValueFormatException,
092: VersionException, LockException,
093: ConstraintViolationException, RepositoryException {
094: throw new UnsupportedOperationException();
095: }
096:
097: /**
098: * Sets the property value to a binary chunk.
099: */
100: public void setValue(InputStream value)
101: throws ValueFormatException, VersionException,
102: LockException, ConstraintViolationException,
103: RepositoryException {
104: setValue(_factory.createValue(value));
105: }
106:
107: /**
108: * Sets the property value to a long.
109: */
110: public void setValue(long value) throws ValueFormatException,
111: VersionException, LockException,
112: ConstraintViolationException, RepositoryException {
113: setValue(_factory.createValue(value));
114: }
115:
116: /**
117: * Sets the property value to a double.
118: */
119: public void setValue(double value) throws ValueFormatException,
120: VersionException, LockException,
121: ConstraintViolationException, RepositoryException {
122: setValue(_factory.createValue(value));
123: }
124:
125: /**
126: * Sets the property value to a date.
127: */
128: public void setValue(Calendar value) throws ValueFormatException,
129: VersionException, LockException,
130: ConstraintViolationException, RepositoryException {
131: setValue(_factory.createValue(value));
132: }
133:
134: /**
135: * Sets the property value to a boolean.
136: */
137: public void setValue(boolean value) throws ValueFormatException,
138: VersionException, LockException,
139: ConstraintViolationException, RepositoryException {
140: setValue(_factory.createValue(value));
141: }
142:
143: /**
144: * Sets the property value to a node reference.
145: */
146: public void setValue(Node value) throws ValueFormatException,
147: VersionException, LockException,
148: ConstraintViolationException, RepositoryException {
149: setValue(_factory.createValue(value));
150: }
151:
152: /**
153: * Returns the property value.
154: */
155: public Value getValue() throws ValueFormatException,
156: RepositoryException {
157: return _value;
158: }
159:
160: /**
161: * Returns the property value as a value array.
162: */
163: public Value[] getValues() throws ValueFormatException,
164: RepositoryException {
165: throw new UnsupportedOperationException(getClass().getName());
166: }
167:
168: /**
169: * Returns the property value as a string.
170: */
171: public String getString() throws ValueFormatException,
172: RepositoryException {
173: return getValue().getString();
174: }
175:
176: /**
177: * Returns the property value as a binary stream.
178: */
179: public InputStream getStream() throws ValueFormatException,
180: RepositoryException {
181: return getValue().getStream();
182: }
183:
184: /**
185: * Returns the property value as a long.
186: */
187: public long getLong() throws ValueFormatException,
188: RepositoryException {
189: return getValue().getLong();
190: }
191:
192: /**
193: * Returns the property value as a double.
194: */
195: public double getDouble() throws ValueFormatException,
196: RepositoryException {
197: return getValue().getDouble();
198: }
199:
200: /**
201: * Returns the property value as a date.
202: */
203: public Calendar getDate() throws ValueFormatException,
204: RepositoryException {
205: return getValue().getDate();
206: }
207:
208: /**
209: * Returns the property value as a boolean.
210: */
211: public boolean getBoolean() throws ValueFormatException,
212: RepositoryException {
213: return getValue().getBoolean();
214: }
215:
216: /**
217: * Returns the property value as a node reference.
218: */
219: public Node getNode() throws ValueFormatException,
220: RepositoryException {
221: throw new UnsupportedOperationException();
222: }
223:
224: /**
225: * Returns the size of the property.
226: */
227: public long getLength() throws ValueFormatException,
228: RepositoryException {
229: return 0;
230: }
231:
232: /**
233: * Returns the size of all the properties.
234: */
235: public long[] getLengths() throws ValueFormatException,
236: RepositoryException {
237: return new long[0];
238: }
239:
240: /**
241: * Returns the property's definition.
242: */
243: public PropertyDefinition getDefinition()
244: throws RepositoryException {
245: throw new UnsupportedOperationException();
246: }
247:
248: /**
249: * Returns the property's base type.
250: */
251: public int getType() throws RepositoryException {
252: return getDefinition().getRequiredType();
253: }
254: }
|