DNA SVN: r311 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-26 17:19:31 -0400 (Thu, 26 Jun 2008)
New Revision: 311
Modified:
trunk/pom.xml
Log:
Added Michael Trezzi (Developer) and Greg Haber (Contributor). Also added license info.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-06-25 21:39:59 UTC (rev 310)
+++ trunk/pom.xml 2008-06-26 21:19:31 UTC (rev 311)
@@ -12,12 +12,24 @@
<scm>
<connection>scm:svn:https://svn.jboss.org/repos/dna/trunk</connection>
</scm>
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License</name>
+ <url>http://www.gnu.org/licenses/lgpl.html</url>
+ <distribution>repo</distribution>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+ <organization>
+ <name>JBoss, a division of Red Hat</name>
+ <url>http://www.jboss.org</url>
+ </organization>
<developers>
<developer>
<name>Randall Hauch</name>
<id>randall</id>
<email>rhauch(a)redhat.com</email>
- <organization>Red Hat</organization>
+ <organization>JBoss, a division of Red Hat</organization>
<roles>
<role>Project Lead</role>
<role>Developer</role>
@@ -28,7 +40,7 @@
<name>John Verhaeg</name>
<id>johnny</id>
<email>jverhaeg(a)redhat.com</email>
- <organization>Red Hat</organization>
+ <organization>JBoss, a division of Red Hat</organization>
<roles>
<role>Developer</role>
</roles>
@@ -38,7 +50,7 @@
<name>Dan Florian</name>
<id>dan</id>
<email>dflorian(a)redhat.com</email>
- <organization>Red Hat</organization>
+ <organization>JBoss, a division of Red Hat</organization>
<roles>
<role>Developer</role>
</roles>
@@ -62,7 +74,24 @@
</roles>
<timezone>+1</timezone>
</developer>
+ <developer>
+ <name>Michael Trezzi</name>
+ <id>mathwizard</id>
+ <email>michael(a)mathwizard.org</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
</developers>
+ <contributors>
+ <contributor>
+ <name>Greg Haber</name>
+ <id>ghaber</id>
+ <organization>JBoss, a division of Red Hat</organization>
+ <timezone>-5</timezone>
+ </contributor>
+ </contributors>
<modules>
<module>dna-common</module>
<module>dna-spi</module>
15 years, 10 months
DNA SVN: r310 - in trunk/dna-common/src: test/java/org/jboss/dna/common and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-25 17:39:59 -0400 (Wed, 25 Jun 2008)
New Revision: 310
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/AbstractProblems.java
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/ThreadSafeProblems.java
trunk/dna-common/src/test/java/org/jboss/dna/common/collection/
trunk/dna-common/src/test/java/org/jboss/dna/common/collection/AbstractProblemsTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ProblemTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/collection/SimpleProblemsTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ThreadSafeProblemsTest.java
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/Problem.java
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java
Log:
DNA-166 - Create threadsafe Problems implementation
http://jira.jboss.com/jira/browse/DNA-166
Added a thread-safe implementation of Problems, and added unit tests for SimpleProblems and the new ThreadSafeProblems.
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/AbstractProblems.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/collection/AbstractProblems.java (rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/collection/AbstractProblems.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * A list of problems for some execution context. The problems will be {@link #iterator() returned} in the order in which they
+ * were encountered (although this cannot be guaranteed in contexts involving multiple threads or processes).
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public abstract class AbstractProblems implements Problems {
+
+ protected static final List<Problem> EMPTY_PROBLEMS = Collections.emptyList();
+
+ public void addError( I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, null));
+ }
+
+ public void addError( Throwable throwable,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, throwable));
+ }
+
+ public void addError( I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, null));
+ }
+
+ public void addError( Throwable throwable,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
+ }
+
+ public void addError( int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, null));
+ }
+
+ public void addError( Throwable throwable,
+ int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, throwable));
+ }
+
+ public void addError( int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, null));
+ }
+
+ public void addError( Throwable throwable,
+ int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, throwable));
+ }
+
+ public void addWarning( I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, null));
+ }
+
+ public void addWarning( Throwable throwable,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, throwable));
+ }
+
+ public void addWarning( I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, null));
+ }
+
+ public void addWarning( Throwable throwable,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
+ }
+
+ public void addWarning( int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, null));
+ }
+
+ public void addWarning( Throwable throwable,
+ int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, throwable));
+ }
+
+ public void addWarning( int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, null));
+ }
+
+ public void addWarning( Throwable throwable,
+ int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, throwable));
+ }
+
+ public void addInfo( I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, null));
+ }
+
+ public void addInfo( Throwable throwable,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, throwable));
+ }
+
+ public void addInfo( I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, null));
+ }
+
+ public void addInfo( Throwable throwable,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
+ }
+
+ public void addInfo( int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, null));
+ }
+
+ public void addInfo( Throwable throwable,
+ int code,
+ I18n message,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, throwable));
+ }
+
+ public void addInfo( int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, null));
+ }
+
+ public void addInfo( Throwable throwable,
+ int code,
+ I18n message,
+ String resource,
+ String location,
+ Object... params ) {
+ addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, throwable));
+ }
+
+ public boolean hasProblems() {
+ return getProblems().size() > 0;
+ }
+
+ public boolean hasErrors() {
+ for (Problem problem : this.getProblems()) {
+ if (problem.getStatus() == Problem.Status.ERROR) return true;
+ }
+ return false;
+ }
+
+ public boolean hasWarnings() {
+ for (Problem problem : this.getProblems()) {
+ if (problem.getStatus() == Problem.Status.WARNING) return true;
+ }
+ return false;
+ }
+
+ public boolean hasInfo() {
+ for (Problem problem : this.getProblems()) {
+ if (problem.getStatus() == Problem.Status.INFO) return true;
+ }
+ return false;
+ }
+
+ public boolean isEmpty() {
+ return getProblems().isEmpty();
+ }
+
+ public int size() {
+ return getProblems().size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.Problems#iterator()
+ */
+ public Iterator<Problem> iterator() {
+ return getProblems().iterator();
+ }
+
+ protected abstract void addProblem( Problem problem );
+
+ protected abstract List<Problem> getProblems();
+}
Property changes on: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/AbstractProblems.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/Problem.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/collection/Problem.java 2008-06-25 13:48:37 UTC (rev 309)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/collection/Problem.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -24,6 +24,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.HashCode;
/**
* @author Randall Hauch
@@ -47,11 +48,13 @@
private final String resource;
private final String location;
- public Problem( Status status, int code, I18n message, Object... params ) {
- this(status, code, message, params, null, null, null);
- }
-
- public Problem( Status status, int code, I18n message, Object[] params, String resource, String location, Throwable throwable ) {
+ public Problem( Status status,
+ int code,
+ I18n message,
+ Object[] params,
+ String resource,
+ String location,
+ Throwable throwable ) {
ArgCheck.isNotNull(status, "status");
ArgCheck.isNotNull(message, "message");
this.status = status;
@@ -79,6 +82,7 @@
/**
* Get the message written in the current locale.
+ *
* @return the message
*/
public String getMessageString() {
@@ -117,4 +121,76 @@
return this.throwable;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(status, code, message, resource, location);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Problem) {
+ Problem that = (Problem)obj;
+ if (this.getStatus() != that.getStatus()) return false;
+ if (this.getCode() != that.getCode()) return false;
+ if (!this.getMessage().equals(that.getMessage())) return false;
+ if (!this.getParameters().equals(that.getParameters())) return false;
+
+ String thisResource = this.getResource();
+ String thatResource = that.getResource();
+ if (thisResource != thatResource) {
+ if (thisResource == null || !thisResource.equals(thatResource)) return false;
+ }
+
+ String thisLocation = this.getLocation();
+ String thatLocation = that.getLocation();
+ if (thisLocation != thatLocation) {
+ if (thisLocation == null || !thisLocation.equals(thatLocation)) return false;
+ }
+
+ Throwable thisThrowable = this.getThrowable();
+ Throwable thatThrowable = that.getThrowable();
+ if (thisThrowable != thatThrowable) {
+ if (thisThrowable == null || !thisThrowable.equals(thatThrowable)) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(this.getStatus()).append(": ");
+ if (this.getCode() != DEFAULT_CODE) {
+ sb.append("(").append(this.getCode()).append(") ");
+ }
+ sb.append(this.getMessageString());
+ if (this.getResource() != null) {
+ sb.append(" Resource=\"").append(this.getResource()).append("\"");
+ }
+ if (this.getLocation() != null) {
+ sb.append(" At \"").append(this.getLocation()).append("\"");
+ }
+ if (this.getThrowable() != null) {
+ sb.append(" (threw ").append(this.getThrowable().getLocalizedMessage()).append(")");
+ }
+ return sb.toString();
+ }
+
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java 2008-06-25 13:48:37 UTC (rev 309)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -21,12 +21,9 @@
*/
package org.jboss.dna.common.collection;
-import java.util.Collections;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.common.i18n.I18n;
/**
* A list of problems for some execution context. The problems will be {@link #iterator() returned} in the order in which they
@@ -36,229 +33,29 @@
* @author John Verhaeg
*/
@NotThreadSafe
-public class SimpleProblems implements Problems {
+public class SimpleProblems extends AbstractProblems {
- private static final List<Problem> EMPTY_PROBLEMS = Collections.emptyList();
-
private List<Problem> problems;
- public void addError( I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params));
- }
-
- public void addError( Throwable throwable,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, null, null, throwable));
- }
-
- public void addError( I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, resource, location));
- }
-
- public void addError( Throwable throwable,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, resource, location, throwable));
- }
-
- public void addError( int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, code, message));
- }
-
- public void addError( Throwable throwable,
- int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, code, message, null, null, throwable));
- }
-
- public void addError( int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, code, message, resource, location));
- }
-
- public void addError( Throwable throwable,
- int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.ERROR, code, message, resource, location, throwable));
- }
-
- public void addWarning( I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message));
- }
-
- public void addWarning( Throwable throwable,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, null, null, throwable));
- }
-
- public void addWarning( I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, resource, location));
- }
-
- public void addWarning( Throwable throwable,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, resource, location, throwable));
- }
-
- public void addWarning( int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, code, message));
- }
-
- public void addWarning( Throwable throwable,
- int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, code, message, null, null, throwable));
- }
-
- public void addWarning( int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, code, message, resource, location));
- }
-
- public void addWarning( Throwable throwable,
- int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.WARNING, code, message, resource, location, throwable));
- }
-
- public void addInfo( I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message));
- }
-
- public void addInfo( Throwable throwable,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, null, null, throwable));
- }
-
- public void addInfo( I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, resource, location));
- }
-
- public void addInfo( Throwable throwable,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, resource, location, throwable));
- }
-
- public void addInfo( int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, code, message));
- }
-
- public void addInfo( Throwable throwable,
- int code,
- I18n message,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, code, message, null, null, throwable));
- }
-
- public void addInfo( int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, code, message, resource, location));
- }
-
- public void addInfo( Throwable throwable,
- int code,
- I18n message,
- String resource,
- String location,
- Object... params ) {
- addProblem(new Problem(Problem.Status.INFO, code, message, resource, location, throwable));
- }
-
- public boolean hasProblems() {
- return this.problems != null && this.problems.size() > 0;
- }
-
- public boolean hasErrors() {
- if (this.problems == null) return false;
- for (Problem problem : this.problems) {
- if (problem.getStatus() == Problem.Status.ERROR) return true;
- }
- return false;
- }
-
- public boolean hasWarnings() {
- if (this.problems == null) return false;
- for (Problem problem : this.problems) {
- if (problem.getStatus() == Problem.Status.WARNING) return true;
- }
- return false;
- }
-
- public boolean hasInfo() {
- if (this.problems == null) return false;
- for (Problem problem : this.problems) {
- if (problem.getStatus() == Problem.Status.INFO) return true;
- }
- return false;
- }
-
- public boolean isEmpty() {
- return this.problems == null || this.problems.isEmpty();
- }
-
- public int size() {
- if (this.problems == null) return 0;
- return this.problems.size();
- }
-
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.common.collection.Problems#iterator()
+ * @see org.jboss.dna.common.collection.AbstractProblems#addProblem(Problem)
*/
- public Iterator<Problem> iterator() {
- return (problems == null ? EMPTY_PROBLEMS.iterator() : problems.iterator());
- }
-
+ @Override
protected void addProblem( Problem problem ) {
if (problem == null) return;
if (problems == null) problems = new LinkedList<Problem>();
problems.add(problem);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#getProblems()
+ */
+ @Override
+ protected List<Problem> getProblems() {
+ return this.problems != null ? problems : EMPTY_PROBLEMS;
+ }
}
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/ThreadSafeProblems.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/collection/ThreadSafeProblems.java (rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/collection/ThreadSafeProblems.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * A thread-safe list of problems for some execution context. The problems will be {@link #iterator() returned} in the order in
+ * which they were encountered.
+ *
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class ThreadSafeProblems extends AbstractProblems {
+
+ private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private final List<Problem> problems = new LinkedList<Problem>();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#hasErrors()
+ */
+ @Override
+ public boolean hasErrors() {
+ try {
+ lock.readLock().lock();
+ return super.hasErrors();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#hasProblems()
+ */
+ @Override
+ public boolean hasProblems() {
+ try {
+ lock.readLock().lock();
+ return super.hasProblems();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#hasInfo()
+ */
+ @Override
+ public boolean hasInfo() {
+ try {
+ lock.readLock().lock();
+ return super.hasInfo();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#hasWarnings()
+ */
+ @Override
+ public boolean hasWarnings() {
+ try {
+ lock.readLock().lock();
+ return super.hasWarnings();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#isEmpty()
+ */
+ @Override
+ public boolean isEmpty() {
+ try {
+ lock.readLock().lock();
+ return super.isEmpty();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#size()
+ */
+ @Override
+ public int size() {
+ try {
+ lock.readLock().lock();
+ return super.size();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#addProblem(Problem)
+ */
+ @Override
+ protected void addProblem( Problem problem ) {
+ try {
+ lock.writeLock().lock();
+ problems.add(problem);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblems#getProblems()
+ */
+ @Override
+ protected List<Problem> getProblems() {
+ // Return an unmodifiable copy ...
+ try {
+ lock.readLock().lock();
+ return Collections.unmodifiableList(new ArrayList<Problem>(this.problems));
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+}
Property changes on: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/ThreadSafeProblems.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/AbstractProblemsTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/collection/AbstractProblemsTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/collection/AbstractProblemsTest.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,395 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.util.Iterator;
+import org.jboss.dna.common.CommonI18n;
+import org.jboss.dna.common.collection.Problem.Status;
+import org.jboss.dna.common.i18n.I18n;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public abstract class AbstractProblemsTest {
+
+ private Problems problems;
+ private Problem error;
+ private Problem warning;
+ private Problem info;
+ private I18n message;
+ private Throwable throwable;
+ private String location;
+ private String resource;
+
+ @Before
+ public void beforeEach() throws Exception {
+ problems = createProblems();
+ message = CommonI18n.argumentMayNotBeNull;
+ error = new Problem(Status.ERROR, 1, message, new Object[] {"error msg"}, null, null, null);
+ warning = new Problem(Status.WARNING, 1, message, new Object[] {"warning msg"}, null, null, null);
+ info = new Problem(Status.INFO, 1, message, new Object[] {"info msg"}, null, null, null);
+ throwable = new IllegalArgumentException(message.text("throwable"));
+ resource = "SomeResource";
+ location = "/Meaningless/location";
+ }
+
+ protected abstract Problems createProblems();
+
+ @Test
+ public void shouldBeEmptyImmediatelyAfterInstantiation() {
+ assertThat(problems.isEmpty(), is(true));
+ assertThat(problems.size(), is(0));
+ }
+
+ @Test
+ public void shouldAddErrorByMessageAndParametersUsingDefaultCode() {
+ error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"error msg"}, null, null, null);
+ problems.addError(error.getMessage(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByCodeAndMesssageAndParameters() {
+ problems.addError(error.getCode(), error.getMessage(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByThrowableAndMessageAndParametersUsingDefaultCode() {
+ error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"error msg"}, null, null, throwable);
+ problems.addError(error.getThrowable(), error.getMessage(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByThrowableAndCodeAndMessageAndParameters() {
+ error = new Problem(Status.ERROR, 1, message, new Object[] {"error msg"}, null, null, throwable);
+ problems.addError(error.getThrowable(), error.getCode(), error.getMessage(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"error msg"}, resource, location, null);
+ problems.addError(error.getMessage(), error.getResource(), error.getLocation(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByCodeAndMesssageAndResourceAndLocationAndParameters() {
+ error = new Problem(Status.ERROR, 1, message, new Object[] {"error msg"}, resource, location, null);
+ problems.addError(error.getCode(), error.getMessage(), error.getResource(), error.getLocation(), error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByThrowableAndMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"error msg"}, resource, location,
+ throwable);
+ problems.addError(error.getThrowable(),
+ error.getMessage(),
+ error.getResource(),
+ error.getLocation(),
+ error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddErrorByThrowableAndCodeAndMessageAndResourceAndLocationAndParameters() {
+ error = new Problem(Status.ERROR, 1, message, new Object[] {"error msg"}, resource, location, throwable);
+ problems.addError(error.getThrowable(),
+ error.getCode(),
+ error.getMessage(),
+ error.getResource(),
+ error.getLocation(),
+ error.getParameters());
+ assertThat(problems.iterator().next(), is(error));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByMessageAndParametersUsingDefaultCode() {
+ warning = new Problem(Status.WARNING, Problem.DEFAULT_CODE, message, new Object[] {"warning msg"}, null, null, null);
+ problems.addWarning(warning.getMessage(), warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByCodeAndMesssageAndParameters() {
+ problems.addWarning(warning.getCode(), warning.getMessage(), warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByThrowableAndMessageAndParametersUsingDefaultCode() {
+ warning = new Problem(Status.WARNING, Problem.DEFAULT_CODE, message, new Object[] {"warning msg"}, null, null, throwable);
+ problems.addWarning(warning.getThrowable(), warning.getMessage(), warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByThrowableAndCodeAndMessageAndParameters() {
+ warning = new Problem(Status.WARNING, 1, message, new Object[] {"warning msg"}, null, null, throwable);
+ problems.addWarning(warning.getThrowable(), warning.getCode(), warning.getMessage(), warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ warning = new Problem(Status.WARNING, Problem.DEFAULT_CODE, message, new Object[] {"warning msg"}, resource, location,
+ null);
+ problems.addWarning(warning.getMessage(), warning.getResource(), warning.getLocation(), warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByCodeAndMesssageAndResourceAndLocationAndParameters() {
+ warning = new Problem(Status.WARNING, 1, message, new Object[] {"warning msg"}, resource, location, null);
+ problems.addWarning(warning.getCode(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByThrowableAndMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ warning = new Problem(Status.WARNING, Problem.DEFAULT_CODE, message, new Object[] {"warning msg"}, resource, location,
+ throwable);
+ problems.addWarning(warning.getThrowable(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddWarningByThrowableAndCodeAndMessageAndResourceAndLocationAndParameters() {
+ warning = new Problem(Status.WARNING, 1, message, new Object[] {"warning msg"}, resource, location, throwable);
+ problems.addWarning(warning.getThrowable(),
+ warning.getCode(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ assertThat(problems.iterator().next(), is(warning));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByMessageAndParametersUsingDefaultCode() {
+ info = new Problem(Status.INFO, Problem.DEFAULT_CODE, message, new Object[] {"info msg"}, null, null, null);
+ problems.addInfo(info.getMessage(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByCodeAndMesssageAndParameters() {
+ problems.addInfo(info.getCode(), info.getMessage(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByThrowableAndMessageAndParametersUsingDefaultCode() {
+ info = new Problem(Status.INFO, Problem.DEFAULT_CODE, message, new Object[] {"info msg"}, null, null, throwable);
+ problems.addInfo(info.getThrowable(), info.getMessage(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByThrowableAndCodeAndMessageAndParameters() {
+ info = new Problem(Status.INFO, 1, message, new Object[] {"info msg"}, null, null, throwable);
+ problems.addInfo(info.getThrowable(), info.getCode(), info.getMessage(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ info = new Problem(Status.INFO, Problem.DEFAULT_CODE, message, new Object[] {"info msg"}, resource, location, null);
+ problems.addInfo(info.getMessage(), info.getResource(), info.getLocation(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByCodeAndMesssageAndResourceAndLocationAndParameters() {
+ info = new Problem(Status.INFO, 1, message, new Object[] {"info msg"}, resource, location, null);
+ problems.addInfo(info.getCode(), info.getMessage(), info.getResource(), info.getLocation(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByThrowableAndMessageAndResourceAndLocationAndParametersUsingDefaultCode() {
+ info = new Problem(Status.INFO, Problem.DEFAULT_CODE, message, new Object[] {"info msg"}, resource, location, throwable);
+ problems.addInfo(info.getThrowable(), info.getMessage(), info.getResource(), info.getLocation(), info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddInfoByThrowableAndCodeAndMessageAndResourceAndLocationAndParameters() {
+ info = new Problem(Status.INFO, 1, message, new Object[] {"info msg"}, resource, location, throwable);
+ problems.addInfo(info.getThrowable(),
+ info.getCode(),
+ info.getMessage(),
+ info.getResource(),
+ info.getLocation(),
+ info.getParameters());
+ assertThat(problems.iterator().next(), is(info));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ }
+
+ @Test
+ public void shouldAddProblemsAndMaintainOrder() {
+ assertThat(problems.hasErrors(), is(false));
+ assertThat(problems.hasWarnings(), is(false));
+ assertThat(problems.hasInfo(), is(false));
+ assertThat(problems.isEmpty(), is(true));
+ assertThat(problems.size(), is(0));
+ problems.addWarning(warning.getThrowable(),
+ warning.getCode(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ assertThat(problems.hasErrors(), is(false));
+ assertThat(problems.hasWarnings(), is(true));
+ assertThat(problems.hasInfo(), is(false));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(1));
+ problems.addError(error.getThrowable(),
+ error.getCode(),
+ error.getMessage(),
+ error.getResource(),
+ error.getLocation(),
+ error.getParameters());
+ assertThat(problems.hasErrors(), is(true));
+ assertThat(problems.hasWarnings(), is(true));
+ assertThat(problems.hasInfo(), is(false));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(2));
+ problems.addInfo(info.getThrowable(),
+ info.getCode(),
+ info.getMessage(),
+ info.getResource(),
+ info.getLocation(),
+ info.getParameters());
+ assertThat(problems.hasErrors(), is(true));
+ assertThat(problems.hasWarnings(), is(true));
+ assertThat(problems.hasInfo(), is(true));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(3));
+ problems.addWarning(warning.getThrowable(),
+ warning.getCode(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ problems.addError(error.getThrowable(),
+ error.getCode(),
+ error.getMessage(),
+ error.getResource(),
+ error.getLocation(),
+ error.getParameters());
+ problems.addWarning(warning.getThrowable(),
+ warning.getCode(),
+ warning.getMessage(),
+ warning.getResource(),
+ warning.getLocation(),
+ warning.getParameters());
+ problems.addError(error.getThrowable(),
+ error.getCode(),
+ error.getMessage(),
+ error.getResource(),
+ error.getLocation(),
+ error.getParameters());
+ assertThat(problems.hasErrors(), is(true));
+ assertThat(problems.hasWarnings(), is(true));
+ assertThat(problems.hasInfo(), is(true));
+ assertThat(problems.isEmpty(), is(false));
+ assertThat(problems.size(), is(7));
+ Iterator<Problem> iter = problems.iterator();
+ assertThat(iter.next(), is(warning));
+ assertThat(iter.next(), is(error));
+ assertThat(iter.next(), is(info));
+ assertThat(iter.next(), is(warning));
+ assertThat(iter.next(), is(error));
+ assertThat(iter.next(), is(warning));
+ assertThat(iter.next(), is(error));
+ assertThat(iter.hasNext(), is(false));
+ assertThat(problems.size(), is(7));
+ assertThat(problems.hasErrors(), is(true));
+ assertThat(problems.hasWarnings(), is(true));
+ assertThat(problems.hasInfo(), is(true));
+ assertThat(problems.isEmpty(), is(false));
+ }
+
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/AbstractProblemsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ProblemTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ProblemTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ProblemTest.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.jboss.dna.common.CommonI18n;
+import org.jboss.dna.common.collection.Problem.Status;
+import org.jboss.dna.common.i18n.I18n;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ProblemTest {
+
+ private Problem error;
+ private Problem warning;
+ private Problem info;
+ private I18n message;
+ private Object[] messageParameters;
+ private Throwable throwable;
+ private String location;
+ private String resource;
+
+ @Before
+ public void beforeEach() throws Exception {
+ message = CommonI18n.argumentMayNotBeNull;
+ throwable = new IllegalArgumentException(message.text("throwable"));
+ messageParameters = new Object[] {"message"};
+ resource = "SomeResource";
+ location = "/Meaningless/location";
+ error = new Problem(Status.ERROR, 1, message, messageParameters, resource, location, throwable);
+ warning = new Problem(Status.WARNING, 1, message, messageParameters, resource, location, throwable);
+ info = new Problem(Status.INFO, 1, message, messageParameters, resource, location, throwable);
+ }
+
+ @Test
+ public void shouldHaveToString() {
+ assertThat(error.toString(), is("ERROR: (1) " + message.text("message") + " Resource=\"" + resource + "\" At \""
+ + location + "\" (threw " + throwable.getLocalizedMessage() + ")"));
+ }
+
+ @Test
+ public void shouldHaveToStringWithoutDefaultCode() {
+ error = new Problem(Status.ERROR, Problem.DEFAULT_CODE, message, new Object[] {"message"}, null, null, null);
+ assertThat(error.toString(), is("ERROR: " + message.text("message")));
+ }
+
+ @Test
+ public void shouldHaveMessageString() {
+ messageParameters = new Object[] {"error msg"};
+ error = new Problem(Status.ERROR, 1, message, messageParameters, resource, location, throwable);
+ messageParameters = new Object[] {"warning msg"};
+ warning = new Problem(Status.WARNING, 1, message, messageParameters, resource, location, throwable);
+ messageParameters = new Object[] {"info msg"};
+ info = new Problem(Status.INFO, 1, message, messageParameters, resource, location, throwable);
+ assertThat(error.getMessageString(), is(message.text("error msg")));
+ assertThat(warning.getMessageString(), is(message.text("warning msg")));
+ assertThat(info.getMessageString(), is(message.text("info msg")));
+ }
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ProblemTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/SimpleProblemsTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/collection/SimpleProblemsTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/collection/SimpleProblemsTest.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+
+/**
+ * @author Randall Hauch
+ */
+public class SimpleProblemsTest extends AbstractProblemsTest {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblemsTest#createProblems()
+ */
+ @Override
+ protected Problems createProblems() {
+ return new SimpleProblems();
+ }
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/SimpleProblemsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ThreadSafeProblemsTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ThreadSafeProblemsTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ThreadSafeProblemsTest.java 2008-06-25 21:39:59 UTC (rev 310)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.collection;
+
+/**
+ * @author Randall Hauch
+ */
+public class ThreadSafeProblemsTest extends AbstractProblemsTest {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.collection.AbstractProblemsTest#createProblems()
+ */
+ @Override
+ protected Problems createProblems() {
+ return new ThreadSafeProblems();
+ }
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/collection/ThreadSafeProblemsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r308 - trunk.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-24 14:50:28 -0400 (Tue, 24 Jun 2008)
New Revision: 308
Modified:
trunk/eclipse-preferences.epf
Log:
Removed code template for types containing @author tag, since this is always custom per user. Unfortunately, removing it doesn't prevent an import from replacing an existing types code template with the default one. So users will always have to remember to update the @author tag value from {$user} to their actual name, but at least this can be done with a global replace function.
Modified: trunk/eclipse-preferences.epf
===================================================================
--- trunk/eclipse-preferences.epf 2008-06-23 16:28:28 UTC (rev 307)
+++ trunk/eclipse-preferences.epf 2008-06-24 18:50:28 UTC (rev 308)
@@ -85,7 +85,7 @@
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.packages.cuchildren=false
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.staticondemandthreshold=99
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.code_templates_migrated=true
-/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return ${bare_field_name}\n */</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} Sets ${bare_field_name} to the specified value.\n */</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\!
="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * JBoss, Home of Professional Open Source.\n * Copyright 2008, Red Hat Middleware LLC, and individual contributors\n * as indicated by the @author tags. See the copyright.txt file in the\n * distribution for a full listing of individual contributors. \n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You sh!
ould have received a copy of the GNU Lesser General Public\n * License
along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_contex!
t" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_overridden}\n */</template><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock"></template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template a!
utoinsert\="false" context\="constructorbody_context" deleted\="false"
description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n</template><template autoinsert\="false" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="false" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return ${bare_field_name}\n */</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} Sets ${bare_field_name} to the specified value.\n */</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\!
="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * JBoss, Home of Professional Open Source.\n * Copyright 2008, Red Hat Middleware LLC, and individual contributors\n * as indicated by the @author tags. See the copyright.txt file in the\n * distribution for a full listing of individual contributors. \n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You sh!
ould have received a copy of the GNU Lesser General Public\n * License
along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_overridden}\n */</template><template !
autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock"></template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n</t!
emplate><template autoinsert\="false" context\="getterbody_context" de
leted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="false" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
/instance/org.eclipse.jdt.ui/outlinesortoption=SF,SI,SM,F,I,C,M,T,
/instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code=true
/instance/org.eclipse.jdt.ui/sp_cleanup.on_save_use_additional_actions=true
15 years, 10 months
DNA SVN: r307 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository/sequencers and 1 other directory.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-23 12:28:28 -0400 (Mon, 23 Jun 2008)
New Revision: 307
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/eclipse-preferences.epf
Log:
Removed incorrect @see tag in SequencerNodeContext.getNamespaceRegistry and changed javaDoc prefs to not produce errors/warnings for references to deprecated code
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-06-20 17:27:55 UTC (rev 306)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-06-23 16:28:28 UTC (rev 307)
@@ -161,8 +161,6 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
*/
public NamespaceRegistry getNamespaceRegistry() {
return factories.getNameFactory().getNamespaceRegistry();
Modified: trunk/eclipse-preferences.epf
===================================================================
--- trunk/eclipse-preferences.epf 2008-06-20 17:27:55 UTC (rev 306)
+++ trunk/eclipse-preferences.epf 2008-06-23 16:28:28 UTC (rev 307)
@@ -28,7 +28,7 @@
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error
-/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private
15 years, 10 months
DNA SVN: r306 - trunk/dna-common/src/main/java/org/jboss/dna/common/text.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-20 13:27:55 -0400 (Fri, 20 Jun 2008)
New Revision: 306
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/text/Inflector.java
Log:
Added some JavaDoc to the Inflector class.
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/Inflector.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/Inflector.java 2008-06-19 14:10:59 UTC (rev 305)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/Inflector.java 2008-06-20 17:27:55 UTC (rev 306)
@@ -29,7 +29,10 @@
import org.jboss.dna.common.util.ArgCheck;
/**
- * Transforms words to singular, plural, humanized (human readable), underscore, camel case, or ordinal form.
+ * Transforms words to singular, plural, humanized (human readable), underscore, camel case, or ordinal form. This is inspired by
+ * the <a href="http://api.rubyonrails.org/classes/Inflector.html">Inflector</a> class in <a
+ * href="http://www.rubyonrails.org">Ruby on Rails</a>, which is distributed under the <a
+ * href="http://wiki.rubyonrails.org/rails/pages/License">Rails license</a>.
*
* @author Randall Hauch
*/
15 years, 10 months
DNA SVN: r305 - trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-19 10:10:59 -0400 (Thu, 19 Jun 2008)
New Revision: 305
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
Log:
DNA-124: Updated test to run successfully with use of new SequencerContext
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-18 20:17:14 UTC (rev 304)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-19 14:10:59 UTC (rev 305)
@@ -25,6 +25,7 @@
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -73,6 +74,8 @@
assertThat(xml4, is(notNullValue()));
xsd = this.getClass().getClassLoader().getResource("Descriptor.1.0.xsd");
assertThat(xsd, is(notNullValue()));
+ stub(context.getFactories()).toReturn(output.getFactories());
+ stub(context.getNamespaceRegistry()).toReturn(output.getNamespaceRegistry());
}
@After
15 years, 10 months
DNA SVN: r304 - trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-18 16:17:14 -0400 (Wed, 18 Jun 2008)
New Revision: 304
Modified:
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
Log:
DNA-124: Updated test to run successfully with use of new SequencerContext
Modified: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18 19:12:50 UTC (rev 303)
+++ trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18 20:17:14 UTC (rev 304)
@@ -25,6 +25,7 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -57,14 +58,15 @@
@Before
public void beforeEach() {
MockitoAnnotations.initMocks(this);
- this.sequencer = new ImageMetadataSequencer();
- this.output = new MockSequencerOutput();
+ sequencer = new ImageMetadataSequencer();
+ output = new MockSequencerOutput();
output.getNamespaceRegistry().register("image", "http://jboss.org/dna/images/1.0");
- this.progress = new SimpleProgressMonitor("Test activity");
- this.cautionGif = this.getClass().getClassLoader().getResource("caution.gif");
- this.cautionJpg = this.getClass().getClassLoader().getResource("caution.jpg");
- this.cautionPict = this.getClass().getClassLoader().getResource("caution.pict");
- this.cautionPng = this.getClass().getClassLoader().getResource("caution.png");
+ progress = new SimpleProgressMonitor("Test activity");
+ cautionGif = this.getClass().getClassLoader().getResource("caution.gif");
+ cautionJpg = this.getClass().getClassLoader().getResource("caution.jpg");
+ cautionPict = this.getClass().getClassLoader().getResource("caution.pict");
+ cautionPng = this.getClass().getClassLoader().getResource("caution.png");
+ stub(context.getFactories()).toReturn(output.getFactories());
}
@After
15 years, 10 months
DNA SVN: r303 - trunk.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-18 15:12:50 -0400 (Wed, 18 Jun 2008)
New Revision: 303
Modified:
trunk/eclipse-preferences.epf
Log:
Removed my author tag from the code templates
Modified: trunk/eclipse-preferences.epf
===================================================================
--- trunk/eclipse-preferences.epf 2008-06-18 19:07:44 UTC (rev 302)
+++ trunk/eclipse-preferences.epf 2008-06-18 19:12:50 UTC (rev 303)
@@ -85,7 +85,7 @@
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.packages.cuchildren=false
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.staticondemandthreshold=99
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.code_templates_migrated=true
-/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return ${bare_field_name}\n */</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} Sets ${bare_field_name} to the specified value.\n */</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\!
="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * JBoss, Home of Professional Open Source.\n * Copyright 2008, Red Hat Middleware LLC, and individual contributors\n * as indicated by the @author tags. See the copyright.txt file in the\n * distribution for a full listing of individual contributors. \n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You sh!
ould have received a copy of the GNU Lesser General Public\n * License
along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author John Verhaeg\n * ${tags}\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context!
\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_overridden}\n */</template><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock"></template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_stateme!
nt}</template><template autoinsert\="false" context\="constructorbody_
context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n</template><template autoinsert\="false" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="false" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return ${bare_field_name}\n */</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} Sets ${bare_field_name} to the specified value.\n */</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\!
="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * JBoss, Home of Professional Open Source.\n * Copyright 2008, Red Hat Middleware LLC, and individual contributors\n * as indicated by the @author tags. See the copyright.txt file in the\n * distribution for a full listing of individual contributors. \n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You sh!
ould have received a copy of the GNU Lesser General Public\n * License
along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_contex!
t" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_overridden}\n */</template><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * {@inheritDoc}\n *\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock"></template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template a!
utoinsert\="false" context\="constructorbody_context" deleted\="false"
description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n</template><template autoinsert\="false" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="false" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
/instance/org.eclipse.jdt.ui/outlinesortoption=SF,SI,SM,F,I,C,M,T,
/instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code=true
/instance/org.eclipse.jdt.ui/sp_cleanup.on_save_use_additional_actions=true
15 years, 10 months
DNA SVN: r302 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml and 12 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-18 15:07:44 -0400 (Wed, 18 Jun 2008)
New Revision: 302
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java
trunk/sequencers/dna-sequencer-images/pom.xml
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
trunk/sequencers/dna-sequencer-java/pom.xml
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
Log:
DNA-124: Created SequencerContext that provides access to input node's path and properties, and replaces SequencerOutput as the provider of the namespace repository and value factories. The replaced methods in SequencerOutput have been deprecated. Also updated all sequencers affected by this change.
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.sequencers;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Node;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.repository.RepositoryI18n;
+import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.sequencers.SequencerContext;
+import org.jboss.dna.spi.sequencers.StreamSequencer;
+
+/**
+ * Contains context information that is passed to {@link StreamSequencer stream sequencers}, including information about the
+ * input node containing the data being sequenced.
+ *
+ * @author John Verhaeg
+ */
+@Immutable
+public class SequencerNodeContext implements SequencerContext {
+
+ private final ValueFactories factories;
+ private final Path path;
+ private final Set<Property> props;
+
+ SequencerNodeContext( Node input,
+ ExecutionContext context ) throws RepositoryException {
+ assert input != null;
+ assert context != null;
+ this.factories = context.getValueFactories();
+ path = factories.getPathFactory().create(input.getPath());
+ Set<Property> props = new HashSet<Property>();
+ for (PropertyIterator iter = input.getProperties(); iter.hasNext();) {
+ javax.jcr.Property jcrProp = iter.nextProperty();
+ Property prop;
+ if (jcrProp.getDefinition().isMultiple()) {
+ Value[] jcrVals = jcrProp.getValues();
+ Object[] vals = new Object[jcrVals.length];
+ int ndx = 0;
+ for (Value jcrVal : jcrVals) {
+ vals[ndx++] = convert(factories, jcrProp.getName(), jcrVal);
+ }
+ prop = context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()), vals);
+ } else {
+ Value jcrVal = jcrProp.getValue();
+ Object val = convert(factories, jcrProp.getName(), jcrVal);
+ prop = context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()), val);
+ }
+ props.add(prop);
+ }
+ this.props = Collections.unmodifiableSet(props);
+ }
+
+ private Object convert( ValueFactories factories,
+ String name,
+ Value jcrValue ) throws RepositoryException {
+ switch (jcrValue.getType()) {
+ case PropertyType.BINARY: {
+ return factories.getBinaryFactory().create(jcrValue.getStream());
+ }
+ case PropertyType.BOOLEAN: {
+ return factories.getBooleanFactory().create(jcrValue.getBoolean());
+ }
+ case PropertyType.DATE: {
+ return factories.getDateFactory().create(jcrValue.getDate());
+ }
+ case PropertyType.DOUBLE: {
+ return factories.getDoubleFactory().create(jcrValue.getDouble());
+ }
+ case PropertyType.LONG: {
+ return factories.getLongFactory().create(jcrValue.getLong());
+ }
+ case PropertyType.NAME: {
+ return factories.getNameFactory().create(jcrValue.getString());
+ }
+ case PropertyType.PATH: {
+ return factories.getPathFactory().create(jcrValue.getString());
+ }
+ case PropertyType.REFERENCE: {
+ return factories.getReferenceFactory().create(jcrValue.getString());
+ }
+ case PropertyType.STRING: {
+ return factories.getStringFactory().create(jcrValue.getString());
+ }
+ default: {
+ throw new RepositoryException(RepositoryI18n.unknownPropertyValueType.text(name, jcrValue.getType()));
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getFactories() {
+ return factories;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputPath()
+ */
+ public Path getInputPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputProperties()
+ */
+ public Set<Property> getInputProperties() {
+ return props;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputProperty(org.jboss.dna.spi.graph.Name)
+ */
+ public Property getInputProperty( Name name ) {
+ ArgCheck.isNotNull(name, "name");
+ for (Property prop : props) {
+ if (name.equals(prop.getName())) {
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return factories.getNameFactory().getNamespaceRegistry();
+ }
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -80,7 +80,7 @@
String sequencedPropertyName,
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
- ExecutionContext context,
+ ExecutionContext execContext,
ProgressMonitor progressMonitor ) throws RepositoryException, SequencerException {
// 'sequencedPropertyName' contains the name of the modified property on 'input' that resuled the call to this sequencer
// 'changes' contains all of the changes to this node that occurred in the transaction.
@@ -100,13 +100,14 @@
progressMonitor.worked(10);
// Get the binary property with the image content, and build the image metadata from the image ...
- SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories());
+ SequencerOutputMap output = new SequencerOutputMap(execContext.getValueFactories());
InputStream stream = null;
Throwable firstError = null;
ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
try {
stream = imageDataProperty.getStream();
- this.streamSequencer.sequence(stream, output, sequencingMonitor);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ this.streamSequencer.sequence(stream, output, sequencerContext, sequencingMonitor);
} catch (Throwable t) {
// Record the error ...
firstError = t;
@@ -143,13 +144,13 @@
final String nodePath = outputPath.getNodePath();
// Create a session to the repository where the data should be written ...
- session = context.getSessionFactory().createSession(repositoryWorkspaceName);
+ session = execContext.getSessionFactory().createSession(repositoryWorkspaceName);
// Find or create the output node in this session ...
- Node outputNode = context.getTools().findOrCreateNode(session, nodePath);
+ Node outputNode = execContext.getTools().findOrCreateNode(session, nodePath);
// Now save the image metadata to the output node ...
- if (saveOutput(outputNode, output, context)) {
+ if (saveOutput(outputNode, output, execContext)) {
session.save();
}
} finally {
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -35,6 +35,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.xml.sax.Attributes;
@@ -73,21 +74,19 @@
private static final String LEXICAL_HANDLER_FEATURE = "http://xml.org/sax/properties/lexical-handler";
/**
- * <p>
* {@inheritDoc}
- * </p>
*
- * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream,
- * org.jboss.dna.spi.sequencers.SequencerOutput, org.jboss.dna.common.monitor.ProgressMonitor)
+ * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext, ProgressMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor monitor ) {
monitor.beginTask(100.0, RepositoryI18n.sequencingXmlDocument);
XMLReader reader;
try {
reader = XMLReaderFactory.createXMLReader();
- Handler handler = new Handler(output, monitor);
+ Handler handler = new Handler(output, context, monitor);
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
// Ensure handler acting as entity resolver 2
@@ -113,16 +112,18 @@
}
}
- private class Handler extends DefaultHandler2 {
+ private final class Handler extends DefaultHandler2 {
- private ProgressMonitor monitor;
- private SequencerOutput output;
+ private final SequencerOutput output;
+ private final SequencerContext context;
+ private final ProgressMonitor monitor;
+
private double progress;
private Path path; // The DNA path of the node representing the current XML element
// Cached instances of the name factory and commonly referenced names
- private NameFactory nameFactory;
+ private final NameFactory nameFactory;
private Name commentContentName;
private Name commentName;
private Name elementContentName;
@@ -133,11 +134,11 @@
private Map<Name, List<IndexedName>> nameToIndexedNamesMap = new HashMap<Name, List<IndexedName>>();
// The stack of recursive maps being processed, with the head entry being the map for the current path
- private LinkedList<Map<Name, List<IndexedName>>> nameToIndexedNamesMapStack = new LinkedList<Map<Name, List<IndexedName>>>();
+ private final LinkedList<Map<Name, List<IndexedName>>> nameToIndexedNamesMapStack = new LinkedList<Map<Name, List<IndexedName>>>();
// The stack of XML namespace in scope, with the head entry being namespace of the closest ancestor element declaring a
// namespace.
- private LinkedList<String> nsStack = new LinkedList<String>();
+ private final LinkedList<String> nsStack = new LinkedList<String>();
// Builder used to concatenate concurrent lines of CDATA into a single value.
private StringBuilder cDataBuilder;
@@ -149,13 +150,18 @@
private String entity;
Handler( SequencerOutput output,
+ SequencerContext context,
ProgressMonitor monitor ) {
+ assert output != null;
+ assert monitor != null;
+ assert context != null;
this.output = output;
+ this.context = context;
this.monitor = monitor;
// Initialize path to a an empty path relative to the SequencerOutput's target path.
- path = output.getFactories().getPathFactory().createRelativePath();
+ path = context.getFactories().getPathFactory().createRelativePath();
// Cache name factory since it is frequently used
- nameFactory = output.getFactories().getNameFactory();
+ nameFactory = context.getFactories().getNameFactory();
}
/**
@@ -574,7 +580,7 @@
indexedNames.add(indexedName);
// Add element name and the appropriate index to the path.
// Per the JCR spec, the index must be relative to same-name sibling nodes
- path = output.getFactories().getPathFactory().create(path, name, indexedNames.size());
+ path = context.getFactories().getPathFactory().create(path, name, indexedNames.size());
// Add the indexed name map to the stack and set the current map to the new element's map
nameToIndexedNamesMapStack.addFirst(nameToIndexedNamesMap);
nameToIndexedNamesMap = indexedName.nameToIndexedNamesMap;
@@ -641,7 +647,7 @@
String uri ) throws SAXException {
stopIfCancelled();
// Register any unregistered namespaces
- NamespaceRegistry registry = output.getNamespaceRegistry();
+ NamespaceRegistry registry = context.getNamespaceRegistry();
if (!registry.isRegisteredNamespaceUri(uri)) {
registry.register(prefix, uri);
}
Added: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java (rev 0)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.sequencers;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.util.Iterator;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
+import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.repository.util.JcrNamespaceRegistry;
+import org.jboss.dna.repository.util.JcrTools;
+import org.jboss.dna.repository.util.SessionFactory;
+import org.jboss.dna.repository.util.SimpleExecutionContext;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.sequencers.SequencerContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author John Verhaeg
+ */
+public class SequencerNodeContextTest extends AbstractJcrRepositoryTest {
+
+ private ExecutionContext execContext;
+ private Session session;
+ private JcrTools tools;
+
+ @Before
+ public void before() throws Exception {
+ final SessionFactory sessionFactory = new SessionFactory() {
+
+ public Session createSession( String name ) throws RepositoryException {
+ try {
+ return getRepository().login(getTestCredentials());
+ } catch (IOException error) {
+ throw new RepositoryException(error);
+ }
+ }
+ };
+ NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory, "doesn't matter");
+ execContext = new SimpleExecutionContext(sessionFactory, registry, null, null);
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+ tools = new JcrTools();
+ }
+
+ @After
+ public void after() {
+ if (session != null) {
+ try {
+ session.logout();
+ } finally {
+ session = null;
+ }
+ }
+ }
+
+ private void verifyProperty( SequencerContext context,
+ String name,
+ Object... values ) {
+ Property prop = context.getInputProperty(execContext.getValueFactories().getNameFactory().create(name));
+ assertThat(prop, notNullValue());
+ assertThat(prop.getName(), is(execContext.getValueFactories().getNameFactory().create(name)));
+ assertThat(prop.isEmpty(), is(false));
+ assertThat(prop.size(), is(values.length));
+ assertThat(prop.isMultiple(), is(values.length > 1));
+ // TODO: Uncomment after DNA-163 has been addressed
+ // assertThat(prop.isSingle(), is(values.length == 1));
+ Iterator<?> iter = prop.getValues();
+ for (Object val : values) {
+ assertThat(iter.hasNext(), is(true));
+ assertThat(iter.next(), is(val));
+ }
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullInputNode() throws Exception {
+ new SequencerNodeContext(null, execContext);
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullValueFactories() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a");
+ new SequencerNodeContext(input, null);
+ }
+
+ @Test
+ public void shouldProvideNamespaceRegistry() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ assertThat(sequencerContext.getNamespaceRegistry(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvideValueFactories() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ assertThat(sequencerContext.getFactories(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvidePathToInput() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ assertThat(sequencerContext.getInputPath(), is(execContext.getValueFactories().getPathFactory().create("/a/b/c")));
+ }
+
+ @Test
+ public void shouldNeverReturnNullInputProperties() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldProvideInputProperties() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ input.setProperty("x", true);
+ input.setProperty("y", new String[] {"asdf", "xyzzy"});
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input, execContext);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ assertThat(sequencerContext.getInputProperties().size(), is(3));
+ verifyProperty(sequencerContext,
+ NameFactory.JCR_PRIMARY_TYPE,
+ execContext.getValueFactories().getNameFactory().create("{http://www.jcp.org/jcr/nt/1.0}unstructured"));
+ verifyProperty(sequencerContext, "x", true);
+ verifyProperty(sequencerContext, "y", "asdf", "xyzzy");
+ }
+}
Property changes on: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -35,6 +35,7 @@
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.observation.Event;
+import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.RecordingProgressMonitor;
@@ -47,6 +48,7 @@
import org.jboss.dna.repository.util.SimpleExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.junit.After;
@@ -93,6 +95,7 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
Path nodePath = entry.getPath();
@@ -125,6 +128,37 @@
}
}
+ protected void testSequencer( final StreamSequencer sequencer ) throws Exception {
+ StreamSequencer streamSequencer = new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ try {
+ sequencer.sequence(stream, output, context, progressMonitor);
+ } catch (AssertionError err) {
+ progressMonitor.getProblems().addError(err, null);
+ }
+ }
+ };
+ StreamSequencerAdapter adapter = new StreamSequencerAdapter(streamSequencer);
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+ Node inputNode = tools.findOrCreateNode(session, "/a/b/c");
+ Node outputNode = tools.findOrCreateNode(session, "/d/e");
+ inputNode.setProperty("sequencedProperty", new ByteArrayInputStream(sampleData.getBytes()));
+ NodeChange nodeChange = new NodeChange(repositoryWorkspaceName, inputNode.getPath(), Event.PROPERTY_CHANGED,
+ Collections.singleton("sequencedProperty"), null);
+ Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>();
+ outputPaths.add(new RepositoryNodePath(repositoryWorkspaceName, outputNode.getPath()));
+ sequencerOutput.setProperty("alpha/beta", "isSomething", true);
+ adapter.execute(inputNode, "sequencedProperty", nodeChange, outputPaths, context, progressMonitor);
+ for (Problem problem : progressMonitor.getProblems()) {
+ throw (AssertionError)problem.getThrowable();
+ }
+ }
+
@Test
public void shouldNotHaveSequencerUponInstantiation() {
assertThat(sequencer.getConfiguration(), is(nullValue()));
@@ -338,4 +372,56 @@
public void shouldSequencerOutputProvideAccessToNamespaceRegistry() {
assertThat(sequencerOutput.getNamespaceRegistry(), notNullValue());
}
+
+ @Test
+ public void shouldPassNonNullInputStreamToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(stream, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullSequencerOutputToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(output, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullSequencerContextToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(context, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullProgressMonitorToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(progressMonitor, notNullValue());
+ }
+ });
+ }
}
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -32,11 +32,13 @@
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author John Verhaeg
@@ -52,20 +54,14 @@
private URL xml3;
private URL xml4;
private URL xsd;
+ @Mock
+ private SequencerContext context;
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
sequencer = new XmlSequencer();
- output = new MockSequencerOutput() {
-
- @Override
- public void setProperty( Path nodePath,
- Name propertyName,
- Object... values ) {
- super.setProperty(nodePath, propertyName, values);
- // System.out.println(nodePath + "." + propertyName + " = " + Arrays.asList(values));
- }
- };
+ output = new MockSequencerOutput();
monitor = new SimpleProgressMonitor("Test activity");
xml1 = this.getClass().getClassLoader().getResource("jackrabbitInMemoryTestRepositoryConfig.xml");
assertThat(xml1, is(notNullValue()));
@@ -193,7 +189,7 @@
private void verifyDocument( URL url ) throws IOException {
stream = url.openStream();
assertThat(stream, is(notNullValue()));
- sequencer.sequence(stream, output, monitor);
+ sequencer.sequence(stream, output, context, monitor);
verifyName("", NameFactory.JCR_PRIMARY_TYPE, XmlSequencer.DOCUMENT);
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.sequencers;
+
+import java.util.Set;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author John Verhaeg
+ */
+public interface SequencerContext {
+
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property values.
+ *
+ * @return the collection of factories; never <code>null</code>.
+ */
+ ValueFactories getFactories();
+
+ /**
+ * Return the path of the input node containing the content being sequenced.
+ *
+ * @return input node's path.
+ */
+ Path getInputPath();
+
+ /**
+ * Return the set of properties from the input node containing the content being sequenced.
+ *
+ * @return the input node's properties; never <code>null</code>.
+ */
+ Set<Property> getInputProperties();
+
+ /**
+ * Return the property with the supplied name from the input node containing the content being sequenced.
+ *
+ * @param name
+ * @return the input node property, or <code>null</code> if none exists.
+ */
+ Property getInputProperty( Name name );
+
+ /**
+ * Convenience method to get the namespace registry used by the {@link ValueFactories#getNameFactory() name value factory}.
+ *
+ * @return the namespace registry; never <code>null</code>.
+ */
+ NamespaceRegistry getNamespaceRegistry();
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -28,74 +28,79 @@
/**
* Interface for sequencers to use to generate their output.
- *
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface SequencerOutput {
- /**
- * Get the factories that can be used to create {@link Path paths} and other property values.
- *
- * @return the collection of factories; never null
- */
- ValueFactories getFactories();
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property values.
+ *
+ * @return the collection of factories; never null
+ * @deprecated Replaced by {@link SequencerContext#getFactories()}.
+ */
+ @Deprecated
+ ValueFactories getFactories();
- /**
- * Convenience method to get the namespace registry used by the {@link ValueFactories#getNameFactory() name value factory}.
- *
- * @return the namespace registry; never <code>null</code>
- */
- NamespaceRegistry getNamespaceRegistry();
+ /**
+ * Convenience method to get the namespace registry used by the {@link ValueFactories#getNameFactory() name value factory}.
+ *
+ * @return the namespace registry; never <code>null</code>
+ * @deprecated Replaced by {@link SequencerContext#getNamespaceRegistry()}.
+ */
+ @Deprecated
+ NamespaceRegistry getNamespaceRegistry();
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
- * to create new values or convert values from one property type to another. (Note that each of the factories have methods
- * that create values from all of the property types.)
- * </p>
- * <p>
- * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
- * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is to be removed
- */
- void setProperty( String nodePath,
- String propertyName,
- Object... values );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( String nodePath,
+ String propertyName,
+ Object... values );
- /**
- * Set the supplied reference on the supplied node.
- * <p>
- * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
- * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
- * may be empty if any existing property is to be removed
- */
- void setReference( String nodePath,
- String propertyName,
- String... paths );
+ /**
+ * Set the supplied reference on the supplied node.
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
+ * may be empty if any existing property is to be removed
+ */
+ void setReference( String nodePath,
+ String propertyName,
+ String... paths );
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
- * to create new values or convert values from one property type to another. (Note that each of the factories have methods
- * that create values from all of the property types.)
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is to be removed
- */
- void setProperty( Path nodePath,
- Name propertyName,
- Object... values );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -30,6 +30,7 @@
* <p>
* Implementations must provide a no-argument constructor.
* </p>
+ *
* @author Randall Hauch
*/
public interface StreamSequencer {
@@ -58,11 +59,15 @@
* <p>
* Finally, the implementation should call {@link ProgressMonitor#done()} when the operation has finished.
* </p>
- * @param stream the stream with the data to be sequenced; never null
- * @param output the output from the sequencing operation; never null
+ *
+ * @param stream the stream with the data to be sequenced; never <code>null</code>
+ * @param output the output from the sequencing operation; never <code>null</code>
+ * @param context the context for the sequencing operation; never <code>null</code>
* @param progressMonitor the progress monitor that should be kept updated with the sequencer's progress and that should be
- * frequently consulted as to whether this operation has been {@link ProgressMonitor#isCancelled() cancelled}.
+ * frequently consulted as to whether this operation has been {@link ProgressMonitor#isCancelled() cancelled}.
*/
- void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor );
-
+ void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor );
}
Modified: trunk/sequencers/dna-sequencer-images/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-images/pom.xml 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-images/pom.xml 2008-06-18 19:07:44 UTC (rev 302)
@@ -57,6 +57,10 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
-->
Modified: trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -26,6 +26,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -62,6 +63,7 @@
* vendors to store custom metadata. This structure could be mapped with each directory (e.g. "EXIF" or "Nikon Makernote" or
* "IPTC") as the name of a child node, with the EXIF tags values stored as either properties or child nodes.
* </p>
+ *
* @author Randall Hauch
*/
public class ImageMetadataSequencer implements StreamSequencer {
@@ -84,8 +86,13 @@
/**
* {@inheritDoc}
+ *
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext, ProgressMonitor)
*/
- public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor ) {
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
ImageMetadata metadata = new ImageMetadata();
@@ -102,8 +109,8 @@
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
- NameFactory nameFactory = output.getFactories().getNameFactory();
- PathFactory pathFactory = output.getFactories().getPathFactory();
+ NameFactory nameFactory = context.getFactories().getNameFactory();
+ PathFactory pathFactory = context.getFactories().getPathFactory();
Path metadataNode = pathFactory.create(METADATA_NODE);
// Place the image metadata into the output map ...
Modified: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -31,9 +31,12 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
@@ -48,9 +51,12 @@
private URL cautionJpg;
private URL cautionPict;
private URL cautionPng;
+ @Mock
+ private SequencerContext context;
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
this.sequencer = new ImageMetadataSequencer();
this.output = new MockSequencerOutput();
output.getNamespaceRegistry().register("image", "http://jboss.org/dna/images/1.0");
@@ -78,7 +84,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata", "jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/jpeg"}));
assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"JPEG"}));
@@ -101,7 +107,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata", "jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/png"}));
assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"PNG"}));
@@ -122,7 +128,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/gif"}));
assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"GIF"}));
assertThat(output.getPropertyValues("image:metadata", "image:width"), is(new Object[] {48}));
@@ -142,7 +148,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.hasProperties(), is(false));
}
Modified: trunk/sequencers/dna-sequencer-java/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-java/pom.xml 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-java/pom.xml 2008-06-18 19:07:44 UTC (rev 302)
@@ -63,6 +63,10 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
-->
Modified: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -27,6 +27,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -48,29 +49,32 @@
*/
public class JavaMetadataSequencer implements StreamSequencer {
-
public static final String JAVA_COMPILATION_UNIT_NODE = "java:compilationUnit";
public static final String JAVA_COMPILATION_UNIT_PRIMARY_TYPE = "jcr:primaryType";
public static final String JAVA_PACKAGE_CHILD_NODE = "java:package";
- public static final String JAVA_PACKAGE_DECLARATION_CHILD_NODE ="java:packageDeclaration";
- public static final String JAVA_PACKAGE_NAME ="java:packageName";
- public static final String JAVA_ANNOTATION_CHILD_NODE ="java:annotation";
-
- private static final String SLASH ="/";
+ public static final String JAVA_PACKAGE_DECLARATION_CHILD_NODE = "java:packageDeclaration";
+ public static final String JAVA_PACKAGE_NAME = "java:packageName";
+ public static final String JAVA_ANNOTATION_CHILD_NODE = "java:annotation";
-
- /* (non-Javadoc)
- * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream, org.jboss.dna.spi.sequencers.SequencerOutput, org.jboss.dna.common.monitor.ProgressMonitor)
+ private static final String SLASH = "/";
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream,
+ * org.jboss.dna.spi.sequencers.SequencerOutput, org.jboss.dna.spi.sequencers.SequencerContext,
+ * org.jboss.dna.common.monitor.ProgressMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
-
+
JavaMetadata javaMetadata = null;
- NameFactory nameFactory = output.getFactories().getNameFactory();
- PathFactory pathFactory = output.getFactories().getPathFactory();
-
+ NameFactory nameFactory = context.getFactories().getNameFactory();
+ PathFactory pathFactory = context.getFactories().getPathFactory();
+
try {
javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream), null, progressMonitor.createSubtask(10));
if (progressMonitor.isCancelled()) return;
@@ -78,12 +82,18 @@
e.printStackTrace();
return;
}
- if(javaMetadata != null) {
+ if (javaMetadata != null) {
Path javaCompilationUnitNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE);
- output.setProperty(javaCompilationUnitNode, nameFactory.create(JAVA_COMPILATION_UNIT_PRIMARY_TYPE), "java:compilationUnit");
- Path javaPackageDeclarationChildNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH + JAVA_PACKAGE_CHILD_NODE + SLASH + JAVA_PACKAGE_DECLARATION_CHILD_NODE);
- output.setProperty(javaPackageDeclarationChildNode, nameFactory.create(JAVA_PACKAGE_NAME), javaMetadata.getPackageMetadata().getName());
-
+ output.setProperty(javaCompilationUnitNode,
+ nameFactory.create(JAVA_COMPILATION_UNIT_PRIMARY_TYPE),
+ "java:compilationUnit");
+ Path javaPackageDeclarationChildNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH
+ + JAVA_PACKAGE_CHILD_NODE + SLASH
+ + JAVA_PACKAGE_DECLARATION_CHILD_NODE);
+ output.setProperty(javaPackageDeclarationChildNode,
+ nameFactory.create(JAVA_PACKAGE_NAME),
+ javaMetadata.getPackageMetadata().getName());
+
}
progressMonitor.done();
}
Modified: trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -74,7 +74,7 @@
}
@After
- public void afterEach() throws Exception {
+ public void afterEach() {
try {
if (session != null) session.logout();
} finally {
@@ -98,7 +98,7 @@
}
@Test
- public void testMap() throws Exception {
+ public void testMap() {
Map<String, String> errors = new HashMap<String, String>();
errors.put("login", "field.isNull");
if (!errors.containsKey("login")) errors.put("login", "field.regexp");
Modified: trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -24,6 +24,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -32,9 +33,12 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Serge Pagop
@@ -45,14 +49,18 @@
private MockSequencerOutput output;
private ProgressMonitor progress;
private File source;
+ @Mock
+ private SequencerContext context;
@Before
- public void beforeEach() throws Exception {
- this.sequencer = new JavaMetadataSequencer();
- this.output = new MockSequencerOutput();
+ public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
+ sequencer = new JavaMetadataSequencer();
+ output = new MockSequencerOutput();
output.getNamespaceRegistry().register("java", "http://jboss.org/dna/java/1.0");
this.progress = new SimpleProgressMonitor("Test java monitor activity");
source = new File("src/test/resources/org/acme/MySource.java");
+ stub(context.getFactories()).toReturn(output.getFactories());
}
@After
@@ -74,7 +82,7 @@
public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
content = getJavaSrc(source);
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("java:compilationUnit", "jcr:primaryType"), is(new Object[] {"java:compilationUnit"}));
assertThat(output.getPropertyValues("java:compilationUnit/java:package/java:packageDeclaration", "java:packageName"),
is(new Object[] {"org.acme"}));
Modified: trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -23,6 +23,7 @@
import java.io.InputStream;
import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -43,6 +44,7 @@
* </li>
* </ul>
* </p>
+ *
* @author Stefano Maestri
* @author Randall Hauch
*/
@@ -58,8 +60,13 @@
/**
* {@inheritDoc}
+ *
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext, ProgressMonitor)
*/
- public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor ) {
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
Mp3Metadata metadata = Mp3Metadata.instance(stream);
if (metadata != null) {
Modified: trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-06-18 19:07:44 UTC (rev 302)
@@ -31,6 +31,7 @@
import org.jboss.dna.sequencer.msoffice.powerpoint.PowerPointMetadataReader;
import org.jboss.dna.sequencer.msoffice.powerpoint.SlideMetadata;
import org.jboss.dna.sequencer.msoffice.word.WordMetadataReader;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -114,6 +115,7 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, MSOfficeMetadataI18n.sequencerTaskName);
15 years, 10 months
DNA SVN: r301 - trunk/dna-common/src/main/java/org/jboss/dna/common/collection.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-18 15:01:04 -0400 (Wed, 18 Jun 2008)
New Revision: 301
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java
Log:
DNA-164: Changed iterator method to return iterator for Collections.emptyList if no problems exist.
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java 2008-06-18 18:53:54 UTC (rev 300)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/collection/SimpleProblems.java 2008-06-18 19:01:04 UTC (rev 301)
@@ -21,6 +21,7 @@
*/
package org.jboss.dna.common.collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -37,6 +38,8 @@
@NotThreadSafe
public class SimpleProblems implements Problems {
+ private static final List<Problem> EMPTY_PROBLEMS = Collections.emptyList();
+
private List<Problem> problems;
public void addError( I18n message,
@@ -245,14 +248,12 @@
}
/**
- * <p>
* {@inheritDoc}
- * </p>
*
* @see org.jboss.dna.common.collection.Problems#iterator()
*/
public Iterator<Problem> iterator() {
- return problems.iterator();
+ return (problems == null ? EMPTY_PROBLEMS.iterator() : problems.iterator());
}
protected void addProblem( Problem problem ) {
15 years, 10 months