jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1128270 - in /jackrabbit/sandbox/spi2microkernel: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/jackrabbit/ src/main/java/org/apache/jackrabbit/spi2microkernel/ src/main/java/org/apa...
Date Fri, 27 May 2011 11:52:33 GMT
Author: mduerig
Date: Fri May 27 11:52:32 2011
New Revision: 1128270

URL: http://svn.apache.org/viewvc?rev=1128270&view=rev
Log:
spi2microkernel prototype (WIP)

Added:
    jackrabbit/sandbox/spi2microkernel/pom.xml
    jackrabbit/sandbox/spi2microkernel/src/
    jackrabbit/sandbox/spi2microkernel/src/main/
    jackrabbit/sandbox/spi2microkernel/src/main/java/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryFactoryImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceFactoryImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Exceptions.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.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/main/resources/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
    jackrabbit/sandbox/spi2microkernel/src/test/
    jackrabbit/sandbox/spi2microkernel/src/test/java/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Added: jackrabbit/sandbox/spi2microkernel/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/pom.xml?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/pom.xml (added)
+++ jackrabbit/sandbox/spi2microkernel/pom.xml Fri May 27 11:52:32 2011
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                             http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.jackrabbit</groupId>
+    <artifactId>spi2microkernel</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <name>SPI2MicroKernel</name>
+    <description>Microkernel based SPI implementation</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <version>2.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi-commons</artifactId>
+            <version>2.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-jcr2spi</artifactId>
+            <version>2.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>microkernel</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>com.googlecode.json-simple</groupId>
+            <artifactId>json-simple</artifactId>
+            <version>1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+                <version>2.0.2</version>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryFactoryImpl.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryFactoryImpl.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryFactoryImpl.java Fri May 27 11:52:32 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory;
+import org.apache.jackrabbit.jcr2spi.RepositoryImpl;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import java.util.Map;
+
+public class RepositoryFactoryImpl implements RepositoryFactory {
+
+    public Repository getRepository(Map parameters) {
+        try {
+            return RepositoryImpl.create(
+                    new Jcr2spiRepositoryFactory.RepositoryConfigImpl(
+                            new RepositoryServiceFactoryImpl(), parameters));
+        }
+        catch (RepositoryException e) {
+            return null;
+        }
+    }
+
+}

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceFactoryImpl.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceFactoryImpl.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceFactoryImpl.java Fri May 27 11:52:32 2011
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.RepositoryServiceFactory;
+
+import javax.jcr.RepositoryException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+public class RepositoryServiceFactoryImpl implements RepositoryServiceFactory {
+    public static final String PARAM_HOME_DIR = "org.apache.jackrabbit.spi2microkernel.home-dir";
+    
+    public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException {
+        String homeDir = getHomeDir(parameters);
+        return new RepositoryServiceImpl(homeDir);
+    }
+
+    //------------------------------------------< private >---
+
+    private static String getHomeDir(Map<?, ?> parameters) {
+        Object uri = parameters.get(PARAM_HOME_DIR);
+        URI homeDir;
+        if (uri instanceof URI) {
+            homeDir = (URI) uri;
+        }
+        else if (uri instanceof String) {
+            try {
+                homeDir = new URI((String) uri);
+            }
+            catch (URISyntaxException e) {
+                return null; 
+            }
+        }
+        else {
+            return null;
+        }
+
+        return "file".equals(homeDir.getScheme())
+            ? homeDir.getPath()
+            : null;
+    }
+}

Added: 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=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java Fri May 27 11:52:32 2011
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.apache.jackrabbit.mk.MicroKernelImpl;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.spi.Batch;
+import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.ItemInfo;
+import org.apache.jackrabbit.spi.ItemInfoCache;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.commons.AbstractRepositoryService;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
+import org.apache.jackrabbit.spi2microkernel.util.Json;
+import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
+import org.apache.jackrabbit.spi2microkernel.util.Paths;
+import org.apache.jackrabbit.spi2microkernel.util.Values;
+
+import javax.jcr.Credentials;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class RepositoryServiceImpl extends AbstractRepositoryService {
+    private static final Map<String, QValue[]> DESCRIPTORS = new HashMap<String, QValue[]>() {{
+        put(Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, new QValue[] { Values.FALSE });
+    }};
+
+    private static final Map<String, String> NAMESPACES = Collections.emptyMap();
+
+    private final MicroKernel microKernel;
+    private final Map<SessionInfo, String> sessions = new HashMap<SessionInfo, String>();
+
+    public RepositoryServiceImpl(String homeDir) throws RepositoryException {
+        super(DESCRIPTORS, NAMESPACES, NodeTypes.getDefaultNodeTypes());
+
+        try {
+            microKernel = new MicroKernelImpl(homeDir);  // xxx who disposes the micro kernel?
+            // todo add default and system wsp if necessary
+        }
+        catch (MicroKernelException e) {
+            throw new RepositoryException(e.getMessage(), e); 
+        }
+    }
+
+    public ItemInfoCache getItemInfoCache(SessionInfo sessionInfo) throws RepositoryException {
+        return new ItemInfoCacheImpl();
+    }
+
+    @Override
+    protected QNodeDefinition createRootNodeDefinition(SessionInfo sessionInfo) throws RepositoryException {
+        throw new UnsupportedRepositoryOperationException();
+        // todo implement createRootNodeDefinition
+    }
+
+    //------------------------------------------< Session and Workspace handling >---
+
+
+    @Override
+    protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName) throws RepositoryException {
+        SessionInfo s = super.createSessionInfo(sessionInfo, workspaceName);
+        initSessionInfo(s);
+        return s;
+    }
+
+    @Override
+    protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName) throws RepositoryException {
+        SessionInfo s = super.createSessionInfo(credentials, workspaceName);
+        initSessionInfo(s);
+        return s;
+    }
+
+    @Override
+    public void dispose(SessionInfo sessionInfo) throws RepositoryException {
+        sessions.remove(sessionInfo);
+    }
+
+    public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException {
+        return new String[0]; // todo implement getWorkspaceNames
+    }
+
+    @Override
+    protected void checkWorkspace(String workspaceName) throws NoSuchWorkspaceException {
+        // todo implement checkWorkspace
+    }
+
+    //------------------------------------------< Access Control >---
+
+    public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException {
+        return true;
+    }
+
+    //------------------------------------------< Reading Items >---
+
+    public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
+        try {
+            String wspName = sessionInfo.getWorkspaceName();
+            Path path = nodeId.getPath();
+            String mkPath = Paths.translateQPath(wspName, path);
+            String rev = getRevision(sessionInfo);
+
+            String json = microKernel.getNodes(mkPath, 1, rev);
+            return Json.buildItemInfos(path, json);
+        }
+        catch (MicroKernelException e) {
+            // todo throw correct exceptions
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
+        try {
+            String wspName = sessionInfo.getWorkspaceName();
+            Path path = nodeId.getPath();
+            String mkPath = Paths.translateQPath(wspName, path);
+            String rev = getRevision(sessionInfo);
+
+            String json = microKernel.getNodes(mkPath, 1, rev);
+            return Json.buildNodeInfo(path, json);
+        }
+        catch (MicroKernelException e) {
+            // todo throw correct exceptions
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
+        try {
+            String wspName = sessionInfo.getWorkspaceName();
+            Path path = propertyId.getPath();
+            String mkPath = Paths.translateQPath(wspName, path.getAncestor(1));
+            String rev = getRevision(sessionInfo);
+
+            String json = microKernel.getNodes(mkPath, 0, rev);
+            return Json.buildPropertyInfo(path, json);
+        }
+        catch (MicroKernelException e) {
+            // todo throw correct exceptions
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
+        throw new UnsupportedRepositoryOperationException();
+        // todo implement getChildInfos
+    }
+
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences)
+            throws RepositoryException {
+
+        throw new UnsupportedRepositoryOperationException();
+        // todo implement getReferences
+    }
+
+    //-----------------------------< write methods >----------------------------
+
+    @Override
+    public Batch createBatch(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
+        // todo implement createBatch
+        throw new UnsupportedRepositoryOperationException();
+    }
+
+    @Override
+    public void submit(Batch batch) throws RepositoryException {
+        // todo implement submit
+        throw new UnsupportedRepositoryOperationException();
+    }
+
+    //------------------------------------------< private >---
+
+    private String getRevision(SessionInfo sessionInfo) throws RepositoryException {
+        String rev = sessions.get(sessionInfo);
+
+        if (rev == null) {
+            throw new RepositoryException("Invalid session");
+        }
+        else {
+            return rev;
+        }
+    }
+
+    private void initSessionInfo(SessionInfo sessionInfo) throws RepositoryException {
+        try {
+            sessions.put(sessionInfo, microKernel.getHeadRevision());
+        }
+        catch (MicroKernelException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+}

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Exceptions.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Exceptions.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Exceptions.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Exceptions.java Fri May 27 11:52:32 2011
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+public final class Exceptions {
+    private Exceptions() {}
+
+    @SuppressWarnings("unchecked")
+    public static <E extends Throwable> E setCause(E exception, Throwable cause) {
+        return (E) exception.initCause(cause);
+    }
+
+}

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java Fri May 27 11:52:32 2011
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.ItemInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.commons.ItemInfoBuilder;
+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.json.simple.parser.ContentHandler;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import static org.apache.jackrabbit.spi2microkernel.util.Exceptions.setCause;
+
+public final class Json {
+    private Json() {}
+
+    public static Iterator<? extends ItemInfo> buildItemInfos(Path path, String json) throws RepositoryException {
+        final LinkedList<ItemInfo> itemInfos = new LinkedList<ItemInfo>();
+
+        InfoListener infoListener = new InfoListener() {
+            public void createNodeInfo(NodeInfo nodeInfo) {
+                itemInfos.addFirst(nodeInfo);
+            }
+
+            public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos) {}
+
+            public void createPropertyInfo(PropertyInfo propertyInfo) {
+                itemInfos.addFirst(propertyInfo);
+            }
+
+            public boolean done() {
+                return false;
+            }
+        };
+
+        try {
+            JSONParser parser = new JSONParser();
+            parser.parse(json, new JsonHandler(parent(path), infoListener));
+            return itemInfos.iterator();
+        }
+        catch (ParseException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    public static NodeInfo buildNodeInfo(Path path, String json) throws RepositoryException {
+        final Name name = path.getName();
+        final NodeInfo[] nodeInfos = new NodeInfo[1];
+
+        InfoListener infoListener = new InfoListener() {
+            public void createNodeInfo(NodeInfo nodeInfo) {
+                if (name.equals(nodeInfo.getPath().getName())) {
+                    nodeInfos[0] = nodeInfo;
+                }
+            }
+
+            public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos) {}
+            public void createPropertyInfo(PropertyInfo propertyInfo) {}
+
+            public boolean done() {
+                return nodeInfos[0] != null;
+            }
+        };
+
+        try {
+            JSONParser parser = new JSONParser();
+            parser.parse(json, new JsonHandler(parent(parent(path)), infoListener));
+            return nodeInfos[0];
+        }
+        catch (ParseException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    public static PropertyInfo buildPropertyInfo(Path path, String json) throws RepositoryException {
+        final Name name = path.getName();
+        final PropertyInfo[] propertyInfos = new PropertyInfo[1];
+        
+        InfoListener infoListener = new InfoListener() {
+            public void createNodeInfo(NodeInfo nodeInfo) {}
+            public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos) {}
+
+            public void createPropertyInfo(PropertyInfo propertyInfo) {
+                if (name.equals(propertyInfo.getPath().getName())) {
+                    propertyInfos[0] = propertyInfo;
+                }
+            }
+
+            public boolean done() {
+                return propertyInfos[0] != null;
+            }
+        };
+
+        try {
+            JSONParser parser = new JSONParser();
+            parser.parse(json, new JsonHandler(parent(parent(path)), infoListener));
+            return propertyInfos[0];
+        }
+        catch (ParseException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    //------------------------------------------< private >---
+
+    private interface InfoListener extends Listener {
+        boolean done();
+    }
+
+    private static Path parent(Path path) throws RepositoryException {
+        return path.denotesRoot() ? null : path.getAncestor(1);
+    }
+    
+    private static class JsonHandler implements ContentHandler {
+        private final Path parent;
+        private final InfoListener infoListener;
+
+        private String currentKey;
+        private boolean isObjectEmpty;
+        private NodeInfoBuilder nodeInfoBuilder;
+
+        public JsonHandler(Path parent, InfoListener infoListener) {
+            this.infoListener = infoListener;
+            this.parent = parent;
+        }
+
+        public void startJSON() throws ParseException, IOException {}
+
+        public void endJSON() throws ParseException, IOException {}
+
+        public boolean startObject() throws ParseException, IOException {
+            if (nodeInfoBuilder == null) {
+                nodeInfoBuilder = ItemInfoBuilder.nodeInfoBuilder(infoListener);
+                nodeInfoBuilder.setParentPath(parent);
+            }
+            else {
+                nodeInfoBuilder = nodeInfoBuilder.createNodeInfo();
+            }
+
+            isObjectEmpty = true;
+            return !infoListener.done();
+        }
+
+        public boolean endObject() throws ParseException, IOException {
+            try {
+                nodeInfoBuilder = isObjectEmpty
+                    ? nodeInfoBuilder.getParent()
+                    : nodeInfoBuilder.build();
+
+                isObjectEmpty = false;
+                return !infoListener.done();
+            }
+            catch (RepositoryException e) {
+                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION), e);
+            }
+        }
+
+        public boolean startObjectEntry(String key) throws ParseException, IOException {
+            isObjectEmpty = false;
+            currentKey = key;
+            return !infoListener.done();
+        }
+
+        public boolean endObjectEntry() throws ParseException, IOException {
+            currentKey = null;
+            return !infoListener.done();
+        }
+
+        public boolean primitive(Object value) throws ParseException, IOException {
+            if (":name".equals(currentKey)) {
+                Name name = Paths.translateName((String) value);
+                nodeInfoBuilder.setName(name);
+                return !infoListener.done();
+            }
+
+            if (currentKey.startsWith(":")) {  // ignore internal values
+                return !infoListener.done();
+            }
+
+            try {
+                PropertyInfoBuilder propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo();
+                Name name = Paths.translateName(currentKey);
+                propertyInfoBuilder.setName(name);
+                propertyInfoBuilder.addValue(Values.create(value));
+                propertyInfoBuilder.build();
+                return !infoListener.done();
+            }
+            catch (RepositoryException e) {
+                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION), e);
+            }
+        }
+
+        public boolean startArray() throws ParseException, IOException {
+            throw new ParseException(3, "Array not expected");
+        }
+
+        public boolean endArray() throws ParseException, IOException {
+            throw new ParseException(3, "Array not expected");
+        }
+    }
+    
+}
\ No newline at end of file

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java Fri May 27 11:52:32 2011
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi2microkernel.RepositoryServiceImpl;
+
+import javax.jcr.RepositoryException;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+public final class NodeTypes {
+    private static final String DEFAULT_NODETYPES = "default-nodetypes.cnd";
+    private NodeTypes() {}
+
+    public static Reader getDefaultNodeTypes() throws RepositoryException {
+        InputStream is = RepositoryServiceImpl.class.getResourceAsStream(DEFAULT_NODETYPES);
+        if (is == null) {
+            throw new RepositoryException("Resource not found: " + DEFAULT_NODETYPES);
+        }
+
+        return new InputStreamReader(new BufferedInputStream(is));
+    }
+
+}

Added: 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=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java Fri May 27 11:52:32 2011
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+
+import javax.jcr.RepositoryException;
+
+public final class Paths {
+    public static final String ROOT = "/";
+
+    private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
+
+    private Paths() {}
+
+    public static Name translateName(String name) {
+        return name.startsWith("{")
+            ? NAME_FACTORY.create(name)
+            : NAME_FACTORY.create(Name.NS_DEFAULT_URI, name);
+    }
+
+    public static String translateQName(Name name) {
+        String nameSpaceURI = name.getNamespaceURI();
+        return '{' + escapeNameSpaceURI(nameSpaceURI) + '}' + name.getLocalName();
+    }
+
+    public static String translateQPath(String wspName, Path path) throws RepositoryException {
+        return translateQPath(path); // todo honor wspName
+    }
+
+    //------------------------------------------< private >---
+
+    private static String escapeNameSpaceURI(String nameSpaceURI) {
+        return nameSpaceURI.replace('/', '\\');
+    }
+
+    private static String unescapeNameSpaceURI(String nameSpaceURI) {
+        return nameSpaceURI.replace('\\', '/');
+    }
+
+    private static String cat(String absPath, String relPath) {
+        return ROOT.equals(absPath)
+            ? absPath + relPath
+            : absPath + '/' + relPath;
+    }
+
+    private static String translateQPath(Path path) throws RepositoryException {
+        return path.denotesRoot()
+            ? "/"
+            : cat(translateQPath(path.getAncestor(1)), translateQName(path.getName()));
+    }
+
+}

Added: 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=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java Fri May 27 11:52:32 2011
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+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 javax.jcr.UnsupportedRepositoryOperationException;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class Values {
+    private static final QValueFactory FACTORY = QValueFactoryImpl.getInstance();
+
+    public static final QValue FALSE = create(false);
+    public static final QValue TRUE = create(true);
+
+    private static final Map<Class<?>, ValueFactory> VALUE_FACTORIES = new HashMap<Class<?>, ValueFactory>() {{
+        put(String.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((String) value, PropertyType.STRING);
+            }
+        });
+        put(Boolean.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((Boolean) value);
+            }
+        });
+        put(Double.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((Double) value);
+            }
+        });
+        put(Long.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((Long) value);
+            }
+        });
+        put(Integer.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((Integer) value);
+            }
+        });
+        put(BigDecimal.class, new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                return FACTORY.create((BigDecimal) value);
+            }
+        });
+        // todo handle other value types
+    }};
+
+    private Values() {}
+
+    public static QValue create(Object value) throws RepositoryException {
+        ValueFactory valueFactory = VALUE_FACTORIES.get(value.getClass());
+        if (valueFactory == null) {
+            throw new UnsupportedRepositoryOperationException("Not supported value " + value);
+        }
+        else {
+            return valueFactory.create(value);
+        }
+    }
+
+    //------------------------------------------< private >---
+
+    private static QValue create(boolean value) {
+        try {
+            return FACTORY.create(value);
+        }
+        catch (RepositoryException e) {
+            // Should not happen
+            throw new IllegalStateException(e.getMessage(), e);  
+        }
+    }
+
+    private interface ValueFactory {
+        QValue create(Object value) throws RepositoryException;
+    }
+}

Added: jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory Fri May 27 11:52:32 2011
@@ -0,0 +1,17 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+org.apache.jackrabbit.spi2microkernel.RepositoryFactoryImpl
+
+

Added: jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd (added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd Fri May 27 11:52:32 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<''=''>
+<rep='internal'>
+<jcr='http://www.jcp.org/jcr/1.0'>
+<xs='http://www.w3.org/2001/XMLSchema'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<sv='http://www.jcp.org/jcr/sv/1.0'>
+<xml='http://www.w3.org/XML/1998/namespace'>
+
+//------------------------------------------------------------------------------
+// B A S E  T Y P E S
+//------------------------------------------------------------------------------
+
+[nt:base]
+  - jcr:primaryType (name) mandatory autocreated protected compute
+  - jcr:mixinTypes (name) protected multiple compute
+
+[nt:unstructured] > nt:base
+  orderable
+  - * (undefined) multiple
+  - * (undefined)
+  + * (nt:base) = nt:unstructured version
+
+[rep:root] > nt:unstructured
+

Added: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1128270&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java (added)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java Fri May 27 11:52:32 2011
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.apache.jackrabbit.mk.MicroKernelImpl;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import java.io.File;
+import java.util.Collections;
+import java.util.Iterator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class Tests {
+    private static final File REPO_HOME_DIR = new File("target/repository");
+
+    @Before
+    public void setup() {
+        MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
+        String head = mk.getHeadRevision();
+
+        if (!mk.nodeExists("/{}foo", head)) {
+            mk.commit("/",
+                "+{}foo : {" +
+                    "\"{}stringProp\":\"stringVal\"," +
+                    "\"{}intProp\":42," +
+                    "\"{}mvProp\":[1,2,3]} " +
+                "\r+{}bar : {}", head);
+        }
+    }
+
+    @Test
+    public void createRepository() throws RepositoryException {
+        Repository repository = acquireRepository(REPO_HOME_DIR);
+        assertNotNull(repository);        
+    }
+
+    @Test
+    public void login() throws RepositoryException {
+        Session session = getSession();
+        assertNotNull(session);
+    }
+
+    @Test
+    public void getRoot() throws RepositoryException {
+        Session session = getSession();
+        Node root = session.getRootNode();
+        assertNotNull(root);
+        assertEquals("", root.getName());
+        assertEquals("/", root.getPath());
+    }
+
+    @Test
+    public void getRootFromPath() throws RepositoryException {
+        Node root = getNode("/");
+        assertEquals("", root.getName());
+        assertEquals("/", root.getPath());
+    }
+
+    @Test
+    public void getNode() throws RepositoryException {
+        Node node = getNode("/foo");
+        assertNotNull(node);
+        assertEquals("foo", node.getName());
+        assertEquals("/foo", node.getPath());
+    }
+
+    @Ignore  // todo RepositoryServiceImpl throws wrong exception 
+    @Test(expected = PathNotFoundException.class)
+    public void getNonexNode() throws RepositoryException {
+        getNode("/qoo");
+    }
+
+    @Test
+    public void getProperty() throws RepositoryException {
+        Session session = getSession();
+        Property property = session.getProperty("/foo/stringProp");
+        assertNotNull(property);
+        assertEquals("stringProp", property.getName());
+        assertEquals("/foo/stringProp", property.getPath());
+
+        Value value = property.getValue();
+        assertNotNull(value);
+        assertEquals(PropertyType.STRING, value.getType());
+        assertEquals("stringVal", value.getString());
+    }
+
+    @Test
+    public void getPropertyFromNode() throws RepositoryException {
+        Node node = getNode("/foo");
+        Property property = node.getProperty("stringProp");
+        assertNotNull(property);
+        assertEquals("stringProp", property.getName());
+        assertEquals("/foo/stringProp", property.getPath());
+
+        Value value = property.getValue();
+        assertNotNull(value);
+        assertEquals(PropertyType.STRING, value.getType());
+        assertEquals("stringVal", value.getString());
+    }
+
+    //------------------------------------------< private >---
+
+    private static Repository acquireRepository(File homeDir) throws RepositoryException {
+        Repository repository = null;
+
+        Iterator<RepositoryFactory> factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);
+        while (repository == null && factories.hasNext()) {
+            RepositoryFactory factory = factories.next();
+            repository = factory.getRepository(Collections.singletonMap(
+                    RepositoryServiceFactoryImpl.PARAM_HOME_DIR, "file:///" + homeDir.getAbsolutePath()));  
+        }
+
+        return repository;
+    }
+
+    private static Session getSession() throws RepositoryException {
+        Repository repository = acquireRepository(REPO_HOME_DIR);
+        return repository.login();
+    }
+
+    private static Node getNode(String path) throws RepositoryException {
+        Session session = getSession();
+        return session.getNode(path);
+    }
+}



Mime
View raw message