You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Michael Dürig <md...@apache.org> on 2012/05/30 18:10:49 UTC
The revenge of the checked exception....
Author: mduerig
Date: Wed May 30 16:09:19 2012
New Revision: 1344328
URL: http://svn.apache.org/viewvc?rev=1344328&view=rev
Log:
OAK-68 - Extension point for commit validation
commit hook implementation which validates a commit against a set of
validators
[...]
+ /**
+ * Checked exceptions don't compose. So we need to hack around. See
+ * <ul>
+ * <li>http://markmail.org/message/ak67n5k7mr3vqylm</li>
+ * <li>http://markmail.org/message/7l26cofhyr3sk5pr</li>
+ * <li>http://markmail.org/message/nw7mg4cmgpeqq4i5</li>
+ * <li>http://markmail.org/message/bhocbruikljpuhu6</li>
+ * </ul>
+ */
+ private static class BreakOutException extends RuntimeException {
+ public BreakOutException(CommitFailedException cause) {
+ super(cause);
+ }
+ }
+
+ private static void validate(final NodeStore store, NodeState
before, NodeState after,
+ final Validator validator) throws CommitFailedException {
+
+ try {
+ store.compare(before, after, new NodeStateDiff() {
+ @Override
+ public void propertyAdded(PropertyState after) {
+ try {
+ validator.propertyAdded(after);
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+
+ @Override
+ public void propertyChanged(PropertyState before,
PropertyState after) {
+ try {
+ validator.propertyChanged(before, after);
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+
+ @Override
+ public void propertyDeleted(PropertyState before) {
+ try {
+ validator.propertyDeleted(before);
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+
+ @Override
+ public void childNodeAdded(String name, NodeState after) {
+ try {
+ Validator childValidator =
validator.childNodeAdded(name, after);
+ if (childValidator != null) {
+ validate(after, validator);
+ }
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+
+ @Override
+ public void childNodeChanged(String name, NodeState
before, NodeState after) {
+ try {
+ Validator childValidator =
validator.childNodeChanged(name, before, after);
+ if (childValidator != null) {
+ validate(store, before, after, childValidator);
+ }
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+
+ @Override
+ public void childNodeDeleted(String name, NodeState
before) {
+ try {
+ validator.childNodeDeleted(name, before);
+ }
+ catch (CommitFailedException e) {
+ throw new BreakOutException(e);
+ }
+ }
+ });
+ }
+ catch (BreakOutException e) {
+ throw new CommitFailedException(e);
+ }
+ }
+
+ private static void validate(NodeState nodeState, Validator validator)
+ throws CommitFailedException {
+
+ for (PropertyState property : nodeState.getProperties()) {
+ validator.propertyAdded(property);
+ }
+
+ for (ChildNodeEntry child : nodeState.getChildNodeEntries()) {
+ Validator childValidator = validator.childNodeAdded(
+ child.getName(), child.getNodeState());
+ validate(child.getNodeState(), childValidator);
+ }
+ }
+}
Re: The revenge of the checked exception....
Posted by Michael Dürig <mi...@gmail.com>.
Wrong list. Sorry for the noise.
Michael
On 30.5.12 18:10, Michael Dürig wrote:
>
> Author: mduerig
> Date: Wed May 30 16:09:19 2012
> New Revision: 1344328
>
> URL: http://svn.apache.org/viewvc?rev=1344328&view=rev
> Log:
> OAK-68 - Extension point for commit validation
> commit hook implementation which validates a commit against a set of
> validators
>
> [...]
> + /**
> + * Checked exceptions don't compose. So we need to hack around. See
> + * <ul>
> + * <li>http://markmail.org/message/ak67n5k7mr3vqylm</li>
> + * <li>http://markmail.org/message/7l26cofhyr3sk5pr</li>
> + * <li>http://markmail.org/message/nw7mg4cmgpeqq4i5</li>
> + * <li>http://markmail.org/message/bhocbruikljpuhu6</li>
> + * </ul>
> + */
> + private static class BreakOutException extends RuntimeException {
> + public BreakOutException(CommitFailedException cause) {
> + super(cause);
> + }
> + }
> +
> + private static void validate(final NodeStore store, NodeState before,
> NodeState after,
> + final Validator validator) throws CommitFailedException {
> +
> + try {
> + store.compare(before, after, new NodeStateDiff() {
> + @Override
> + public void propertyAdded(PropertyState after) {
> + try {
> + validator.propertyAdded(after);
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> +
> + @Override
> + public void propertyChanged(PropertyState before, PropertyState after) {
> + try {
> + validator.propertyChanged(before, after);
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> +
> + @Override
> + public void propertyDeleted(PropertyState before) {
> + try {
> + validator.propertyDeleted(before);
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> +
> + @Override
> + public void childNodeAdded(String name, NodeState after) {
> + try {
> + Validator childValidator = validator.childNodeAdded(name, after);
> + if (childValidator != null) {
> + validate(after, validator);
> + }
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> +
> + @Override
> + public void childNodeChanged(String name, NodeState before, NodeState
> after) {
> + try {
> + Validator childValidator = validator.childNodeChanged(name, before,
> after);
> + if (childValidator != null) {
> + validate(store, before, after, childValidator);
> + }
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> +
> + @Override
> + public void childNodeDeleted(String name, NodeState before) {
> + try {
> + validator.childNodeDeleted(name, before);
> + }
> + catch (CommitFailedException e) {
> + throw new BreakOutException(e);
> + }
> + }
> + });
> + }
> + catch (BreakOutException e) {
> + throw new CommitFailedException(e);
> + }
> + }
> +
> + private static void validate(NodeState nodeState, Validator validator)
> + throws CommitFailedException {
> +
> + for (PropertyState property : nodeState.getProperties()) {
> + validator.propertyAdded(property);
> + }
> +
> + for (ChildNodeEntry child : nodeState.getChildNodeEntries()) {
> + Validator childValidator = validator.childNodeAdded(
> + child.getName(), child.getNodeState());
> + validate(child.getNodeState(), childValidator);
> + }
> + }
> +}
>
>