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.PropertyType;
036: import javax.jcr.RepositoryException;
037: import javax.jcr.Value;
038: import javax.jcr.ValueFactory;
039: import javax.jcr.ValueFormatException;
040: import java.io.InputStream;
041: import java.util.Calendar;
042:
043: /**
044: * Creates a value.
045: */
046: public class BaseValueFactory implements ValueFactory {
047: private static final L10N L = new L10N(BaseValueFactory.class);
048:
049: public static final ValueFactory FACTORY = new BaseValueFactory();
050:
051: /**
052: * Returns the expected property type.
053: */
054: protected int getPropertyType() {
055: return PropertyType.STRING;
056: }
057:
058: /**
059: * Creates a value based on a string.
060: */
061: public Value createValue(String value) {
062: throw new UnsupportedOperationException();
063: }
064:
065: /**
066: * Creates a value based on a string, coerced to the expected PropertyType.
067: *
068: * @param value the new value
069: * @param type the expected PropertyType.
070: */
071: public Value createValue(String value, int type)
072: throws ValueFormatException {
073: throw new UnsupportedOperationException(getClass().getName());
074: }
075:
076: /**
077: * Creates a value based on a long.
078: */
079: public Value createValue(long value) {
080: throw new UnsupportedOperationException();
081: }
082:
083: /**
084: * Creates a value based on a double.
085: */
086: public Value createValue(double value) {
087: throw new UnsupportedOperationException();
088: }
089:
090: /**
091: * Creates a value based on a boolean.
092: */
093: public Value createValue(boolean value) {
094: throw new UnsupportedOperationException();
095: }
096:
097: /**
098: * Creates a value based on a date.
099: */
100: public Value createValue(Calendar value) {
101: throw new UnsupportedOperationException();
102: }
103:
104: /**
105: * Creates a value based on a binary stream.
106: */
107: public Value createValue(InputStream value) {
108: throw new UnsupportedOperationException();
109: }
110:
111: /**
112: * Creates a value based on a node reference
113: */
114: public Value createValue(Node value) throws RepositoryException {
115: return createValue(String.valueOf(value), getPropertyType());
116: }
117: }
|