jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r664550 - in /jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp: ./ nodetype/ state/
Date Sun, 08 Jun 2008 20:32:51 GMT
Author: jukka
Date: Sun Jun  8 13:32:51 2008
New Revision: 664550

URL: http://svn.apache.org/viewvc?rev=664550&view=rev
Log:
ngp: First take on typed and multivalued properties

Added:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/MultiValuedPropertyState.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PropertyState.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/SingleValuedPropertyState.java
Modified:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/NodeState.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PersistentNodeState.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
Sun Jun  8 13:32:51 2008
@@ -29,11 +29,11 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import javax.jcr.lock.Lock;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.version.Version;
@@ -42,8 +42,10 @@
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.ngp.nodetype.NodeDefinitionImpl;
+import org.apache.jackrabbit.ngp.state.MultiValuedPropertyState;
 import org.apache.jackrabbit.ngp.state.NodeState;
 import org.apache.jackrabbit.ngp.state.PersistentNodeState;
+import org.apache.jackrabbit.ngp.state.SingleValuedPropertyState;
 import org.apache.jackrabbit.ngp.state.TransientNodeState;
 
 public class NodeImpl extends AbstractNode {
@@ -149,14 +151,25 @@
     public Property setProperty(String name, Value value)
             throws RepositoryException {
         synchronized (session) {
-            getTransientNodeState().setProperty(name, value.getString());
+            getTransientNodeState().setProperty(
+                    name, new SingleValuedPropertyState(
+                            value.getType(), value.getString()));
             return new PropertyImpl(session, this, name);
         }
     }
 
     public Property setProperty(String name, Value[] values)
             throws RepositoryException {
-        throw new ValueFormatException("Not a multi-valued property");
+        synchronized (session) {
+            int type = values.length > 0 ? values[0].getType() : PropertyType.STRING;
+            String[] vals = new String[values.length];
+            for (int i = 0; i < values.length; i++) {
+                vals[i] = values[i].getString();
+            }
+            getTransientNodeState().setProperty(
+                    name, new MultiValuedPropertyState(type, vals));
+            return new PropertyImpl(session, this, name);
+        }
     }
 
     public NodeIterator getNodes() throws RepositoryException {
@@ -195,7 +208,8 @@
             }
             state = new TransientNodeState(PersistentNodeState.NEW);
             ((TransientNodeState) state).setProperty(
-                    "jcr:primaryType", "nt:unstructured");
+                    "jcr:primaryType", new SingleValuedPropertyState(
+                            PropertyType.NAME, "nt:unstructured"));
             getTransientNodeState().setNode(relPath, state);
             return new NodeImpl(session, this, relPath);
         }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
Sun Jun  8 13:32:51 2008
@@ -21,11 +21,11 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.commons.AbstractProperty;
 import org.apache.jackrabbit.ngp.nodetype.PropertyDefinitionImpl;
+import org.apache.jackrabbit.ngp.state.PropertyState;
 
 public class PropertyImpl extends AbstractProperty {
 
@@ -81,18 +81,26 @@
     }
 
     public PropertyDefinition getDefinition() {
-        return new PropertyDefinitionImpl();
+        synchronized (session) {
+            PropertyState state =
+                parent.getNodeState().getProperties().get(name);
+            return new PropertyDefinitionImpl(
+                    state.getType(), state.isMultiple());
+        }
     }
 
     public Value getValue() throws RepositoryException {
         synchronized (session) {
-            return session.getValueFactory().createValue(
-                    parent.getNodeState().getProperties().get(name));
+            return parent.getNodeState().getProperties().get(name).getValue(
+                    session.getValueFactory());
         }
     }
 
     public Value[] getValues() throws RepositoryException {
-        throw new ValueFormatException("Not a multi-valued property: " + name);
+        synchronized (session) {
+            return parent.getNodeState().getProperties().get(name).getValues(
+                    session.getValueFactory());
+        }
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
Sun Jun  8 13:32:51 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
+import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
@@ -53,7 +54,10 @@
     }
 
     public PropertyDefinition[] getDeclaredPropertyDefinitions() {
-        return new PropertyDefinition[] { new PropertyDefinitionImpl() };
+        return new PropertyDefinition[] {
+                new PropertyDefinitionImpl(PropertyType.UNDEFINED, true),
+                new PropertyDefinitionImpl(PropertyType.UNDEFINED, false)
+        };
     }
 
     public NodeType[] getDeclaredSupertypes() {
@@ -69,7 +73,10 @@
     }
 
     public PropertyDefinition[] getPropertyDefinitions() {
-        return new PropertyDefinition[] { new PropertyDefinitionImpl() };
+        return new PropertyDefinition[] {
+                new PropertyDefinitionImpl(PropertyType.UNDEFINED, true),
+                new PropertyDefinitionImpl(PropertyType.UNDEFINED, false)
+        };
     }
 
     public NodeType[] getSupertypes() {

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
Sun Jun  8 13:32:51 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
-import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
@@ -24,12 +23,21 @@
 
 public class PropertyDefinitionImpl implements PropertyDefinition {
 
+    private int type;
+
+    private boolean multiple;
+
+    public PropertyDefinitionImpl(int type, boolean multiple) {
+        this.type = type;
+        this.multiple = multiple;
+    }
+
     public Value[] getDefaultValues() {
         return null;
     }
 
     public int getRequiredType() {
-        return PropertyType.STRING;
+        return type;
     }
 
     public String[] getValueConstraints() {
@@ -37,7 +45,7 @@
     }
 
     public boolean isMultiple() {
-        return false;
+        return multiple;
     }
 
     public NodeType getDeclaringNodeType() {

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/MultiValuedPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/MultiValuedPropertyState.java?rev=664550&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/MultiValuedPropertyState.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/MultiValuedPropertyState.java
Sun Jun  8 13:32:51 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.ngp.state;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+public class MultiValuedPropertyState extends PropertyState {
+
+    private String[] values;
+
+    public MultiValuedPropertyState(int type, String[] values) {
+        super(type);
+        this.values = values;
+    }
+    
+    public boolean isMultiple() {
+        return true;
+    }
+
+    public Value getValue(ValueFactory factory) throws ValueFormatException {
+        throw new ValueFormatException("Not a single-valued property");
+    }
+
+    public Value[] getValues(ValueFactory factory) throws ValueFormatException {
+        Value[] vals = new Value[values.length];
+        for (int i = 0; i < values.length; i++) {
+            vals[i] = factory.createValue(values[i]);
+        }
+        return vals;
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/NodeState.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/NodeState.java
Sun Jun  8 13:32:51 2008
@@ -35,7 +35,7 @@
 
     NodeState refresh(PersistentNodeState state);
 
-    Map<String, String> getProperties();
+    Map<String, PropertyState> getProperties();
 
     Map<String, NodeState> getNodes();
 

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PersistentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PersistentNodeState.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PersistentNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PersistentNodeState.java
Sun Jun  8 13:32:51 2008
@@ -20,25 +20,32 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.jcr.PropertyType;
 
 public class PersistentNodeState implements NodeState {
 
     public static final PersistentNodeState ROOT = new PersistentNodeState(
-            Collections.singletonMap("jcr:primaryType", "nt:unstructured"),
+            Collections.singletonMap(
+                    "jcr:primaryType",
+                    (PropertyState) new SingleValuedPropertyState(
+                            PropertyType.NAME, "nt:unstructured")),
             new HashMap<String, NodeState>());
 
     public static final PersistentNodeState NEW = new PersistentNodeState(
-            new HashMap<String, String>(), new HashMap<String, NodeState>());
+            new HashMap<String, PropertyState>(),
+            new HashMap<String, NodeState>());
 
     public static final PersistentNodeState DEL = new PersistentNodeState(
-            new HashMap<String, String>(), new HashMap<String, NodeState>());
+            new HashMap<String, PropertyState>(),
+            new HashMap<String, NodeState>());
 
-    private final Map<String, String> properties;
+    private final Map<String, PropertyState> properties;
 
     private final Map<String, NodeState> nodes;
 
     public PersistentNodeState(
-            Map<String, String> properties, Map<String, NodeState> nodes) {
+            Map<String, PropertyState> properties,
+            Map<String, NodeState> nodes) {
         assert properties != null;
         assert nodes != null;
         for (NodeState node : nodes.values()) {
@@ -46,7 +53,7 @@
         }
 
         this.properties = Collections.unmodifiableMap(
-                new HashMap<String, String>(properties));
+                new HashMap<String, PropertyState>(properties));
         this.nodes = Collections.unmodifiableMap(
                 new HashMap<String, NodeState>(nodes));
     }
@@ -81,7 +88,7 @@
         return state;
     }
 
-    public Map<String, String> getProperties() {
+    public Map<String, PropertyState> getProperties() {
         return properties;
     }
 

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PropertyState.java?rev=664550&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PropertyState.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/PropertyState.java
Sun Jun  8 13:32:51 2008
@@ -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.ngp.state;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+public abstract class PropertyState {
+
+    private int type;
+
+    protected PropertyState(int type) {
+        this.type = type;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public abstract boolean isMultiple();
+
+    public abstract Value getValue(ValueFactory factory)
+            throws ValueFormatException;
+
+    public abstract Value[] getValues(ValueFactory factory)
+            throws ValueFormatException;
+
+}

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/SingleValuedPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/SingleValuedPropertyState.java?rev=664550&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/SingleValuedPropertyState.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/SingleValuedPropertyState.java
Sun Jun  8 13:32:51 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.ngp.state;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+public class SingleValuedPropertyState extends PropertyState {
+
+    private String value;
+
+    public SingleValuedPropertyState(int type, String value) {
+        super(type);
+        this.value = value;
+    }
+
+    public boolean isMultiple() {
+        return false;
+    }
+
+    public Value getValue(ValueFactory factory) {
+        return factory.createValue(value);
+    }
+
+    public Value[] getValues(ValueFactory factory) throws ValueFormatException {
+        throw new ValueFormatException("Not a multi-valued property");
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java?rev=664550&r1=664549&r2=664550&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
Sun Jun  8 13:32:51 2008
@@ -24,8 +24,8 @@
 
     private final PersistentNodeState base;
 
-    private final Map<String, String> properties =
-        new HashMap<String, String>();
+    private final Map<String, PropertyState> properties =
+        new HashMap<String, PropertyState>();
 
     private final Map<String, NodeState> nodes =
         new HashMap<String, NodeState>();
@@ -87,11 +87,11 @@
         return this;
     }
 
-    public Map<String, String> getProperties() {
-        Map<String, String> result = base.getProperties();
+    public Map<String, PropertyState> getProperties() {
+        Map<String, PropertyState> result = base.getProperties();
         if (!properties.isEmpty()) {
-            result = new HashMap<String, String>(result);
-            for (Map.Entry<String, String> entry : properties.entrySet()) {
+            result = new HashMap<String, PropertyState>(result);
+            for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
                 if (entry.getValue() != null) {
                     result.put(entry.getKey(), entry.getValue());
                 } else {
@@ -123,7 +123,7 @@
         return base;
     }
 
-    public void setProperty(String name, String value) {
+    public void setProperty(String name, PropertyState value) {
         if (value != null || base.getProperties().containsKey(name)) {
             properties.put(name, value);
         } else {



Mime
View raw message