You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/10/12 12:19:56 UTC
svn commit: r1397504 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
Author: mduerig
Date: Fri Oct 12 10:19:56 2012
New Revision: 1397504
URL: http://svn.apache.org/viewvc?rev=1397504&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
Defer exceptions to access on Value instead of throwing runtime exceptions when value cannot be created
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java?rev=1397504&r1=1397503&r2=1397504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java Fri Oct 12 10:19:56 2012
@@ -82,27 +82,25 @@ public class ValueFactoryImpl implements
}
@Override
- public ValueImpl createValue(InputStream value) {
+ public Value createValue(InputStream value) {
try {
try {
- // TODO add streaming capability to ContentSession via KernelBasedBlob
- return new ValueImpl(PropertyStates.binaryProperty("", ByteStreams.toByteArray(value)), namePathMapper);
+ return createValueImpl(value);
} finally {
value.close();
}
- } catch (IOException ex) {
- // TODO return a value which throws on each access instead
- throw new RuntimeException(ex);
+ } catch (IOException e) {
+ return new ErrorValue(e, PropertyType.BINARY);
}
}
-
@Override
public Value createValue(Binary value) {
try {
- return createValue(value.getStream());
- } catch (RepositoryException ex) {
- // TODO return a value which throws on each access instead
- throw new RuntimeException(ex);
+ return createValueImpl(value.getStream());
+ } catch (RepositoryException e) {
+ return new ErrorValue(e, PropertyType.BINARY);
+ } catch (IOException e) {
+ return new ErrorValue(e, PropertyType.BINARY);
}
}
@@ -225,6 +223,91 @@ public class ValueFactoryImpl implements
@Override
public Binary createBinary(InputStream stream) throws RepositoryException {
- return new BinaryImpl(createValue(stream));
+ try {
+ return new BinaryImpl(createValueImpl(stream));
+ }
+ catch (IOException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ private ValueImpl createValueImpl(InputStream value) throws IOException {
+ try {
+ // TODO add streaming capability to ContentSession via KernelBasedBlob
+ return new ValueImpl(PropertyStates.binaryProperty("", ByteStreams.toByteArray(value)), namePathMapper);
+ } finally {
+ value.close();
+ }
+ }
+
+ //------------------------------------------------------------< ErrorValue >---
+
+ private static class ErrorValue implements Value {
+ private final Exception exception;
+ private final int type;
+
+ private ErrorValue(Exception exception, int type) {
+ this.exception = exception;
+ this.type = type;
+ }
+
+ @Override
+ public String getString() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public InputStream getStream() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public Binary getBinary() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public long getLong() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public double getDouble() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public BigDecimal getDecimal() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public Calendar getDate() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public boolean getBoolean() throws RepositoryException {
+ throw createException();
+ }
+
+ @Override
+ public int getType() {
+ return type;
+ }
+
+ private RepositoryException createException() {
+ return new RepositoryException("Inaccessible value", exception);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "Inaccessible value: " + exception.getMessage();
+ }
}
}