You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2015/02/02 22:05:16 UTC

svn commit: r1656570 - in /sling/whiteboard/sseifert/SLING-4381_nosql: couchbase/ couchbase/src/ couchbase/src/main/ couchbase/src/main/java/ couchbase/src/test/ couchbase/src/test/java/ nosql-generic/ nosql-generic/src/ nosql-generic/src/main/ nosql-g...

Author: sseifert
Date: Mon Feb  2 21:05:15 2015
New Revision: 1656570

URL: http://svn.apache.org/r1656570
Log:
some first steps

Added:
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/src/
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/src/main/
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/src/main/java/
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/src/test/
    sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/src/test/java/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java   (with props)
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/test/
    sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/test/java/

Added: sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml Mon Feb  2 21:05:15 2015
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>22</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.couchbase</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Couchbase Resource Provider</name>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/couchbase</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/couchbase</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/couchbase</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+    	    <groupId>org.apache.sling</groupId>
+    	    <artifactId>org.apache.sling.api</artifactId>
+    	    <version>2.7.0</version>
+    	    <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.felix</groupId>
+        	<artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>org.slf4j</groupId>
+        	<artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>javax.servlet</groupId>
+        	<artifactId>servlet-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/couchbase/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml Mon Feb  2 21:05:15 2015
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>22</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.nosql-generic</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Generic NoSQL Resource Provider</name>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/nosql-generic</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/nosql-generic</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/nosql-generic</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+    	    <groupId>org.apache.sling</groupId>
+    	    <artifactId>org.apache.sling.api</artifactId>
+    	    <version>2.7.0</version>
+    	    <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.felix</groupId>
+        	<artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>org.slf4j</groupId>
+        	<artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>javax.servlet</groupId>
+        	<artifactId>servlet-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,86 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+
+public class GenericModifiableValueMap
+    extends GenericValueMap
+    implements ModifiableValueMap {
+
+    private final GenericResource resource;
+
+    public GenericModifiableValueMap(final GenericResource resource) {
+        super(resource.getProperties());
+        this.resource = resource;
+    }
+
+    /**
+     * @see java.util.Map#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("clear");
+    }
+
+    /**
+     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(final String name, final Object value) {
+        final Object oldValue = this.properties.get(name);
+        final String key = GenericResourceProvider.propNameToKey(name);
+
+        this.resource.getProperties().put(key, value);
+
+        // update map and resource
+        this.createValueMap(this.resource.getProperties());
+        this.resource.changed();
+
+        return oldValue;
+    }
+
+    /**
+     * @see java.util.Map#putAll(java.util.Map)
+     */
+    public void putAll(final Map<? extends String, ? extends Object> m) {
+        for(final Map.Entry<? extends String, ? extends Object> e : m.entrySet() ) {
+            this.put(e.getKey(), e.getValue());
+        }
+    }
+
+    /**
+     * @see java.util.Map#remove(java.lang.Object)
+     */
+    public Object remove(final Object name) {
+        final Object result = this.properties.get(name);
+        if ( result != null ) {
+            final String key = GenericResourceProvider.propNameToKey(name.toString());
+
+            this.resource.getProperties().removeField(key);
+
+            // update map and resource
+            this.createValueMap(this.resource.getProperties());
+            this.resource.changed();
+        }
+        return result;
+    }
+    
+    protected GenericResource getResource() {
+        return this.resource;
+    }
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericModifiableValueMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,140 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.DeepReadModifiableValueMapDecorator;
+import org.apache.sling.api.wrappers.DeepReadValueMapDecorator;
+
+public class GenericResource extends AbstractResource {
+
+    /** The complete resource path. */
+    private final String resourcePath;
+
+    /** The resource resolver. */
+    private final ResourceResolver resourceResolver;
+
+    /** Metadata. */
+    protected ResourceMetadata metadata = new ResourceMetadata();
+
+    /** The internal properties map */
+    private Map<String,Object> properties;
+
+    /** The MongoDB resource provider. */
+    private final GenericResourceProvider provider;
+
+    public GenericResource(final ResourceResolver resolver,
+                    final String resourcePath,
+                    final Map<String,Object> properties,
+                    final GenericResourceProvider provider) {
+        this.resourceResolver = resolver;
+        this.resourcePath = resourcePath;
+        this.properties = properties;
+        this.provider = provider;
+    }
+
+    public GenericResource(final GenericResource source) {
+        this.resourceResolver = source.resourceResolver;
+        this.resourcePath = source.resourcePath;
+        this.properties = source.properties;
+        this.provider = source.provider;
+    }
+    /**
+     * @see org.apache.sling.api.resource.Resource#getPath()
+     */
+    public String getPath() {
+        return this.resourcePath;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceType()
+     */
+    public String getResourceType() {
+        // get resource type from data
+        final Object rt = this.properties.get("sling:resourceType");
+        if ( rt != null ) {
+            return rt.toString();
+        }
+        return "nt:unstructured";
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
+     */
+    public String getResourceSuperType() {
+        // get resource type from data
+        final Object rt = this.properties.get("sling:resourceSuperType");
+        if ( rt != null ) {
+            return rt.toString();
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
+     */
+    public ResourceMetadata getResourceMetadata() {
+        return this.metadata;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceResolver()
+     */
+    public ResourceResolver getResourceResolver() {
+        return this.resourceResolver;
+    }
+
+    /**
+     * @see org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
+        if ( type == ValueMap.class || type == Map.class ) {
+            this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
+            return (AdapterType) new DeepReadValueMapDecorator(this, new GenericValueMap(this.dbObject));
+        } else if ( type == ModifiableValueMap.class ) {
+            this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
+            return (AdapterType) new DeepReadModifiableValueMapDecorator(this, new GenericModifiableValueMap(this));
+        }
+
+        return super.adaptTo(type);
+    }
+
+    /**
+     * Get the current properties.
+     */
+    public Map<String,Object> getProperties() {
+        return this.properties;
+    }
+
+    @Override
+    public String toString() {
+        return "MongoDBResource [resourcePath=" + resourcePath + ", dbPath=" + this.dbObject.get(provider.getPROP_PATH()) + ", "
+                        + "resourceResolver=" + resourceResolver + "]";
+    }
+
+    public void changed() {
+        this.provider.changed(this);
+    }
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,430 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.ModifyingResourceProvider;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.QueriableResourceProvider;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The MongoDB resource provider creates resources based on MongoDB entries.
+ * The resources contain all properties stored in the MongoDB except those starting with a "_".
+ */
+public class GenericResourceProvider implements ResourceProvider, ModifyingResourceProvider {
+
+    /** The special path property containing the (relative) path of the resource in the tree. */
+    private static final String PROP_PATH = "_path";
+
+    /** The id property. */
+    private static final String PROP_ID = "_id";
+
+    /** Logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The global context .*/
+    private final NoSqlContext context;
+
+    private final Map<String, GenericResource> changedResources = new HashMap<String, GenericResource>();
+
+    private final Set<String> deletedResources = new HashSet<String>();
+
+    public GenericResourceProvider(final NoSqlContext context) {
+        this.context = context;
+    }
+
+    public static String propNameToKey(final String name) {
+        if ( name.startsWith("_") ) {
+            return "_" + name;
+        }
+        return name;
+    }
+
+    public static String keyToPropName(final String key) {
+        if ( key.startsWith("__") ) {
+            return key.substring(1);
+        } else if ( key.startsWith("_") ) {
+            return null;
+        }
+        return key;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#create(org.apache.sling.api.resource.ResourceResolver, java.lang.String, java.util.Map)
+     */
+    public Resource create(final ResourceResolver resolver, final String path, final Map<String, Object> properties)
+            throws PersistenceException {
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null && info.length == 2) {
+            final boolean deleted = this.deletedResources.remove(path);
+            final GenericResource oldResource = (GenericResource)this.getResource(resolver, path, info);
+            if ( !deleted && oldResource != null ) {
+                throw new PersistenceException("Resource already exists at " + path, null, path, null);
+            }
+            final DBObject dbObj = new BasicDBObject();
+            dbObj.put(getPROP_PATH(), info[1]);
+            if ( properties != null ) {
+                for(Map.Entry<String, Object> entry : properties.entrySet()) {
+                    final String key = propNameToKey(entry.getKey());
+                    dbObj.put(key, entry.getValue());
+                }
+            }
+            if ( deleted && oldResource != null ) {
+                dbObj.put(PROP_ID, oldResource.getProperties().get(PROP_ID));
+            }
+            final GenericResource rsrc = new GenericResource(resolver, path, info[0], dbObj, this);
+            this.changedResources.put(path, rsrc);
+
+            return rsrc;
+        }
+        throw new PersistenceException("Illegal path - unable to create resource at " + path, null, path, null);
+    }
+
+    /**
+     * TODO - we should handle delete different and not put all child resources into the
+     * deleted set.
+     * Instead when getting resources, the parents of the resource should be checked
+     * first.
+     * This minimizes concurrency issues.
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
+     */
+    public void delete(final ResourceResolver resolver, final String path)
+            throws PersistenceException {
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null ) {
+            boolean deletedResource = false;
+            if ( !deletedResources.contains(path) ) {
+                final Resource rsrc = this.getResource(resolver, path, info);
+                if ( rsrc instanceof GenericResource ) {
+                    this.deletedResources.add(path);
+                    this.changedResources.remove(path);
+
+                    final DBCollection col = this.getCollection(info[0]);
+                    final String pattern = "^" + Pattern.quote(info[1]) + "/";
+
+                    final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
+                    final DBCursor cur = col.find(query);
+                    while ( cur.hasNext() ) {
+                        final DBObject dbObj = cur.next();
+                        final String childPath = info[0] + '/' + dbObj.get(getPROP_PATH());
+                        this.deletedResources.add(childPath);
+                        this.changedResources.remove(childPath);
+                    }
+                    deletedResource = true;
+                }
+            } else {
+                deletedResource = true;
+            }
+            if ( deletedResource ) {
+                final String prefix = path + "/";
+                final Iterator<Map.Entry<String, GenericResource>> i = this.changedResources.entrySet().iterator();
+                while ( i.hasNext() ) {
+                    final Map.Entry<String, GenericResource> entry = i.next();
+                    if ( entry.getKey().startsWith(prefix) ) {
+                        i.remove();
+                    }
+                }
+                return;
+            }
+
+        }
+        throw new PersistenceException("Unable to delete resource at {}" + path, null, path, null);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#revert(ResourceResolver)
+     */
+    public void revert(final ResourceResolver resolver) {
+        this.changedResources.clear();
+        this.deletedResources.clear();
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#commit(ResourceResolver)
+     */
+    public void commit(final ResourceResolver resolver) throws PersistenceException {
+        try {
+            for(final String deleted : this.deletedResources) {
+                final String[] info = this.extractResourceInfo(deleted);
+
+                // check if the collection still exists
+                final DBCollection col = this.getCollection(info[0]);
+                if ( col != null ) {
+                    if ( col.findAndRemove(QueryBuilder.start(getPROP_PATH()).is(info[1]).get()) != null ) {
+                        this.context.notifyRemoved(info);
+                    }
+                }
+            }
+            for(final GenericResource changed : this.changedResources.values()) {
+
+                final DBCollection col = this.context.getDatabase().getCollection(changed.getCollection());
+                if ( col != null ) {
+                    final String[] info = new String[] {changed.getCollection(),
+                            changed.getProperties().get(getPROP_PATH()).toString()};
+                    // create or update?
+                    if ( changed.getProperties().get(PROP_ID) != null ) {
+                        col.update(QueryBuilder.start(getPROP_PATH()).is(changed.getProperties().get(getPROP_PATH())).get(),
+                                changed.getProperties());
+                        this.context.notifyUpdated(info);
+                    } else {
+                        // create
+                        col.save(changed.getProperties());
+                        this.context.notifyUpdated(info);
+                    }
+                } else {
+                    throw new PersistenceException("Unable to create collection " + changed.getCollection(), null, changed.getPath(), null);
+                }
+            }
+        } finally {
+            this.revert(resolver);
+        }
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#hasChanges(ResourceResolver)
+     */
+    public boolean hasChanges(final ResourceResolver resolver) {
+        return this.changedResources.size() > 0 || this.deletedResources.size() > 0;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
+     */
+    public Resource getResource(final ResourceResolver resourceResolver, final String path) {
+        if ( this.deletedResources.contains(path) ) {
+            return null;
+        }
+        if ( this.changedResources.containsKey(path) ) {
+            return new GenericResource(this.changedResources.get(path));
+        }
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null ) {
+            return this.getResource(resourceResolver, path, info);
+        }
+        return null;
+    }
+
+    /**
+     * Inform about changes of a resource.
+     */
+    public void changed(final GenericResource resource) {
+        this.deletedResources.remove(resource.getPath());
+        this.changedResources.put(resource.getPath(), resource);
+    }
+
+    /**
+     * TODO - we have to check for deleted and added resources
+     * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
+     */
+    public Iterator<Resource> listChildren(final Resource parent) {
+        final String[] info = this.extractResourceInfo(parent.getPath());
+        if ( info != null ) {
+            if ( info.length == 0 ) {
+                // all collections
+                final Set<String> names = new HashSet<String>(context.getDatabase().getCollectionNames());
+                names.removeAll(this.context.getFilterCollectionNames());
+                final Iterator<String> i = names.iterator();
+                return new Iterator<Resource>() {
+
+                    public boolean hasNext() {
+                        return i.hasNext();
+                    }
+
+                    public Resource next() {
+                        final String name = i.next();
+                        return new MongoDBCollectionResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
+                    }
+
+                    public void remove() {
+                        throw new UnsupportedOperationException("remove");
+                    }
+
+                };
+            }
+            final DBCollection col = this.getCollection(info[0]);
+            if ( col != null ) {
+                final String pattern;
+                if ( info.length == 1 ) {
+                    pattern = "^([^/])*$";
+                } else {
+                    pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
+                }
+
+                final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
+                final DBCursor cur = col.find(query).
+                        sort(BasicDBObjectBuilder.start(getPROP_PATH(), 1).get());
+                return new Iterator<Resource>() {
+
+                    public boolean hasNext() {
+                        return cur.hasNext();
+                    }
+
+                    public Resource next() {
+                        final DBObject obj = cur.next();
+                        final String objPath = obj.get(getPROP_PATH()).toString();
+                        final int lastSlash = objPath.lastIndexOf('/');
+                        final String name;
+                        if (lastSlash == -1) {
+                            name = objPath;
+                        } else {
+                            name = objPath.substring(lastSlash + 1);
+                        }
+                        return new GenericResource(parent.getResourceResolver(),
+                                parent.getPath() + '/' + name,
+                                info[0],
+                                obj,
+                                GenericResourceProvider.this);
+                    }
+
+                    public void remove() {
+                        throw new UnsupportedOperationException("remove");
+                    }
+
+                };
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, javax.servlet.http.HttpServletRequest, java.lang.String)
+     */
+    public Resource getResource(final ResourceResolver resourceResolver,
+            final HttpServletRequest request,
+            final String path) {
+        return this.getResource(resourceResolver, path);
+    }
+
+    /**
+     * Extract info about collection and path
+     */
+    protected String[] extractResourceInfo(final String path) {
+        if ( path.startsWith(this.context.getRootWithSlash()) ) {
+            if ( path.length() == this.context.getRootWithSlash().length() ) {
+                // special resource - show all collections
+                return new String[0];
+            }
+            final String info = path.substring(this.context.getRootWithSlash().length());
+            final int slashPos = info.indexOf('/');
+            if ( slashPos != -1 ) {
+                return new String[] {info.substring(0, slashPos), info.substring(slashPos + 1)};
+            }
+            // special resource - collection
+            return new String[] {info};
+        }
+
+        if ( path.equals(this.context.getRoot()) ) {
+            // special resource - show all collections
+            return new String[0];
+        }
+
+        return null;
+    }
+
+    /**
+     * Check if a collection with a given name exists
+     */
+    protected boolean hasCollection(final String name) {
+        logger.info("Mongo: Getting collection names");
+        final Set<String> names = this.context.getDatabase().getCollectionNames();
+        return names.contains(name) && !this.context.isFilterCollectionName(name);
+    }
+
+
+    /**
+     * Check if a collection with a given name exists and return it
+     */
+    protected DBCollection getCollection(final String name) {
+        if ( this.hasCollection(name) ) {
+            return this.context.getDatabase().getCollection(name);
+        }
+        return null;
+    }
+
+    /**
+     * Get a resource
+     */
+    protected Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
+        if ( info.length == 0 ) {
+            // special resource : all collections
+            return new MongoDBCollectionResource(resourceResolver, path);
+        } else if ( info.length == 1 ) {
+            // special resource : collection
+            if ( this.hasCollection(info[0]) ) {
+                return new MongoDBCollectionResource(resourceResolver, path);
+            }
+            return null;
+        }
+        logger.debug("Searching {} in {}", info[1], info[0]);
+        final DBCollection col = this.getCollection(info[0]);
+        if ( col != null ) {
+            final DBObject obj = col.findOne(QueryBuilder.start(getPROP_PATH()).is(info[1]).get());
+            logger.debug("Found {}", obj);
+            if ( obj != null ) {
+                return new GenericResource(resourceResolver,
+                        path,
+                        info[0],
+                        obj,
+                        this);
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Check if there is a newer db object for that path.
+     */
+    public DBObject getUpdatedDBObject(final String path, final DBObject dbObj) {
+        final GenericResource stored = this.changedResources.get(path);
+        if ( stored != null ) {
+            return stored.getProperties();
+        }
+        return dbObj;
+    }
+
+    protected Set<String> getDeletedResources() {
+        return this.deletedResources;
+    }
+
+    protected Map<String, GenericResource> getChangedResources() {
+        return this.changedResources;
+    }
+
+    protected NoSqlContext getContext() {
+        return this.context;
+    }
+
+    protected String getPROP_PATH() {
+        return PROP_PATH;
+    }
+
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,59 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GenericResourceProviderFactory implements ResourceProviderFactory {
+
+    /** Logger. */
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The global context passed to each resource provider. */
+    protected NoSqlContext context;
+
+    @Reference
+    private EventAdmin eventAdmin;
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProviderFactory#getResourceProvider(java.util.Map)
+     */
+    public ResourceProvider getResourceProvider(final Map<String, Object> authenticationInfo) throws LoginException {
+        // for now we allow anonymous access
+        return new GenericResourceProvider(this.context);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProviderFactory#getAdministrativeResourceProvider(java.util.Map)
+     */
+    public ResourceProvider getAdministrativeResourceProvider(final Map<String, Object> authenticationInfo) throws LoginException {
+        // for now we allow anonymous access
+        return new GenericResourceProvider(this.context);
+    }
+    
+    protected NoSqlContext getContext() {
+        return this.context;
+    }
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericResourceProviderFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,207 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.api.resource.ValueMap;
+
+public class GenericValueMap implements ValueMap {
+
+    protected Map<String, Object> properties;
+
+    public GenericValueMap(final Map<String, Object> map) {
+        this.properties = map;
+    }
+
+    /**
+     * @see java.util.Map#containsKey(java.lang.Object)
+     */
+    public boolean containsKey(final Object key) {
+        return this.properties.containsKey(key);
+    }
+
+    /**
+     * @see java.util.Map#containsValue(java.lang.Object)
+     */
+    public boolean containsValue(final Object value) {
+        return this.properties.containsValue(value);
+    }
+
+    /**
+     * @see java.util.Map#entrySet()
+     */
+    public Set<java.util.Map.Entry<String, Object>> entrySet() {
+        return this.properties.entrySet();
+    }
+
+    /**
+     * @see java.util.Map#get(java.lang.Object)
+     */
+    public Object get(final Object key) {
+        return this.properties.get(key);
+    }
+
+    /**
+     * @see java.util.Map#isEmpty()
+     */
+    public boolean isEmpty() {
+        return this.properties.isEmpty();
+    }
+
+    /**
+     * @see java.util.Map#keySet()
+     */
+    public Set<String> keySet() {
+        return this.properties.keySet();
+    }
+
+    /**
+     * @see java.util.Map#size()
+     */
+    public int size() {
+        return this.properties.size();
+    }
+
+    /**
+     * @see java.util.Map#values()
+     */
+    public Collection<Object> values() {
+        return this.properties.values();
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T get(final String key, final Class<T> type) {
+        if (type == null) {
+            return (T) get(key);
+        }
+
+        final Object val = this.get(key);
+        if ( val == null ) {
+            return null;
+        }
+        return convertToType(val, type);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Object)
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T get(final String key,final T defaultValue) {
+        if (defaultValue == null) {
+            return (T) get(key);
+        }
+
+        T value = get(key, (Class<T>) defaultValue.getClass());
+        if (value == null) {
+            value = defaultValue;
+        }
+
+        return value;
+    }
+
+    /**
+     * @see java.util.Map#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("clear");
+    }
+
+    /**
+     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(String key, Object value) {
+        throw new UnsupportedOperationException("put");
+    }
+
+    /**
+     * @see java.util.Map#putAll(java.util.Map)
+     */
+    public void putAll(Map<? extends String, ? extends Object> m) {
+        throw new UnsupportedOperationException("putAll");
+    }
+
+    /**
+     * @see java.util.Map#remove(java.lang.Object)
+     */
+    public Object remove(Object key) {
+        throw new UnsupportedOperationException("remove");
+    }
+
+    /**
+     * Converts the object to the given type.
+     * @param obj object
+     * @param type type
+     * @return the converted object
+     */
+    @SuppressWarnings("unchecked")
+    private <T> T convertToType(final Object obj, final Class<T> type) {
+        // todo: do smarter checks
+        try {
+            if (obj == null) {
+                return null;
+            } else if (type.isAssignableFrom(obj.getClass())) {
+                return (T) obj;
+            } else if (type.isArray()) {
+                return (T) convertToArray(obj, type.getComponentType());
+            } else if (type == String.class) {
+                return (T) String.valueOf(obj);
+            } else if (type == Integer.class) {
+                return (T) (Integer) Integer.parseInt(obj.toString());
+            } else if (type == Long.class) {
+                return (T) (Long) Long.parseLong(obj.toString());
+            } else if (type == Double.class) {
+                return (T) (Double) Double.parseDouble(obj.toString());
+            } else if (type == Boolean.class) {
+                return (T) (Boolean) Boolean.parseBoolean(obj.toString());
+            } else {
+                return null;
+            }
+        } catch (final NumberFormatException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Converts the object to an array of the given type
+     * @param obj the object or object array
+     * @param type the component type of the array
+     * @return and array of type T
+     */
+    private <T> T[] convertToArray(Object obj, Class<T> type) {
+        List<T> values = new LinkedList<T>();
+        if (obj.getClass().isArray()) {
+            for (Object o: (Object[]) obj) {
+                values.add(convertToType(o, type));
+            }
+        } else {
+            values.add(convertToType(obj, type));
+        }
+        @SuppressWarnings("unchecked")
+        T[] result = (T[]) Array.newInstance(type, values.size());
+        return values.toArray(result);
+    }
+    
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/GenericValueMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java?rev=1656570&view=auto
==============================================================================
--- sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java (added)
+++ sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java Mon Feb  2 21:05:15 2015
@@ -0,0 +1,90 @@
+/*
+ * 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.sling.nosql.generic.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.api.SlingConstants;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
+public class NoSqlContext {
+
+    /** The roots. */
+    private final String root;
+
+    /** The roots ended by a slash. */
+    private final String rootWithSlash;
+
+    private final EventAdmin eventAdmin;
+
+    public NoSqlContext(final String configuredRoot,
+            final EventAdmin eventAdmin) {
+        if ( configuredRoot != null ) {
+            final String value = configuredRoot.trim();
+            if ( value.length() > 0 ) {
+                if ( value.endsWith("/") ) {
+                    this.rootWithSlash = configuredRoot;
+                    this.root = configuredRoot.substring(0, configuredRoot.length() - 1);
+                } else {
+                    this.rootWithSlash = configuredRoot + "/";
+                    this.root = configuredRoot;
+                }
+            } else {
+                this.root = "";
+                this.rootWithSlash = "/";
+            }
+        } else {
+            this.root = "";
+            this.rootWithSlash = "/";
+        }
+        this.eventAdmin = eventAdmin;
+    }
+
+    public String getRoot() {
+        return root;
+    }
+
+    public String getRootWithSlash() {
+        return this.rootWithSlash;
+    }
+
+    public void notifyRemoved(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_REMOVED, props);
+        this.eventAdmin.postEvent(event);
+    }
+
+    public void notifyAddeed(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_ADDED, props);
+        this.eventAdmin.postEvent(event);
+    }
+
+    public void notifyUpdated(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED, props);
+        this.eventAdmin.postEvent(event);
+    }    
+}

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Feb  2 21:05:15 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/whiteboard/sseifert/SLING-4381_nosql/nosql-generic/src/main/java/org/apache/sling/nosql/generic/impl/NoSqlContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain