jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1392343 - /jackrabbit/oak/trunk/doc/nodestate.md
Date Mon, 01 Oct 2012 14:09:52 GMT
Author: jukka
Date: Mon Oct  1 14:09:52 2012
New Revision: 1392343

URL: http://svn.apache.org/viewvc?rev=1392343&view=rev
Log:
OAK-301: Document Oak internals

Add a basic commit validator example

Modified:
    jackrabbit/oak/trunk/doc/nodestate.md

Modified: jackrabbit/oak/trunk/doc/nodestate.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/doc/nodestate.md?rev=1392343&r1=1392342&r2=1392343&view=diff
==============================================================================
--- jackrabbit/oak/trunk/doc/nodestate.md (original)
+++ jackrabbit/oak/trunk/doc/nodestate.md Mon Oct  1 14:09:52 2012
@@ -181,6 +181,81 @@ TODO
 
 TODO
 
+TODO: Basic validator class
+
+    class DenyContentWithName extends DefaultValidator {
+
+        private final String name;
+
+        public DenyContentWithName(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public void propertyAdded(PropertyState after)
+                throws CommitFailedException {
+            if (name.equals(after.getName())) {
+                throw new CommitFailedException(
+                        "Properties named " + name + " are not allowed");
+            }
+        }
+
+
+    }
+
+TODO: Example of how the validator works
+
+    ContentRepository contentRepository = new Oak()
+        .with(new DenyContentWithName("bar"))
+        .createContentRepository();
+
+    Repository repository = new RepositoryImpl(contentRepository);
+    Session session = repository.login();
+    Node root = session.getRootNode();
+    root.setProperty("foo", "test");
+    session.save();
+    root.setProperty("bar", "test");
+    session.save(); // will throw an exception
+
+TODO: Extended example that also works below root and covers also node names
+
+    class DenyContentWithName extends DefaultValidator {
+
+        private final String name;
+
+        public DenyContentWithName(String name) {
+            this.name = name;
+        }
+
+        private void testName(String addedName) throws CommitFailedException {
+            if (name.equals(addedName)) {
+                throw new CommitFailedException(
+                        "Content named " + name + " is not allowed");
+            }
+        }
+
+        @Override
+        public void propertyAdded(PropertyState after)
+                throws CommitFailedException {
+            testName(after.getName());
+        }
+
+        @Override
+        public Validator childNodeAdded(String name, NodeState after)
+                throws CommitFailedException {
+            testName(name);
+            return this;
+        }
+
+        @Override
+        public Validator childNodeChanged(
+                String name, NodeState before, NodeState after)
+                throws CommitFailedException {
+            return this;
+        }
+
+    }
+
 ## Commit modification
 
 TODO



Mime
View raw message