internalvalue.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 495 行 · 第 1/2 页
JAVA
495 行
/** * @param values * @return the created value */ public static InternalValue[] create(String[] values) { InternalValue[] ret = new InternalValue[values.length]; for (int i = 0; i < values.length; i++) { ret[i] = new InternalValue(values[i]); } return ret; } /** * @param values * @return the created value */ public static InternalValue[] create(Calendar[] values) { InternalValue[] ret = new InternalValue[values.length]; for (int i = 0; i < values.length; i++) { ret[i] = new InternalValue(values[i]); } return ret; } /** * @param value * @return the created value */ public static InternalValue create(Path value) { return new InternalValue(value); } /** * @param value * @return the created value */ public static InternalValue create(UUID value) { return new InternalValue(value); } //----------------------------------------------------< conversions, etc. > /** * @param nsResolver * @return * @throws RepositoryException */ public Value toJCRValue(NamespaceResolver nsResolver) throws RepositoryException { switch (type) { case PropertyType.BINARY: return new BinaryValue(((BLOBFileValue) val).getStream()); case PropertyType.BOOLEAN: return new BooleanValue(((Boolean) val)); case PropertyType.DATE: return new DateValue((Calendar) val); case PropertyType.DOUBLE: return new DoubleValue((Double) val); case PropertyType.LONG: return new LongValue((Long) val); case PropertyType.REFERENCE: return ReferenceValue.valueOf(val.toString()); case PropertyType.PATH: try { return PathValue.valueOf(PathFormat.format((Path) val, nsResolver)); } catch (NoPrefixDeclaredException npde) { // should never get here... throw new RepositoryException("internal error: encountered unregistered namespace", npde); } case PropertyType.NAME: try { return NameValue.valueOf(NameFormat.format((QName) val, nsResolver)); } catch (NoPrefixDeclaredException npde) { // should never get here... throw new RepositoryException("internal error: encountered unregistered namespace", npde); } case PropertyType.STRING: return new StringValue((String) val); default: throw new RepositoryException("illegal internal value type"); } } /** * @return the internal object */ public Object internalValue() { return val; } /** * @return the type */ public int getType() { return type; } /** * @return * @throws RepositoryException */ public InternalValue createCopy() throws RepositoryException { if (type == PropertyType.BINARY) { // return a copy since the wrapped BLOBFileValue instance is mutable try { InputStream stream = ((BLOBFileValue) val).getStream(); try { return new InternalValue(new BLOBFileValue(stream)); } finally { try { stream.close(); } catch (IOException e) { // ignore } } } catch (IOException ioe) { throw new RepositoryException("failed to copy binary value", ioe); } } else { // for all other types it's safe to return 'this' because the // wrapped value is immutable (and therefore this instance as well) return this; } } /** * Parses the given string as an <code>InternalValue</code> of the * specified type. The string must be in the format returned by the * <code>InternalValue.toString()</code> method. * * @param s a <code>String</code> containing the <code>InternalValue</code> * representation to be parsed. * @param type * @return the <code>InternalValue</code> represented by the arguments * @throws IllegalArgumentException if the specified string can not be parsed * as an <code>InternalValue</code> of the * specified type. * @see #toString() */ public static InternalValue valueOf(String s, int type) { switch (type) { case PropertyType.BOOLEAN: return new InternalValue(Boolean.valueOf(s).booleanValue()); case PropertyType.DATE: return new InternalValue(ISO8601.parse(s)); case PropertyType.DOUBLE: return new InternalValue(Double.valueOf(s).doubleValue()); case PropertyType.LONG: return new InternalValue(Long.valueOf(s).longValue()); case PropertyType.REFERENCE: return new InternalValue(new UUID(s)); case PropertyType.PATH: return new InternalValue(Path.valueOf(s)); case PropertyType.NAME: return new InternalValue(QName.valueOf(s)); case PropertyType.STRING: return new InternalValue(s); case PropertyType.BINARY: throw new IllegalArgumentException( "this method does not support the type PropertyType.BINARY"); default: throw new IllegalArgumentException("illegal type"); } } //-------------------------------------------< java.lang.Object overrides > /** * Returns the string representation of this internal value. * * @return string representation of this internal value */ public String toString() { if (type == PropertyType.DATE) { return ISO8601.format((Calendar) val); } else { return val.toString(); } } /** * {@inheritDoc} */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof InternalValue) { InternalValue other = (InternalValue) obj; return val.equals(other.val); } return false; } /** * {@inheritDoc} */ public int hashCode() { return val.hashCode(); } //-------------------------------------------------------< implementation > private InternalValue(String value) { val = value; type = PropertyType.STRING; } private InternalValue(QName value) { val = value; type = PropertyType.NAME; } private InternalValue(long value) { val = new Long(value); type = PropertyType.LONG; } private InternalValue(double value) { val = new Double(value); type = PropertyType.DOUBLE; } private InternalValue(Calendar value) { val = value; type = PropertyType.DATE; } private InternalValue(boolean value) { val = Boolean.valueOf(value); type = PropertyType.BOOLEAN; } private InternalValue(BLOBFileValue value) { val = value; type = PropertyType.BINARY; } private InternalValue(Path value) { val = value; type = PropertyType.PATH; } private InternalValue(UUID value) { val = value; type = PropertyType.REFERENCE; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?