jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136476 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Thu, 16 Jun 2011 15:08:45 GMT
Author: mduerig
Date: Thu Jun 16 15:08:44 2011
New Revision: 1136476

URL: http://svn.apache.org/viewvc?rev=1136476&view=rev
Log:
spi2microkernel prototype (WIP)
cleanup, minor refactor

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1136476&r1=1136475&r2=1136476&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Thu Jun 16 15:08:44 2011
@@ -40,8 +40,6 @@ import org.apache.jackrabbit.spi.Session
 import org.apache.jackrabbit.spi.commons.AbstractRepositoryService;
 import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi2microkernel.util.ItemInfos;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
@@ -52,7 +50,6 @@ import org.json.simple.parser.ParseExcep
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import java.io.IOException;
@@ -63,16 +60,19 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import static javax.jcr.Repository.*;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.*;
 import static org.apache.jackrabbit.spi2microkernel.util.Arrays.contains;
+import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.*;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     private static final Map<String, QValue[]> DESCRIPTORS = new HashMap<String,
QValue[]>() {{
         QValue[] FALSE = new QValue[]{Values.FALSE};
         QValue[] TRUE = new QValue[]{Values.TRUE};
 
-        put(Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, FALSE);
-        put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, TRUE);
-        put(Repository.LEVEL_2_SUPPORTED, TRUE);
+        put(NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, FALSE);
+        put(OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, TRUE);
+        put(LEVEL_2_SUPPORTED, TRUE);
     }};
 
     private static final Map<String, String> NAMESPACES = Collections.emptyMap();
@@ -192,12 +192,12 @@ public class RepositoryServiceImpl exten
         try {
             String wspName = sessionInfo.getWorkspaceName();
             Path path = nodeId.getPath();
-            String mkPath = Paths.translateQPath(wspName, path);
+            String mkPath = Paths.pathToString(wspName, path);
             String rev = getRevision(sessionInfo);
 
             if (microKernel.nodeExists(mkPath, rev)) {
                 String json = microKernel.getNodes(mkPath, rev);
-                return ItemInfos.buildItemInfos(path, json);
+                return buildItemInfos(path, json);
             }
             else {
                 throw new PathNotFoundException(path.toString());
@@ -212,13 +212,13 @@ public class RepositoryServiceImpl exten
         try {
             String wspName = sessionInfo.getWorkspaceName();
             Path path = nodeId.getPath();
-            String mkPath = Paths.translateQPath(wspName, path);
+            String mkPath = Paths.pathToString(wspName, path);
             String rev = getRevision(sessionInfo);
 
             NodeInfo info = null;
             if (microKernel.nodeExists(mkPath, rev)) {
                 String json = microKernel.getNodes(mkPath, rev);
-                info = ItemInfos.buildNodeInfo(path, json);
+                info = buildNodeInfo(path, json);
             }
 
             if (info == null) {
@@ -237,13 +237,13 @@ public class RepositoryServiceImpl exten
         try {
             String wspName = sessionInfo.getWorkspaceName();
             Path path = propertyId.getPath();
-            String mkPath = Paths.translateQPath(wspName, path.getAncestor(1));
+            String mkPath = Paths.pathToString(wspName, path.getAncestor(1));
             String rev = getRevision(sessionInfo);
 
             PropertyInfo info = null;
             if (microKernel.nodeExists(mkPath, rev)) {
                 String json = microKernel.getNodes(mkPath, rev);
-                info = ItemInfos.buildPropertyInfo(path, json);
+                info = buildPropertyInfo(path, json);
             }
 
             if (info == null) {
@@ -402,7 +402,7 @@ public class RepositoryServiceImpl exten
             try {
                 StringBuilder sb = new StringBuilder();
                 JsonBuilder.create(sb)
-                    .value(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE), nodetypeName.toString())
+                    .value(Paths.nameToString(JCR_PRIMARYTYPE), nodetypeName.toString())
                     .build();
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
@@ -413,19 +413,19 @@ public class RepositoryServiceImpl exten
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue value) throws
RepositoryException {
-            setProperty(parentId, propertyName, Values.create(value));
+            setProperty(parentId, propertyName, Values.valueToString(value));
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws
RepositoryException {
-            setProperty(parentId, propertyName, Values.create(values));
+            setProperty(parentId, propertyName, Values.valuesToString(values));
         }
 
         public void setValue(PropertyId propertyId, QValue value) throws RepositoryException
{
-            setProperty(propertyId.getParentId(), propertyId.getName(), Values.create(value));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valueToString(value));
         }
 
         public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException
{
-            setProperty(propertyId.getParentId(), propertyId.getName(), Values.create(values));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valuesToString(values));
         }
 
         public void remove(ItemId itemId) throws RepositoryException {
@@ -451,20 +451,20 @@ public class RepositoryServiceImpl exten
 
         public void setMixins(NodeId nodeId, Name[] mixinNodeTypeNames) throws RepositoryException
{
             if (mixinNodeTypeNames.length == 0) {
-                setProperty(nodeId, NameConstants.JCR_MIXINTYPES, "null");
+                setProperty(nodeId, JCR_MIXINTYPES, "null");
             }
             else {
-                setProperty(nodeId, NameConstants.JCR_MIXINTYPES, Values.create(mixinNodeTypeNames));
+                setProperty(nodeId, JCR_MIXINTYPES, Values.namesToString(mixinNodeTypeNames));
             }
 
-            if (contains(mixinNodeTypeNames, NameConstants.MIX_REFERENCEABLE)) {
+            if (contains(mixinNodeTypeNames, MIX_REFERENCEABLE)) {
                 // todo uuid is not stable across move operations
-                setProperty(nodeId, NameConstants.JCR_UUID, Values.create(nodeId.getPath()));
+                setProperty(nodeId, JCR_UUID, Values.pathToString(nodeId.getPath()));
             }
         }
 
         public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException
{
-            setProperty(nodeId, NameConstants.JCR_PRIMARYTYPE, Values.create(primaryNodeTypeName));
+            setProperty(nodeId, JCR_PRIMARYTYPE, Values.nameToString(primaryNodeTypeName));
         }
 
         public void move(NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws
RepositoryException {
@@ -480,12 +480,12 @@ public class RepositoryServiceImpl exten
 
         private String target(NodeId nodeId) throws RepositoryException {
             return '\"' + JsonBuilder.escape(
-                PathUtil.relativize("/", Paths.translateQPath(sessionInfo.getWorkspaceName(),
nodeId.getPath()))) + '\"';
+                PathUtil.relativize("/", Paths.pathToString(sessionInfo.getWorkspaceName(),
nodeId.getPath()))) + '\"';
         }
 
         private String target(NodeId parentId, Name itemName) throws RepositoryException
{
-            String path = Paths.translateQPath(sessionInfo.getWorkspaceName(), parentId.getPath());
-            String name = Paths.translateQName(itemName);
+            String path = Paths.pathToString(sessionInfo.getWorkspaceName(), parentId.getPath());
+            String name = Paths.nameToString(itemName);
             return '\"' + JsonBuilder.escape(PathUtil.concat(PathUtil.relativize("/", path),
name)) + '\"';
         }
 

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java?rev=1136476&r1=1136475&r2=1136476&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
Thu Jun 16 15:08:44 2011
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.Listener;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
@@ -39,7 +38,9 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.LinkedList;
 
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.*;
 import static org.apache.jackrabbit.spi2microkernel.util.Exceptions.setCause;
+import static org.json.simple.parser.ParseException.ERROR_UNEXPECTED_EXCEPTION;
 
 public final class ItemInfos {
     private ItemInfos() {}
@@ -171,7 +172,7 @@ public final class ItemInfos {
                 nodeInfoBuilder = nodeInfoBuilder.createNodeInfo();
             }
             if (currentKey != null) {
-                name = Paths.translateName(currentKey);
+                name = Paths.stringToName(currentKey);
             }
             nodeInfoBuilder.setName(name);
 
@@ -190,7 +191,7 @@ public final class ItemInfos {
                 return !infoListener.done();
             }
             catch (RepositoryException e) {
-                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION),
e);
+                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
             }
         }
 
@@ -210,14 +211,14 @@ public final class ItemInfos {
         @Override
         public boolean primitive(Object value) throws ParseException, IOException {
             try {
-                if (Paths.translateQName(NameConstants.JCR_PRIMARYTYPE).equals(currentKey))
{
-                    nodeInfoBuilder.setPrimaryType(Values.create(value).getName());
+                if (Paths.nameToString(JCR_PRIMARYTYPE).equals(currentKey)) {
+                    nodeInfoBuilder.setPrimaryType(Values.objectToValue(value).getName());
                 }
-                else if (Paths.translateQName(NameConstants.JCR_MIXINTYPES).equals(currentKey))
{
-                    nodeInfoBuilder.addMixin(Values.create(value).getName());
+                else if (Paths.nameToString(JCR_MIXINTYPES).equals(currentKey)) {
+                    nodeInfoBuilder.addMixin(Values.objectToValue(value).getName());
                 }
-                else if (Paths.translateQName(NameConstants.JCR_UUID).equals(currentKey))
{
-                    nodeInfoBuilder.setUUID(Values.create(value).getString());
+                else if (Paths.nameToString(JCR_UUID).equals(currentKey)) {
+                    nodeInfoBuilder.setUUID(Values.objectToValue(value).getString());
                 }
                 else if (currentKey.startsWith(":")) {  // ignore other internal values
                     return !infoListener.done();
@@ -225,26 +226,26 @@ public final class ItemInfos {
 
                 if (propertyInfoBuilder == null) {
                     nodeInfoBuilder.createPropertyInfo()
-                        .setName(Paths.translateName(currentKey))
-                        .addValue(Values.create(value))
+                        .setName(Paths.stringToName(currentKey))
+                        .addValue(Values.objectToValue(value))
                         .build();
 
                     return !infoListener.done();
                 }
                 else {
-                    propertyInfoBuilder.addValue(Values.create(value));
+                    propertyInfoBuilder.addValue(Values.objectToValue(value));
                     return true;
                 }
             }
             catch (RepositoryException e) {
-                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION),
e);
+                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
             }
         }
 
         @Override
         public boolean startArray() throws ParseException, IOException {
             propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo()
-                .setName(Paths.translateName(currentKey))
+                .setName(Paths.stringToName(currentKey))
                 .setMultivalued(true);
             
             return true;
@@ -258,7 +259,7 @@ public final class ItemInfos {
                 return !infoListener.done();
             }
             catch (RepositoryException e) {
-                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION),
e);
+                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
             }
         }
 

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java?rev=1136476&r1=1136475&r2=1136476&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
Thu Jun 16 15:08:44 2011
@@ -27,6 +27,8 @@ import org.apache.jackrabbit.spi.commons
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
 
+import static org.apache.jackrabbit.spi.Name.*;
+
 public final class Paths {
     public static final String DEFAULT_WORKSPACE = "default";
     public static final String SYSTEM_WORKSPACE = "system";
@@ -35,7 +37,7 @@ public final class Paths {
 
     private Paths() {}
 
-    public static Name translateName(String name) {
+    public static Name stringToName(String name) {
         if (name.startsWith("{")) {
             int i = name.indexOf('}');
             if (i == -1 || i == name.length() - 1) {
@@ -47,16 +49,16 @@ public final class Paths {
             return NAME_FACTORY.create(ns, localName);
         }
         else {
-            return NAME_FACTORY.create(Name.NS_DEFAULT_URI, name);
+            return NAME_FACTORY.create(NS_DEFAULT_URI, name);
         }
     }
 
-    public static String translateQName(Name name) {
+    public static String nameToString(Name name) {
         String nameSpaceURI = name.getNamespaceURI();
         return '{' + escapeNameSpaceURI(nameSpaceURI) + '}' + name.getLocalName();
     }
 
-    public static String translateQPath(String wspName, Path path) throws RepositoryException
{
+    public static String pathToString(String wspName, Path path) throws RepositoryException
{
         return cat('/' + getWorkspaceName(wspName), translateQPath(path));
     }
 
@@ -95,7 +97,7 @@ public final class Paths {
     private static String translateQPath(Path path) throws RepositoryException {
         return path.denotesRoot()
             ? ""
-            : cat(translateQPath(path.getAncestor(1)), translateQName(path.getName()));
+            : cat(translateQPath(path.getAncestor(1)), nameToString(path.getName()));
     }
 
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1136476&r1=1136475&r2=1136476&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Thu Jun 16 15:08:44 2011
@@ -26,28 +26,18 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import java.util.HashMap;
 import java.util.Map;
 
+import static javax.jcr.PropertyType.*;
+
 public final class Values {
     private static final QValueFactory FACTORY = QValueFactoryImpl.getInstance();
 
     private static final Character[] TYPES = {
-        toHex(PropertyType.UNDEFINED),
-            toHex(PropertyType.STRING),
-            toHex(PropertyType.BINARY),
-            toHex(PropertyType.LONG),
-            toHex(PropertyType.DOUBLE),
-            toHex(PropertyType.DATE),
-            toHex(PropertyType.BOOLEAN),
-            toHex(PropertyType.NAME),
-            toHex(PropertyType.PATH),
-            toHex(PropertyType.REFERENCE),
-            toHex(PropertyType.WEAKREFERENCE),
-            toHex(PropertyType.URI),
-            toHex(PropertyType.DECIMAL),
+        toHex(UNDEFINED), toHex(STRING), toHex(BINARY), toHex(LONG), toHex(DOUBLE), toHex(DATE),
toHex(BOOLEAN),
+        toHex(NAME), toHex(PATH), toHex(REFERENCE), toHex(WEAKREFERENCE), toHex(URI), toHex(DECIMAL),
     };
 
     public static final QValue FALSE = create(false);
@@ -60,11 +50,11 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.STRING);
+                return FACTORY.create(value, STRING);
             }
         };
         put(String.class, valueFactory);
-        put(TYPES[PropertyType.STRING], valueFactory);
+        put(TYPES[STRING], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -72,11 +62,11 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.LONG);
+                return FACTORY.create(value, LONG);
             }
         };
         put(Long.class, valueFactory);
-        put(TYPES[PropertyType.LONG], valueFactory);
+        put(TYPES[LONG], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -84,11 +74,11 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.DOUBLE);
+                return FACTORY.create(value, DOUBLE);
             }
         };
         put(Double.class, valueFactory);
-        put(TYPES[PropertyType.DOUBLE], valueFactory);
+        put(TYPES[DOUBLE], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -96,11 +86,11 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.BOOLEAN);
+                return FACTORY.create(value, BOOLEAN);
             }
         };
         put(Boolean.class, valueFactory);
-        put(TYPES[PropertyType.BOOLEAN], valueFactory);
+        put(TYPES[BOOLEAN], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -108,10 +98,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.DECIMAL);
+                return FACTORY.create(value, DECIMAL);
             }
         };
-        put(TYPES[PropertyType.DECIMAL], valueFactory);
+        put(TYPES[DECIMAL], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -119,10 +109,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.DATE);
+                return FACTORY.create(value, DATE);
             }
         };
-        put(TYPES[PropertyType.DATE], valueFactory);
+        put(TYPES[DATE], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -130,10 +120,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.URI);
+                return FACTORY.create(value, URI);
             }
         };
-        put(TYPES[PropertyType.URI], valueFactory);
+        put(TYPES[URI], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -141,10 +131,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.NAME);
+                return FACTORY.create(value, NAME);
             }
         };
-        put(TYPES[PropertyType.NAME], valueFactory);
+        put(TYPES[NAME], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -152,10 +142,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.PATH);
+                return FACTORY.create(value, PATH);
             }
         };
-        put(TYPES[PropertyType.PATH], valueFactory);
+        put(TYPES[PATH], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -163,10 +153,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.BINARY);
+                return FACTORY.create(value, BINARY);
             }
         };
-        put(TYPES[PropertyType.BINARY], valueFactory);
+        put(TYPES[BINARY], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -174,10 +164,10 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.REFERENCE);
+                return FACTORY.create(value, REFERENCE);
             }
         };
-        put(TYPES[PropertyType.REFERENCE], valueFactory);
+        put(TYPES[REFERENCE], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
@@ -185,13 +175,15 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.WEAKREFERENCE);
+                return FACTORY.create(value, WEAKREFERENCE);
             }
         };
-        put(TYPES[PropertyType.WEAKREFERENCE], valueFactory);
+        put(TYPES[WEAKREFERENCE], valueFactory);
     }};
 
-    public static QValue create(Object value) throws RepositoryException {
+    private Values() {}
+
+    public static QValue objectToValue(Object value) throws RepositoryException {
         // Type encoded value
         if (value instanceof String) {
             String val = (String) value;
@@ -216,24 +208,24 @@ public final class Values {
         }
     }
 
-    public static String create(Path path) {
-        return typeEncode(PropertyType.PATH, JsonBuilder.escape(path.getString()));
+    public static String pathToString(Path path) {
+        return typeEncode(PATH, JsonBuilder.escape(path.getString()));
     }
 
-    public static String create(Name name) {
-        return typeEncode(PropertyType.NAME, JsonBuilder.escape(name.toString()));
+    public static String nameToString(Name name) {
+        return typeEncode(NAME, JsonBuilder.escape(name.toString()));
     }
 
-    public static String create(Name[] names) {
+    public static String namesToString(Name[] names) {
         if (names.length == 0) {
             return "[]";
         }
         else {
             StringBuilder sb = new StringBuilder("[");
-            sb.append(create(names[0]));
+            sb.append(nameToString(names[0]));
 
             for (int k = 1; k < names.length; k++) {
-                sb.append(',').append(create(names[k]));
+                sb.append(',').append(nameToString(names[k]));
             }
             sb.append(']');
 
@@ -242,57 +234,57 @@ public final class Values {
         }
     }
 
-    public static String create(QValue value) throws RepositoryException {
+    public static String valueToString(QValue value) throws RepositoryException {
         int type = value.getType();
         
         switch(type) {
-            case PropertyType.STRING:
+            case STRING:
                 String s = value.getString();
                 return s.length() >= 2 && s.charAt(1) == ':'
                     ? typeEncode(type, JsonBuilder.escape(s))
                     : JsonBuilder.quote(JsonBuilder.escape(s));
 
-            case PropertyType.DOUBLE:
+            case DOUBLE:
                 return Double.isNaN(value.getDouble())
                     ? typeEncode(type, "NaN")
                     : value.getString();
 
-            case PropertyType.LONG:
-            case PropertyType.BOOLEAN:
+            case LONG:
+            case BOOLEAN:
                 return value.getString();
             
-            case PropertyType.DECIMAL:
-            case PropertyType.DATE:
+            case DECIMAL:
+            case DATE:
                 return typeEncode(type, value.getString());
 
-            case PropertyType.URI:
-            case PropertyType.NAME:
-            case PropertyType.PATH:
+            case URI:
+            case NAME:
+            case PATH:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));
             
-            case PropertyType.BINARY:
+            case BINARY:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));  // todo
improve handling of binary values
 
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
+            case REFERENCE:
+            case WEAKREFERENCE:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));
             
             default:
                 throw new RepositoryException("Cannot handle value of type " +
-                        PropertyType.nameFromValue(value.getType()));
+                        nameFromValue(value.getType()));
         }
     }
 
-    public static String create(QValue[] values) throws RepositoryException {
+    public static String valuesToString(QValue[] values) throws RepositoryException {
         if (values.length == 0) {
             return "[]";
         }
 
         StringBuilder sb = new StringBuilder("[");
-        sb.append(create(values[0]));
+        sb.append(valueToString(values[0]));
 
         for (int k = 1; k < values.length; k++) {
-            sb.append(',').append(create(values[k]));
+            sb.append(',').append(valueToString(values[k]));
         }
         sb.append(']');
 

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1136476&r1=1136475&r2=1136476&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun 16 15:08:44 2011
@@ -70,7 +70,7 @@ public class RepositoryTest {
         MicroKernel mk = MicroKernelFactory.getInstance(URL + ";clean");
         String head = mk.getHeadRevision();
 
-        String ptUnstructured = '\"' + JsonBuilder.escape(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE))
+ "\":" +
+        String ptUnstructured = '\"' + JsonBuilder.escape(Paths.nameToString(NameConstants.JCR_PRIMARYTYPE))
+ "\":" +
                 "\"7:" + NodeType.NT_UNSTRUCTURED + '\"';
 
         if (!mk.nodeExists("/default", head)) {



Mime
View raw message