DNA SVN: r289 - in trunk: sequencers and 27 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-16 15:06:55 -0400 (Mon, 16 Jun 2008)
New Revision: 289
Added:
trunk/sequencers/dna-sequencer-java/
trunk/sequencers/dna-sequencer-java/.classpath
trunk/sequencers/dna-sequencer-java/.project
trunk/sequencers/dna-sequencer-java/pom.xml
trunk/sequencers/dna-sequencer-java/src/
trunk/sequencers/dna-sequencer-java/src/main/
trunk/sequencers/dna-sequencer-java/src/main/java/
trunk/sequencers/dna-sequencer-java/src/main/java/org/
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadata.java
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataI18n.java
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/JavaMetadataUtil.java
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/PackageMetadata.java
trunk/sequencers/dna-sequencer-java/src/main/resources/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/JavaMetadataI18n.properties
trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
trunk/sequencers/dna-sequencer-java/src/test/
trunk/sequencers/dna-sequencer-java/src/test/java/
trunk/sequencers/dna-sequencer-java/src/test/java/org/
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/
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/
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataI18nTest.java
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/JavaMetadataTest.java
trunk/sequencers/dna-sequencer-java/src/test/resources/
trunk/sequencers/dna-sequencer-java/src/test/resources/jackrabbitInMemoryTestRepositoryConfig.xml
trunk/sequencers/dna-sequencer-java/src/test/resources/java-source-artifact.cnd
trunk/sequencers/dna-sequencer-java/src/test/resources/org/
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/MySource.java
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyClassAnnotation.java
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyPackageAnnotation.java
trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/package-info.java
Modified:
trunk/pom.xml
Log:
Added the Java Sequencer project in its current form, which was contributed by Serge Pagop.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-06-13 18:25:41 UTC (rev 288)
+++ trunk/pom.xml 2008-06-16 19:06:55 UTC (rev 289)
@@ -64,6 +64,7 @@
<module>sequencers/dna-sequencer-mp3</module>
<!--module>sequencers/dna-sequencer-esbMessage</module-->
<module>sequencers/dna-sequencer-cnd</module>
+ <module>sequencers/dna-sequencer-java</module>
<module>connectors/dna-connector-jbosscache</module>
<module>dna-integration-tests</module>
</modules>
Property changes on: trunk/sequencers/dna-sequencer-java
___________________________________________________________________
Name: svn:ignore
+ target
Added: trunk/sequencers/dna-sequencer-java/.classpath
===================================================================
--- trunk/sequencers/dna-sequencer-java/.classpath (rev 0)
+++ trunk/sequencers/dna-sequencer-java/.classpath 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-java/.project
===================================================================
--- trunk/sequencers/dna-sequencer-java/.project (rev 0)
+++ trunk/sequencers/dna-sequencer-java/.project 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-sequencer-java</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: trunk/sequencers/dna-sequencer-java/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-java/pom.xml (rev 0)
+++ trunk/sequencers/dna-sequencer-java/pom.xml 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <!-- The groupId and version values are inherited from parent -->
+ <artifactId>dna-sequencer-java</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss DNA Java Sequencer</name>
+ <description> JBoss DNA Sequencer that processes java sources </description>
+ <url>http://labs.jboss.org/dna</url>
+ <properties>
+ <dna-version>0.2-SNAPSHOT</dna-version>
+ </properties>
+ <!--
+ Define the dependencies. Note that all version and scopes default to those
+ defined in the dependencyManagement section of the parent pom.
+ -->
+ <dependencies>
+ <!--
+ Common
+ -->
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-integration-tests</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ Testing (note the scope)
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ <!--
+ Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
+ -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <!--
+ Java Concurrency in Practice annotations
+ -->
+ <dependency>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>core</artifactId>
+ <version>3.2.3.v_686_R32x</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>runtime</artifactId>
+ <version>3.3.100-v20070530</version>
+ <!-- Exclude this problem library -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>app</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>resources</artifactId>
+ <version>3.3.0-v20070604</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <!--
+ Apache Jackrabbit (JCR Implementation)
+ -->
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ </dependency>
+ </dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,46 @@
+/*
+ * 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.sequencer.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+
+/**
+ * @author Serge Pagop
+ */
+public abstract class AbstractJavaMetadata {
+
+ /**
+ * Create a <code>PackageMetadata</code> of the a compilation unit.
+ *
+ * @param unit - the compilation unit.
+ * @return the package meta data of a compilation unit.
+ */
+ @SuppressWarnings( "unchecked" )
+ protected PackageMetadata createPackageMetadata( CompilationUnit unit ) {
+ PackageMetadata packageMetadata = new PackageMetadata();
+ packageMetadata.setJavadoc(unit.getPackage().getJavadoc());
+ packageMetadata.setAnnotations(unit.getPackage().annotations());
+ packageMetadata.setName(unit.getPackage().getName().getFullyQualifiedName());
+ return packageMetadata;
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,58 @@
+/*
+ * 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.sequencer.java;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+
+/**
+ * The Parser, tha process the a compilation unit.
+ *
+ * @author Serge Pagop
+ *
+ */
+public class CompilationUnitParser {
+
+ /**
+ * Parses and process the java source code as a compilation unit and the result it abstract syntax tree (AST) representation
+ * and this action uses the third edition of java Language Specification, that gets the possibility to support J2SE 5 during
+ * the parsing.
+ *
+ * @param source - the java source to be parsed (i.e. the char[] contains Java source).
+ * @param resolveBindings - for resolving bindings to get more informations from the unit.
+ * @return Abstract syntax tree representation.
+ */
+ public static ASTNode runJLS3Conversion( char[] source,
+ boolean resolveBindings ) {
+ // Create parser
+ ASTParser parser;
+ parser = ASTParser.newParser(AST.JLS3);
+ parser.setSource(source);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setResolveBindings(resolveBindings);
+ // Parse compilation unit
+ ASTNode result = parser.createAST(null);
+ return result;
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadata.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadata.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadata.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,77 @@
+/*
+ * 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.sequencer.java;
+
+import java.io.InputStream;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+
+/**
+ * @author Serge Pagop
+ */
+public class JavaMetadata extends AbstractJavaMetadata {
+ private PackageMetadata packageMetadata;
+
+ private JavaMetadata() {
+ }
+
+ /**
+ * Creates a new instance of <code>JavaMetadata</code>, that will be used to get informations of a compilation unit.
+ *
+ * @param inputStream - the <code>InputStream</code> in our case a <code>FileInputStream</code> of the java file.
+ * @param length - the length of the java file.
+ * @param encoding - the encoding that can be used.
+ * @param progressMonitor - The basic <code>ProgressMonitor</code> that facilitates the updating and monitoring of progress
+ * towards the completion of an activity.
+ * @return the new instace of <code>JavaMetadata</code>
+ * @see java.io.File#length()
+ */
+ public static JavaMetadata instance( InputStream inputStream,
+ long length,
+ String encoding,
+ ProgressMonitor progressMonitor ) {
+
+ JavaMetadata javaMetadata = new JavaMetadata();
+ char[] source = null;
+ try {
+ source = JavaMetadataUtil.getJavaSourceFromTheInputStream(inputStream, length, encoding);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ ASTNode rootNode = CompilationUnitParser.runJLS3Conversion(source, true);
+ javaMetadata.packageMetadata = javaMetadata.createPackageMetadata((CompilationUnit)rootNode);
+ return javaMetadata;
+ }
+
+ /**
+ * Gets the PackageMetadata.
+ *
+ * @return the packageMetadata
+ */
+ public final PackageMetadata getPackageMetadata() {
+ return packageMetadata;
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataI18n.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataI18n.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataI18n.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,54 @@
+/*
+ * 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.sequencer.java;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Serge Pagop
+ */
+public class JavaMetadataI18n {
+ public static I18n sequencerTaskName;
+
+ static {
+ try {
+ I18n.initialize(JavaMetadataI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(JavaMetadataI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(JavaMetadataI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(JavaMetadataI18n.class, locale);
+ }
+
+}
Added: 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 (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,90 @@
+/*
+ * 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.sequencer.java;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+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.SequencerOutput;
+import org.jboss.dna.spi.sequencers.StreamSequencer;
+
+/**
+ * A sequencer that processes a compilation unit, extracts the meta data for the compilation unit, and then writes these
+ * informations to the repository.
+ * <p>
+ * The structural representation of the informations from the compilation unit looks like this:
+ * <ul>
+ * <li><strong>java:compilationUnit</strong> node of type <code>java:compilationUnit</code>
+ * <ul>
+ * <li><strong>java:package</strong> - optional child node that represents the package declaration of the compilation unit</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * </p>
+ *
+ * @author Serge Pagop
+ */
+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 ="/";
+
+
+ /* (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)
+ */
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ ProgressMonitor progressMonitor ) {
+ progressMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
+
+ JavaMetadata javaMetadata = null;
+ NameFactory nameFactory = output.getFactories().getNameFactory();
+ PathFactory pathFactory = output.getFactories().getPathFactory();
+
+ try {
+ javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream), null, progressMonitor.createSubtask(10));
+ if (progressMonitor.isCancelled()) return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ 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());
+
+ }
+ progressMonitor.done();
+ }
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,58 @@
+/*
+ * 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.sequencer.java;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.eclipse.jdt.internal.compiler.util.Util;
+
+/**
+ * @author Serge Pagop
+ */
+public class JavaMetadataUtil {
+ /**
+ * Get the length of the inputstream.
+ *
+ * @param stream - the <code>InputStream</code>
+ * @return the length of the stream.
+ * @throws IOException - exceptional situation during calculating the length.
+ */
+ public static long length( InputStream stream ) throws IOException {
+ return stream.available();
+ }
+
+ /**
+ * Gets Java source from the <code>InputStream</code>.
+ *
+ * @param inputStream - the <code>FileInputStream</code>.
+ * @param length - the length of the java file.
+ * @param encoding - the encoding of the sourece, if there is one.
+ * @return the array character of the java source.
+ * @throws IOException - exceptional error can be thrown during the reading of the file.
+ */
+ public static char[] getJavaSourceFromTheInputStream( InputStream inputStream,
+ long length,
+ String encoding ) throws IOException {
+ char[] source = Util.getInputStreamAsCharArray(inputStream, (int)length, encoding);
+ return source;
+ }
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/PackageMetadata.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/PackageMetadata.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/PackageMetadata.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,64 @@
+/*
+ * 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.sequencer.java;
+
+import java.util.List;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.Javadoc;
+
+/**
+ * Package meta data.
+ *
+ * @author Serge Pagop.
+ */
+public class PackageMetadata {
+ private Javadoc javadoc;
+ private List<Annotation> annotations;
+ private String name;
+
+ public void setName( String name ) {
+ this.name = name;
+
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setAnnotations( List<Annotation> annotations ) {
+ this.annotations = annotations;
+ }
+
+ public List<Annotation> getAnnotations() {
+ return this.annotations;
+ }
+
+ public void setJavadoc( Javadoc javadoc ) {
+ this.javadoc = javadoc;
+
+ }
+
+ public Javadoc getJavadoc() {
+ return this.javadoc;
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/JavaMetadataI18n.properties
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/JavaMetadataI18n.properties (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/JavaMetadataI18n.properties 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+sequencerTaskName = Processing Java source
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,261 @@
+/*
+ * 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.
+ */
+
+/**
+ * @author Serge Pagop (serge.pagop(a)innoq.com)
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<java='http://www.jboss.org/dna/java/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// B A S E T Y P E S
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationType, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:sampleName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationType] > nt:unstructured
+ + java:annotation (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:typeName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - typeName (string)
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ - java:name (string)
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+/**
+ * No Return type
+ */
+[java:noReturnType] > nt:unstructured
+ - java:noReturn (string)
+ < 'void'
+
+/**
+ * Integral type
+ */
+[java:integralType] > nt:unstructured
+ - java:predefinedIntegralType (string) mandatory
+ < 'byte', 'short', 'int', 'long', 'char'
+
+/**
+ * Floating point type
+ */
+[java:floatingPointType] > nt:unstructured
+ - java:predefinedFloatingType (string) mandatory
+ < 'float', 'double'
+
+/**
+ * Primitive type
+ */
+[java:primitiveType] > nt:unstructured
+ - java:booleanType (string)
+ < 'boolean'
+ + java:numericType (java:integralType, java:floatingPointType)
+
+
+/**
+ * Reference type (TODO to enhance)
+ */
+[java:referenceType] > nt:unstructured
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ - java:declaredAs (string) multiple
+ < 'static','final', 'transient', 'volatile'
+ - java:name (string) mandatory
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ + java:resultType (java:noReturnType, java:primitiveType, java:referenceType) mandatory
+ - java:name (string) mandatory
+ - java:declaredAs (string) multiple
+ < 'static','final', 'native', 'strictfp', 'synchronized'
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ - java:name (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationType) = java:annotationType
+ - java:keyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - keyword (string) mandatory
+ < 'import'
+ - typeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - keyword (string) mandatory
+ < 'import'
+ - packageOrTypeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:singleStaticImportDeclaration] > nt:unstructured
+ - single_static (string) mandatory
+ < 'import static'
+ - typeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:staticImportOnDemandDeclaration] > nt:unstructured
+ - static_import (string) mandatory
+ < 'import static'
+ - typeName (string) mandatory
+
+[java:importDeclaration] > nt:unstructured
+ + java:singleTypeImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:typeImportOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+ + java:singleStaticImport (java:singleStaticImportDeclaration) = java:singleStaticImportDeclaration
+ + java:staticImportOnDemand (java:staticImportOnDemandDeclaration) = java:staticImportOnDemandDeclaration
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier = 'public'
+ - java:declaredAs (string)
+ < 'abstract', 'final'
+ - java:name (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+ //TODO
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:type (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
Added: 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 (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,115 @@
+/*
+ * 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 MyClass 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.jackrabbitcdnsupport;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.FileInputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.nodetype.NodeType;
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.jboss.dna.common.util.FileUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * jackrabbitCNDSupportsTest tests some CND (Compact Node Type Definition) features of jackrabbbit.
+ *
+ * @author serge.pagop(a)innoq.com
+ */
+public class jackrabbitCNDSupportsTest {
+
+ public static final String TESTATA_PATH = "./src/test/resources/";
+ public static final String JACKRABBIT_DATA_PATH = "./target/testdata/jackrabbittest/";
+ public static final String REPOSITORY_DIRECTORY_PATH = JACKRABBIT_DATA_PATH + "repository";
+ public static final String REPOSITORY_CONFIG_PATH = TESTATA_PATH + "jackrabbitInMemoryTestRepositoryConfig.xml";
+ public static final String USERNAME = "jsmith";
+ public static final char[] PASSWORD = "secret".toCharArray();
+
+ // private Logger logger;
+ private Repository repository;
+ private Session session;
+
+ @Before
+ public void beforeEach() throws Exception {
+ // Clean up the test data ...
+ FileUtil.delete(JACKRABBIT_DATA_PATH);
+
+ // logger = Logger.getLogger(jackrabbitCNDSupportsTest.class);
+
+ // Set up the transient repository ...
+ this.repository = new TransientRepository(REPOSITORY_CONFIG_PATH, REPOSITORY_DIRECTORY_PATH);
+
+ SimpleCredentials creds = new SimpleCredentials(USERNAME, PASSWORD);
+ session = this.repository.login(creds);
+ assertNotNull(session);
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ try {
+ if (session != null) session.logout();
+ } finally {
+ session = null;
+ // No matter what, clean up the test data ...
+ FileUtil.delete(JACKRABBIT_DATA_PATH);
+ }
+ }
+
+ @Test
+ public void shouldSupportCNDNodeTypes() throws Exception {
+ JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)session.getWorkspace().getNodeTypeManager();
+ assertNotNull(ntm);
+ FileInputStream cndFile = new FileInputStream(TESTATA_PATH + "java-source-artifact.cnd");
+ assertNotNull(cndFile);
+ NodeType[] nodeTypes = ntm.registerNodeTypes(cndFile, JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+ assertEquals(29, nodeTypes.length);
+ for (NodeType nodeType : nodeTypes) {
+ System.out.println("node type name: " + nodeType.getName());
+ }
+ }
+
+ @Test
+ public void testMap() throws Exception {
+ Map<String, String> errors = new HashMap<String, String>();
+ errors.put("login", "field.isNull");
+ if (!errors.containsKey("login")) errors.put("login", "field.regexp");
+
+ Collection<String> keys = errors.keySet();
+ assertTrue(keys.size() == 1);
+ Collection<String> values = errors.values();
+ for (Iterator<String> i = values.iterator(); i.hasNext();) {
+ System.out.println(i.next());
+
+ }
+
+ }
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataI18nTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataI18nTest.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataI18nTest.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,34 @@
+/*
+ * 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.sequencer.java;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author Randall Hauch
+ */
+public class JavaMetadataI18nTest extends AbstractI18nTest {
+
+ public JavaMetadataI18nTest() {
+ super(JavaMetadataI18n.class);
+ }
+}
Added: 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 (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,83 @@
+/*
+ * 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.sequencer.java;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Serge Pagop
+ */
+public class JavaMetadataSequencerTest {
+ private JavaMetadataSequencer sequencer;
+ private InputStream content;
+ private MockSequencerOutput output;
+ private ProgressMonitor progress;
+ private File source;
+
+ @Before
+ public void beforeEach() throws Exception {
+ this.sequencer = new JavaMetadataSequencer();
+ this.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");
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (content != null) {
+ try {
+ content.close();
+ } finally {
+ content = null;
+ }
+ }
+ }
+
+ protected FileInputStream getJavaSrc( File file ) throws FileNotFoundException {
+ return new FileInputStream(file);
+ }
+
+ @Test
+ public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
+ content = getJavaSrc(source);
+ assertThat(content, is(notNullValue()));
+ sequencer.sequence(content, output, 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"}));
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,106 @@
+/*
+ * 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.sequencer.java;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.List;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Serge Pagop
+ */
+public class JavaMetadataTest {
+ private File source;
+ private InputStream stream;
+ JavaMetadata javaMetadata;
+
+ @Before
+ public void beforeEach() throws Exception {
+ source = new File("src/test/resources/org/acme/MySource.java");
+ stream = getJavaSrc(source);
+
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (stream != null) {
+ try {
+ stream.close();
+ } finally {
+ stream = null;
+ }
+ }
+ }
+
+ protected FileInputStream getJavaSrc( File file ) throws FileNotFoundException {
+ return new FileInputStream(file);
+ }
+
+ @Test
+ public void shouldGetJavaSourceFromTheInputStream() throws Exception {
+
+ char[] c = JavaMetadataUtil.getJavaSourceFromTheInputStream(stream, JavaMetadataUtil.length(stream), null);
+ assertThat(c, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldRunJLS3Conversion() throws Exception {
+ ASTNode rootNode = CompilationUnitParser.runJLS3Conversion(JavaMetadataUtil.getJavaSourceFromTheInputStream(getJavaSrc(source),
+ source.length(),
+ null),
+ true);
+ assertThat(rootNode, is(notNullValue()));
+ // Verify we get a compilation unit node and that binding are correct
+ assertTrue("Not a compilation unit", rootNode.getNodeType() == ASTNode.COMPILATION_UNIT);
+ }
+
+ @Test
+ public void shouldCreatePackageMetadata() throws Exception {
+ javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream), null, null);
+ ASTNode rootNode = CompilationUnitParser.runJLS3Conversion(JavaMetadataUtil.getJavaSourceFromTheInputStream(getJavaSrc(source),
+ source.length(),
+ null),
+ true);
+ PackageMetadata packageMetadata = javaMetadata.createPackageMetadata((CompilationUnit)rootNode);
+ assertThat(packageMetadata, is(notNullValue()));
+ assertThat(packageMetadata.getName(), is("org.acme"));
+ List<Annotation> annotations = packageMetadata.getAnnotations();
+ for (Annotation annotation : annotations) {
+ if (annotation instanceof MarkerAnnotation) {
+ assertThat(annotation.getTypeName().getFullyQualifiedName(), is("org.acme.annotation.MyPackageAnnotation"));
+ }
+ }
+ }
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/jackrabbitInMemoryTestRepositoryConfig.xml
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/jackrabbitInMemoryTestRepositoryConfig.xml (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/jackrabbitInMemoryTestRepositoryConfig.xml 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
+ "http://jackrabbit.apache.org/dtd/repository-1.2.dtd">
+<!-- Example Repository Configuration File -->
+<Repository>
+ <!--
+ virtual file system where the repository stores global state
+ (e.g. registered namespaces, custom node types, etc.)
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/repository"/>
+ </FileSystem>
+
+ <!--
+ security configuration
+ -->
+ <Security appName="Jackrabbit">
+ <!--
+ access manager:
+ class: FQN of class implementing the AccessManager interface
+ -->
+ <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+ <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+ </AccessManager>
+
+ <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+ <!-- anonymous user name ('anonymous' is the default value) -->
+ <param name="anonymousId" value="anonymous"/>
+ <!--
+ default user name to be used instead of the anonymous user
+ when no login credentials are provided (unset by default)
+ -->
+ <!-- <param name="defaultUserId" value="superuser"/> -->
+ </LoginModule>
+ </Security>
+
+ <!--
+ location of workspaces root directory and name of default workspace
+ -->
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+ <!--
+ workspace configuration template:
+ used to create the initial workspace if there's no workspace yet
+ -->
+ <Workspace name="Jackrabbit Core">
+ <!--
+ virtual file system of the workspace:
+ class: FQN of class implementing the FileSystem interface
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${wsp.home}"/>
+ </FileSystem>
+ <!--
+ persistence manager of the workspace:
+ class: FQN of class implementing the PersistenceManager interface
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager">
+ <param name="persistent" value="false"/>
+ </PersistenceManager>
+ <!--
+ Search index and the file system it uses.
+ class: FQN of class implementing the QueryHandler interface
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index"/>
+ </SearchIndex>
+ </Workspace>
+
+ <!--
+ Configures the versioning
+ -->
+ <Versioning rootPath="${rep.home}/version">
+ <!--
+ Configures the filesystem to use for versioning for the respective
+ persistence manager
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/version" />
+ </FileSystem>
+
+ <!--
+ Configures the persistence manager to be used for persisting version state.
+ Please note that the current versioning implementation is based on
+ a 'normal' persistence manager, but this could change in future
+ implementations.
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager">
+ <param name="persistent" value="false"/>
+ </PersistenceManager>
+ </Versioning>
+
+ <!--
+ Search index for content that is shared repository wide
+ (/jcr:system tree, contains mainly versions)
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index"/>
+ </SearchIndex>
+</Repository>
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/java-source-artifact.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/java-source-artifact.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/java-source-artifact.cnd 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,260 @@
+/*
+ * 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.
+ */
+
+/**
+ * @author Serge Pagop (serge.pagop(a)innoq.com)
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<java='http://www.jboss.org/dna/java/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// B A S E T Y P E S
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationType, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:sampleName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationType] > nt:unstructured
+ + java:annotation (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:typeName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - typeName (string)
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ - java:name (string)
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+/**
+ * No Return type
+ */
+[java:noReturnType] > nt:unstructured
+ - java:noReturn (string)
+ < 'void'
+
+/**
+ * Integral type
+ */
+[java:integralType] > nt:unstructured
+ - java:predefinedIntegralType (string) mandatory
+ < 'byte', 'short', 'int', 'long', 'char'
+
+/**
+ * Floating point type
+ */
+[java:floatingPointType] > nt:unstructured
+ - java:predefinedFloatingType (string) mandatory
+ < 'float', 'double'
+
+/**
+ * Primitive type
+ */
+[java:primitiveType] > nt:unstructured
+ - java:booleanType (string)
+ < 'boolean'
+ + java:numericType (java:integralType, java:floatingPointType)
+
+
+/**
+ * Reference type (TODO to enhance)
+ */
+[java:referenceType] > nt:unstructured
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ - java:declaredAs (string) multiple
+ < 'static','final', 'transient', 'volatile'
+ - java:name (string) mandatory
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ + java:resultType (java:noReturnType, java:primitiveType, java:referenceType) mandatory
+ - java:name (string) mandatory
+ - java:declaredAs (string) multiple
+ < 'static','final', 'native', 'strictfp', 'synchronized'
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier (string)
+ < 'public', 'protected', 'private'
+ - java:name (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationType) = java:annotationType
+ - java:keyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - keyword (string) mandatory
+ < 'import'
+ - typeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - keyword (string) mandatory
+ < 'import'
+ - packageOrTypeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:singleStaticImportDeclaration] > nt:unstructured
+ - single_static (string) mandatory
+ < 'import static'
+ - typeName (string) mandatory
+
+// TODO: needs to be enhance
+[java:staticImportOnDemandDeclaration] > nt:unstructured
+ - static_import (string) mandatory
+ < 'import static'
+ - typeName (string) mandatory
+
+[java:importDeclaration] > nt:unstructured
+ + java:singleTypeImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:typeImportOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+ + java:singleStaticImport (java:singleStaticImportDeclaration) = java:singleStaticImportDeclaration
+ + java:staticImportOnDemand (java:staticImportOnDemandDeclaration) = java:staticImportOnDemandDeclaration
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ - java:modifier = 'public'
+ - java:declaredAs (string)
+ < 'abstract', 'final'
+ - java:name (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:typeDeclaration (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/MySource.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/MySource.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/MySource.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,37 @@
+/*
+ * 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.acme;
+
+import org.acme.annotation.MyClassAnnotation;
+
+@MyClassAnnotation
+public class MySource {
+ private int i;
+
+ public int getI() {
+ return this.i;
+ }
+
+ public void setI( int i ) {
+ this.i = i;
+ }
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyClassAnnotation.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyClassAnnotation.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyClassAnnotation.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,36 @@
+/*
+ * 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.acme.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Randall Hauch
+ */
+@Retention( RetentionPolicy.CLASS )
+@Target( ElementType.TYPE )
+public @interface MyClassAnnotation {
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyPackageAnnotation.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyPackageAnnotation.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/annotation/MyPackageAnnotation.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,36 @@
+/*
+ * 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.acme.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Randall Hauch
+ */
+@Retention( RetentionPolicy.CLASS )
+@Target( ElementType.PACKAGE )
+public @interface MyPackageAnnotation {
+
+}
Added: trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/package-info.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/package-info.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/test/resources/org/acme/package-info.java 2008-06-16 19:06:55 UTC (rev 289)
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+@MyPackageAnnotation
+package org.acme;
+
+import org.acme.annotation.MyPackageAnnotation;
+
15 years, 10 months
DNA SVN: r288 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository and 12 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-13 14:25:41 -0400 (Fri, 13 Jun 2008)
New Revision: 288
Added:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/NodeConflictBehavior.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RecordBranchCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicRecordBranchCommand.java
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
Log:
Added array-based methods to PropertyValueFactory, modified several of the commands, and further implemented the Federation Service components
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -202,7 +202,8 @@
for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
Name propertyName = data.getKey();
Object values = data.getValue();
- theCommand.setProperty(propertyName, values);
+ Property property = env.getPropertyFactory().create(propertyName, values);
+ theCommand.setProperty(property);
}
}
if (command instanceof SetPropertiesCommand) {
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -112,6 +112,7 @@
public static I18n warningSequencingXmlDocument;
public static I18n interruptedWhileConnectingToFederationConfigurationRepository;
+ public static I18n interruptedWhileUsingFederationConfigurationRepository;
public static I18n interruptedWhileClosingConnectionToFederationConfigurationRepository;
public static I18n unableToCreateConnectionToFederatedRepository;
public static I18n unableToAuthenticateConnectionToFederatedRepository;
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -56,20 +56,34 @@
protected static final String RETRY_LIMIT = "retryLimit";
protected static final String FEDERATION_SERVICE_JNDI_NAME = "fedServiceJndiName";
- private final String repositoryName;
- private final FederationService federationService;
+ private String repositoryName;
+ private FederationService federationService;
private String sourceName;
- private int retryLimit;
+ private int retryLimit = DEFAULT_RETRY_LIMIT;
private String username;
private String credentials;
- protected FederatedRepositorySource( FederationService federationService,
- String repositoryName ) {
+ /**
+ * Create a new instance of the source, which must still be properly initialized with a
+ * {@link #setRepositoryName(String) repository name} and a reference to the
+ * {@link #setFederationService(FederationService) federation service}.
+ */
+ public FederatedRepositorySource() {
+ }
+
+ /**
+ * Create a new instance of the source with the required repository name and federation service.
+ *
+ * @param federationService the {@link FederationService}
+ * @param repositoryName the repository name
+ * @throws IllegalArgumentException if the federation service is null or the repository name is null or blank
+ */
+ public FederatedRepositorySource( FederationService federationService,
+ String repositoryName ) {
ArgCheck.isNotNull(federationService, "federationService");
ArgCheck.isNotNull(repositoryName, "repositoryName");
this.federationService = federationService;
this.repositoryName = repositoryName;
- this.retryLimit = DEFAULT_RETRY_LIMIT;
}
/**
@@ -80,6 +94,14 @@
}
/**
+ * @param federationService Sets federationService to the specified value.
+ */
+ public void setFederationService( FederationService federationService ) {
+ ArgCheck.isNotNull(federationService, "federatedService");
+ this.federationService = federationService;
+ }
+
+ /**
* {@inheritDoc}
*/
public int getRetryLimit() {
@@ -165,6 +187,14 @@
}
/**
+ * @param repositoryName Sets repositoryName to the specified value.
+ */
+ public void setRepositoryName( String repositoryName ) {
+ ArgCheck.isNotEmpty(repositoryName, "repositoryName");
+ this.repositoryName = repositoryName;
+ }
+
+ /**
* {@inheritDoc}
*/
public Reference getReference() {
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -27,11 +27,15 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.component.ClassLoaderFactory;
+import org.jboss.dna.common.component.StandardClassLoaderFactory;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.repository.RepositoryI18n;
import org.jboss.dna.repository.services.AbstractServiceAdministrator;
import org.jboss.dna.repository.services.AdministeredService;
import org.jboss.dna.repository.services.ServiceAdministrator;
+import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
import org.jboss.dna.spi.graph.connection.RepositorySource;
@@ -80,12 +84,15 @@
/**
* {@inheritDoc}
*/
- public boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+ public boolean awaitTermination( long timeout,
+ TimeUnit unit ) throws InterruptedException {
return FederationService.this.awaitTermination(timeout, unit);
}
}
+ private final ClassLoaderFactory classLoaderFactory;
+ private final ExecutionContext executionContext;
private final RepositorySource configurationSource;
private final Administrator administrator = new Administrator();
private final ConcurrentMap<String, FederatedRepository> repositories = new ConcurrentHashMap<String, FederatedRepository>();
@@ -95,12 +102,22 @@
* Create a federation service instance
*
* @param configurationSource the repository source that contains the configuration for this federation service (including the
- * respositories and the sources used by the federated repositories)
- * @throws IllegalArgumentException if the bootstrap source is null
+ * respositories and the sources used by the federated repositories)
+ * @param executionContext the context in which this service should run
+ * @param classLoaderFactory the class loader factory used to instantiate {@link RepositorySource} instances; may be null if
+ * this instance should use a default factory that attempts to load classes first from the
+ * {@link Thread#getContextClassLoader() thread's current context class loader} and then from the class loader that
+ * loaded this class.
+ * @throws IllegalArgumentException if the bootstrap source is null or the execution context is null
*/
- public FederationService( RepositorySource configurationSource ) {
+ public FederationService( RepositorySource configurationSource,
+ ExecutionContext executionContext,
+ ClassLoaderFactory classLoaderFactory ) {
ArgCheck.isNotNull(configurationSource, "configurationSource");
+ ArgCheck.isNotNull(executionContext, "executionContext");
this.configurationSource = configurationSource;
+ this.executionContext = executionContext;
+ this.classLoaderFactory = classLoaderFactory != null ? classLoaderFactory : new StandardClassLoaderFactory();
}
/**
@@ -119,21 +136,136 @@
return this.configurationSource;
}
+ /**
+ * @return executionContext
+ */
+ public ExecutionContext getExecutionContext() {
+ return this.executionContext;
+ }
+
+ /**
+ * @return classLoaderFactory
+ */
+ public ClassLoaderFactory getClassLoaderFactory() {
+ return this.classLoaderFactory;
+ }
+
public String getJndiName() {
// TODO
return null;
}
- protected void startService() {
+ protected synchronized void startService() {
if (this.configurationConnection == null) {
try {
this.configurationConnection = this.configurationSource.getConnection();
} catch (InterruptedException err) {
- throw new FederationException(RepositoryI18n.interruptedWhileConnectingToFederationConfigurationRepository.text(this.configurationSource.getName()));
+ I18n msg = RepositoryI18n.interruptedWhileConnectingToFederationConfigurationRepository;
+ throw new FederationException(msg.text(configurationSource.getName()));
}
+ // // Read the configuration and obtain the RepositorySource instances for each of the
+ // // federated repositories. Each repository configuration is rooted at
+ // // "/dna:repositories/[repositoryName]", and under this node at "dna:federation"
+ // // is the RepositorySource for the integrated repository, and under the
+ // // "dna:sources/[sourceName]" are the nodes representing the inital RepositorySource
+ // // instances for each of the sources.
+ // //
+ // // The integrated repository for each federated repository contains the complete unified
+ // // graph merged from all of the sources. It also contains the configuration for the federated
+ // // repository at "/dna:system/dna:federation", including under "dna:sources" a node for each of the current
+ // // sources (e.g., "/dna:system/dna:federation/dna:sources/[sourceName]"). If this area of the
+ // // graph does not yet exist, the sources are copied from the
+ // // "/dna:repositories/[repositoryName]/dna:sources" area of the service's configuration repository.
+ // // However, after that, the federated repository manages its own sources.
+ //
+ // ValueFactories valueFactories = executionContext.getValueFactories();
+ // PathFactory pathFactory = valueFactories.getPathFactory();
+ //
+ // // Get the list of repositories in the configuration, and create a FederatedRepository for each one ...
+ // try {
+ // Path repositoriesNode = pathFactory.create("dna:repositories");
+ // BasicGetChildrenCommand getRepositories = new BasicGetChildrenCommand(repositoriesNode);
+ // configurationConnection.execute(executionContext, getRepositories);
+ //
+ // // For each repository ...
+ // for (Path.Segment child : getRepositories.getChildren()) {
+ //
+ // // Get the repository's name ...
+ // final String repositoryName = child.getUnencodedString();
+ // final Path pathToRepository = pathFactory.create(repositoriesNode, child);
+ //
+ // // Record the initial sources ...
+ // final Path.Segment sourcesSegment = pathFactory.createSegment("dna:sources");
+ // final Path pathToRepositorySourcesNode = pathFactory.create(pathToRepository, sourcesSegment);
+ // BasicRecordBranchCommand getSources = new BasicRecordBranchCommand(pathToRepositorySourcesNode,
+ // NodeConflictBehavior.DO_NOT_REPLACE);
+ //
+ // // Get the source of the integrated repository ...
+ // final Path.Segment integratedRepositorySegment = pathFactory.createSegment("dna:federatedRepository");
+ // final Path pathToIntegratedRepositoryNode = pathFactory.create(pathToRepository, integratedRepositorySegment);
+ // BasicGetNodeCommand getSource = new BasicGetNodeCommand(pathToIntegratedRepositoryNode);
+ // configurationConnection.execute(executionContext, getSource);
+ // RepositorySource integratedRepositorySource = createRepositorySource(valueFactories,
+ // getSource.getProperties());
+ //
+ // // Copy these to the federated repository ...
+ // RepositoryConnection integratedConnection = integratedReposi
+ // // Look for the
+ // // Read the initial sources ...
+ //
+ // // Get the repository source information for the integrated repository ...
+ //
+ // // Look for existing sources and load them ...
+ //
+ // // Otherwise, read the intial sources from the
+ //
+ // }
+ // } catch (InterruptedException err) {
+ // I18n msg = RepositoryI18n.interruptedWhileUsingFederationConfigurationRepository;
+ // throw new FederationException(msg.text(configurationSource.getName()));
+ // }
+ // // TODO
}
}
+ // protected RepositorySource createRepositorySource( ValueFactories values,
+ // Iterable<Property> properties ) {
+ // // Put the properties in a map so we can find them by name ...
+ // Map<Name, Property> byName = new HashMap<Name, Property>();
+ // for (Property property : properties) {
+ // byName.put(property.getName(), property);
+ // }
+ //
+ // // Get the concrete class ...
+ // Name classnameName = values.getNameFactory().create("dna:className");
+ // Property classProperty = byName.get(classnameName);
+ // if (classProperty == null) return null;
+ // if (classProperty.isEmpty()) return null;
+ // String className = values.getStringFactory().create(classProperty.getValues().next());
+ // if (className == null) return null;
+ //
+ // Name classpathName = values.getNameFactory().create("dna:classpath");
+ // Property classpathProperty = byName.get(classpathName);
+ // String[] classpath = null;
+ // if (classpathProperty != null) {
+ // classpath = values.getStringFactory().create(classpathProperty.getValuesAsArray());
+ // }
+ //
+ // // Load the class and look for the constructors ...
+ // RepositorySource source = null;
+ // try {
+ // ClassLoader loader = getClassLoaderFactory().getClassLoader(classpath);
+ // Class<?> sourceClass = loader.loadClass(className);
+ // source = (RepositorySource)sourceClass.newInstance();
+ // } catch (ClassNotFoundException err) {
+ // return null;
+ // } catch (InstantiationException err) {
+ //
+ // } catch (IllegalAccessException err) {
+ // }
+ // return null;
+ // }
+
/**
* Get the federated repository object with the given name. The resulting repository will be started and ready to use.
*
@@ -157,12 +289,13 @@
return repository;
}
- protected void shutdownService() {
+ protected synchronized void shutdownService() {
if (this.configurationConnection != null) {
try {
this.configurationConnection.close();
} catch (InterruptedException err) {
- throw new FederationException(RepositoryI18n.interruptedWhileClosingConnectionToFederationConfigurationRepository.text(this.configurationSource.getName()));
+ throw new FederationException(
+ RepositoryI18n.interruptedWhileClosingConnectionToFederationConfigurationRepository.text(this.configurationSource.getName()));
}
// Now shut down all repositories ...
for (String repositoryName : this.repositories.keySet()) {
@@ -181,7 +314,8 @@
return true;
}
- protected boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+ protected boolean awaitTermination( long timeout,
+ TimeUnit unit ) throws InterruptedException {
// Now shut down all repositories ...
for (String repositoryName : this.repositories.keySet()) {
FederatedRepository repository = this.repositories.get(repositoryName);
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -61,6 +61,7 @@
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.PropertyFactory;
import org.jboss.dna.spi.graph.ValueFactories;
/**
@@ -656,6 +657,13 @@
/**
* {@inheritDoc}
*/
+ public PropertyFactory getPropertyFactory() {
+ return this.delegate.getPropertyFactory();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public SessionFactory getSessionFactory() {
return this.factory;
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -22,36 +22,26 @@
package org.jboss.dna.repository.util;
import javax.jcr.Session;
-import org.jboss.dna.spi.graph.NamespaceRegistry;
-import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.connection.ExecutionEnvironment;
/**
* The context of an execution.
+ *
* @author Randall Hauch
*/
-public interface ExecutionContext {
+public interface ExecutionContext extends ExecutionEnvironment {
/**
- * Get the namespace registry.
- * @return the namespace registry; never null
- */
- NamespaceRegistry getNamespaceRegistry();
-
- /**
- * Get the factories that are to be used to create property values of various types.
- * @return the set of value factories; never null
- */
- ValueFactories getValueFactories();
-
- /**
* Get the session factory, which can be used to obtain sessions temporarily for this context. Any session obtained from this
* factory should be {@link Session#logout() closed} before the execution finishes.
+ *
* @return the session factory
*/
SessionFactory getSessionFactory();
/**
* Get a set of utilities for working with JCR.
+ *
* @return the tools
*/
JcrTools getTools();
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -23,7 +23,9 @@
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.PropertyFactory;
import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.BasicPropertyFactory;
import org.jboss.dna.spi.graph.impl.StandardValueFactories;
/**
@@ -32,24 +34,31 @@
public class SimpleExecutionContext implements ExecutionContext {
private final JcrTools tools = new JcrTools();
+ private final PropertyFactory propertyFactory;
private final SessionFactory sessionFactory;
private final ValueFactories valueFactories;
private final NamespaceRegistry namespaceRegistry;
- public SimpleExecutionContext( SessionFactory sessionFactory, String repositoryWorkspaceForNamespaceRegistry ) {
- this(sessionFactory, new JcrNamespaceRegistry(sessionFactory, repositoryWorkspaceForNamespaceRegistry), null);
+ public SimpleExecutionContext( SessionFactory sessionFactory,
+ String repositoryWorkspaceForNamespaceRegistry ) {
+ this(sessionFactory, new JcrNamespaceRegistry(sessionFactory, repositoryWorkspaceForNamespaceRegistry), null, null);
}
- public SimpleExecutionContext( SessionFactory sessionFactory, NamespaceRegistry namespaceRegistry ) {
- this(sessionFactory, namespaceRegistry, null);
+ public SimpleExecutionContext( SessionFactory sessionFactory,
+ NamespaceRegistry namespaceRegistry ) {
+ this(sessionFactory, namespaceRegistry, null, null);
}
- public SimpleExecutionContext( SessionFactory sessionFactory, NamespaceRegistry namespaceRegistry, ValueFactories valueFactories ) {
+ public SimpleExecutionContext( SessionFactory sessionFactory,
+ NamespaceRegistry namespaceRegistry,
+ ValueFactories valueFactories,
+ PropertyFactory propertyFactory ) {
ArgCheck.isNotNull(sessionFactory, "session factory");
ArgCheck.isNotNull(namespaceRegistry, "namespace registry");
this.sessionFactory = sessionFactory;
this.namespaceRegistry = namespaceRegistry;
this.valueFactories = valueFactories != null ? valueFactories : new StandardValueFactories(this.namespaceRegistry);
+ this.propertyFactory = propertyFactory != null ? propertyFactory : new BasicPropertyFactory(this.valueFactories);
}
/**
@@ -69,6 +78,13 @@
/**
* {@inheritDoc}
*/
+ public PropertyFactory getPropertyFactory() {
+ return this.propertyFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
Modified: trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
===================================================================
--- trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2008-06-13 18:25:41 UTC (rev 288)
@@ -98,8 +98,9 @@
canceledSequencingXmlDocument = Canceled sequencing XML
warningSequencingXmlDocument = A warning was received while sequencing XML: {0}
-interruptedWhileConnectingToFederationConfigurationRepository = Interrupted while connecting to federation configuration repository for "{0}" repository
-interruptedWhileClosingConnectionToFederationConfigurationRepository = Interrupted while closing connection to federation configuration repository for "{0}" repository
+interruptedWhileConnectingToFederationConfigurationRepository = Interrupted while connecting to federation configuration repository "{0}"
+interruptedWhileUsingFederationConfigurationRepository = Interrupted while using federation configuration repository "{0}"
+interruptedWhileClosingConnectionToFederationConfigurationRepository = Interrupted while closing connection to federation configuration repository "{0}"
unableToCreateConnectionToFederatedRepository = Unable to create a connection to the repository "{0}". Check the Federation Service configuration.
unableToAuthenticateConnectionToFederatedRepository = Unable to authenticate "{1}" for repository "{0}"
repositoryHasBeenShutDown = The "{0}" repository has been shut down and may no longer be used.
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-13 18:16:28 UTC (rev 287)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -81,7 +81,7 @@
}
};
NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory, "doesn't matter");
- this.context = new SimpleExecutionContext(sessionFactory, registry, null);
+ this.context = new SimpleExecutionContext(sessionFactory, registry, null, null);
this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
this.progressMonitor = new RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -185,6 +185,15 @@
public boolean isParentReference();
/**
+ * Get the raw string form of the segment using the {@link Path#NO_OP_ENCODER no-op encoder}. This is equivalent to
+ * calling <code>getString(Path.NO_OP_ENCODER)</code>.
+ *
+ * @return the un-encoded string
+ * @see #getString(TextEncoder)
+ */
+ public String getUnencodedString();
+
+ /**
* Get the string form of the segment. The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each
* of the path segments.
*
@@ -208,7 +217,7 @@
* prefix. The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each of the path segments.
*
* @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
- * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link #getName() name}
+ * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link #getName() name}
* @return the encoded string
* @throws IllegalArgumentException if the namespace registry is null
* @see #getString(NamespaceRegistry,TextEncoder)
@@ -220,13 +229,14 @@
* to a prefix and the supplied encoder to encode characters in each of the path segments.
*
* @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
- * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link #getName() name}
+ * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link #getName() name}
* @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default encoder} should be used
* @return the encoded string
* @throws IllegalArgumentException if the namespace registry is null
* @see #getString(NamespaceRegistry)
*/
- public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder );
+ public String getString( NamespaceRegistry namespaceRegistry,
+ TextEncoder encoder );
}
/**
@@ -417,7 +427,7 @@
* @param beginIndex the beginning index, inclusive.
* @return the specified subpath
* @exception IndexOutOfBoundsException if the <code>beginIndex</code> is negative or larger than the length of this
- * <code>Path</code> object
+ * <code>Path</code> object
*/
public Path subpath( int beginIndex );
@@ -429,9 +439,11 @@
* @param endIndex the ending index, exclusive.
* @return the specified subpath
* @exception IndexOutOfBoundsException if the <code>beginIndex</code> is negative, or <code>endIndex</code> is larger
- * than the length of this <code>Path</code> object, or <code>beginIndex</code> is larger than <code>endIndex</code>.
+ * than the length of this <code>Path</code> object, or <code>beginIndex</code> is larger than
+ * <code>endIndex</code>.
*/
- public Path subpath( int beginIndex, int endIndex );
+ public Path subpath( int beginIndex,
+ int endIndex );
/**
* {@inheritDoc}
@@ -475,7 +487,7 @@
* The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each of the path segments.
*
* @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
- * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
+ * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
* @return the encoded string
* @throws IllegalArgumentException if the namespace registry is null
* @see #getString(NamespaceRegistry,TextEncoder)
@@ -487,12 +499,13 @@
* prefixes and the supplied encoder to encode characters in each of the path segments.
*
* @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
- * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
+ * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
* @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default encoder} should be used
* @return the encoded string
* @throws IllegalArgumentException if the namespace registry is null
* @see #getString(NamespaceRegistry)
*/
- public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder );
+ public String getString( NamespaceRegistry namespaceRegistry,
+ TextEncoder encoder );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -37,7 +37,7 @@
*
* @return the new path
*/
- Path create();
+ Path createRootPath();
/**
* Create an absolute path with the supplied segment names, in order. If no segments are provided, the result will be the root
@@ -47,7 +47,7 @@
* @return the new path
* @throws IllegalArgumentException if at least one segment name is provided and if any of the supplied segment names are null
*/
- Path create( Name... segmentNames );
+ Path createAbsolutePath( Name... segmentNames );
/**
* Create an absolute path with the supplied segments, in order. If no segments are provided, the result will be the root
@@ -57,7 +57,7 @@
* @return the new path
* @throws IllegalArgumentException if at least one segment is provided and if any of the supplied segments are null
*/
- Path create( Path.Segment... segments );
+ Path createAbsolutePath( Path.Segment... segments );
/**
* Create an empty relative path (i.e., equivalent to {@link #createRelativePath(Path.Segment...) createRelativePath}({@link Path#SELF_SEGMENT})).
@@ -95,7 +95,9 @@
* @return the new path
* @throws IllegalArgumentException if the parent path reference or the segment name is null, or if the index is invalid
*/
- Path create( Path parentPath, Name segmentName, int index );
+ Path create( Path parentPath,
+ Name segmentName,
+ int index );
/**
* Create a path by appending the supplied names to the parent path. If no names are appended, the parent path is returned.
@@ -104,9 +106,10 @@
* @param segmentNames the names of the segments that are to be appended, in order, to the parent path
* @return the new path
* @throws IllegalArgumentException if the parent path reference is null, or if at least one segment name is provided and if
- * any of the supplied segment names are null
+ * any of the supplied segment names are null
*/
- Path create( Path parentPath, Name... segmentNames );
+ Path create( Path parentPath,
+ Name... segmentNames );
/**
* Create a path by appending the supplied names to the parent path. If no names are appended, the parent path is returned.
@@ -115,9 +118,10 @@
* @param segments the segments that are to be appended, in order, to the parent path
* @return the new path
* @throws IllegalArgumentException if the parent path reference is null, or if at least one segment name is provided and if
- * any of the supplied segment names are null
+ * any of the supplied segment names are null
*/
- Path create( Path parentPath, Path.Segment... segments );
+ Path create( Path parentPath,
+ Path.Segment... segments );
/**
* Create a path segment given the supplied segment name. The resulting segment will have no index.
@@ -125,7 +129,7 @@
* @param segmentName the name of the segment
* @return the segment
* @throws IllegalArgumentException if the segment name reference is <code>null</code> or the value could not be created
- * from the supplied string
+ * from the supplied string
*/
Path.Segment createSegment( String segmentName );
@@ -136,9 +140,10 @@
* @param decoder the decoder that should be used to decode the qualified name
* @return the segment
* @throws IllegalArgumentException if the segment name reference is <code>null</code> or the value could not be created
- * from the supplied string
+ * from the supplied string
*/
- Path.Segment createSegment( String segmentName, TextDecoder decoder );
+ Path.Segment createSegment( String segmentName,
+ TextDecoder decoder );
/**
* Create a path segment given the supplied segment name and index.
@@ -148,7 +153,8 @@
* @return the segment
* @throws IllegalArgumentException if the segment name reference is <code>null</code> or if the index is invalid
*/
- Path.Segment createSegment( String segmentName, int index );
+ Path.Segment createSegment( String segmentName,
+ int index );
/**
* Create a path segment given the supplied segment name. The resulting segment will have no index.
@@ -167,6 +173,7 @@
* @return the segment
* @throws IllegalArgumentException if the segment name reference is null or if the index is invalid
*/
- Path.Segment createSegment( Name segmentName, int index );
+ Path.Segment createSegment( Name segmentName,
+ int index );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -21,8 +21,6 @@
*/
package org.jboss.dna.spi.graph;
-import java.math.BigDecimal;
-import java.net.URI;
import java.util.Iterator;
import net.jcip.annotations.Immutable;
@@ -43,13 +41,6 @@
Name getName();
/**
- * Get the name of the property's definition.
- *
- * @return the property definition's name; never null
- */
- Name getDefinitionName();
-
- /**
* Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
* method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
* will return either 0 or 1. This method may return 0 regardless of whether the property allows a
@@ -91,15 +82,7 @@
boolean isEmpty();
/**
- * Get the type for this property.
- *
- * @return the property's type, which is never null
- */
- PropertyType getPropertyType();
-
- /**
- * Obtain the property's values in their natural form, as defined by {@link #getPropertyType()}. This is equivalent to
- * calling {@link Iterable#iterator() iterator()}.
+ * Obtain the property's values in their natural form. This is equivalent to calling {@link Iterable#iterator() iterator()}.
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
@@ -114,7 +97,7 @@
Iterator<?> getValues();
/**
- * Obtain the property's values as an array of objects in their natural form, as defined by {@link #getPropertyType()}.
+ * Obtain the property's values as an array of objects in their natural form.
* <p>
* A valid array is return if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}, or a
* null value is returned if the property is {@link #isEmpty() empty}.
@@ -129,181 +112,4 @@
*/
Object[] getValuesAsArray();
- /**
- * Obtain the property's values in their natural form, converting the values to the supplied {@link PropertyType} if it is
- * different than this property's {@link #getPropertyType() property type}. Note that it is not always possible to convert
- * between PropertyTypes.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @param type the property type defining the form of the values to be returned; if null, the
- * {@link #getPropertyType() property's type} is used
- * @return an iterator over the values; never null
- */
- Iterator<?> getValues( PropertyType type );
-
- /**
- * Obtain the property's values as String objects, converting the values if the {@link #getPropertyType() property type} is
- * not {@link PropertyType#STRING}. Note that it is always possible to convert to a String value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the String values; never null
- */
- Iterator<String> getStringValues();
-
- /**
- * Obtain the property's values as Binary objects, converting the values if the {@link #getPropertyType() property type} is
- * not {@link PropertyType#BINARY}. Note that it is always possible to convert to a {@link Binary} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the {@link Binary} values; never null
- */
- Iterator<Binary> getBinaryValues();
-
- /**
- * Obtain the property's values as longs, converting the values if the {@link #getPropertyType() property type} is not
- * {@link PropertyType#LONG}. Note that it is not always possible to convert to a {@link PropertyType#LONG long} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the long values; never null
- */
- Iterator<Long> getLongValues();
-
- /**
- * Obtain the property's values as doubles, converting the values if the {@link #getPropertyType() property type} is not
- * {@link PropertyType#DOUBLE}. Note that it is not always possible to convert to a {@link PropertyType#DOUBLE double} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the double values; never null
- */
- Iterator<Double> getDoubleValues();
-
- /**
- * Obtain the property's values as decimal values, converting the values if the {@link #getPropertyType() property type} is
- * not {@link PropertyType#DECIMAL}. Note that it is not always possible to convert to a {@link PropertyType#DECIMAL decimal}
- * value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the decimal values; never null
- */
- Iterator<BigDecimal> getDecimalValues();
-
- /**
- * Obtain the property's values as {@link DateTime dates}, converting the values if the
- * {@link #getPropertyType() property type} is not {@link PropertyType#DATE}. Note that it is not always possible to convert
- * to a {@link PropertyType#DATE date} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the DateTime values; never null
- */
- Iterator<DateTime> getDateValues();
-
- /**
- * Obtain the property's values as booleans, converting the values if the {@link #getPropertyType() property type} is not
- * {@link PropertyType#BOOLEAN}. Note that it is not always possible to convert to a {@link PropertyType#BOOLEAN boolean}
- * value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the Boolean values; never null
- */
- Iterator<Boolean> getBooleanValues();
-
- /**
- * Obtain the property's values as {@link Name names}, converting the values if the {@link #getPropertyType() property type}
- * is not {@link PropertyType#NAME}. Note that it is not always possible to convert to a {@link PropertyType#NAME long}
- * value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the Name values; never null
- */
- Iterator<Name> getNameValues();
-
- /**
- * Obtain the property's values as {@link Path paths}, converting the values if the {@link #getPropertyType() property type}
- * is not {@link PropertyType#PATH}. Note that it is not always possible to convert to a {@link PropertyType#PATH path}
- * value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the Path values; never null
- */
- Iterator<Path> getPathValues();
-
- /**
- * Obtain the property's values as references, converting the values if the {@link #getPropertyType() property type} is not
- * {@link PropertyType#REFERENCE}. Note that it is not always possible to convert to a
- * {@link PropertyType#REFERENCE reference} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the Reference values; never null
- */
- Iterator<Reference> getReferenceValues();
-
- /**
- * Obtain the property's values as {@link URI URIs}, converting the values if the {@link #getPropertyType() property type} is
- * not {@link PropertyType#URI}. Note that it is not always possible to convert to a {@link PropertyType#URI URI} value.
- * <p>
- * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
- * </p>
- * <p>
- * The resulting iterator is immutable, and all property values are immutable.
- * </p>
- *
- * @return an iterator over the URI values; never null
- */
- Iterator<URI> getUriValues();
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -27,11 +27,70 @@
* @author Randall Hauch
*/
public interface PropertyFactory {
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ Object... values );
- Property create( Name name, PropertyType type, Name definitionName, Object... values );
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ Iterable<?> values );
- Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values );
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ Iterator<?> values );
- Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values );
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param desiredType the type that the objects should be converted to; if null, they will be used as is
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ PropertyType desiredType,
+ Object... values );
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param desiredType the type that the objects should be converted to; if null, they will be used as is
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ PropertyType desiredType,
+ Iterable<?> values );
+
+ /**
+ * Create a property with the supplied name and values
+ *
+ * @param name the property name; may not be null
+ * @param desiredType the type that the objects should be converted to; if null, they will be used as is
+ * @param values the values
+ * @return the resulting property
+ */
+ Property create( Name name,
+ PropertyType desiredType,
+ Iterator<?> values );
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -228,4 +228,154 @@
*/
T create( Object value ) throws IoException;
+ /**
+ * Create an array of values from an array of string values, using no decoding.
+ *
+ * @param values the values
+ * @return the values, or null if the supplied string is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ * @see #create(String[], TextDecoder)
+ */
+ T[] create( String[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of strings, using the supplied decoder.
+ *
+ * @param values the string values from which the values are to be created
+ * @param decoder the decoder that should be used; if null, the {@link #DEFAULT_DECODER default decoder} is used
+ * @return the value, or null if the supplied string is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ * @see #create(String)
+ */
+ T[] create( String[] values,
+ TextDecoder decoder ) throws IoException;
+
+ /**
+ * Create an array of values from an array of integers.
+ *
+ * @param values the integers from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( int[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of longs.
+ *
+ * @param values the longs from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( long[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of booleans.
+ *
+ * @param values the booleans from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( boolean[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of booleans.
+ *
+ * @param values the floats from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( float[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of doubles.
+ *
+ * @param values the doubles from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( double[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of decimal values.
+ *
+ * @param values the decimals from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( BigDecimal[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of Calendar instances.
+ *
+ * @param values the Calendar instances from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Calendar[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of dates.
+ *
+ * @param values the dates from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Date[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of names.
+ *
+ * @param values the names from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Name[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of paths.
+ *
+ * @param values the paths from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Path[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of references.
+ *
+ * @param values the references from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Reference[] values ) throws IoException;
+
+ /**
+ * Create an array of values from an array of URIs.
+ *
+ * @param values the URIs from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( URI[] values ) throws IoException;
+
+ /**
+ * Create an array of values from the array of binary content.
+ *
+ * @param values the array of content to be used to create the values
+ * @return the value, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( byte[][] values ) throws IoException;
+
+ /**
+ * Create an array of values from the specified information by determining which other <code>create</code> method applies
+ * for each object and then delegating to that method. Note that this method will not consider
+ * {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ *
+ * @param values the values
+ * @return the new value, or null if the supplied parameter is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( Object[] values ) throws IoException;
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -28,12 +28,14 @@
* Aspect interface for any repository command that acts upon or updates properties on a given node. This aspect also allows for
* the recipient to {@link Cacheable#setCachePolicy(org.jboss.dna.spi.cache.CachePolicy) update the cache policy} for the updated
* information.
+ *
* @author Randall Hauch
*/
-public interface ActsOnProperties extends ActsOnPath, Cacheable {
+public interface ActsOnProperties extends ActsOnPath {
/**
* Get the properties. Any property with no values will be removed.
+ *
* @return the properties
*/
Iterable<Property> getProperties();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -22,19 +22,28 @@
package org.jboss.dna.spi.graph.commands;
import java.util.Iterator;
-import org.jboss.dna.spi.cache.Cacheable;
import org.jboss.dna.spi.graph.Property;
/**
* A command to get the children of a single node given its path.
+ *
* @author Randall Hauch
*/
-public interface CreateNodeCommand extends GraphCommand, ActsOnPath, Cacheable, ActsOnProperties, ActsAsUpdate {
+public interface CreateNodeCommand
+ extends GraphCommand, ActsOnPath, ActsOnProperties, ActsAsUpdate, Comparable<CreateNodeCommand> {
/**
* Get the properties for this new node. The recipient of the command should {@link Iterator#remove() remove} any property
* that will not be stored.
+ *
* @return the property iterator; never null, but possibly empty
*/
Iterable<Property> getProperties();
+
+ /**
+ * Get the desired behavior when a node at the target {@link ActsOnPath#getPath() path} already exists.
+ *
+ * @return the desired behavior; never null
+ */
+ NodeConflictBehavior getConflictBehavior();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -41,7 +41,8 @@
* </p>
* <p>
* The caller may supply a custom iterator implementation, which will be called on this same connection within the same
- * transaction when the node data is processed and consumed.
+ * transaction when the node data is processed and consumed. This is useful, for example, if the iterator to transparently
+ * page through the information without requiring all children to be pulled into memory.
* </p>
*
* @param namesOfChildren the iterator over the names of children; may be null if there are no children
@@ -55,8 +56,9 @@
* The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
* </p>
* <p>
- * The caller may supply a custom iterator implementation, which will be called on this same connection within the same
- * transaction when the node data is processed and consumed.
+ * The caller may supply a custom {@link Iterable} implementation, which will be called on this same connection within the
+ * same transaction when the node data is processed and consumed. This is useful, for example, if the iterator to
+ * transparently page through the information without requiring all children to be pulled into memory.
* </p>
*
* @param namesOfChildren the iterable names of children; may be null if there are no children
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -21,9 +21,8 @@
*/
package org.jboss.dna.spi.graph.commands;
-import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
-import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
/**
* A command to obtain from the source the properties for a single node given its path.
@@ -35,34 +34,9 @@
/**
* Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
* no property vlaues or if all of the property values are null, the property will be removed.
- * <p>
- * The implementation should be capable of accepting an array, {@link Iterator}, or {@link Iterable} as a sole single
- * parameter, and properly extracting the values. This is so that callers that have an {@link Object} reference to an array,
- * Iterator, or Iterable don't need to type check and cast in order to call {@link #setProperty(Name, Iterable...) the}
- * {@link #setProperty(Name, Iterator...) appropriate} method.
- * </p>
*
- * @param propertyName the name of the property
- * @param values the property values
+ * @param property the property
*/
- void setProperty( Name propertyName, Object... values );
+ void setProperty( Property property );
- /**
- * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
- * no property vlaues or if all of the property values are null, the property will be removed.
- *
- * @param propertyName the name of the property
- * @param values the iterable property values
- */
- void setProperty( Name propertyName, Iterable<?> values );
-
- /**
- * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
- * no property vlaues or if all of the property values are null, the property will be removed.
- *
- * @param propertyName the name of the property
- * @param values the iterator over the property values
- */
- void setProperty( Name propertyName, Iterator<?> values );
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -25,13 +25,22 @@
/**
* Command that moves a branch from one path to another.
+ *
* @author Randall Hauch
*/
public interface MoveBranchCommand extends GraphCommand, ActsOnPath, ActsAsUpdate {
/**
* Get the new path to which the branch is to be moved.
+ *
* @return the new path; never null
*/
Path getNewPath();
+
+ /**
+ * Get the desired behavior when a node at the target {@link ActsOnPath#getPath() path} already exists.
+ *
+ * @return the desired behavior; never null
+ */
+ NodeConflictBehavior getConflictBehavior();
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/NodeConflictBehavior.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/NodeConflictBehavior.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/NodeConflictBehavior.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -0,0 +1,36 @@
+/*
+ * 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.graph.commands;
+
+/**
+ * An enumeration used by several commands for the choice of handling duplicate nodes, such as when a node is to be copied to
+ * another location where a node already exists.
+ *
+ * @author Randall Hauch
+ */
+public enum NodeConflictBehavior {
+
+ DO_NOT_REPLACE,
+ APPEND,
+ REPLACE;
+
+}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RecordBranchCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RecordBranchCommand.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RecordBranchCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -0,0 +1,95 @@
+/*
+ * 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.graph.commands;
+
+import java.util.Iterator;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * Command that records the structure of a branch. To process this command, the recipient should walk the branch rooted at
+ * {@link ActsOnPath#getPath()} and, for each node in the branch, {@link #record(Path, Iterable)} the node's information. If
+ * {@link #record(Path, Iterable)} returns true, then the children of that node should also be recorded; if false, then the
+ * recording the children of that node can be ignored.
+ *
+ * @author Randall Hauch
+ */
+public interface RecordBranchCommand extends GraphCommand, ActsOnPath {
+
+ /**
+ * Sets the properties of the supplied node.
+ * <p>
+ * If the supplied path is a relative path, it is assumed to be relative to the {@link ActsOnPath#getPath() branch root}. If
+ * the supplied path is an absolute path, it must be a {@link Path#isDecendantOf(Path) decendant} of the
+ * {@link ActsOnPath#getPath() branch root}; if not, this method returns false and ignores the call.
+ * </p>
+ * <p>
+ * This method should not be called multiple times with the same path. The behavior for such cases is not defined.
+ * </p>
+ *
+ * @param path the path for the node; may not be null
+ * @param properties the properties for the node; may be null if there are no properties
+ * @return true if the children of the node should be recorded, or false if this new node is as deep as the recording should
+ * go
+ */
+ boolean record( Path path,
+ Iterable<Property> properties );
+
+ /**
+ * Sets the properties of the supplied node.
+ * <p>
+ * If the supplied path is a relative path, it is assumed to be relative to the {@link ActsOnPath#getPath() branch root}. If
+ * the supplied path is an absolute path, it must be a {@link Path#isDecendantOf(Path) decendant} of the
+ * {@link ActsOnPath#getPath() branch root}; if not, this method returns false and ignores the call.
+ * </p>
+ * <p>
+ * This method should not be called multiple times with the same path. The behavior for such cases is not defined.
+ * </p>
+ *
+ * @param path the path for the node; may not be null
+ * @param properties the properties for the node; may be null if there are no properties
+ * @return true if the children of the node should be recorded, or false if this new node is as deep as the recording should
+ * go
+ */
+ boolean record( Path path,
+ Iterator<Property> properties );
+
+ /**
+ * Sets the properties of the supplied node.
+ * <p>
+ * If the supplied path is a relative path, it is assumed to be relative to the {@link ActsOnPath#getPath() branch root}. If
+ * the supplied path is an absolute path, it must be a {@link Path#isDecendantOf(Path) decendant} of the
+ * {@link ActsOnPath#getPath() branch root}; if not, this method returns false and ignores the call.
+ * </p>
+ * <p>
+ * This method should not be called multiple times with the same path. The behavior for such cases is not defined.
+ * </p>
+ *
+ * @param path the path for the node; may not be null
+ * @param properties the properties for the node; may be null if there are no properties
+ * @return true if the children of the node should be recorded, or false if this new node is as deep as the recording should
+ * go
+ */
+ boolean record( Path path,
+ Property... properties );
+
+}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -23,10 +23,10 @@
import java.util.List;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
/**
* @author Randall Hauch
@@ -39,20 +39,23 @@
private static final long serialVersionUID = -5452285887178397354L;
private final Path path;
private final List<Property> properties;
- private CachePolicy cachePolicy;
- private long timeLoaded;
+ private final NodeConflictBehavior conflictBehavior;
/**
* @param path the path to the node; may not be null
* @param properties the properties of the node; may not be null
+ * @param conflictBehavior the desired behavior when a node exists at the <code>path</code>; may not be null
*/
public BasicCreateNodeCommand( Path path,
- List<Property> properties ) {
+ List<Property> properties,
+ NodeConflictBehavior conflictBehavior ) {
super();
assert path != null;
assert properties != null;
+ assert conflictBehavior != null;
this.properties = properties;
this.path = path;
+ this.conflictBehavior = conflictBehavior;
}
/**
@@ -72,29 +75,36 @@
/**
* {@inheritDoc}
*/
- public CachePolicy getCachePolicy() {
- return cachePolicy;
+ public NodeConflictBehavior getConflictBehavior() {
+ return this.conflictBehavior;
}
/**
* {@inheritDoc}
*/
- public long getTimeLoaded() {
- return timeLoaded;
+ public int compareTo( CreateNodeCommand that ) {
+ if (this == that) return 0;
+ return this.path.compareTo(that.getPath());
}
/**
- * @param timeLoaded Sets timeLoaded to the specified value.
+ * {@inheritDoc}
*/
- public void setTimeLoaded( long timeLoaded ) {
- this.timeLoaded = timeLoaded;
+ @Override
+ public int hashCode() {
+ return path.hashCode();
}
/**
* {@inheritDoc}
*/
- public void setCachePolicy( CachePolicy cachePolicy ) {
- this.cachePolicy = cachePolicy;
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof CreateNodeCommand) {
+ CreateNodeCommand that = (CreateNodeCommand)obj;
+ return this.path.equals(that.getPath());
+ }
+ return false;
}
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -22,13 +22,12 @@
package org.jboss.dna.spi.graph.commands.impl;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
/**
@@ -40,7 +39,7 @@
/**
*/
private static final long serialVersionUID = -7816393217506909521L;
- private final Map<Name, List<Object>> propertyValues = new HashMap<Name, List<Object>>();
+ private final Map<Name, Property> properties = new HashMap<Name, Property>();
private final Path path;
private CachePolicy cachePolicy;
private long timeLoaded;
@@ -57,31 +56,19 @@
/**
* {@inheritDoc}
*/
- public void setProperty( Name propertyName, Object... values ) {
- setProperty(propertyValues, propertyName, values);
+ public void setProperty( Property property ) {
+ if (property != null) {
+ properties.put(property.getName(), property);
+ }
}
/**
- * {@inheritDoc}
- */
- public void setProperty( Name propertyName, Iterable<?> values ) {
- setProperty(propertyValues, propertyName, values);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setProperty( Name propertyName, Iterator<?> values ) {
- setProperty(propertyValues, propertyName, values);
- }
-
- /**
* Get the property values that were added to the command
*
* @return the map of property name to values
*/
- public Map<Name, List<Object>> getPropertyValues() {
- return this.propertyValues;
+ public Iterable<Property> getProperties() {
+ return this.properties.values();
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -24,6 +24,7 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.commands.MoveBranchCommand;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
/**
* @author Randall Hauch
@@ -33,17 +34,23 @@
private final Path oldPath;
private final Path newPath;
+ private final NodeConflictBehavior conflictBehavior;
/**
* @param oldPath the path to the original; may not be null
* @param newPath the path to the new location; may not be null
+ * @param conflictBehavior the desired behavior when a node exists at the <code>path</code>; may not be null
*/
- public BasicMoveBranchCommand( Path oldPath, Path newPath ) {
+ public BasicMoveBranchCommand( Path oldPath,
+ Path newPath,
+ NodeConflictBehavior conflictBehavior ) {
super();
assert oldPath != null;
assert newPath != null;
+ assert conflictBehavior != null;
this.oldPath = oldPath;
this.newPath = newPath;
+ this.conflictBehavior = conflictBehavior;
}
/**
@@ -60,4 +67,11 @@
return newPath;
}
+ /**
+ * {@inheritDoc}
+ */
+ public NodeConflictBehavior getConflictBehavior() {
+ return conflictBehavior;
+ }
+
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicRecordBranchCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicRecordBranchCommand.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicRecordBranchCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -0,0 +1,185 @@
+/*
+ * 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.graph.commands.impl;
+
+import java.util.ArrayList;
+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.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
+import org.jboss.dna.spi.graph.commands.RecordBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicRecordBranchCommand extends BasicGraphCommand implements RecordBranchCommand {
+
+ private final int maxDepth;
+ private final Path topOfBranch;
+ private final List<CreateNodeCommand> commands;
+ private final NodeConflictBehavior conflictBehavior;
+
+ /**
+ * @param topOfBranch the top node in the branch that is to be recorded; may not be null
+ * @param conflictBehavior the desired behavior when a node exists at the <code>path</code>; may not be null
+ */
+ public BasicRecordBranchCommand( Path topOfBranch,
+ NodeConflictBehavior conflictBehavior ) {
+ this(topOfBranch, conflictBehavior, null, Integer.MAX_VALUE);
+ }
+
+ /**
+ * @param topOfBranch the top node in the branch that is to be recorded; may not be null
+ * @param conflictBehavior the desired behavior when a node exists at the <code>path</code>; may not be null
+ * @param commands the list into which the {@link CreateNodeCommand}s should be place; may be null
+ */
+ public BasicRecordBranchCommand( Path topOfBranch,
+ NodeConflictBehavior conflictBehavior,
+ List<CreateNodeCommand> commands ) {
+ this(topOfBranch, conflictBehavior, commands, Integer.MAX_VALUE);
+ }
+
+ /**
+ * @param topOfBranch the top node in the branch that is to be recorded; may not be null
+ * @param conflictBehavior the desired behavior when a node exists at the <code>path</code>; may not be null
+ * @param commands the list into which the {@link CreateNodeCommand}s should be place; may be null
+ * @param maxDepthOfBranch the maximum depth of the branch that should be recorded, or {@link Integer#MAX_VALUE} if there is
+ * no limit
+ */
+ public BasicRecordBranchCommand( Path topOfBranch,
+ NodeConflictBehavior conflictBehavior,
+ List<CreateNodeCommand> commands,
+ int maxDepthOfBranch ) {
+ super();
+ assert topOfBranch != null;
+ assert conflictBehavior != null;
+ assert maxDepthOfBranch > 0;
+ this.topOfBranch = topOfBranch;
+ this.maxDepth = maxDepthOfBranch;
+ this.conflictBehavior = conflictBehavior;
+ this.commands = commands != null ? commands : new LinkedList<CreateNodeCommand>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return topOfBranch;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean record( Path path,
+ Iterable<Property> properties ) {
+ // Determine the relative path for this node ...
+ if (path.isAbsolute()) {
+ if (!path.isDecendantOf(this.topOfBranch)) return false;
+ path = path.relativeTo(this.topOfBranch);
+ }
+ int numberOfLevelsLeft = maxDepth - path.size();
+ if (numberOfLevelsLeft < 0) return false;
+ List<Property> propertyList = Collections.emptyList();
+ if (properties != null) {
+ if (properties instanceof List) {
+ propertyList = (List<Property>)properties;
+ } else {
+ propertyList = new LinkedList<Property>();
+ for (Property property : properties) {
+ propertyList.add(property);
+ }
+ }
+ }
+ record(new BasicCreateNodeCommand(path, propertyList, this.conflictBehavior));
+ return numberOfLevelsLeft > 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean record( Path path,
+ Iterator<Property> properties ) {
+ int numberOfLevelsLeft = maxDepth - path.size();
+ if (numberOfLevelsLeft < 0) return false;
+ List<Property> propertyList = Collections.emptyList();
+ if (properties != null) {
+ propertyList = new LinkedList<Property>();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ propertyList.add(property);
+ }
+ }
+ record(new BasicCreateNodeCommand(path, propertyList, this.conflictBehavior));
+ return numberOfLevelsLeft > 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean record( Path path,
+ Property... properties ) {
+ int numberOfLevelsLeft = maxDepth - path.size();
+ if (numberOfLevelsLeft < 0) return false;
+ List<Property> propertyList = Collections.emptyList();
+ if (properties != null) {
+ propertyList = new ArrayList<Property>(properties.length);
+ for (Property property : properties) {
+ propertyList.add(property);
+ }
+ }
+ record(new BasicCreateNodeCommand(path, propertyList, this.conflictBehavior));
+ return numberOfLevelsLeft > 0;
+ }
+
+ /**
+ * @return maxDepth
+ */
+ public int getMaxDepth() {
+ return this.maxDepth;
+ }
+
+ /**
+ * Method that is called whenver a node is recorded by the recipient of this command. This implementation simply records it,
+ * but subclasses can override this method to respond immediately.
+ *
+ * @param command the command containing the node information; never null and always above the
+ * {@link #getMaxDepth() maximum depth}.
+ */
+ protected void record( CreateNodeCommand command ) {
+ commands.add(command);
+ }
+
+ /**
+ * Return the commands to create the nodes, in the order they were recorded.
+ *
+ * @return the mutable list of {@link CreateNodeCommand create node commands}; never null
+ */
+ public List<CreateNodeCommand> getCreateNodeCommands() {
+ return this.commands;
+ }
+}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -23,7 +23,6 @@
import java.util.List;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
@@ -39,14 +38,13 @@
private static final long serialVersionUID = -2693642411179501304L;
private final Path path;
private final List<Property> properties;
- private CachePolicy cachePolicy;
- private long timeLoaded;
/**
* @param path the path to the node; may not be null
* @param properties the properties of the node; may not be null
*/
- public BasicSetPropertiesCommand( Path path, List<Property> properties ) {
+ public BasicSetPropertiesCommand( Path path,
+ List<Property> properties ) {
super();
assert path != null;
assert properties != null;
@@ -67,33 +65,4 @@
public Iterable<Property> getProperties() {
return properties;
}
-
- /**
- * {@inheritDoc}
- */
- public CachePolicy getCachePolicy() {
- return cachePolicy;
- }
-
- /**
- * {@inheritDoc}
- */
- public long getTimeLoaded() {
- return timeLoaded;
- }
-
- /**
- * @param timeLoaded Sets timeLoaded to the specified value.
- */
- public void setTimeLoaded( long timeLoaded ) {
- this.timeLoaded = timeLoaded;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setCachePolicy( CachePolicy cachePolicy ) {
- this.cachePolicy = cachePolicy;
- }
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -46,13 +46,6 @@
NamespaceRegistry getNamespaceRegistry();
/**
- * Return the repository source against which this environment applies.
- *
- * @return the repository source; never null
- */
- RepositorySource getRepositorySource();
-
- /**
* Get the factory for creating {@link Property} objects.
*
* @return the property factory; never null
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -33,6 +33,11 @@
* leaving that entirely to the implementation classes.
* </p>
* <p>
+ * Implementations should also provide a no-arg constructor so that it is possible to easily create instances and initialize using
+ * the standard getters and setters. One example where this is required is when a RepositorySource instance is recorded in a
+ * repository (e.g., in a configuration area), and needs to be reinstantiated.
+ * </p>
+ * <p>
* Objects that implement this <code>RepositorySource</code> interface are typically registered with a naming service such as
* Java Naming and Directory Interface<sup><font size=-3>TM</font></sup> (JNDI). This interface extends both
* {@link Referenceable} and {@link Serializable} so that such objects can be stored in any JNDI naming context and enable proper
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -30,6 +30,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -116,4 +117,215 @@
return create(value.toString());
}
+ protected abstract T[] createEmptyArray( int length );
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( BigDecimal[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( boolean[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( byte[][] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Calendar[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Date[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( double[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( float[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( int[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( long[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Name[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Object[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Path[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( Reference[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( String[] values,
+ TextDecoder decoder ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i], decoder);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( String[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T[] create( URI[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -25,8 +25,6 @@
import java.util.NoSuchElementException;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -36,12 +34,9 @@
/**
* @param name
- * @param type
- * @param definitionName
- * @param valueFactories
*/
- public BasicEmptyProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
- super(name, type, definitionName, valueFactories);
+ public BasicEmptyProperty( Name name ) {
+ super(name);
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -25,8 +25,6 @@
import java.util.List;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -38,13 +36,11 @@
/**
* @param name
- * @param type
- * @param definitionName
- * @param valueFactories
* @param values
*/
- public BasicMultiValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, List<Object> values ) {
- super(name, type, definitionName, valueFactories);
+ public BasicMultiValueProperty( Name name,
+ List<Object> values ) {
+ super(name);
this.values = values;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -30,6 +30,7 @@
/**
* A basic implementation of {@link Path.Segment}.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -54,7 +55,8 @@
* @param index the segment index
* @throws IllegalArgumentException if the name is null or if the index is invalid
*/
- public BasicPathSegment( Name name, int index ) {
+ public BasicPathSegment( Name name,
+ int index ) {
ArgCheck.isNotNull(name, "name");
ArgCheck.isNotLessThan(index, Path.NO_INDEX, "index");
this.name = name;
@@ -142,6 +144,13 @@
/**
* {@inheritDoc}
*/
+ public String getUnencodedString() {
+ return getString(Path.NO_OP_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String getString() {
return getString(Path.DEFAULT_ENCODER);
}
@@ -168,7 +177,8 @@
/**
* {@inheritDoc}
*/
- public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ public String getString( NamespaceRegistry namespaceRegistry,
+ TextEncoder encoder ) {
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
if (encoder == null) encoder = Path.DEFAULT_ENCODER;
String encodedName = this.getName().getString(namespaceRegistry, encoder);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -21,19 +21,10 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.math.BigDecimal;
-import java.net.URI;
import java.util.Iterator;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.spi.graph.Binary;
-import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.Reference;
-import org.jboss.dna.spi.graph.ValueFactories;
-import org.jboss.dna.spi.graph.ValueFactory;
/**
* @author Randall Hauch
@@ -42,21 +33,12 @@
public abstract class BasicProperty implements Property {
private final Name name;
- private final Name definitionName;
- private final PropertyType type;
- private final ValueFactories factories;
/**
* @param name
- * @param type
- * @param definitionName
- * @param valueFactories
*/
- public BasicProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
+ public BasicProperty( Name name ) {
this.name = name;
- this.type = type;
- this.definitionName = definitionName;
- this.factories = valueFactories;
}
/**
@@ -69,97 +51,6 @@
/**
* {@inheritDoc}
*/
- public Name getDefinitionName() {
- return definitionName;
- }
-
- /**
- * {@inheritDoc}
- */
- public PropertyType getPropertyType() {
- return type;
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Binary> getBinaryValues() {
- return new ValueIterator<Binary>(factories.getBinaryFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Boolean> getBooleanValues() {
- return new ValueIterator<Boolean>(factories.getBooleanFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<DateTime> getDateValues() {
- return new ValueIterator<DateTime>(factories.getDateFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<BigDecimal> getDecimalValues() {
- return new ValueIterator<BigDecimal>(factories.getDecimalFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Double> getDoubleValues() {
- return new ValueIterator<Double>(factories.getDoubleFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Long> getLongValues() {
- return new ValueIterator<Long>(factories.getLongFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Name> getNameValues() {
- return new ValueIterator<Name>(factories.getNameFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Path> getPathValues() {
- return new ValueIterator<Path>(factories.getPathFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Reference> getReferenceValues() {
- return new ValueIterator<Reference>(factories.getReferenceFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<String> getStringValues() {
- return new ValueIterator<String>(factories.getStringFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<URI> getUriValues() {
- return new ValueIterator<URI>(factories.getUriFactory(), iterator());
- }
-
- /**
- * {@inheritDoc}
- */
public Iterator<?> getValues() {
return iterator();
}
@@ -167,39 +58,6 @@
/**
* {@inheritDoc}
*/
- public Iterator<?> getValues( PropertyType type ) {
- switch (type) {
- case BINARY:
- return getBinaryValues();
- case BOOLEAN:
- return getBooleanValues();
- case DATE:
- return getDateValues();
- case DECIMAL:
- return getDecimalValues();
- case DOUBLE:
- return getDoubleValues();
- case LONG:
- return getLongValues();
- case NAME:
- return getNameValues();
- case OBJECT:
- return getValues();
- case PATH:
- return getPathValues();
- case REFERENCE:
- return getReferenceValues();
- case STRING:
- return getStringValues();
- case URI:
- return getUriValues();
- }
- return getValues(); // should never get here ...
- }
-
- /**
- * {@inheritDoc}
- */
public Object[] getValuesAsArray() {
if (size() == 0) return null;
Object[] results = new Object[size()];
@@ -236,7 +94,6 @@
if (obj instanceof Property) {
Property that = (Property)obj;
if (!this.getName().equals(that.getName())) return false;
- if (this.getPropertyType() != that.getPropertyType()) return false;
if (this.size() != that.size()) return false;
Iterator<?> thisIter = iterator();
Iterator<?> thatIter = that.iterator();
@@ -254,40 +111,4 @@
}
return false;
}
-
- protected class ValueIterator<T> implements Iterator<T> {
-
- private final ValueFactory<T> factory;
- private final Iterator<Object> values;
-
- protected ValueIterator( ValueFactory<T> factory, Iterator<Object> values ) {
- assert factory != null;
- assert values != null;
- this.factory = factory;
- this.values = values;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasNext() {
- return values.hasNext();
- }
-
- /**
- * {@inheritDoc}
- */
- public T next() {
- return factory.create(values.next());
- }
-
- /**
- * {@inheritDoc}
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- }
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -52,44 +52,71 @@
/**
* {@inheritDoc}
*/
- public Property create( Name name, PropertyType type, Name definitionName, Object... values ) {
+ public Property create( Name name,
+ Iterable<?> values ) {
+ return create(name, PropertyType.OBJECT, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property create( Name name,
+ Iterator<?> values ) {
+ return create(name, PropertyType.OBJECT, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property create( Name name,
+ Object... values ) {
+ return create(name, PropertyType.OBJECT, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property create( Name name,
+ PropertyType desiredType,
+ Object... values ) {
ArgCheck.isNotNull(name, "name");
- ArgCheck.isNotNull(type, "type");
if (values == null || values.length == 0) {
- return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ return new BasicEmptyProperty(name);
}
final int len = values.length;
- final ValueFactory<?> factory = factories.getValueFactory(type);
+ if (desiredType == null) desiredType = PropertyType.OBJECT;
+ final ValueFactory<?> factory = factories.getValueFactory(desiredType);
if (values.length == 1) {
Object value = values[0];
// Check whether the sole value was a collection ...
if (value instanceof Collection) {
// The single value is a collection, so create property with the collection's contents ...
- return create(name, type, definitionName, (Collection<?>)value);
+ return create(name, (Collection<?>)value);
}
value = factory.create(values[0]);
- return new BasicSingleValueProperty(name, type, definitionName, this.factories, value);
+ return new BasicSingleValueProperty(name, value);
}
List<Object> valueList = new ArrayList<Object>(len);
for (int i = 0; i != len; ++i) {
Object value = factory.create(values[i]);
valueList.add(value);
}
- return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ return new BasicMultiValueProperty(name, valueList);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings( "unchecked" )
- public Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values ) {
+ public Property create( Name name,
+ PropertyType desiredType,
+ Iterable<?> values ) {
ArgCheck.isNotNull(name, "name");
- ArgCheck.isNotNull(type, "type");
List<Object> valueList = null;
if (values instanceof Collection) {
Collection<Object> originalValues = (Collection<Object>)values;
if (originalValues.isEmpty()) {
- return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ return new BasicEmptyProperty(name);
}
valueList = new ArrayList<Object>(originalValues.size());
} else {
@@ -97,39 +124,42 @@
valueList = new ArrayList<Object>();
}
// Copy the values, ensuring that the values are the correct type ...
- final ValueFactory<?> factory = factories.getValueFactory(type);
+ if (desiredType == null) desiredType = PropertyType.OBJECT;
+ final ValueFactory<?> factory = factories.getValueFactory(desiredType);
for (Object value : values) {
valueList.add(factory.create(value));
}
if (valueList.isEmpty()) { // may not have been a collection earlier
- return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ return new BasicEmptyProperty(name);
}
if (valueList.size() == 1) {
- return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+ return new BasicSingleValueProperty(name, valueList.get(0));
}
- return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ return new BasicMultiValueProperty(name, valueList);
}
/**
* {@inheritDoc}
*/
- public Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values ) {
+ public Property create( Name name,
+ PropertyType desiredType,
+ Iterator<?> values ) {
ArgCheck.isNotNull(name, "name");
- ArgCheck.isNotNull(type, "type");
final List<Object> valueList = new ArrayList<Object>();
- final ValueFactory<?> factory = factories.getValueFactory(type);
+ if (desiredType == null) desiredType = PropertyType.OBJECT;
+ final ValueFactory<?> factory = factories.getValueFactory(desiredType);
while (values.hasNext()) {
Object value = values.next();
value = factory.create(value);
valueList.add(value);
}
if (valueList.isEmpty()) {
- return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ return new BasicEmptyProperty(name);
}
if (valueList.size() == 1) {
- return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+ return new BasicSingleValueProperty(name, valueList.get(0));
}
- return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ return new BasicMultiValueProperty(name, valueList);
}
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -25,8 +25,6 @@
import java.util.NoSuchElementException;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -38,13 +36,11 @@
/**
* @param name
- * @param type
- * @param definitionName
- * @param valueFactories
* @param value
*/
- public BasicSingleValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, Object value ) {
- super(name, type, definitionName, valueFactories);
+ public BasicSingleValueProperty( Name name,
+ Object value ) {
+ super(name);
this.value = value;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -199,4 +199,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Boolean[] createEmptyArray( int length ) {
+ return new Boolean[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -195,4 +195,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected BigDecimal[] createEmptyArray( int length ) {
+ return new BigDecimal[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -202,4 +202,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Double[] createEmptyArray( int length ) {
+ return new Double[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -193,8 +193,9 @@
byte[] value = IoUtil.readBytes(stream);
return create(value);
} catch (IOException err) {
- throw new IoException(SpiI18n.errorConvertingIo.text(InputStream.class.getSimpleName(),
- Binary.class.getSimpleName()), err);
+ throw new IoException(
+ SpiI18n.errorConvertingIo.text(InputStream.class.getSimpleName(), Binary.class.getSimpleName()),
+ err);
}
}
@@ -209,8 +210,15 @@
String value = IoUtil.read(reader);
return create(this.getStringValueFactory().create(value));
} catch (IOException err) {
- throw new IoException(SpiI18n.errorConvertingIo.text(Reader.class.getSimpleName(),
- Binary.class.getSimpleName()), err);
+ throw new IoException(SpiI18n.errorConvertingIo.text(Reader.class.getSimpleName(), Binary.class.getSimpleName()), err);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Binary[] createEmptyArray( int length ) {
+ return new Binary[length];
+ }
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -247,4 +247,12 @@
return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond,
timeZoneId);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected DateTime[] createEmptyArray( int length ) {
+ return new DateTime[length];
+ }
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -196,4 +196,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Long[] createEmptyArray( int length ) {
+ return new Long[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -297,4 +297,12 @@
public NamespaceRegistry getNamespaceRegistry() {
return namespaceRegistry;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Name[] createEmptyArray( int length ) {
+ return new Name[length];
+ }
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -185,4 +185,12 @@
return getBinaryValueFactory().create(reader, approximateLength);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object[] createEmptyArray( int length ) {
+ return new Object[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -95,9 +95,9 @@
* {@inheritDoc}
* </p>
*
- * @see org.jboss.dna.spi.graph.PathFactory#create()
+ * @see org.jboss.dna.spi.graph.PathFactory#createRootPath()
*/
- public Path create() {
+ public Path createRootPath() {
return BasicPath.ROOT;
}
@@ -251,7 +251,7 @@
/**
* {@inheritDoc}
*/
- public Path create( Name... segmentNames ) {
+ public Path createAbsolutePath( Name... segmentNames ) {
if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
for (Name segmentName : segmentNames) {
@@ -266,7 +266,7 @@
/**
* {@inheritDoc}
*/
- public Path create( Segment... segments ) {
+ public Path createAbsolutePath( Segment... segments ) {
if (segments == null || segments.length == 0) return BasicPath.ROOT;
List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
for (Segment segment : segments) {
@@ -494,4 +494,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Path[] createEmptyArray( int length ) {
+ return new Path[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -212,8 +212,9 @@
String.class.getSimpleName(),
value), err);
} catch (IOException err) {
- throw new IoException(SpiI18n.errorConvertingIo.text(InputStream.class.getSimpleName(),
- String.class.getSimpleName()), err);
+ throw new IoException(
+ SpiI18n.errorConvertingIo.text(InputStream.class.getSimpleName(), String.class.getSimpleName()),
+ err);
}
}
@@ -226,9 +227,16 @@
try {
return IoUtil.read(reader);
} catch (IOException err) {
- throw new IoException(SpiI18n.errorConvertingIo.text(Reader.class.getSimpleName(),
- String.class.getSimpleName()), err);
+ throw new IoException(SpiI18n.errorConvertingIo.text(Reader.class.getSimpleName(), String.class.getSimpleName()), err);
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String[] createEmptyArray( int length ) {
+ return new String[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -214,4 +214,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected URI[] createEmptyArray( int length ) {
+ return new URI[length];
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -207,4 +207,12 @@
return create(getStringValueFactory().create(reader, approximateLength));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Reference[] createEmptyArray( int length ) {
+ return new Reference[length];
+ }
+
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -44,7 +44,7 @@
/**
*/
private static final long serialVersionUID = -2756725117087437347L;
- private final String identifier;
+ private String name;
private final AtomicInteger retryLimit = new AtomicInteger(0);
private final AtomicInteger connectionsOpenedCount = new AtomicInteger(0);
private final AtomicInteger connectionsClosedCount = new AtomicInteger(0);
@@ -56,17 +56,24 @@
private CachePolicy defaultCachePolicy;
public TimeDelayingRepositorySource( String identifier ) {
- this.identifier = identifier;
+ this.name = identifier;
}
/**
* {@inheritDoc}
*/
public String getName() {
- return this.identifier;
+ return this.name;
}
/**
+ * @param name the identifier
+ */
+ public void setName( String name ) {
+ this.name = name;
+ }
+
+ /**
* {@inheritDoc}
*/
public int getRetryLimit() {
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-13 18:16:28 UTC (rev 287)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-13 18:25:41 UTC (rev 288)
@@ -126,6 +126,14 @@
int approximateLength ) {
return null;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String[] createEmptyArray( int length ) {
+ return new String[length];
+ }
}
private AbstractValueFactory<String> factory;
15 years, 10 months
DNA SVN: r287 - in trunk/dna-common/src: test/java/org/jboss/dna/common/util and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-13 14:16:28 -0400 (Fri, 13 Jun 2008)
New Revision: 287
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/Reflection.java
trunk/dna-common/src/test/java/org/jboss/dna/common/util/ReflectionTest.java
Log:
Added a reflection utility.
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/util/Reflection.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/Reflection.java (rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/Reflection.java 2008-06-13 18:16:28 UTC (rev 287)
@@ -0,0 +1,404 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * Utility class for working reflectively with objects.
+ *
+ * @author Randall Hauch
+ */
+public class Reflection {
+
+ /**
+ * Build the list of classes that correspond to the list of argument objects.
+ *
+ * @param arguments the list of argument objects.
+ * @return the list of Class instances that correspond to the list of argument objects; the resulting list will contain a null
+ * element for each null argument.
+ */
+ public static Class<?>[] buildArgumentClasses( Object... arguments ) {
+ if (arguments == null || arguments.length == 0) return EMPTY_CLASS_ARRAY;
+ Class<?>[] result = new Class<?>[arguments.length];
+ int i = 0;
+ for (Object argument : arguments) {
+ if (argument != null) {
+ result[i] = argument.getClass();
+ } else {
+ result[i] = null;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Build the list of classes that correspond to the list of argument objects.
+ *
+ * @param arguments the list of argument objects.
+ * @return the list of Class instances that correspond to the list of argument objects; the resulting list will contain a null
+ * element for each null argument.
+ */
+ public static List<Class<?>> buildArgumentClassList( Object... arguments ) {
+ if (arguments == null || arguments.length == 0) return Collections.emptyList();
+ List<Class<?>> result = new ArrayList<Class<?>>(arguments.length);
+ for (Object argument : arguments) {
+ if (argument != null) {
+ result.add(argument.getClass());
+ } else {
+ result.add(null);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Convert any argument classes to primitives.
+ *
+ * @param arguments the list of argument classes.
+ * @return the list of Class instances in which any classes that could be represented by primitives (e.g., Boolean) were
+ * replaced with the primitive classes (e.g., Boolean.TYPE).
+ */
+ public static List<Class<?>> convertArgumentClassesToPrimitives( Class<?>... arguments ) {
+ if (arguments == null || arguments.length == 0) return Collections.emptyList();
+ List<Class<?>> result = new ArrayList<Class<?>>(arguments.length);
+ for (Class<?> clazz : arguments) {
+ if (clazz == Boolean.class) clazz = Boolean.TYPE;
+ else if (clazz == Character.class) clazz = Character.TYPE;
+ else if (clazz == Byte.class) clazz = Byte.TYPE;
+ else if (clazz == Short.class) clazz = Short.TYPE;
+ else if (clazz == Integer.class) clazz = Integer.TYPE;
+ else if (clazz == Long.class) clazz = Long.TYPE;
+ else if (clazz == Float.class) clazz = Float.TYPE;
+ else if (clazz == Double.class) clazz = Double.TYPE;
+ else if (clazz == Void.class) clazz = Void.TYPE;
+ result.add(clazz);
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the name of the class. The result will be the fully-qualified class name, or the readable form for arrays and
+ * primitive types.
+ *
+ * @param clazz the class for which the class name is to be returned.
+ * @return the readable name of the class.
+ */
+ public static String getClassName( final Class<?> clazz ) {
+ final String fullName = clazz.getName();
+ final int fullNameLength = fullName.length();
+
+ // Check for array ('[') or the class/interface marker ('L') ...
+ int numArrayDimensions = 0;
+ while (numArrayDimensions < fullNameLength) {
+ final char c = fullName.charAt(numArrayDimensions);
+ if (c != '[') {
+ String name = null;
+ // Not an array, so it must be one of the other markers ...
+ switch (c) {
+ case 'L': {
+ name = fullName.subSequence(numArrayDimensions + 1, fullNameLength).toString();
+ break;
+ }
+ case 'B': {
+ name = "byte";
+ break;
+ }
+ case 'C': {
+ name = "char";
+ break;
+ }
+ case 'D': {
+ name = "double";
+ break;
+ }
+ case 'F': {
+ name = "float";
+ break;
+ }
+ case 'I': {
+ name = "int";
+ break;
+ }
+ case 'J': {
+ name = "long";
+ break;
+ }
+ case 'S': {
+ name = "short";
+ break;
+ }
+ case 'Z': {
+ name = "boolean";
+ break;
+ }
+ case 'V': {
+ name = "void";
+ break;
+ }
+ default: {
+ name = fullName.subSequence(numArrayDimensions, fullNameLength).toString();
+ }
+ }
+ if (numArrayDimensions == 0) {
+ // No array markers, so just return the name ...
+ return name;
+ }
+ // Otherwise, add the array markers and the name ...
+ if (numArrayDimensions < BRACKETS_PAIR.length) {
+ name = name + BRACKETS_PAIR[numArrayDimensions];
+ } else {
+ for (int i = 0; i < numArrayDimensions; i++) {
+ name = name + BRACKETS_PAIR[1];
+ }
+ }
+ return name;
+ }
+ ++numArrayDimensions;
+ }
+
+ return fullName;
+ }
+
+ private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[] {};
+ private static final String[] BRACKETS_PAIR = new String[] {"", "[]", "[][]", "[][][]", "[][][][]", "[][][][][]"};
+
+ private Class<?> targetClass;
+ private Map<String, LinkedList<Method>> methodMap = null; // used for the brute-force method finder
+
+ /**
+ * Construct a Reflection instance that cache's some information about the target class. The target class is the Class object
+ * upon which the methods will be found.
+ *
+ * @param targetClass the target class
+ * @throws IllegalArgumentException if the target class is null
+ */
+ public Reflection( Class<?> targetClass ) {
+ ArgCheck.isNotNull(targetClass, "targetClass");
+ this.targetClass = targetClass;
+ }
+
+ /**
+ * Return the class that is the target for the reflection methods.
+ *
+ * @return the target class
+ */
+ public Class<?> getTargetClass() {
+ return this.targetClass;
+ }
+
+ /**
+ * Find the method on the target class that matches the supplied method name.
+ *
+ * @param methodName the name of the method that is to be found.
+ * @return the Method objects that have a matching name, or an empty array if there are no methods that have a matching name.
+ */
+ public Method[] findMethods( String methodName ) {
+ return findMethods(Pattern.compile(methodName));
+ }
+
+ /**
+ * Find the method on the target class that matches the supplied method name.
+ *
+ * @param methodNamePattern the regular expression pattern for the name of the method that is to be found.
+ * @return the Method objects that have a matching name, or an empty array if there are no methods that have a matching name.
+ */
+ public Method[] findMethods( Pattern methodNamePattern ) {
+ final Method[] allMethods = this.targetClass.getMethods();
+ final List<Method> result = new ArrayList<Method>();
+ for (int i = 0; i < allMethods.length; i++) {
+ final Method m = allMethods[i];
+ if (methodNamePattern.matcher(m.getName()).matches()) {
+ result.add(m);
+ }
+ }
+ return result.toArray(new Method[result.size()]);
+ }
+
+ /**
+ * Find the method on the target class that matches the supplied method name.
+ *
+ * @param methodName the name of the method that is to be found.
+ * @return the first Method object found that has a matching name, or null if there are no methods that have a matching name.
+ */
+ public Method findFirstMethod( String methodName ) {
+ return findFirstMethod(Pattern.compile(methodName));
+ }
+
+ /**
+ * Find the method on the target class that matches the supplied method name.
+ *
+ * @param methodNamePattern the regular expression pattern for the name of the method that is to be found.
+ * @return the first Method object found that has a matching name, or null if there are no methods that have a matching name.
+ */
+ public Method findFirstMethod( Pattern methodNamePattern ) {
+ final Method[] allMethods = this.targetClass.getMethods();
+ for (int i = 0; i < allMethods.length; i++) {
+ final Method m = allMethods[i];
+ if (methodNamePattern.matcher(m.getName()).matches()) {
+ return m;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the best method on the target class that matches the signature specified with the specified name and the list of
+ * arguments. This method first attempts to find the method with the specified arguments; if no such method is found, a
+ * NoSuchMethodException is thrown.
+ * <P>
+ * This method is unable to find methods with signatures that include both primitive arguments <i>and</i> arguments that are
+ * instances of <code>Number</code> or its subclasses.
+ *
+ * @param methodName the name of the method that is to be invoked.
+ * @param arguments the array of Object instances that correspond to the arguments passed to the method.
+ * @return the Method object that references the method that satisfies the requirements, or null if no satisfactory method
+ * could be found.
+ * @throws NoSuchMethodException if a matching method is not found.
+ * @throws SecurityException if access to the information is denied.
+ */
+ public Method findBestMethodOnTarget( String methodName,
+ Object... arguments ) throws NoSuchMethodException, SecurityException {
+ Class<?>[] argumentClasses = buildArgumentClasses(arguments);
+ return findBestMethodWithSignature(methodName, argumentClasses);
+ }
+
+ /**
+ * Find the best method on the target class that matches the signature specified with the specified name and the list of
+ * argument classes. This method first attempts to find the method with the specified argument classes; if no such method is
+ * found, a NoSuchMethodException is thrown.
+ *
+ * @param methodName the name of the method that is to be invoked.
+ * @param argumentsClasses the list of Class instances that correspond to the classes for each argument passed to the method.
+ * @return the Method object that references the method that satisfies the requirements, or null if no satisfactory method
+ * could be found.
+ * @throws NoSuchMethodException if a matching method is not found.
+ * @throws SecurityException if access to the information is denied.
+ */
+ public Method findBestMethodWithSignature( String methodName,
+ Class<?>... argumentsClasses ) throws NoSuchMethodException, SecurityException {
+
+ // Attempt to find the method
+ Method result;
+
+ // -------------------------------------------------------------------------------
+ // First try to find the method with EXACTLY the argument classes as specified ...
+ // -------------------------------------------------------------------------------
+ Class<?>[] classArgs = null;
+ try {
+ classArgs = argumentsClasses != null ? argumentsClasses : new Class[] {};
+ result = this.targetClass.getMethod(methodName, classArgs); // this may throw an exception if not found
+ return result;
+ } catch (NoSuchMethodException e) {
+ // No method found, so continue ...
+ }
+
+ // ---------------------------------------------------------------------------------------------
+ // Then try to find a method with the argument classes converted to a primitive, if possible ...
+ // ---------------------------------------------------------------------------------------------
+ List<Class<?>> argumentsClassList = convertArgumentClassesToPrimitives(argumentsClasses);
+ try {
+ classArgs = argumentsClassList.toArray(new Class[argumentsClassList.size()]);
+ result = this.targetClass.getMethod(methodName, classArgs); // this may throw an exception if not found
+ return result;
+ } catch (NoSuchMethodException e) {
+ // No method found, so continue ...
+ }
+
+ // ---------------------------------------------------------------------------------------------
+ // Still haven't found anything. So far, the "getMethod" logic only finds methods that EXACTLY
+ // match the argument classes (i.e., not methods declared with superclasses or interfaces of
+ // the arguments). There is no canned algorithm in Java to do this, so we have to brute-force it.
+ // The following algorithm will find the first method that matches by doing "instanceof", so it
+ // may not be the best method. Since there is some overhead to this algorithm, the first time
+ // caches some information in class members.
+ // ---------------------------------------------------------------------------------------------
+ Method method;
+ LinkedList<Method> methodsWithSameName;
+ if (this.methodMap == null) {
+ this.methodMap = new HashMap<String, LinkedList<Method>>();
+ Method[] methods = this.targetClass.getMethods();
+ for (int i = 0; i != methods.length; ++i) {
+ method = methods[i];
+ methodsWithSameName = this.methodMap.get(method.getName());
+ if (methodsWithSameName == null) {
+ methodsWithSameName = new LinkedList<Method>();
+ this.methodMap.put(method.getName(), methodsWithSameName);
+ }
+ methodsWithSameName.addFirst(method); // add lower methods first
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Find the set of methods with the same name (do this twice, once with the
+ // original methods and once with the primitives) ...
+ // ------------------------------------------------------------------------
+ // List argClass = argumentsClasses;
+ for (int j = 0; j != 2; ++j) {
+ methodsWithSameName = this.methodMap.get(methodName);
+ if (methodsWithSameName == null) {
+ throw new NoSuchMethodException(methodName);
+ }
+ Iterator<Method> iter = methodsWithSameName.iterator();
+ Class<?>[] args;
+ Class<?> clazz;
+ boolean allMatch;
+ while (iter.hasNext()) {
+ method = iter.next();
+ args = method.getParameterTypes();
+ if (args.length == argumentsClassList.size()) {
+ allMatch = true; // assume they all match
+ for (int i = 0; i < args.length; ++i) {
+ clazz = argumentsClassList.get(i);
+ if (clazz != null) {
+ if (!args[i].isAssignableFrom(clazz)) {
+ allMatch = false; // found one that doesn't match
+ i = args.length; // force completion
+ }
+ } else {
+ // a null is assignable for everything except a primitive
+ if (args[i].isPrimitive()) {
+ allMatch = false; // found one that doesn't match
+ i = args.length; // force completion
+ }
+ }
+ }
+ if (allMatch) {
+ return method;
+ }
+ }
+ }
+ }
+
+ throw new NoSuchMethodException(methodName);
+ }
+
+}
Property changes on: trunk/dna-common/src/main/java/org/jboss/dna/common/util/Reflection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/util/ReflectionTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/ReflectionTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/ReflectionTest.java 2008-06-13 18:16:28 UTC (rev 287)
@@ -0,0 +1,167 @@
+/*
+ * 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.util;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReflectionTest {
+
+ private String string;
+ private List<String> stringList;
+ private Reflection stringReflection;
+ private Reflection stringListReflection;
+
+ @Before
+ public void setUp() throws Exception {
+ string = "This is string #";
+ stringList = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i) {
+ stringList.add(string + (i + 1));
+ }
+ stringReflection = new Reflection(String.class);
+ stringListReflection = new Reflection(List.class);
+ }
+
+ @Test
+ public void shouldGetClassNameForClass() {
+ assertThat(Reflection.getClassName(String.class), is(String.class.getName()));
+ assertThat(Reflection.getClassName(ArrayList.class), is(ArrayList.class.getName()));
+ assertThat(Reflection.getClassName(StringUtil.class), is(StringUtil.class.getName()));
+ }
+
+ @Test
+ public void shouldGetClassNameOfInterface() {
+ assertThat(Reflection.getClassName(CharSequence.class), is(CharSequence.class.getName()));
+ assertThat(Reflection.getClassName(List.class), is(List.class.getName()));
+ }
+
+ @Test
+ public void shouldGetClassNameWithPrimitive() {
+ assertThat(Reflection.getClassName(Integer.TYPE), is("int"));
+ assertThat(Reflection.getClassName(Boolean.TYPE), is("boolean"));
+ assertThat(Reflection.getClassName(Long.TYPE), is("long"));
+ assertThat(Reflection.getClassName(Short.TYPE), is("short"));
+ assertThat(Reflection.getClassName(Float.TYPE), is("float"));
+ assertThat(Reflection.getClassName(Double.TYPE), is("double"));
+ assertThat(Reflection.getClassName(Character.TYPE), is("char"));
+ assertThat(Reflection.getClassName(Byte.TYPE), is("byte"));
+ assertThat(Reflection.getClassName(Void.TYPE), is("void"));
+ }
+
+ @Test
+ public void shouldGetClassNameWith1DPrimitiveArray() {
+ assertThat(Reflection.getClassName(new int[0].getClass()), is("int[]"));
+ assertThat(Reflection.getClassName(new boolean[0].getClass()), is("boolean[]"));
+ assertThat(Reflection.getClassName(new long[0].getClass()), is("long[]"));
+ assertThat(Reflection.getClassName(new short[0].getClass()), is("short[]"));
+ assertThat(Reflection.getClassName(new float[0].getClass()), is("float[]"));
+ assertThat(Reflection.getClassName(new double[0].getClass()), is("double[]"));
+ assertThat(Reflection.getClassName(new char[0].getClass()), is("char[]"));
+ assertThat(Reflection.getClassName(new byte[0].getClass()), is("byte[]"));
+ }
+
+ @Test
+ public void shouldGetClassNameWith2DPrimitiveArray() {
+ assertThat(Reflection.getClassName(new int[0][0].getClass()), is("int[][]"));
+ assertThat(Reflection.getClassName(new boolean[0][0].getClass()), is("boolean[][]"));
+ assertThat(Reflection.getClassName(new long[0][0].getClass()), is("long[][]"));
+ assertThat(Reflection.getClassName(new short[0][0].getClass()), is("short[][]"));
+ assertThat(Reflection.getClassName(new float[0][0].getClass()), is("float[][]"));
+ assertThat(Reflection.getClassName(new double[0][0].getClass()), is("double[][]"));
+ assertThat(Reflection.getClassName(new char[0][0].getClass()), is("char[][]"));
+ assertThat(Reflection.getClassName(new byte[0][0].getClass()), is("byte[][]"));
+ }
+
+ @Test
+ public void shouldGetClassNameWith3DPrimitiveArray() {
+ assertThat(Reflection.getClassName(new int[0][0][0].getClass()), is("int[][][]"));
+ assertThat(Reflection.getClassName(new boolean[0][0][0].getClass()), is("boolean[][][]"));
+ assertThat(Reflection.getClassName(new long[0][0][0].getClass()), is("long[][][]"));
+ assertThat(Reflection.getClassName(new short[0][0][0].getClass()), is("short[][][]"));
+ assertThat(Reflection.getClassName(new float[0][0][0].getClass()), is("float[][][]"));
+ assertThat(Reflection.getClassName(new double[0][0][0].getClass()), is("double[][][]"));
+ assertThat(Reflection.getClassName(new char[0][0][0].getClass()), is("char[][][]"));
+ assertThat(Reflection.getClassName(new byte[0][0][0].getClass()), is("byte[][][]"));
+ }
+
+ @Test
+ public void shouldGetClassNameWith8DPrimitiveArray() {
+ assertThat(Reflection.getClassName(new int[0][0][0][0][0][0][0][0].getClass()), is("int[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new boolean[0][0][0][0][0][0][0][0].getClass()), is("boolean[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new long[0][0][0][0][0][0][0][0].getClass()), is("long[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new short[0][0][0][0][0][0][0][0].getClass()), is("short[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new float[0][0][0][0][0][0][0][0].getClass()), is("float[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new double[0][0][0][0][0][0][0][0].getClass()), is("double[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new char[0][0][0][0][0][0][0][0].getClass()), is("char[][][][][][][][]"));
+ assertThat(Reflection.getClassName(new byte[0][0][0][0][0][0][0][0].getClass()), is("byte[][][][][][][][]"));
+ }
+
+ @Test
+ public void shouldHaveTargetClass() {
+ assertThat(stringReflection.getTargetClass() == String.class, is(true));
+ assertThat(stringListReflection.getTargetClass() == List.class, is(true));
+ }
+
+ @Test
+ public void shouldFindMethodsWithExactMatchingName() {
+ Method[] stringMethods = stringReflection.findMethods("indexOf");
+ assertThat(stringMethods.length, is(4));
+ for (Method method : stringMethods) {
+ assertThat(method.getName(), is("indexOf"));
+ }
+ stringMethods = stringReflection.findMethods("length");
+ assertThat(stringMethods.length, is(1));
+ for (Method method : stringMethods) {
+ assertThat(method.getName(), is("length"));
+ }
+ }
+
+ @Test
+ public void shouldFindMethodsWithNameMatchingRegularExpression() {
+ Method[] stringMethods = stringReflection.findMethods("indexO.");
+ assertThat(stringMethods.length, is(4));
+ for (Method method : stringMethods) {
+ assertThat(method.getName(), is("indexOf"));
+ }
+ stringMethods = stringReflection.findMethods(".+gth");
+ assertThat(stringMethods.length, is(1));
+ for (Method method : stringMethods) {
+ assertThat(method.getName(), is("length"));
+ }
+ }
+
+ @Test
+ public void shouldNotFindMethodsWhenThereAreNoMethodsWithThatName() {
+ assertThat(stringReflection.findMethods("size").length, is(0));
+ assertThat(stringListReflection.findMethods("argleBargle").length, is(0));
+ }
+
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/util/ReflectionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r286 - trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd.
by dna-commits@lists.jboss.org
Author: elvisisking
Date: 2008-06-13 11:19:31 -0400 (Fri, 13 Jun 2008)
New Revision: 286
Modified:
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g
Log:
DNA-73 Added copyright statement to grammar file so that it gets into the generated code.
Modified: trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g 2008-06-13 14:32:54 UTC (rev 285)
+++ trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g 2008-06-13 15:19:31 UTC (rev 286)
@@ -63,9 +63,55 @@
VALUE_CONSTRAINTS;
}
-@header {package org.jboss.dna.sequencer.cnd;}
+@header {
+/*
+ * 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.sequencer.cnd;
+}
-@lexer::header {package org.jboss.dna.sequencer.cnd;}
+@lexer::header {
+/*
+ * 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.sequencer.cnd;
+}
// Make the parser exit immediately upon recognition error by overriding the following two methods,
// and by altering how the parser responds to thrown exceptions.
15 years, 10 months
DNA SVN: r285 - in trunk/sequencers/dna-sequencer-cnd: .settings and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-13 10:32:54 -0400 (Fri, 13 Jun 2008)
New Revision: 285
Added:
trunk/sequencers/dna-sequencer-cnd/.settings/
trunk/sequencers/dna-sequencer-cnd/.settings/org.eclipse.jdt.core.prefs
Log:
Added project-specific Eclipse compiler preferences to remove warnings and compilation errors in the generated code. The generated source is in the 'target' folder, so cannot be changed post-generation. Also, having the 100+ errors and warnings show up in Eclipse would hide other warnings and errors in other projects that developers should see and eliminate.
Added: trunk/sequencers/dna-sequencer-cnd/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/.settings/org.eclipse.jdt.core.prefs 2008-06-13 14:32:54 UTC (rev 285)
@@ -0,0 +1,60 @@
+#Fri Jun 13 09:26:33 CDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=error
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=error
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=error
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=error
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=error
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=error
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeUncheckedExceptions=disabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error
Property changes on: trunk/sequencers/dna-sequencer-cnd/.settings/org.eclipse.jdt.core.prefs
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r284 - in trunk: sequencers and 17 other directories.
by dna-commits@lists.jboss.org
Author: elvisisking
Date: 2008-06-13 10:13:50 -0400 (Fri, 13 Jun 2008)
New Revision: 284
Added:
trunk/sequencers/dna-sequencer-cnd/
trunk/sequencers/dna-sequencer-cnd/.classpath
trunk/sequencers/dna-sequencer-cnd/.project
trunk/sequencers/dna-sequencer-cnd/pom.xml
trunk/sequencers/dna-sequencer-cnd/src/
trunk/sequencers/dna-sequencer-cnd/src/main/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/
trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g
trunk/sequencers/dna-sequencer-cnd/src/main/java/
trunk/sequencers/dna-sequencer-cnd/src/main/resources/
trunk/sequencers/dna-sequencer-cnd/src/test/
trunk/sequencers/dna-sequencer-cnd/src/test/java/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java
trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java
trunk/sequencers/dna-sequencer-cnd/src/test/resources/
trunk/sequencers/dna-sequencer-cnd/src/test/resources/builtin_nodetypes.cnd
trunk/sequencers/dna-sequencer-cnd/src/test/resources/empty.cnd
trunk/sequencers/dna-sequencer-cnd/src/test/resources/images.cnd
trunk/sequencers/dna-sequencer-cnd/src/test/resources/invalid.cnd
trunk/sequencers/dna-sequencer-cnd/src/test/resources/mp3.cnd
Modified:
trunk/pom.xml
Log:
DNA-73 Added CND Sequencer project, still incomplete
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-06-13 13:49:24 UTC (rev 283)
+++ trunk/pom.xml 2008-06-13 14:13:50 UTC (rev 284)
@@ -63,6 +63,7 @@
<module>sequencers/dna-sequencer-images</module>
<module>sequencers/dna-sequencer-mp3</module>
<!--module>sequencers/dna-sequencer-esbMessage</module-->
+ <module>sequencers/dna-sequencer-cnd</module>
<module>connectors/dna-connector-jbosscache</module>
<module>dna-integration-tests</module>
</modules>
Property changes on: trunk/sequencers/dna-sequencer-cnd
___________________________________________________________________
Name: svn:ignore
+ target
Added: trunk/sequencers/dna-sequencer-cnd/.classpath
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/.classpath (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/.classpath 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" path="target/generated-sources/antlr"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/antlr"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: trunk/sequencers/dna-sequencer-cnd/.project
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/.project (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/.project 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-sequencer-cnd</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.antlr.eclipse.core.warningcleanerbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.antlr.eclipse.core.smapbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: trunk/sequencers/dna-sequencer-cnd/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/pom.xml (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/pom.xml 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <parent>
+ <artifactId>dna</artifactId>
+ <groupId>org.jboss.dna</groupId>
+ <version>0.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-cnd</artifactId>
+ <name>JBoss DNA CND Sequencer</name>
+ <version>0.2-SNAPSHOT</version>
+ <description>JBoss DNA Sequencer that processes JCR CND files</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr-runtime</artifactId>
+ <version>3.0.1</version>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>antlr3-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>antlr</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/main/antlr/org/jboss/dna/sequencer/cnd/Cnd.g 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,390 @@
+/*
+ * 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.
+ */
+grammar Cnd;
+
+options {// backtrack=true;
+// memoize=true;
+ output=AST;
+ }
+
+tokens {
+ COMMA = ',';
+ DASH = '-';
+ DOT = '.';
+ EQUALS = '=';
+ EXCLAMATION = '!';
+ GREATER_THAN = '>';
+ LEFT_BRACKET = '[';
+ LEFT_PAREN = '(';
+ LESS_THAN = '<';
+ PLUS = '+';
+ RIGHT_BRACKET = ']';
+ RIGHT_PAREN = ')';
+ SINGLE_QUOTE = '\'';
+ SLASH = '/';
+ STAR = '*';
+
+ ATTRIBUTES;
+ COMMENTS;
+ DEFAULT_TYPE;
+ DEFAULT_VALUES;
+ JCR_NAME;
+ NAME;
+ NAMESPACES;
+ CHILD_NODE_DEFINITION;
+ CHILD_NODE_DEFINITIONS;
+ NODE_TYPE_DEFINITION;
+ NODE_TYPE_DEFINITIONS;
+ NODE_TYPE_OPTIONS;
+ PROPERTIES;
+ PROPERTY_DEFINITION;
+ PROPERTY_TYPE;
+ REQUIRED_TYPES;
+ SUPERTYPES;
+ VALUE_CONSTRAINTS;
+}
+
+@header {package org.jboss.dna.sequencer.cnd;}
+
+@lexer::header {package org.jboss.dna.sequencer.cnd;}
+
+// Make the parser exit immediately upon recognition error by overriding the following two methods,
+// and by altering how the parser responds to thrown exceptions.
+@members {
+ /**
+ * Make the parser exit immediately upon a recognition error by throwing an exception after a mismatch.
+ */
+ @Override
+ protected void mismatch( IntStream input, int ttype, BitSet follow ) throws RecognitionException {
+ throw new MismatchedTokenException(ttype,input);
+ }
+
+ /**
+ * Make the parser exit immediately upon a recognition error by not recovering from a mismatched set.
+ */
+ @Override
+ public void recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) throws RecognitionException {
+ throw e;
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * PARSER RULES
+ *---------------------------------------------------------------------------*/
+
+cnd
+ : ( comment
+ | ns_mapping
+ | node_type_def
+ )*
+
+ -> ^(COMMENTS comment*)?
+ ^(NAMESPACES ns_mapping*)?
+ ^(NODE_TYPE_DEFINITIONS node_type_def*)?
+ ;
+
+comment
+ : SINGLE_LINE_COMMENT
+ | MULTI_LINE_COMMENT
+ ;
+
+ns_mapping
+ : NAMESPACE_MAPPING
+ ;
+
+node_type_def
+ : ( node_type_name
+ supertypes?
+ node_type_options?
+ ( property_def
+ | child_node_def
+ )*
+ )
+
+ -> ^( NODE_TYPE_DEFINITION
+ ^(JCR_NAME node_type_name)
+ ^(SUPERTYPES supertypes)?
+ ^(NODE_TYPE_OPTIONS node_type_options)?
+ ^(PROPERTIES property_def*)?
+ ^(CHILD_NODE_DEFINITIONS child_node_def*)?
+ )
+ ;
+
+node_type_name
+ : ( LEFT_BRACKET
+ string
+ RIGHT_BRACKET
+ )
+
+ -> string
+ ;
+
+supertypes
+ : ( GREATER_THAN
+ string_list
+ )
+
+ -> string_list
+ ;
+
+fragment
+node_type_options
+ : (abs_opt ord_mix_opt?)
+ | (ord_mix_opt abs_opt?)
+ ;
+
+fragment
+abs_opt
+ : 'abstract'
+ | 'abs'
+ | 'a'
+ ;
+
+fragment
+ord_mix_opt
+ : (orderable_opt mixin_opt?)
+ | (mixin_opt orderable_opt?)
+ ;
+
+fragment
+orderable_opt
+ : 'orderable'
+ | 'ord'
+ | 'o'
+ ;
+
+fragment
+mixin_opt
+ : 'mixin'
+ | 'mix'
+ | 'm'
+ ;
+
+
+property_def
+ : ( DASH
+ jcr_name
+ property_type_decl?
+ default_values?
+ attributes*
+ value_constraints?
+ )
+
+ -> ^( PROPERTY_DEFINITION
+ ^(JCR_NAME jcr_name)
+ ^(PROPERTY_TYPE property_type_decl)?
+ ^(DEFAULT_VALUES default_values)?
+ ^(ATTRIBUTES attributes*)?
+ ^(VALUE_CONSTRAINTS value_constraints)?
+ )
+ ;
+
+child_node_def
+ : PLUS
+ jcr_name
+ required_types?
+ default_type?
+ attributes?
+
+ -> ^( CHILD_NODE_DEFINITION
+ ^(JCR_NAME jcr_name)
+ ^(REQUIRED_TYPES required_types)?
+ ^(DEFAULT_TYPE default_type)?
+ ^(ATTRIBUTES attributes*)?
+ )
+ ;
+
+fragment
+jcr_name
+ : string
+ | STAR
+ ;
+
+fragment
+property_type_decl
+ : LEFT_PAREN
+ property_type
+ RIGHT_PAREN
+
+ -> property_type
+ ;
+
+fragment
+property_type
+ : 'BINARY' | 'Binary' | 'binary'
+ | 'BOOLEAN' | 'Boolean' | 'boolean'
+ | 'DATE' | 'Date' | 'date'
+ | 'DECIMAL' | 'Decimal' | 'decimal'
+ | 'DOUBLE' | 'Double' | 'double'
+ | 'LONG' | 'Long' | 'long'
+ | 'NAME' | 'Name' | 'name'
+ | 'PATH' | 'Path' | 'path'
+ | 'REFERENCE' | 'Reference' | 'reference'
+ | 'STRING' | 'String' | 'string'
+ | 'UNDEFINED' | 'Undefined' | 'undefined'
+ | 'URI' | 'Uri' | 'uri'
+ | 'WEAKREFERENCE' | 'WeakReference' | 'weakreference'
+ | STAR
+ ;
+
+fragment
+default_values
+ : EQUALS
+ string_list
+
+ -> string_list
+ ;
+
+fragment
+value_constraints
+ : LESS_THAN
+ string_list
+
+ -> string_list
+ ;
+
+fragment
+required_types
+ : LEFT_PAREN
+ string_list
+ RIGHT_PAREN
+
+ -> string_list
+ ;
+
+fragment
+default_type
+ : EQUALS
+ string
+
+ -> string
+ ;
+
+fragment
+attributes
+ : 'ABORT' | 'Abort' | 'abort'
+ | 'autocreated' | 'aut' | 'a'
+ | 'COMPUTE' | 'Compute' | 'compute'
+ | 'COPY' | 'Copy' | 'copy'
+ | 'IGNORE' | 'Ignore' | 'ignore'
+ | 'INITIALIZE' | 'Initialize' | 'initialize'
+ | 'mandatory' | 'man' | 'm'
+ | 'multiple' | 'mul' | STAR
+ | 'primary' | 'pri' | EXCLAMATION
+ | 'protected' | 'pro' | 'p'
+ | 'VERSION' | 'Version' | 'version'
+ ;
+
+fragment
+string
+ : QUOTED_STRING
+ | UNQUOTED_STRING
+ ;
+
+fragment
+string_list
+ : string
+ ( COMMA
+ string
+ )*
+
+ -> string+
+ ;
+
+fragment
+uri_string
+ : QUOTED_URI_STRING
+ | UNQUOTED_URI_STRING
+ ;
+
+/*-----------------------------------------------------------------------------
+ * LEXER RULES
+ *---------------------------------------------------------------------------*/
+
+MULTI_LINE_COMMENT
+ : ( '/*'
+ ( options {greedy=false;} : . )*
+ '*/'
+ )
+ ;
+
+NAMESPACE_MAPPING
+ : ( LESS_THAN
+ (QUOTED_STRING | UNQUOTED_STRING)
+ EQUALS
+ (QUOTED_URI_STRING | UNQUOTED_URI_STRING)
+ GREATER_THAN
+ )
+ ;
+
+QUOTED_STRING
+ : ( SINGLE_QUOTE
+ UNQUOTED_STRING
+ SINGLE_QUOTE
+ )
+ ;
+
+
+QUOTED_URI_STRING
+ : ( SINGLE_QUOTE
+ UNQUOTED_URI_STRING
+ SINGLE_QUOTE
+ )
+ ;
+
+SINGLE_LINE_COMMENT
+ : '//'
+ ~('\n' | '\r')*
+ ;
+
+
+UNQUOTED_STRING
+ : ( 'a' .. 'z'
+ | 'A' .. 'Z'
+ | '0' .. '9'
+ | ':'
+ | '_'
+ )+
+ ;
+
+fragment
+URI_SPECIAL_CHARS
+ : SLASH
+ | DOT
+ ;
+
+
+UNQUOTED_URI_STRING
+ : ( UNQUOTED_STRING
+ | URI_SPECIAL_CHARS
+ )+
+ ;
+
+WS
+ : ( ' '
+ | '\r'
+ |'\t'
+ |'\u000C'
+ |'\n'
+ )+
+ {$channel=HIDDEN;}
+ ;
Added: trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,365 @@
+/*
+ * 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.sequencer.cnd;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.antlr.runtime.ANTLRInputStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RuleReturnScope;
+import org.antlr.runtime.tree.Tree;
+import org.junit.After;
+import org.junit.Test;
+
+public class CndParseFilesTest {
+
+ /*
+ * AST looks like this:
+ *
+ * root (nil)
+ * COMMENTS (*)
+ * comment-1
+ * comment-2
+ * ...
+ * NAMESPACES (*)
+ * namespace_mapping-1
+ * namespace_mapping-2
+ * ...
+ * NODE_TYPE_DEFINITIONS (*)
+ * NODE_TYPE_DEFINITION
+ * JCR_NAME
+ * node_type_definition_name-1
+ * SUPERTYPES (*)
+ * supertype-1
+ * supertype-2
+ * ...
+ * NODE_TYPE_OPTIONS (*)
+ * option-1
+ * option-2
+ * ...
+ * PROPERTIES (*)
+ * PROPERTY_DEFINITION
+ * JCR_NAME
+ * property_name-1
+ * PROPERTY_TYPE (*)
+ * property type
+ * ATTRIBUTES (*)
+ * attribute-1
+ * attribute-2
+ * ...
+ * PROPERTY_DEFINITION
+ * JCR_NAME
+ * property_name-2
+ * ...
+ * ...
+ * CHILD_NODE_DEFINTIONS (*)
+ * CHILD_NODE_DEFINTION
+ * JCR_NAME
+ * child_node_name-1
+ * REQUIRED_TYPES (*)
+ * required_type-1
+ * required_type-2
+ * ...
+ * DEFAULT_TYPE (*)
+ * default_type
+ * ATTRIBUTES (*)
+ * attribute-1
+ * attribute-2
+ * ...
+ * CHILD_NODE_DEFINTION
+ * JCR_NAME
+ * child_node_name-2
+ * ...
+ * ...
+ * NODE_TYPE_DEFINITION
+ * JCR_NAME
+ * node_type_definition_name-2
+ * ...
+ * ...
+ *
+ * Note: (*) indicates node only appears if a child node exists
+ */
+
+ // =============================================================================================================================
+ // Constants
+ // =============================================================================================================================
+ private static final String TEST_DATA_PATH = "./src/test/resources/";
+
+ private static final String BUILTIN_NODETYPES_CND = TEST_DATA_PATH + "builtin_nodetypes.cnd";
+ private static final String EMPTY_CND = TEST_DATA_PATH + "empty.cnd";
+ private static final String IMAGES_CND = TEST_DATA_PATH + "images.cnd";
+ private static final String INVALID_CND = TEST_DATA_PATH + "invalid.cnd";
+ private static final String MP3_CND = TEST_DATA_PATH + "mp3.cnd";
+
+ private static final int COMMENTS_INDEX = 0;
+ private static final int NAMESPACES_INDEX = 1;
+ private static final int NODE_TYPE_DEFINITIONS_INDEX = 2;
+ private static final int PROPERTIES_INDEX = 2;
+
+ // =============================================================================================================================
+ // Fields
+ // =============================================================================================================================
+
+ private InputStream stream;
+
+ // =============================================================================================================================
+ // Methods
+ // =============================================================================================================================
+
+ @After
+ public void afterEach() throws IOException {
+ if (this.stream != null) {
+ try {
+ this.stream.close();
+ } finally {
+ this.stream = null;
+ }
+ }
+ }
+
+ private void assertCommentsCount( Tree root,
+ int count ) {
+ Tree comments = root.getChild(COMMENTS_INDEX);
+ assertThat("Tree type was not CndParser.COMMENTS", comments.getType(), is(CndParser.COMMENTS));
+
+ // make sure right number of comments
+ assertThat("Incorrect number of comments", comments.getChildCount(), is(count));
+ }
+
+ private void assertNamespacesCount( Tree root,
+ int count ) {
+ Tree namespaces = getNamespaces(root);
+ assertThat("Incorrect number of namespaces", namespaces.getChildCount(), is(count));
+ }
+
+ private void assertNodeTypeDefinitionsCount( Tree root,
+ int count ) {
+ Tree nodeTypeDefinitions = getNodeTypeDefinitions(root);
+ assertThat("Incorrect number of node type definitions", nodeTypeDefinitions.getChildCount(), is(count));
+ }
+
+ private void assertNodeTypeDefinitionsPropertiesCount( Tree root,
+ int nodeTypeDefinitionIndex,
+ int count ) {
+ Tree nodeTypeDefinitions = getNodeTypeDefinitions(root);
+
+ Tree nodeType = nodeTypeDefinitions.getChild(nodeTypeDefinitionIndex);
+ assertThat("Tree type was not CndParser.NODE_TYPE_DEFINITION", nodeType.getType(), is(CndParser.NODE_TYPE_DEFINITION));
+
+ Tree properties = nodeType.getChild(PROPERTIES_INDEX); // properties container node
+ assertThat("Tree type was not CndParser.PROPERTIES", properties.getType(), is(CndParser.PROPERTIES));
+
+ // make sure right number of properties
+ assertThat("Incorrect number of node type properties for first node type", properties.getChildCount(), is(count));
+ }
+
+ private CndParser createParser( File file ) throws IOException {
+ afterEach(); // make sure previous stream is closed
+ assertThat('\'' + file.getAbsolutePath() + "' does not exist", file.exists(), is(true));
+
+ this.stream = new FileInputStream(file);
+ CndLexer lexer = new CndLexer(new ANTLRInputStream(this.stream));
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+
+ return new CndParser(tokens);
+ }
+
+ /**
+ * @param root the AST root
+ * @return the NAMESPACES tree node
+ */
+ private Tree getNamespaces( Tree root ) {
+ Tree namespaces = root.getChild(NAMESPACES_INDEX);
+
+ if (namespaces != null) {
+ assertThat("Tree type was not CndParser.NAMESPACES", namespaces.getType(), is(CndParser.NAMESPACES));
+ }
+
+ return namespaces;
+ }
+
+ /**
+ * @param root the AST root
+ * @return the NODE_TYPE_DEFINITIONS tree node
+ */
+ private Tree getNodeTypeDefinitions( Tree root ) {
+ Tree nodeTypeDefinitions = root.getChild(NODE_TYPE_DEFINITIONS_INDEX);
+
+ if (nodeTypeDefinitions != null) {
+ assertThat("Tree type was not CndParser.NODE_TYPE_DEFINITIONS",
+ nodeTypeDefinitions.getType(),
+ is(CndParser.NODE_TYPE_DEFINITIONS));
+ }
+
+ return nodeTypeDefinitions;
+ }
+
+ /**
+ * @param fileName the name of the file to parse
+ * @return the root node of the AST
+ * @throws Exception if root is null
+ */
+ private Tree parse( String fileName ) throws Exception {
+ return parse(new File(fileName).getCanonicalFile());
+ }
+
+ /**
+ * @param file the file to parse
+ * @return the root node of the AST
+ * @throws Exception if root is null
+ */
+ private Tree parse( File file ) throws Exception {
+ CndParser parser = createParser(file);
+ RuleReturnScope result = parser.cnd();
+ Tree root = (Tree)result.getTree();
+ assertThat(root, notNullValue());
+
+ return root;
+ }
+
+ // =============================================================================================================================
+ // Tests
+ // =============================================================================================================================
+
+ @Test
+ public void shouldParseEmptyCnd() throws Exception {
+ Tree root = parse(EMPTY_CND);
+
+ // make sure no children
+ assertThat(root.getChildCount(), is(0));
+
+ // make sure nothing got parsed
+ assertThat(root.getTokenStartIndex(), is(-1));
+ }
+
+ @Test
+ public void shouldNotParseInvalidCnd() throws Exception {
+ Tree root = parse(INVALID_CND);
+
+ // make sure nothing got parsed
+ assertThat(root.getTokenStopIndex(), is(0));
+ }
+
+ // @Test
+ public void shouldParseBuiltinNodeTypesCndComments() throws Exception {
+ Tree root = parse(BUILTIN_NODETYPES_CND);
+ assertCommentsCount(root, 16);
+ }
+
+ @Test
+ public void shouldParseBuiltinNodeTypesCndNamespaces() throws Exception {
+ Tree root = parse(BUILTIN_NODETYPES_CND);
+ assertNamespacesCount(root, 4);
+ }
+
+ // @Test
+ public void shouldParseBuiltinNodeTypesCndNodeTypeDefinitions() throws Exception {
+ Tree root = parse(BUILTIN_NODETYPES_CND);
+
+ // make sure correct number of node type definitions
+ assertNodeTypeDefinitionsCount(root, 23);
+
+ // make sure right number of node type definitions for each node type
+ assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [nt:base]
+ assertNodeTypeDefinitionsPropertiesCount(root, 1, 2); // [nt:unstructured]
+ assertNodeTypeDefinitionsPropertiesCount(root, 2, 1); // [mix:referenceable]
+ assertNodeTypeDefinitionsPropertiesCount(root, 3, 2); // [mix:lockable]
+ assertNodeTypeDefinitionsPropertiesCount(root, 4, 5); // [mix:versionable]
+ assertNodeTypeDefinitionsPropertiesCount(root, 5, 1); // [nt:versionHistory]
+ assertNodeTypeDefinitionsPropertiesCount(root, 6, 1); // [nt:versionLabels]
+ assertNodeTypeDefinitionsPropertiesCount(root, 7, 3); // [nt:version]
+ assertNodeTypeDefinitionsPropertiesCount(root, 8, 5); // [nt:frozenNode]
+ assertNodeTypeDefinitionsPropertiesCount(root, 9, 1); // [nt:versionedChild]
+ assertNodeTypeDefinitionsPropertiesCount(root, 10, 5); // [nt:nodeType]
+ assertNodeTypeDefinitionsPropertiesCount(root, 11, 9); // [nt:propertyDefinition]
+ assertNodeTypeDefinitionsPropertiesCount(root, 12, 8); // [nt:childNodeDefinition]
+ assertNodeTypeDefinitionsPropertiesCount(root, 13, 1); // [nt:hierarchyNode]
+ assertNodeTypeDefinitionsPropertiesCount(root, 14, 0); // [nt:folder]
+ assertNodeTypeDefinitionsPropertiesCount(root, 15, 0); // [nt:file]
+ assertNodeTypeDefinitionsPropertiesCount(root, 16, 1); // [nt:linkedFile]
+ assertNodeTypeDefinitionsPropertiesCount(root, 17, 4); // [nt:resource]
+ assertNodeTypeDefinitionsPropertiesCount(root, 18, 2); // [nt:query]
+ assertNodeTypeDefinitionsPropertiesCount(root, 19, 0); // [rep:nodeTypes]
+ assertNodeTypeDefinitionsPropertiesCount(root, 20, 0); // [rep:root]
+ assertNodeTypeDefinitionsPropertiesCount(root, 21, 0); // [rep:system]
+ assertNodeTypeDefinitionsPropertiesCount(root, 22, 0); // [rep:versionStorage]
+ }
+
+ @Test
+ public void shouldParseImagesCndComments() throws Exception {
+ Tree root = parse(IMAGES_CND);
+ assertCommentsCount(root, 11);
+ }
+
+ @Test
+ public void shouldParseImagesCndNamespaces() throws Exception {
+ Tree root = parse(IMAGES_CND);
+ assertNamespacesCount(root, 4);
+ }
+
+ @Test
+ public void shouldParseImagesCndNodeTypeDefinitions() throws Exception {
+ Tree root = parse(IMAGES_CND);
+
+ // make sure correct number of node type definitions
+ assertNodeTypeDefinitionsCount(root, 2);
+
+ // make sure right number of node type definitions for each node type
+ assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [mix:mimeType]
+ assertNodeTypeDefinitionsPropertiesCount(root, 1, 10); // [image:metadata]
+ }
+
+ @Test
+ public void shouldParseMp3CndComments() throws Exception {
+ Tree root = parse(MP3_CND);
+
+ // this will be the COMMENTS imaginary container token
+ Tree comments = root.getChild(COMMENTS_INDEX);
+ assertThat("Tree type was not CndParser.COMMENTS", comments.getType(), is(CndParser.COMMENTS));
+
+ // make sure right number of comments
+ assertThat("Incorrect number of comments", comments.getChildCount(), is(10));
+ }
+
+ @Test
+ public void shouldParseMp3CndNamespaces() throws Exception {
+ Tree root = parse(MP3_CND);
+ assertNamespacesCount(root, 4);
+ }
+
+ @Test
+ public void shouldParseMp3CndNodeTypeDefinitions() throws Exception {
+ Tree root = parse(MP3_CND);
+
+ // make sure correct number of node type definitions
+ assertNodeTypeDefinitionsCount(root, 2);
+
+ // make sure right number of node type definitions for each node type
+ assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [mix:mimeType]
+ assertNodeTypeDefinitionsPropertiesCount(root, 1, 5); // [mp3:metadata]
+ }
+}
Added: trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,766 @@
+/*
+ * 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.sequencer.cnd;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.antlr.runtime.ANTLRInputStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RuleReturnScope;
+import org.antlr.runtime.tree.RewriteEmptyStreamException;
+import org.junit.After;
+import org.junit.Test;
+
+public class CndParserTest {
+
+ // =============================================================================================================================
+ // Fields
+ // =============================================================================================================================
+
+ private InputStream stream;
+
+ // =============================================================================================================================
+ // Methods
+ // =============================================================================================================================
+
+ @After
+ public void afterEach() throws IOException {
+ if (this.stream != null) {
+ try {
+ this.stream.close();
+ } finally {
+ this.stream = null;
+ }
+ }
+ }
+
+ private CndParser createParser( String input ) throws IOException {
+ afterEach(); // make sure previous stream is closed
+ this.stream = new ByteArrayInputStream(input.getBytes("UTF-8"));
+ CndLexer lexer = new CndLexer(new ANTLRInputStream(this.stream));
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ return new CndParser(tokens);
+ }
+
+ // =============================================================================================================================
+ // Comment Parsing Tests
+ // =============================================================================================================================
+
+ private void parseComment( String option,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(option);
+ RuleReturnScope scope = parser.comment();
+
+ if (success) {
+ assertThat("Value '" + option + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(option, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + option + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseSingleLineComment() throws Exception {
+ parseComment("// This is a single line comment", true);
+ }
+
+ @Test
+ public void shouldParseMultiLineComment() throws Exception {
+ parseComment("/* This\nis\na\nmulti-line\ncomment */", true);
+ }
+
+ @Test
+ public void shouldNotParseNonComment() throws Exception {
+ parseComment("This is not a valid comment", false);
+ }
+
+ @Test
+ public void shouldNotParseMalformedComment() throws Exception {
+ parseComment("/* This comment is missing ending delimeters", false);
+ }
+
+ // =============================================================================================================================
+ // Node Type Name Parsing Tests
+ // =============================================================================================================================
+
+ private void parseNodeTypeName( String name,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(name);
+ RuleReturnScope scope = parser.node_type_name();
+
+ if (success) {
+ assertThat("Value '" + name + "' did not parse and should have", scope.getTree(), notNullValue());
+
+ // strip off brackets
+ assertThat(name.substring(1, name.length() - 1), is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + name + "' should not parse", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseUnquotedNodeTypeName() throws Exception {
+ parseNodeTypeName("[typeName]", true);
+ }
+
+ @Test
+ public void shouldParseQuotedNodeTypeName() throws Exception {
+ parseNodeTypeName("['quotedName']", true);
+ }
+
+ @Test
+ public void shouldNotParseNodeTypeNameWithSpaces() throws Exception {
+ parseNodeTypeName("[no spaces allowed]", false);
+ }
+
+ @Test
+ public void shouldNotParseNodeTypeNameWithMissingEndBracket() throws Exception {
+ parseNodeTypeName("[missingClosingBracket", false);
+ }
+
+ @Test( expected = RewriteEmptyStreamException.class )
+ public void shouldNotParseNodeTypeNameWithMissingBracketsButNoName() throws Exception {
+ parseNodeTypeName("[]", false);
+ }
+
+ // =============================================================================================================================
+ // Node Type Abstract Option Parsing Tests
+ // =============================================================================================================================
+
+ private void parseAbstractOption( String option,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(option);
+ RuleReturnScope scope = parser.abs_opt();
+
+ if (success) {
+ assertThat("Value '" + option + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(option, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + option + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseAbstractOption() throws Exception {
+ parseAbstractOption("abstract", true);
+ parseAbstractOption("abs", true);
+ parseAbstractOption("a", true);
+ }
+
+ @Test
+ public void shouldNotParseInvalidAbstractOption() throws Exception {
+ parseAbstractOption("abstractoption", false);
+ parseAbstractOption("A", false);
+ }
+
+ // =============================================================================================================================
+ // Node Type Orderable Option Parsing Tests
+ // =============================================================================================================================
+
+ private void parseOrderableOption( String option,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(option);
+ RuleReturnScope scope = parser.orderable_opt();
+
+ if (success) {
+ assertThat("Value '" + option + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(option, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + option + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseOrderableOption() throws Exception {
+ parseOrderableOption("orderable", true);
+ parseOrderableOption("ord", true);
+ parseOrderableOption("o", true);
+ }
+
+ @Test
+ public void shouldNotParseInvalidOrderableOption() throws Exception {
+ parseOrderableOption("orderableoption", false);
+ parseOrderableOption("O", false);
+ }
+
+ // =============================================================================================================================
+ // Node Type Mixin Option Parsing Tests
+ // =============================================================================================================================
+
+ private void parseMixinOption( String option,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(option);
+ RuleReturnScope scope = parser.mixin_opt();
+
+ if (success) {
+ assertThat("Value '" + option + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(option, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + option + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseMixinOption() throws Exception {
+ parseMixinOption("mixin", true);
+ parseMixinOption("mix", true);
+ parseMixinOption("m", true);
+ }
+
+ @Test
+ public void shouldNotParseInvalidMixinOption() throws Exception {
+ parseMixinOption("mixinoption", false);
+ parseMixinOption("M", false);
+ }
+
+ // =============================================================================================================================
+ // Node Type Orderable Mixin Options Parsing Tests
+ // =============================================================================================================================
+
+ private void parseNodeTypeOrderableMixinOptions( String options,
+ boolean success,
+ int numChildren ) throws Exception {
+ CndParser parser = createParser(options);
+ RuleReturnScope scope = parser.ord_mix_opt();
+
+ if (success) {
+ assertThat("Value '" + options + "' did not parse and should have", scope.getTree(), notNullValue());
+
+ if (numChildren == 0) {
+ assertThat(options, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat(numChildren, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getChildCount()));
+ }
+ } else {
+ assertThat("Value '" + options + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseNodeTypeOrderableMixinOptions() throws Exception {
+ parseNodeTypeOrderableMixinOptions("orderable", true, 0);
+ parseNodeTypeOrderableMixinOptions("orderable mixin", true, 2);
+ parseNodeTypeOrderableMixinOptions("orderable mix", true, 2);
+ parseNodeTypeOrderableMixinOptions("orderable m", true, 2);
+
+ parseNodeTypeOrderableMixinOptions("ord", true, 0);
+ parseNodeTypeOrderableMixinOptions("ord mixin", true, 2);
+ parseNodeTypeOrderableMixinOptions("ord mix", true, 2);
+ parseNodeTypeOrderableMixinOptions("ord m", true, 2);
+
+ parseNodeTypeOrderableMixinOptions("o", true, 0);
+ parseNodeTypeOrderableMixinOptions("o mixin", true, 2);
+ parseNodeTypeOrderableMixinOptions("o mix", true, 2);
+ parseNodeTypeOrderableMixinOptions("o m", true, 2);
+
+ parseNodeTypeOrderableMixinOptions("mixin", true, 0);
+ parseNodeTypeOrderableMixinOptions("mixin orderable", true, 2);
+ parseNodeTypeOrderableMixinOptions("mixin ord", true, 2);
+ parseNodeTypeOrderableMixinOptions("mixin o", true, 2);
+
+ parseNodeTypeOrderableMixinOptions("mix", true, 0);
+ parseNodeTypeOrderableMixinOptions("mix orderable", true, 2);
+ parseNodeTypeOrderableMixinOptions("mix ord", true, 2);
+ parseNodeTypeOrderableMixinOptions("mix o", true, 2);
+
+ parseNodeTypeOrderableMixinOptions("m", true, 0);
+ parseNodeTypeOrderableMixinOptions("m orderable", true, 2);
+ parseNodeTypeOrderableMixinOptions("m ord", true, 2);
+ parseNodeTypeOrderableMixinOptions("m o", true, 2);
+ }
+
+ // =============================================================================================================================
+ // Node Type Options Parsing Tests
+ // =============================================================================================================================
+
+ private void parseNodeTypeOptions( String options,
+ boolean success,
+ int numChildren ) throws Exception {
+ CndParser parser = createParser(options);
+ RuleReturnScope scope = parser.node_type_options();
+
+ if (success) {
+ assertThat("Value '" + options + "' did not parse and should have", scope.getTree(), notNullValue());
+
+ if (numChildren == 0) {
+ assertThat(options, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat(numChildren, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getChildCount()));
+ }
+ } else {
+ assertThat("Value '" + options + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseNodeTypeOptions() throws Exception {
+ parseNodeTypeOptions("abstract", true, 0);
+ parseNodeTypeOptions("abs", true, 0);
+ parseNodeTypeOptions("a", true, 0);
+
+ parseNodeTypeOptions("abstract orderable", true, 2);
+ parseNodeTypeOptions("abstract ord", true, 2);
+ parseNodeTypeOptions("abstract o", true, 2);
+
+ parseNodeTypeOptions("abs orderable", true, 2);
+ parseNodeTypeOptions("abs ord", true, 2);
+ parseNodeTypeOptions("abs o", true, 2);
+
+ parseNodeTypeOptions("a orderable", true, 2);
+ parseNodeTypeOptions("a ord", true, 2);
+ parseNodeTypeOptions("a o", true, 2);
+
+ parseNodeTypeOptions("abstract mixin", true, 2);
+ parseNodeTypeOptions("abstract mix", true, 2);
+ parseNodeTypeOptions("abstract m", true, 2);
+
+ parseNodeTypeOptions("abs mixin", true, 2);
+ parseNodeTypeOptions("abs mix", true, 2);
+ parseNodeTypeOptions("abs m", true, 2);
+
+ parseNodeTypeOptions("a mixin", true, 2);
+ parseNodeTypeOptions("a mix", true, 2);
+ parseNodeTypeOptions("a m", true, 2);
+
+ parseNodeTypeOptions("abstract orderable mixin", true, 3);
+ parseNodeTypeOptions("abstract orderable mix", true, 3);
+ parseNodeTypeOptions("abstract orderable m", true, 3);
+
+ parseNodeTypeOptions("abstract ord mixin", true, 3);
+ parseNodeTypeOptions("abstract ord mix", true, 3);
+ parseNodeTypeOptions("abstract ord m", true, 3);
+
+ parseNodeTypeOptions("abstract o mixin", true, 3);
+ parseNodeTypeOptions("abstract o mix", true, 3);
+ parseNodeTypeOptions("abstract o m", true, 3);
+
+ parseNodeTypeOptions("abs orderable mixin", true, 3);
+ parseNodeTypeOptions("abs orderable mix", true, 3);
+ parseNodeTypeOptions("abs orderable m", true, 3);
+
+ parseNodeTypeOptions("abs ord mixin", true, 3);
+ parseNodeTypeOptions("abs ord mix", true, 3);
+ parseNodeTypeOptions("abs ord m", true, 3);
+
+ parseNodeTypeOptions("abs o mixin", true, 3);
+ parseNodeTypeOptions("abs o mix", true, 3);
+ parseNodeTypeOptions("abs o m", true, 3);
+
+ parseNodeTypeOptions("a orderable mixin", true, 3);
+ parseNodeTypeOptions("a orderable mix", true, 3);
+ parseNodeTypeOptions("a orderable m", true, 3);
+
+ parseNodeTypeOptions("a ord mixin", true, 3);
+ parseNodeTypeOptions("a ord mix", true, 3);
+ parseNodeTypeOptions("a ord m", true, 3);
+
+ parseNodeTypeOptions("a o mixin", true, 3);
+ parseNodeTypeOptions("a o mix", true, 3);
+ parseNodeTypeOptions("a o m", true, 3);
+
+ parseNodeTypeOptions("abstract mixin orderable", true, 3);
+ parseNodeTypeOptions("abstract mixin ord", true, 3);
+ parseNodeTypeOptions("abstract mixin o", true, 3);
+
+ parseNodeTypeOptions("abstract mix orderable", true, 3);
+ parseNodeTypeOptions("abstract mix ord", true, 3);
+ parseNodeTypeOptions("abstract mix o", true, 3);
+
+ parseNodeTypeOptions("abstract m orderable", true, 3);
+ parseNodeTypeOptions("abstract m ord", true, 3);
+ parseNodeTypeOptions("abstract m o", true, 3);
+
+ parseNodeTypeOptions("abs mixin orderable", true, 3);
+ parseNodeTypeOptions("abs mixin ord", true, 3);
+ parseNodeTypeOptions("abs mixin o", true, 3);
+
+ parseNodeTypeOptions("abs mix orderable", true, 3);
+ parseNodeTypeOptions("abs mix ord", true, 3);
+ parseNodeTypeOptions("abs mix o", true, 3);
+
+ parseNodeTypeOptions("abs m orderable", true, 3);
+ parseNodeTypeOptions("abs m ord", true, 3);
+ parseNodeTypeOptions("abs m o", true, 3);
+
+ parseNodeTypeOptions("a mixin orderable", true, 3);
+ parseNodeTypeOptions("a mixin ord", true, 3);
+ parseNodeTypeOptions("a mixin o", true, 3);
+
+ parseNodeTypeOptions("a mix orderable", true, 3);
+ parseNodeTypeOptions("a mix ord", true, 3);
+ parseNodeTypeOptions("a mix o", true, 3);
+
+ parseNodeTypeOptions("a m orderable", true, 3);
+ parseNodeTypeOptions("a m ord", true, 3);
+ parseNodeTypeOptions("a m o", true, 3);
+
+ parseNodeTypeOptions("orderable abstract", true, 2);
+ parseNodeTypeOptions("ord abstract", true, 2);
+ parseNodeTypeOptions("o abstract", true, 2);
+
+ parseNodeTypeOptions("orderable abs", true, 2);
+ parseNodeTypeOptions("ord abs", true, 2);
+ parseNodeTypeOptions("o abs", true, 2);
+
+ parseNodeTypeOptions("orderable a", true, 2);
+ parseNodeTypeOptions("ord a", true, 2);
+ parseNodeTypeOptions("o a", true, 2);
+
+ parseNodeTypeOptions("mixin abstract", true, 2);
+ parseNodeTypeOptions("mix abstract", true, 2);
+ parseNodeTypeOptions("m abstract", true, 2);
+
+ parseNodeTypeOptions("mixin abs", true, 2);
+ parseNodeTypeOptions("mix abs", true, 2);
+ parseNodeTypeOptions("m abs", true, 2);
+
+ parseNodeTypeOptions("mixin a", true, 2);
+ parseNodeTypeOptions("mix a", true, 2);
+ parseNodeTypeOptions("m a", true, 2);
+
+ parseNodeTypeOptions("orderable mixin abstract", true, 3);
+ parseNodeTypeOptions("orderable mix abstract", true, 3);
+ parseNodeTypeOptions("orderable m abstract", true, 3);
+
+ parseNodeTypeOptions("ord mixin abstract", true, 3);
+ parseNodeTypeOptions("ord mix abstract", true, 3);
+ parseNodeTypeOptions("ord m abstract", true, 3);
+
+ parseNodeTypeOptions("o mixin abstract", true, 3);
+ parseNodeTypeOptions("o mix abstract", true, 3);
+ parseNodeTypeOptions("o m abstract", true, 3);
+
+ parseNodeTypeOptions("orderable mixin abs", true, 3);
+ parseNodeTypeOptions("orderable mix abs", true, 3);
+ parseNodeTypeOptions("orderable m abs", true, 3);
+
+ parseNodeTypeOptions("ord mixin abs", true, 3);
+ parseNodeTypeOptions("ord mix abs", true, 3);
+ parseNodeTypeOptions("ord m abs", true, 3);
+
+ parseNodeTypeOptions("o mixin abs", true, 3);
+ parseNodeTypeOptions("o mix abs", true, 3);
+ parseNodeTypeOptions("o m abs", true, 3);
+
+ parseNodeTypeOptions("orderable mixin a", true, 3);
+ parseNodeTypeOptions("orderable mix a", true, 3);
+ parseNodeTypeOptions("orderable m a", true, 3);
+
+ parseNodeTypeOptions("ord mixin a", true, 3);
+ parseNodeTypeOptions("ord mix a", true, 3);
+ parseNodeTypeOptions("ord m a", true, 3);
+
+ parseNodeTypeOptions("o mixin a", true, 3);
+ parseNodeTypeOptions("o mix a", true, 3);
+ parseNodeTypeOptions("o m a", true, 3);
+
+ parseNodeTypeOptions("mixin orderable abstract", true, 3);
+ parseNodeTypeOptions("mixin ord abstract", true, 3);
+ parseNodeTypeOptions("mixin o abstract", true, 3);
+
+ parseNodeTypeOptions("mix orderable abstract", true, 3);
+ parseNodeTypeOptions("mix ord abstract", true, 3);
+ parseNodeTypeOptions("mix o abstract", true, 3);
+
+ parseNodeTypeOptions("m orderable abstract", true, 3);
+ parseNodeTypeOptions("m ord abstract", true, 3);
+ parseNodeTypeOptions("m o abstract", true, 3);
+
+ parseNodeTypeOptions("mixin orderable abs", true, 3);
+ parseNodeTypeOptions("mixin ord abs", true, 3);
+ parseNodeTypeOptions("mixin o abs", true, 3);
+
+ parseNodeTypeOptions("mix orderable abs", true, 3);
+ parseNodeTypeOptions("mix ord abs", true, 3);
+ parseNodeTypeOptions("mix o abs", true, 3);
+
+ parseNodeTypeOptions("m orderable abs", true, 3);
+ parseNodeTypeOptions("m ord abs", true, 3);
+ parseNodeTypeOptions("m o abs", true, 3);
+
+ parseNodeTypeOptions("mixin orderable a", true, 3);
+ parseNodeTypeOptions("mixin ord a", true, 3);
+ parseNodeTypeOptions("mixin o a", true, 3);
+
+ parseNodeTypeOptions("mix orderable a", true, 3);
+ parseNodeTypeOptions("mix ord a", true, 3);
+ parseNodeTypeOptions("mix o a", true, 3);
+
+ parseNodeTypeOptions("m orderable a", true, 3);
+ parseNodeTypeOptions("m ord a", true, 3);
+ parseNodeTypeOptions("m o a", true, 3);
+
+ parseNodeTypeOptions("orderable", true, 0);
+ parseNodeTypeOptions("ord", true, 0);
+ parseNodeTypeOptions("o", true, 0);
+
+ parseNodeTypeOptions("mixin", true, 0);
+ parseNodeTypeOptions("mix", true, 0);
+ parseNodeTypeOptions("m", true, 0);
+
+ parseNodeTypeOptions("orderable mixin", true, 2);
+ parseNodeTypeOptions("orderable mix", true, 2);
+ parseNodeTypeOptions("orderable m", true, 2);
+
+ parseNodeTypeOptions("ord mixin", true, 2);
+ parseNodeTypeOptions("ord mix", true, 2);
+ parseNodeTypeOptions("ord m", true, 2);
+
+ parseNodeTypeOptions("o mixin", true, 2);
+ parseNodeTypeOptions("o mix", true, 2);
+ parseNodeTypeOptions("o m", true, 2);
+
+ parseNodeTypeOptions("mixin orderable", true, 2);
+ parseNodeTypeOptions("mixin ord", true, 2);
+ parseNodeTypeOptions("mixin o", true, 2);
+
+ parseNodeTypeOptions("mix orderable", true, 2);
+ parseNodeTypeOptions("mix ord", true, 2);
+ parseNodeTypeOptions("mix o", true, 2);
+
+ parseNodeTypeOptions("m orderable", true, 2);
+ parseNodeTypeOptions("m ord", true, 2);
+ parseNodeTypeOptions("m o", true, 2);
+ }
+
+ // =============================================================================================================================
+ // Property Type Parsing Tests
+ // =============================================================================================================================
+
+ private void parsePropertyType( String propertyType,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(propertyType);
+ RuleReturnScope scope = parser.property_type();
+
+ if (success) {
+ assertThat("Value '" + propertyType + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(propertyType, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + propertyType + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParseStringPropertyType() throws Exception {
+ parsePropertyType("STRING", true);
+ parsePropertyType("String", true);
+ parsePropertyType("string", true);
+ }
+
+ @Test
+ public void shouldParseBinaryPropertyType() throws Exception {
+ parsePropertyType("BINARY", true);
+ parsePropertyType("Binary", true);
+ parsePropertyType("binary", true);
+ }
+
+ @Test
+ public void shouldParseLongPropertyType() throws Exception {
+ parsePropertyType("LONG", true);
+ parsePropertyType("Long", true);
+ parsePropertyType("long", true);
+ }
+
+ @Test
+ public void shouldParseDoublePropertyType() throws Exception {
+ parsePropertyType("DOUBLE", true);
+ parsePropertyType("Double", true);
+ parsePropertyType("double", true);
+ }
+
+ @Test
+ public void shouldParseDecimalPropertyType() throws Exception {
+ parsePropertyType("DECIMAL", true);
+ parsePropertyType("Decimal", true);
+ parsePropertyType("decimal", true);
+ }
+
+ @Test
+ public void shouldParseBooleanPropertyType() throws Exception {
+ parsePropertyType("BOOLEAN", true);
+ parsePropertyType("Boolean", true);
+ parsePropertyType("boolean", true);
+ }
+
+ @Test
+ public void shouldParseDatePropertyType() throws Exception {
+ parsePropertyType("DATE", true);
+ parsePropertyType("Date", true);
+ parsePropertyType("date", true);
+ }
+
+ @Test
+ public void shouldParseNamePropertyType() throws Exception {
+ parsePropertyType("NAME", true);
+ parsePropertyType("Name", true);
+ parsePropertyType("name", true);
+ }
+
+ @Test
+ public void shouldParsePathPropertyType() throws Exception {
+ parsePropertyType("PATH", true);
+ parsePropertyType("Path", true);
+ parsePropertyType("path", true);
+ }
+
+ @Test
+ public void shouldParseReferencePropertyType() throws Exception {
+ parsePropertyType("REFERENCE", true);
+ parsePropertyType("Reference", true);
+ parsePropertyType("reference", true);
+ }
+
+ @Test
+ public void shouldParseWeakReferencePropertyType() throws Exception {
+ parsePropertyType("WEAKREFERENCE", true);
+ parsePropertyType("WeakReference", true);
+ parsePropertyType("weakreference", true);
+ }
+
+ @Test
+ public void shouldParseUriPropertyType() throws Exception {
+ parsePropertyType("URI", true);
+ parsePropertyType("Uri", true);
+ parsePropertyType("uri", true);
+ }
+
+ @Test
+ public void shouldParseUndefinedPropertyType() throws Exception {
+ parsePropertyType("UNDEFINED", true);
+ parsePropertyType("Undefined", true);
+ parsePropertyType("undefined", true);
+ }
+
+ @Test
+ public void shouldNotParseInvalidPropertyType() throws Exception {
+ parsePropertyType("B", false);
+ parsePropertyType("b", false);
+ parsePropertyType("binarytype", false);
+ }
+
+ // =============================================================================================================================
+ // Attributes Parsing Tests
+ // =============================================================================================================================
+
+ private void parseAttribute( String attribute,
+ boolean success ) throws Exception {
+ CndParser parser = createParser(attribute);
+ RuleReturnScope scope = parser.attributes();
+
+ if (success) {
+ assertThat("Value '" + attribute + "' did not parse and should have", scope.getTree(), notNullValue());
+ assertThat(attribute, is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
+ } else {
+ assertThat("Value '" + attribute + "' should not parse and did", scope.getTree(), nullValue());
+ }
+ }
+
+ @Test
+ public void shouldParsePrimaryAttribute() throws Exception {
+ parseAttribute("primary", true);
+ parseAttribute("pri", true);
+ parseAttribute("!", true);
+ }
+
+ @Test
+ public void shouldParseAutoCreatedAttribute() throws Exception {
+ parseAttribute("autocreated", true);
+ parseAttribute("aut", true);
+ parseAttribute("a", true);
+ }
+
+ @Test
+ public void shouldParseMandatoryAttribute() throws Exception {
+ parseAttribute("mandatory", true);
+ parseAttribute("man", true);
+ parseAttribute("m", true);
+ }
+
+ @Test
+ public void shouldParseProtectedAttribute() throws Exception {
+ parseAttribute("protected", true);
+ parseAttribute("pro", true);
+ parseAttribute("p", true);
+ }
+
+ @Test
+ public void shouldParseMultipleAttribute() throws Exception {
+ parseAttribute("multiple", true);
+ parseAttribute("mul", true);
+ parseAttribute("*", true);
+ }
+
+ @Test
+ public void shouldParseCopyAttribute() throws Exception {
+ parseAttribute("COPY", true);
+ parseAttribute("Copy", true);
+ parseAttribute("copy", true);
+ }
+
+ @Test
+ public void shouldParseVersionAttribute() throws Exception {
+ parseAttribute("VERSION", true);
+ parseAttribute("Version", true);
+ parseAttribute("version", true);
+ }
+
+ @Test
+ public void shouldParseInitializeAttribute() throws Exception {
+ parseAttribute("INITIALIZE", true);
+ parseAttribute("Initialize", true);
+ parseAttribute("initialize", true);
+ }
+
+ @Test
+ public void shouldParseComputeAttribute() throws Exception {
+ parseAttribute("COMPUTE", true);
+ parseAttribute("Compute", true);
+ parseAttribute("compute", true);
+ }
+
+ @Test
+ public void shouldParseIgnoreAttribute() throws Exception {
+ parseAttribute("IGNORE", true);
+ parseAttribute("Ignore", true);
+ parseAttribute("ignore", true);
+ }
+
+ @Test
+ public void shouldParseAbortAttribute() throws Exception {
+ parseAttribute("ABORT", true);
+ parseAttribute("Abort", true);
+ parseAttribute("abort", true);
+ }
+
+ @Test
+ public void shouldNotParseInvalidAttribute() throws Exception {
+ parsePropertyType("P", false);
+ parsePropertyType("A", false);
+ parsePropertyType("PRIMARY", false);
+ }
+}
Added: trunk/sequencers/dna-sequencer-cnd/src/test/resources/builtin_nodetypes.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/resources/builtin_nodetypes.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/resources/builtin_nodetypes.cnd 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+<rep='internal'>
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// B A S E T Y P E S
+//------------------------------------------------------------------------------
+
+[nt:base]
+ - jcr:primaryType (name) mandatory autocreated protected compute
+ - jcr:mixinTypes (name) protected multiple compute
+
+[nt:unstructured]
+ orderable
+ - * (undefined) multiple
+ - * (undefined)
+ + * (nt:base) = nt:unstructured multiple version
+
+[mix:referenceable]
+ mixin
+ - jcr:uuid (string) mandatory autocreated protected initialize
+
+[mix:lockable]
+ mixin
+ - jcr:lockOwner (string) protected ignore
+ - jcr:lockIsDeep (boolean) protected ignore
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+[mix:versionable] > mix:referenceable
+ mixin
+ - jcr:versionHistory (reference) mandatory protected
+ < 'nt:versionHistory'
+ - jcr:baseVersion (reference) mandatory protected ignore
+ < 'nt:version'
+ - jcr:isCheckedOut (boolean) = 'true' mandatory autocreated protected ignore
+ - jcr:predecessors (reference) mandatory protected multiple
+ < 'nt:version'
+ - jcr:mergeFailed (reference) protected multiple abort
+
+[nt:versionHistory] > mix:referenceable
+ - jcr:versionableUuid (string) mandatory autocreated protected abort
+ + jcr:rootVersion (nt:version) = nt:version mandatory autocreated protected abort
+ + jcr:versionLabels (nt:versionLabels) = nt:versionLabels mandatory autocreated protected abort
+ + * (nt:version) = nt:version protected abort
+
+[nt:versionLabels]
+ - * (reference) protected abort
+ < 'nt:version'
+
+[nt:version] > mix:referenceable
+ - jcr:created (date) mandatory autocreated protected abort
+ - jcr:predecessors (reference) protected multiple abort
+ < 'nt:version'
+ - jcr:successors (reference) protected multiple abort
+ < 'nt:version'
+ + jcr:frozenNode (nt:frozenNode) protected abort
+
+[nt:frozenNode] > mix:referenceable
+ orderable
+ - jcr:frozenPrimaryType (name) mandatory autocreated protected abort
+ - jcr:frozenMixinTypes (name) protected multiple abort
+ - jcr:frozenUuid (string) mandatory autocreated protected abort
+ - * (undefined) protected abort
+ - * (undefined) protected multiple abort
+ + * (nt:base) protected multiple abort
+
+[nt:versionedChild]
+ - jcr:childVersionHistory (reference) mandatory autocreated protected abort
+ < 'nt:versionHistory'
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[nt:nodeType]
+ - jcr:nodeTypeName (name) mandatory
+ - jcr:supertypes (name) multiple
+ - jcr:isMixin (boolean) mandatory
+ - jcr:hasOrderableChildNodes (boolean) mandatory
+ - jcr:primaryItemName (name)
+ + jcr:propertyDefinition (nt:propertyDefinition) = nt:propertyDefinition multiple version
+ + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition multiple version
+
+[nt:propertyDefinition]
+ - jcr:name (name)
+ - jcr:autoCreated (boolean) mandatory
+ - jcr:mandatory (boolean) mandatory
+ - jcr:onParentVersion (string) mandatory
+ < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+ - jcr:protected (boolean) mandatory
+ - jcr:requiredType (string) mandatory
+ < 'STRING', 'BINARY', 'LONG', 'DOUBLE', 'BOOLEAN', 'DATE', 'NAME', 'PATH', 'REFERENCE', 'UNDEFINED'
+ - jcr:valueConstraints (string) multiple
+ - jcr:defaultValues (undefined) multiple
+ - jcr:multiple (boolean) mandatory
+
+[nt:childNodeDefinition]
+ - jcr:name (name)
+ - jcr:autoCreated (boolean) mandatory
+ - jcr:mandatory (boolean) mandatory
+ - jcr:onParentVersion (string) mandatory
+ < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+ - jcr:protected (boolean) mandatory
+ - jcr:requiredPrimaryTypes (name) = 'nt:base' mandatory multiple
+ - jcr:defaultPrimaryType (name)
+ - jcr:sameNameSiblings (boolean) mandatory
+
+//------------------------------------------------------------------------------
+// M I S C
+//------------------------------------------------------------------------------
+
+[nt:hierarchyNode]
+ - jcr:created (date) autocreated protected initialize
+
+[nt:folder] > nt:hierarchyNode
+ + * (nt:hierarchyNode) version
+
+[nt:file] > nt:hierarchyNode
+ + jcr:content (nt:base) primary mandatory
+
+[nt:linkedFile] > nt:hierarchyNode
+ - jcr:content (reference) primary mandatory
+
+[nt:resource] > mix:referenceable
+ - jcr:encoding (string)
+ - jcr:mimeType (string) mandatory
+ - jcr:data (binary) primary mandatory
+ - jcr:lastModified (date) mandatory ignore
+
+[nt:query]
+ - jcr:statement (string)
+ - jcr:language (string)
+
+//------------------------------------------------------------------------------
+// J A C K R A B B I T I N T E R N A L S
+//------------------------------------------------------------------------------
+
+[rep:nodeTypes]
+ + * (nt:nodeType) = nt:nodeType protected abort
+
+[rep:root] > nt:unstructured
+ orderable
+ + jcr:system (rep:system) = rep:system mandatory ignore
+
+[rep:system]
+ orderable
+ + jcr:versionStorage (rep:versionStorage) = rep:versionStorage mandatory protected abort
+ + jcr:nodeTypes (rep:nodeTypes) = rep:nodeTypes mandatory protected abort
+ + * (nt:base) = nt:unstructured multiple ignore
+
+[rep:versionStorage]
+ + * (nt:versionHistory) = nt:versionHistory protected multiple abort
+ + * (rep:versionStorage) = rep:versionStorage protected multiple abort
Added: trunk/sequencers/dna-sequencer-cnd/src/test/resources/empty.cnd
===================================================================
Added: trunk/sequencers/dna-sequencer-cnd/src/test/resources/images.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/resources/images.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/resources/images.cnd 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<image='http://jboss.org/dna/images/1.0'>
+
+// ----------------------------------------------------------
+// JCR Pre-defined Mixin Types that are not loaded by default
+// ----------------------------------------------------------
+
+[mix:mimeType] mixin
+ - jcr:mimeType (string)
+ - jcr:encoding (string)
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Mixin that defines the metadata for an image
+ */
+[image:metadata] > nt:unstructured, mix:mimeType
+ - image:formatName (string) mandatory
+ < 'JPEG', 'GIF', 'PNG', 'BMP', 'PCX', 'IFF', 'RAS', 'PBM', 'PGM', 'PPM', 'PSD'
+ - image:width (long)
+ - image:height (long)
+ - image:bitsPerPixel (long)
+ - image:progressive (boolean)
+ - image:numberOfImages (long)
+ - image:physicalWidthDpi (long)
+ - image:physicalHeightDpi (long)
+ - image:physicalWidthInches (long)
+ - image:physicalHeightInches (long)
+
+
+
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-cnd/src/test/resources/invalid.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/resources/invalid.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/resources/invalid.cnd 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1 @@
+This is not a valid cnd file.
\ No newline at end of file
Added: trunk/sequencers/dna-sequencer-cnd/src/test/resources/mp3.cnd
===================================================================
--- trunk/sequencers/dna-sequencer-cnd/src/test/resources/mp3.cnd (rev 0)
+++ trunk/sequencers/dna-sequencer-cnd/src/test/resources/mp3.cnd 2008-06-13 14:13:50 UTC (rev 284)
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<mp3='http://jboss.org/dna/mp3/1.0'>
+
+// ----------------------------------------------------------
+// JCR Pre-defined Mixin Types that are not loaded by default
+// ----------------------------------------------------------
+
+[mix:mimeType] mixin
+ - jcr:mimeType (string)
+ - jcr:encoding (string)
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[mp3:metadata] > nt:unstructured, mix:mimeTyped
+ - mp3:title (string)
+ - mp3:author (string)
+ - mp3:album (string)
+ - mp3:year (long)
+ - mp3:comment (string)
+
+
\ No newline at end of file
15 years, 10 months
DNA SVN: r283 - trunk/sequencers.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-13 09:49:24 -0400 (Fri, 13 Jun 2008)
New Revision: 283
Removed:
trunk/sequencers/dna-sequencer-cnd/
Log:
Removed empty directory
15 years, 10 months
DNA SVN: r282 - trunk.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-12 17:56:32 -0400 (Thu, 12 Jun 2008)
New Revision: 282
Modified:
trunk/eclipse-preferences.epf
Log:
Set warning for unused suppress warning annotations
Modified: trunk/eclipse-preferences.epf
===================================================================
--- trunk/eclipse-preferences.epf 2008-06-12 21:25:21 UTC (rev 281)
+++ trunk/eclipse-preferences.epf 2008-06-12 21:56:32 UTC (rev 282)
@@ -68,6 +68,7 @@
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.source=1.5
/instance/org.eclipse.jdt.ui/content_assist_favorite_static_members=org.junit.Assert.*;org.hamcrest.core.IsEqual.*;org.junit.matchers.JUnitMatchers.*;org.hamcrest.core.AllOf.*;org.hamcrest.core.AnyOf.*;org.hamcrest.core.IsInstanceOf.*;org.hamcrest.core.IsNot.*;org.hamcrest.core.IsNull.*;org.hamcrest.core.IsSame.*;org.hamcrest.core.DescribedAs.*;org.junit.matchers.IsCollectionContaining.*;org.junit.matchers.StringContains.*;org.hamcrest.core.Is.is;org.hamcrest.core.IsNot.not;org.hamcrest.core.IsNull.nullValue;org.hamcrest.core.IsNull.notNullValue;org.hamcrest.core.IsSame.sameInstance;org.hamcrest.core.IsInstanceOf.instanceOf;org.hamcrest.core.IsEqual.equalTo;org.hamcrest.core.IsAnything.anything;org.hamcrest.core.IsAnything.any;org.hamcrest.core.DescribedAs.describedAs;org.hamcrest.core.AnyOf.anyOf;org.hamcrest.core.AllOf.allOf;org.junit.matchers.IsCollectionContaining.hasItem;org.junit.matchers.IsCollectionContaining.hasItems;org.junit.matchers.Each.each;org.junit.matchers.!
JUnitMatchers.hasItem;org.junit.matchers.JUnitMatchers.hasItems;org.junit.matchers.JUnitMatchers.containsString;org.junit.matchers.JUnitMatchers.each;org.junit.matchers.JUnitMatchers.both;org.junit.matchers.JUnitMatchers.either;org.junit.matchers.StringContains.containsString;org.junit.matchers.TypeSafeMatcher.matches;org.hamcrest.collection.IsArray.*;org.hamcrest.collection.IsArrayContaining.*;org.hamcrest.number.IsCloseTo.*;org.mockito.Mockito.mock;org.mockito.Mockito.stub;org.mockito.Mockito.verify;org.mockito.Mockito.atLeastOnce;org.mockito.Mockito.inOrder;org.mockito.Mockito.never;org.mockito.Mockito.stubVoid;org.mockito.Mockito.times;org.mockito.Matchers;org.mockito.Matchers.anyBoolean;org.mockito.Matchers.anyByte;org.mockito.Matchers.anyChar;org.mockito.Matchers.anyDouble;org.mockito.Matchers.anyFloat;org.mockito.Matchers.anyInt;org.mockito.Matchers.anyLong;org.mockito.Matchers.anyObject;org.mockito.Matchers.anyShort;org.mockito.Matchers.anyString;org.mockito.Matcher!
s.argThat;org.mockito.Matchers.booleanThat;org.mockito.Matchers.byteTh
at;org.mockito.Matchers.charThat;org.mockito.Matchers.contains;org.mockito.Matchers.doubleThat;org.mockito.Matchers.endsWith;org.mockito.Matchers.eq;org.mockito.Matchers.floatThat;org.mockito.Matchers.intThat;org.mockito.Matchers.isA;org.mockito.Matchers.isNull;org.mockito.Matchers.longThat;org.mockito.Matchers.matches;org.mockito.Matchers.notNull;org.mockito.Matchers.refEq;org.mockito.Matchers.same;org.mockito.Matchers.shortThat;org.mockito.Matchers.startsWith;org.jboss.dna.common.text.StringMatcher.startsWith;org.jboss.dna.spi.graph.connection.RepositorySourceLoadHarness.runLoadTest
15 years, 10 months
DNA SVN: r280 - trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-06-12 16:28:06 -0400 (Thu, 12 Jun 2008)
New Revision: 280
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionPool.java
Log:
Updated code to eliminate compiler warning
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionPool.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionPool.java 2008-06-12 20:22:26 UTC (rev 279)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionPool.java 2008-06-12 20:28:06 UTC (rev 280)
@@ -166,7 +166,8 @@
* @throws IllegalArgumentException if the connection factory is null or any of the supplied arguments are invalid
*/
public RepositoryConnectionPool( RepositoryConnectionFactory connectionFactory ) {
- this(connectionFactory, DEFAULT_CORE_POOL_SIZE, DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_KEEP_ALIVE_TIME_IN_SECONDS, TimeUnit.SECONDS);
+ this(connectionFactory, DEFAULT_CORE_POOL_SIZE, DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_KEEP_ALIVE_TIME_IN_SECONDS,
+ TimeUnit.SECONDS);
}
/**
@@ -176,11 +177,15 @@
* @param corePoolSize the number of connections to keep in the pool, even if they are idle.
* @param maximumPoolSize the maximum number of connections to allow in the pool.
* @param keepAliveTime when the number of connection is greater than the core, this is the maximum time that excess idle
- * connections will be kept before terminating.
+ * connections will be kept before terminating.
* @param unit the time unit for the keepAliveTime argument.
* @throws IllegalArgumentException if the connection factory is null or any of the supplied arguments are invalid
*/
- public RepositoryConnectionPool( RepositoryConnectionFactory connectionFactory, int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit ) {
+ public RepositoryConnectionPool( RepositoryConnectionFactory connectionFactory,
+ int corePoolSize,
+ int maximumPoolSize,
+ long keepAliveTime,
+ TimeUnit unit ) {
ArgCheck.isNonNegative(corePoolSize, "corePoolSize");
ArgCheck.isPositive(maximumPoolSize, "maximumPoolSize");
ArgCheck.isNonNegative(keepAliveTime, "keepAliveTime");
@@ -228,7 +233,8 @@
* @param pingTimeout the time to wait for a ping to complete
* @param unit the time unit of the time argument
*/
- public void setPingTimeout( long pingTimeout, TimeUnit unit ) {
+ public void setPingTimeout( long pingTimeout,
+ TimeUnit unit ) {
ArgCheck.isNonNegative(pingTimeout, "time");
this.pingTimeout.set(unit.toNanos(pingTimeout));
}
@@ -253,12 +259,13 @@
* This overrides any value set in the constructor.
*
* @param time the time to wait. A time value of zero will cause excess connections to terminate immediately after being
- * returned.
+ * returned.
* @param unit the time unit of the time argument
* @throws IllegalArgumentException if time less than zero
* @see #getKeepAliveTime
*/
- public void setKeepAliveTime( long time, TimeUnit unit ) {
+ public void setKeepAliveTime( long time,
+ TimeUnit unit ) {
ArgCheck.isNonNegative(time, "time");
this.keepAliveTime = unit.toNanos(time);
}
@@ -446,8 +453,8 @@
* but no new connections will be created. Invocation has no additional effect if already shut down.
*
* @throws SecurityException if a security manager exists and shutting down this pool may manipulate threads that the caller
- * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>, or
- * the security manager's <tt>checkAccess</tt> method denies access.
+ * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>,
+ * or the security manager's <tt>checkAccess</tt> method denies access.
* @see #shutdownNow()
*/
public void shutdown() {
@@ -497,8 +504,8 @@
* Attempts to close all connections, including those connections currently in use, and prevent the use of other connections.
*
* @throws SecurityException if a security manager exists and shutting down this pool may manipulate threads that the caller
- * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>, or
- * the security manager's <tt>checkAccess</tt> method denies access.
+ * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>,
+ * or the security manager's <tt>checkAccess</tt> method denies access.
* @see #shutdown()
*/
public void shutdownNow() {
@@ -610,10 +617,11 @@
* @param timeout the maximum time to wait for all connections to be closed and returned to the pool
* @param unit the time unit for <code>timeout</code>
* @return true if the pool was terminated in the supplied time (or was already terminated), or false if the timeout occurred
- * before all the connections were closed
+ * before all the connections were closed
* @throws InterruptedException if the thread was interrupted
*/
- public boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+ public boolean awaitTermination( long timeout,
+ TimeUnit unit ) throws InterruptedException {
long nanos = unit.toNanos(timeout);
final ReentrantLock mainLock = this.mainLock;
try {
@@ -652,72 +660,59 @@
/**
* {@inheritDoc}
*/
- @SuppressWarnings( "null" )
public RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException {
int attemptsAllowed = this.maxFailedAttemptsBeforeError.get();
ConnectionWrapper connection = null;
- try {
- // Do this until we get a good connection ...
- int attemptsRemaining = attemptsAllowed;
- while (connection == null && attemptsRemaining > 0) {
- --attemptsRemaining;
- ReentrantLock mainLock = this.mainLock;
+ // Do this until we get a good connection ...
+ int attemptsRemaining = attemptsAllowed;
+ while (connection == null && attemptsRemaining > 0) {
+ --attemptsRemaining;
+ ReentrantLock mainLock = this.mainLock;
+ try {
+ mainLock.lock();
+ // If we're shutting down the pool, then just close the connection ...
+ if (this.runState != RUNNING) {
+ throw new IllegalStateException(SpiI18n.repositoryConnectionPoolIsNotRunning.text());
+ }
+ // If there are fewer total connections than the core size ...
+ if (this.poolSize < this.corePoolSize) {
+ // Immediately create a wrapped connection and return it ...
+ connection = newWrappedConnection();
+ }
+ // Peek to see if there is a connection available ...
+ else if (this.availableConnections.peek() != null) {
+ // There is, so take it and return it ...
+ connection = this.availableConnections.take();
+ }
+ // There is no connection available. If there are fewer total connections than the maximum size ...
+ else if (this.poolSize < this.maximumPoolSize) {
+ // Immediately create a wrapped connection and return it ...
+ connection = newWrappedConnection();
+ }
+ if (connection != null) {
+ this.inUseConnections.add(connection);
+ }
+ } finally {
+ mainLock.unlock();
+ }
+ if (connection == null) {
+ // There are not enough connections, so wait in line for the next available connection ...
+ this.logger.trace("Waiting for a repository connection from pool {0}", getName());
+ connection = this.availableConnections.take();
+ mainLock = this.mainLock;
+ mainLock.lock();
try {
- mainLock.lock();
- // If we're shutting down the pool, then just close the connection ...
- if (this.runState != RUNNING) {
- throw new IllegalStateException(SpiI18n.repositoryConnectionPoolIsNotRunning.text());
- }
- // If there are fewer total connections than the core size ...
- if (this.poolSize < this.corePoolSize) {
- // Immediately create a wrapped connection and return it ...
- connection = newWrappedConnection();
- }
- // Peek to see if there is a connection available ...
- else if (this.availableConnections.peek() != null) {
- // There is, so take it and return it ...
- connection = this.availableConnections.take();
- }
- // There is no connection available. If there are fewer total connections than the maximum size ...
- else if (this.poolSize < this.maximumPoolSize) {
- // Immediately create a wrapped connection and return it ...
- connection = newWrappedConnection();
- }
if (connection != null) {
this.inUseConnections.add(connection);
}
} finally {
mainLock.unlock();
}
- if (connection == null) {
- // There are not enough connections, so wait in line for the next available connection ...
- this.logger.trace("Waiting for a repository connection from pool {0}", getName());
- connection = this.availableConnections.take();
- mainLock = this.mainLock;
- mainLock.lock();
- try {
- if (connection != null) {
- this.inUseConnections.add(connection);
- }
- } finally {
- mainLock.unlock();
- }
- this.logger.trace("Recieved a repository connection from pool {0}", getName());
- }
- if (connection != null && this.validateConnectionBeforeUse.get()) {
- connection = validateConnection(connection);
- }
+ this.logger.trace("Recieved a repository connection from pool {0}", getName());
}
- } catch (InterruptedException e) {
- this.logger.trace("Thread interrupted while waiting for a repository connection from pool {0}", getName());
-
- // If the thread has been interrupted after we've taken a connection from the pool ...
- if (connection != null) {
- // We need to return the connection back into the pool ...
- returnConnection(connection);
+ if (connection != null && this.validateConnectionBeforeUse.get()) {
+ connection = validateConnection(connection);
}
- // And rethrow ...
- throw e;
}
if (connection == null) {
// We were unable to obtain a usable connection, so fail ...
@@ -955,7 +950,8 @@
/**
* {@inheritDoc}
*/
- public void execute( ExecutionEnvironment env, GraphCommand... commands ) throws RepositorySourceException, InterruptedException {
+ public void execute( ExecutionEnvironment env,
+ GraphCommand... commands ) throws RepositorySourceException, InterruptedException {
if (closed) throw new IllegalStateException(SpiI18n.closedConnectionMayNotBeUsed.text());
this.original.execute(env, commands);
}
@@ -963,7 +959,8 @@
/**
* {@inheritDoc}
*/
- public boolean ping( long time, TimeUnit unit ) throws InterruptedException {
+ public boolean ping( long time,
+ TimeUnit unit ) throws InterruptedException {
if (closed) throw new IllegalStateException(SpiI18n.closedConnectionMayNotBeUsed.text());
return this.original.ping(time, unit);
}
15 years, 10 months