001: /*
002: * Copyright 2006 Day Management AG, Switzerland. All rights reserved.
003: */
004: package javax.jcr;
005:
006: import java.io.InputStream;
007: import java.util.Calendar;
008: import java.math.BigDecimal;
009:
010: /**
011: * The <code>ValueFactory</code> object provides methods for the creation Value objects that can then
012: * be used to set properties.
013: */
014: public interface ValueFactory {
015:
016: /**
017: * Returns a <code>Value</code> object of {@link PropertyType#STRING}
018: * with the specified <code>value</code>.
019: *
020: * @param value a <code>String</code>
021: * @return a <code>Value</code> of {@link PropertyType#STRING}
022: */
023: public Value createValue(String value);
024:
025: /**
026: * Returns a <code>Value</code> object of the {@link PropertyType} specified by <code>type</code>
027: * with the specified <code>value</code>.
028: *
029: * A <code>ValueFormatException</code> is thrown if the specified <code>value</code> cannot
030: * be converted to the specifed <code>type</code>.
031: *
032: * @param value a <code>String</code>
033: * @param type one of the constants defined in {@link PropertyType}.
034: * @return a <code>Value</code> of {@link PropertyType} <code>type</code>.
035: * @throws ValueFormatException if the specified <code>value</code> cannot
036: * be converted to the specified <code>type</code>.
037: */
038: public Value createValue(String value, int type)
039: throws ValueFormatException;
040:
041: /**
042: * Returns a <code>Value</code> object of {@link PropertyType#LONG}
043: * with the specified <code>value</code>.
044: *
045: * @param value a <code>long</code>
046: * @return a <code>Value</code> of {@link PropertyType#LONG}
047: */
048: public Value createValue(long value);
049:
050: /**
051: * Returns a <code>Value</code> object of {@link PropertyType#DOUBLE}
052: * with the specified <code>value</code>.
053: *
054: * @param value a <code>double</code>
055: * @return a <code>Value</code> of {@link PropertyType#DOUBLE}
056: */
057: public Value createValue(double value);
058:
059: /**
060: * Returns a <code>Value</code> object of {@link PropertyType#DECIMAL}
061: * with the specified <code>value</code>.
062: *
063: * @param value a <code>double</code>
064: * @return a <code>Value</code> of {@link PropertyType#DECIMAL}
065: * @since JCR 2.0
066: */
067: public Value createValue(BigDecimal value);
068:
069: /**
070: * Returns a <code>Value</code> object of {@link PropertyType#BOOLEAN}
071: * with the specified <code>value</code>.
072: *
073: * @param value a <code>boolean</code>
074: * @return a <code>Value</code> of {@link PropertyType#BOOLEAN}
075: */
076: public Value createValue(boolean value);
077:
078: /**
079: * Returns a <code>Value</code> object of {@link PropertyType#DATE}
080: * with the specified <code>value</code>.
081: *
082: * @param value a <code>Calendar</code>
083: * @return a <code>Value</code> of {@link PropertyType#DATE}
084: */
085: public Value createValue(Calendar value);
086:
087: /**
088: * Returns a <code>Value</code> object of <code>PropertyType.BINARY</code>
089: * with a value consisting of the content of the specified <code>InputStream</code>.
090: * <p/>
091: * The passed <code>InputStream</code> is closed before this method returns either
092: * normally or because of an exception.
093: * <p/>
094: * Throws a <code>RepositoryException</code> if an error occurs.
095: *
096: * @deprecated As of JCR 2.0, {@link #createValue(Binary)} should be used instead.
097: *
098: * @param value an <code>InputStream</code>
099: * @return a <code>Value</code> of {@link PropertyType#BINARY}
100: * @throws RepositoryException if an error occurs.
101: */
102: public Value createValue(InputStream value)
103: throws RepositoryException;
104:
105: /**
106: * Returns a <code>Value</code> object of <code>PropertyType.BINARY</code>
107: * with a value consisting of the content of the specified <code>Binary</code>.
108: *
109: * @param value a <code>Binary</code>
110: * @return a <code>Value</code> of {@link PropertyType#BINARY}
111: * @since JCR 2.0
112: */
113: public Value createValue(Binary value);
114:
115: /**
116: * Returns a <code>Value</code> object of {@link PropertyType#REFERENCE}
117: * that holds the identifier of the specified <code>Node</code>. This <code>Value</code>
118: * object can then be used to set a property that will be a reference to that
119: * <code>Node</code>.<p/>
120: * <p/>
121: * A <code>RepositoryException</code> is thrown if the specified <code>Node</code>
122: * is not referenceable, the current <code>Session</code> is no longer active, or another
123: * error occurs.
124: *
125: * @param value a <code>Node</code>
126: * @return a <code>Value</code> of {@link PropertyType#REFERENCE}
127: * @throws RepositoryException if the specified <code>Node</code>
128: * is not referencable, the current <code>Session</code> is no longer active, or another
129: * error occurs.
130: */
131: public Value createValue(Node value) throws RepositoryException;
132:
133: /**
134: * Returns a <code>Binary</code> object with a value consisting of the
135: * content of the specified <code>InputStream</code>.
136: * <p/>
137: * The passed <code>InputStream</code> is closed before this method returns either
138: * normally or because of an exception.
139: * <p/>
140: * Throws a <code>RepositoryException</code> if an error occurs.
141: *
142: * @param stream an <code>InputStream</code>
143: * @return a <code>Binary</code>
144: * @throws RepositoryException if an error occurs.
145: * @since JCR 2.0
146: */
147: public Binary createBinary(InputStream stream)
148: throws RepositoryException;
149: }
|