Author: spagop
Date: 2008-08-25 19:56:33 -0400 (Mon, 25 Aug 2008)
New Revision: 466
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/config/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/ConsoleInput.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaInfo.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaSequencingClient.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/UserInterface.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/jackrabbitConfig.xml
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/java-source-artifact.cnd
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/log4j.properties
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/JavaSequencingClientTest.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/MockUserInterface.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/MySource.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/package-info.java
Log:
initila java sequencer client exmaple
Added: trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml
(rev 0)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+<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">
+
+ <parent>
+ <artifactId>getting_started</artifactId>
+ <groupId>org.jboss.dna.examples</groupId>
+ <version>0.2-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.dna.sequencer.java</groupId>
+ <artifactId>dna-example-java-sequencer</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Java Sequencer Example</name>
+ <description>
+ Examples that show case how to use Java Sequencer with a JCR
+ repository.
+ </description>
+ <properties>
+ <dna-version>0.2-SNAPSHOT</dna-version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-repository</artifactId>
+ <version>${dna-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>${dna-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-java</artifactId>
+ <version>${dna-version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- collection framework -->
+ <dependency>
+ <groupId>com.google.code.google-collections</groupId>
+ <artifactId>google-collect</artifactId>
+ <version>snapshot-20080530</version>
+ </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 Content Repository API
+ -->
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+ <!--
+ Apache Jackrabbit (JCR Implementation) for repository implementation
+ -->
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ </dependency>
+ <!--
+ Test cases use JUnit
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!--
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/basic.xml</descriptor>
+ </descriptors>
+ <finalName>${pom.artifactId}</finalName>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>directory-inline</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ -->
+
+
+</project>
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/ConsoleInput.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/ConsoleInput.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/ConsoleInput.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,207 @@
+/*
+ * 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.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import org.jboss.dna.repository.sequencers.SequencingService;
+
+/**
+ * @author Randall Hauch
+ */
+public class ConsoleInput implements UserInterface {
+
+ protected static BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
+
+ public ConsoleInput( final JavaSequencingClient client ) {
+ try {
+ System.out.println();
+ System.out.print("Starting repository and sequencing service ...
");
+ client.startRepository();
+ System.out.print("done.\nStarting sequencing service ... ");
+ client.startDnaServices();
+ System.out.println("done.");
+ System.out.println();
+
+ System.out.println(getMenu());
+ Thread eventThread = new Thread(new Runnable() {
+
+ private boolean quit = false;
+
+ public void run() {
+ try {
+ while (!quit) {
+ System.out.print(">");
+ try {
+ String input = in.readLine();
+ if (input.length() != 1) {
+ System.out.println("Please enter a valid
option.");
+ continue;
+ }
+
+ char option = input.charAt(0);
+ switch (option) {
+ case 'u':
+ client.uploadFile();
+ break;
+ case 's':
+ client.search();
+ break;
+ case 'm':
+ case '?':
+ case 'h':
+ System.out.println(getMenu());
+ break;
+ case 'd':
+
System.out.println(getStatistics(client.getStatistics()));
+ break;
+ case 'q':
+ quit = true;
+ break;
+ default:
+ System.out.println("Invalid option.");
+ break;
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("Invalid integer " +
e.getMessage());
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ } finally {
+ try {
+ // Terminate ...
+ System.out.println();
+ System.out.print("Shutting down sequencing service ...
");
+ client.shutdownDnaServices();
+ System.out.print("done.\nShutting down repository ...
");
+ client.shutdownRepository();
+ System.out.print("done.");
+ System.out.println();
+ System.out.println();
+ } catch (Exception err) {
+ System.out.println("Error shutting down sequencing
service and repository: " + err.getLocalizedMessage());
+ err.printStackTrace(System.err);
+ }
+ }
+ }
+ });
+
+ eventThread.start();
+ } catch (Exception err) {
+ System.out.println("Error: " + err.getLocalizedMessage());
+ err.printStackTrace(System.err);
+ }
+ }
+
+ protected String getMenu() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("-----------------------------------\n");
+ buffer.append("Menu:\n");
+ buffer.append("\n");
+ buffer.append("u) Upload a file to the repository\n");
+ buffer.append("s) Search the repository using extracted metadata\n");
+ buffer.append("\n");
+ buffer.append("d) Display statistics\n");
+ buffer.append("\n");
+ buffer.append("?) Show this menu\n");
+ buffer.append("q) Quit");
+ return buffer.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URL getFileToUpload() throws IllegalArgumentException, IOException {
+ System.out.println("Please enter the file to upload:");
+ String path = in.readLine();
+ File file = new File(path);
+ if (!file.exists()) {
+ throw new IllegalArgumentException("The file \"" +
file.getAbsolutePath() + "\" does not exist.");
+ }
+ if (!file.canRead()) {
+ throw new IllegalArgumentException("Unable to read \"" +
file.getAbsolutePath() + "\".");
+ }
+ if (!file.isFile()) {
+ throw new IllegalArgumentException("Please specify a file. The file
\"" + file.getAbsolutePath() + "\" is a directory.");
+ }
+ return file.toURL();
+ }
+
+ public String getRepositoryPath( String defaultPath ) throws
IllegalArgumentException, IOException {
+ if (defaultPath != null) defaultPath = defaultPath.trim();
+ if (defaultPath.length() == 0) defaultPath = null;
+ String displayDefaultPath = defaultPath == null ? "" : " [" +
defaultPath.trim() + "]";
+ System.out.println("Please enter the repository path where the file should
be placed" + displayDefaultPath + ":");
+ String path = in.readLine().trim();
+ if (path.length() == 0) {
+ if (defaultPath == null) {
+ throw new IllegalArgumentException("The path \"" + path +
"\" is not valid.");
+ }
+ path = defaultPath;
+ }
+ return path;
+ }
+
+ public void displaySearchResults( List<JavaInfo> javaInfos ) {
+ System.out.println();
+ if (javaInfos.isEmpty()) {
+ System.out.println("No results were found.");
+ System.out.println();
+ return;
+ }
+ if (javaInfos.size() == 1) {
+ System.out.println("1 image was found:");
+ } else {
+ System.out.println("" + javaInfos.size() + " java sources were
found:");
+ }
+ int counter = 1;
+ for (JavaInfo javaInfo : javaInfos) {
+ System.out.println(" Media " + counter++);
+ System.out.println(" Name: " + javaInfo.getName());
+ System.out.println(" Path: " + javaInfo.getPath());
+ System.out.println(" Type: " + javaInfo.getType());
+ for (Map.Entry<String, String> entry : javaInfo.getMap().entries()) {
+ System.out.println(" " + entry.getKey() + ": " +
entry.getValue());
+ }
+ }
+ System.out.println();
+ }
+
+ public String getStatistics( SequencingService.Statistics stats ) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\n");
+ sb.append("# nodes sequenced:
").append(stats.getNumberOfNodesSequenced()).append("\n");
+ sb.append("# nodes skipped:
").append(stats.getNumberOfNodesSkipped()).append("\n");
+ sb.append("\n");
+ return sb.toString();
+ }
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaInfo.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaInfo.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaInfo.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,84 @@
+/*
+ * 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.Map;
+import java.util.Properties;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public class JavaInfo {
+
+ private final Multimap<String, String> map = new ArrayListMultimap<String,
String>();
+
+ private final String name;
+ private final String path;
+ private final String type;
+
+ protected JavaInfo( String path, String name, String type, Multimap<String,
String> map) {
+ this.name = name;
+ this.path = path;
+ this.type = type;
+ if (map != null) this.map.putAll(map);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (Map.Entry<String, String> entry : map.entries()) {
+
sb.append(entry.getKey()).append("=>").append(entry.getValue());
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ }
+ return this.name + " (at " + this.path + ") of type \""
+ this.type + "\" with properties {" + sb.toString() + "}";
+ }
+
+ /**
+ * @return map
+ */
+ public Multimap<String, String> getMap() {
+ return map;
+ }
+
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaSequencingClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaSequencingClient.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaSequencingClient.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,434 @@
+/*
+ * 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.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.observation.Event;
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.jboss.dna.common.SystemFailureException;
+import org.jboss.dna.repository.observation.ObservationService;
+import org.jboss.dna.repository.sequencers.SequencerConfig;
+import org.jboss.dna.repository.sequencers.SequencingService;
+import org.jboss.dna.repository.util.BasicJcrExecutionContext;
+import org.jboss.dna.repository.util.JcrExecutionContext;
+import org.jboss.dna.repository.util.JcrTools;
+import org.jboss.dna.repository.util.SessionFactory;
+import org.jboss.dna.repository.util.SimpleSessionFactory;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multiset.Entry;
+
+/**
+ * @author serge pagop
+ */
+public class JavaSequencingClient {
+
+ public static final String DEFAULT_JACKRABBIT_CONFIG_PATH =
"jackrabbitConfig.xml";
+ public static final String DEFAULT_WORKING_DIRECTORY = "repositoryData";
+ public static final String DEFAULT_REPOSITORY_NAME = "repo";
+ public static final String DEFAULT_WORKSPACE_NAME = "default";
+ public static final String DEFAULT_USERNAME = "jsmith";
+ public static final char[] DEFAULT_PASSWORD = "secret".toCharArray();
+
+ private Map<String, String> map = new HashMap<String, String>();
+
+ public static void main( String[] args ) {
+ JavaSequencingClient client = new JavaSequencingClient();
+ client.setRepositoryInformation(DEFAULT_REPOSITORY_NAME, DEFAULT_WORKSPACE_NAME,
DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ client.setUserInterface(new ConsoleInput(client));
+ }
+
+ private String repositoryName;
+ private String workspaceName;
+ private String username;
+ private char[] password;
+ private String jackrabbitConfigPath;
+ private String workingDirectory;
+ private Session keepAliveSession;
+ private Repository repository;
+ private SequencingService sequencingService;
+ private ObservationService observationService;
+ private UserInterface userInterface;
+ private JcrExecutionContext executionContext;
+
+ public JavaSequencingClient() {
+ setJackrabbitConfigPath(DEFAULT_JACKRABBIT_CONFIG_PATH);
+ setWorkingDirectory(DEFAULT_WORKING_DIRECTORY);
+ setRepositoryInformation(DEFAULT_REPOSITORY_NAME, DEFAULT_WORKSPACE_NAME,
DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ }
+
+ protected void setWorkingDirectory( String workingDirectoryPath ) {
+ this.workingDirectory = workingDirectoryPath != null ? workingDirectoryPath :
DEFAULT_WORKING_DIRECTORY;
+ }
+
+ protected void setJackrabbitConfigPath( String jackrabbitConfigPath ) {
+ this.jackrabbitConfigPath = jackrabbitConfigPath != null ? jackrabbitConfigPath :
DEFAULT_JACKRABBIT_CONFIG_PATH;
+ }
+
+ protected void setRepositoryInformation( String repositoryName,
+ String workspaceName,
+ String username,
+ char[] password ) {
+ if (this.repository != null) {
+ throw new IllegalArgumentException("Unable to set repository information
when repository is already running");
+ }
+ this.repositoryName = repositoryName != null ? repositoryName :
DEFAULT_REPOSITORY_NAME;
+ this.workspaceName = workspaceName != null ? workspaceName :
DEFAULT_WORKSPACE_NAME;
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Set the user interface that this client should use.
+ *
+ * @param userInterface
+ */
+ public void setUserInterface( UserInterface userInterface ) {
+ this.userInterface = userInterface;
+ }
+
+ /**
+ * Start up the JCR repository. This method only operates using the JCR API and
Jackrabbit-specific API.
+ *
+ * @throws Exception
+ */
+ public void startRepository() throws Exception {
+ if (this.repository == null) {
+ try {
+
+ // Load the Jackrabbit configuration ...
+ File configFile = new File(this.jackrabbitConfigPath);
+ if (!configFile.exists()) {
+ throw new SystemFailureException("The Jackrabbit configuration
file cannot be found at "
+ + configFile.getAbsoluteFile());
+ }
+ if (!configFile.canRead()) {
+ throw new SystemFailureException("Unable to read the Jackrabbit
configuration file at "
+ + configFile.getAbsoluteFile());
+ }
+ String pathToConfig = configFile.getAbsolutePath();
+
+ // Find the directory where the Jackrabbit repository data will be stored
...
+ File workingDirectory = new File(this.workingDirectory);
+ if (workingDirectory.exists()) {
+ if (!workingDirectory.isDirectory()) {
+ throw new SystemFailureException("Unable to create working
directory at "
+ +
workingDirectory.getAbsolutePath());
+ }
+ }
+ String workingDirectoryPath = workingDirectory.getAbsolutePath();
+
+ // Get the Jackrabbit custom node definition (CND) file ...
+ URL cndFile =
Thread.currentThread().getContextClassLoader().getResource("java-source-artifact.cnd");
+
+ // Create the Jackrabbit repository instance and establish a session to
keep the repository alive ...
+ this.repository = new TransientRepository(pathToConfig,
workingDirectoryPath);
+ if (this.username != null) {
+ Credentials credentials = new SimpleCredentials(this.username,
this.password);
+ this.keepAliveSession = this.repository.login(credentials,
this.workspaceName);
+ } else {
+ this.keepAliveSession = this.repository.login();
+ }
+
+ try {
+ // Register the node types (only valid the first time) ...
+ JackrabbitNodeTypeManager mgr =
(JackrabbitNodeTypeManager)this.keepAliveSession.getWorkspace().getNodeTypeManager();
+ mgr.registerNodeTypes(cndFile.openStream(),
JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+ } catch (RepositoryException e) {
+ if (!e.getMessage().contains("already exists")) throw e;
+ }
+
+ } catch (Exception e) {
+ this.repository = null;
+ this.keepAliveSession = null;
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Shutdown the repository. This method only uses the JCR API.
+ *
+ * @throws Exception
+ */
+ public void shutdownRepository() throws Exception {
+ if (this.repository != null) {
+ try {
+ this.keepAliveSession.logout();
+ } finally {
+ this.repository = null;
+ this.keepAliveSession = null;
+ }
+ }
+ }
+
+ /**
+ * Start the DNA services.
+ *
+ * @throws Exception
+ */
+ public void startDnaServices() throws Exception {
+ if (this.repository == null) {
+ this.startRepository();
+ }
+ if (this.sequencingService == null) {
+
+ // Create an execution context for the sequencing service. This execution
context provides an environment
+ // for the DNA services which knows about the JCR repositories, workspaces,
and credentials used to
+ // establish sessions to these workspaces. This example uses the
BasicJcrExecutionContext, but there is
+ // implementation for use with JCR repositories registered in JNDI.
+ final String repositoryWorkspaceName = this.repositoryName + "/" +
this.workspaceName;
+ SimpleSessionFactory sessionFactory = new SimpleSessionFactory();
+ sessionFactory.registerRepository(this.repositoryName, this.repository);
+ if (this.username != null) {
+ Credentials credentials = new SimpleCredentials(this.username,
this.password);
+ sessionFactory.registerCredentials(repositoryWorkspaceName,
credentials);
+ }
+ this.executionContext = new BasicJcrExecutionContext(sessionFactory,
repositoryWorkspaceName);
+
+ // Create the sequencing service, passing in the execution context ...
+ this.sequencingService = new SequencingService();
+ this.sequencingService.setExecutionContext(executionContext);
+
+ // Configure the sequencers. In this example, we only one sequencers that
processes java source.
+ // So create a configurations. Note that the sequencing service expects the
class to be on the thread's current
+ // context
+ // class loader, or if that's null the class loader that loaded the
SequencingService class.
+ //
+ // Part of the configuration includes telling DNA which JCR paths should be
processed by the sequencer.
+ // These path expressions tell the service that this sequencer should be
invoked on the "jcr:data" property
+ // on the "jcr:content" child node of any node uploaded to the
repository whose name ends with one of the
+ // supported extensions, and the sequencer should place the generated output
meta data in a node with the same name as
+ // the file but immediately below the "/compilationUnits" node.
Path expressions can be fairly complex, and can even
+ // specify that the generated information be placed in a different
repository.
+ //
+ // Sequencer configurations can be added before or after the service is
started, but here we do it before the service
+ // is running.
+ String name = "Java Sequencer";
+ String desc = "Sequences java files to extract the characteristics of
the java sources";
+ String classname =
"org.jboss.dna.sequencer.java.JavaMetadataSequencer";
+ String[] classpath = null; // Use the current class path
+ String[] pathExpressions = {"//(*.java)[*]/jcr:content[@jcr:data] =>
/compilationUnits/$1"};
+ SequencerConfig javaSequencerConfig = new SequencerConfig(name, desc,
classname, classpath, pathExpressions);
+ this.sequencingService.addSequencer(javaSequencerConfig);
+
+ // Use the DNA observation service to listen to the JCR repository (or
multiple ones), and
+ // then register the sequencing service as a listener to this observation
service...
+ this.observationService = new
ObservationService(this.executionContext.getSessionFactory());
+ this.observationService.getAdministrator().start();
+ this.observationService.addListener(this.sequencingService);
+ this.observationService.monitor(repositoryWorkspaceName, Event.NODE_ADDED |
Event.PROPERTY_ADDED
+ |
Event.PROPERTY_CHANGED);
+ }
+ // Start up the sequencing service ...
+ this.sequencingService.getAdministrator().start();
+ }
+
+ /**
+ * Shut down the DNA services.
+ *
+ * @throws Exception
+ */
+ public void shutdownDnaServices() throws Exception {
+ if (this.sequencingService == null) return;
+
+ // Shut down the service and wait until it's all shut down ...
+ this.sequencingService.getAdministrator().shutdown();
+ this.sequencingService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
+
+ // Shut down the observation service ...
+ this.observationService.getAdministrator().shutdown();
+ this.observationService.getAdministrator().awaitTermination(5,
TimeUnit.SECONDS);
+ }
+
+ /**
+ * Get the sequencing statistics.
+ *
+ * @return the statistics; never null
+ */
+ public SequencingService.Statistics getStatistics() {
+ return this.sequencingService.getStatistics();
+ }
+
+ /**
+ * Prompt the user interface for the file to upload into the JCR repository, then
upload it using the JCR API.
+ *
+ * @throws Exception
+ */
+ public void uploadFile() throws Exception {
+ URL url = this.userInterface.getFileToUpload();
+ // Grab the last segment of the URL path, using it as the filename
+ String filename = url.getPath().replaceAll("([^/]*/)*", "");
+ String nodePath = this.userInterface.getRepositoryPath("/a/b/" +
filename);
+ String mimeType = getMimeType(url);
+
+ // Now use the JCR API to upload the file ...
+ Session session = createSession();
+ JcrTools tools = this.executionContext.getTools();
+ try {
+ // Create the node at the supplied path ...
+ Node node = tools.findOrCreateNode(session, nodePath, "nt:folder",
"nt:file");
+
+ // Upload the file to that node ...
+ Node contentNode = tools.findOrCreateChild(session, node,
"jcr:content", "nt:resource");
+ contentNode.setProperty("jcr:mimeType", mimeType);
+ contentNode.setProperty("jcr:lastModified",
Calendar.getInstance());
+ contentNode.setProperty("jcr:data", url.openStream());
+
+ // Save the session ...
+ session.save();
+ } finally {
+ session.logout();
+ }
+ }
+
+ /**
+ * Perform a search of the repository for all java compilation units automatically
created by the java sequencer.
+ *
+ * @throws Exception
+ */
+ public void search() throws Exception {
+ // Use JCR to search the repository for image meta data ...
+ List<JavaInfo> javaInfos = new ArrayList<JavaInfo>();
+ Multimap<String, String> multimap = new ArrayListMultimap<String,
String>();
+ Session session = createSession();
+ try {
+ // Find the compilation unit node ...
+ Node root = session.getRootNode();
+ JavaInfo javaInfo = null;
+ if (root.hasNode("compilationUnits")) {
+ Node javaSourcesNode = root.getNode("compilationUnits");
+ for (NodeIterator i = javaSourcesNode.getNodes(); i.hasNext();) {
+ for (NodeIterator j = javaSourcesNode.getNodes(); i.hasNext();) {
+ Node javaSourceNode = i.nextNode();
+ if (javaSourceNode.hasNodes()) {
+ Node javaCompilationUnit =
javaSourceNode.getNodes().nextNode();
+ // package info
+ if (javaCompilationUnit.hasNode("java:package")) {
+ Node javaPackageDeclarationNode =
javaCompilationUnit.getNode("java:package");
+ extractInfo(javaPackageDeclarationNode, multimap);
+ }
+ // import infos
+ if (javaCompilationUnit.hasNode("java:import")) {
+ // single type import
+ Node javaImport =
javaCompilationUnit.getNode("java:import")
+ .getNode("java:importDeclaration");
+ extractInfo(javaImport, multimap);
+ }
+ // class infos
+ if (javaCompilationUnit.hasNode("java:unitType"))
{
+ Node javaNormalClassNode =
javaCompilationUnit.getNode("java:unitType")
+ .getNode("java:classDeclaration")
+ .getNode("java:normalClass")
+ .getNode("java:normalClassDeclaration");
+ extractInfo(javaNormalClassNode, multimap);
+
+ }
+ javaInfo = new JavaInfo(javaCompilationUnit.getPath(),
javaCompilationUnit.getName(), "java:compilationUnit", multimap);
+ javaInfos.add(javaInfo);
+ }
+ }
+ }
+ }
+
+ } finally {
+ session.logout();
+ }
+
+ // Display the search results ...
+ this.userInterface.displaySearchResults(javaInfos);
+ }
+
+ /**
+ * Extract informations from a specific node.
+ *
+ * @param node - node, that contains informations.
+ * @param multimap - a google collection, that support duplicate keys.
+ * @throws RepositoryException
+ * @throws IllegalStateException
+ * @throws ValueFormatException
+ */
+ private void extractInfo( Node node,
+ Multimap<String, String> multimap )
+ throws ValueFormatException, IllegalStateException, RepositoryException {
+ if (node.hasProperties()) {
+ int index = 1;
+ for (PropertyIterator propertyIter = node.getProperties();
propertyIter.hasNext();) {
+ Property property = propertyIter.nextProperty();
+ String name = property.getName();
+ String stringValue = property.getValue().getString();
+ if (!name.equals("jcr:primaryType")) {
+ multimap.put(name, stringValue);
+ }
+ }
+ }
+ if (node.hasNodes()) {
+ for (NodeIterator iterator = node.getNodes(); iterator.hasNext();) {
+ extractInfo(iterator.nextNode(), multimap);
+ }
+ }
+ }
+
+ /**
+ * Utility method to create a new JCR session from the execution context's {@link
SessionFactory}.
+ *
+ * @return the session
+ * @throws RepositoryException
+ */
+ protected Session createSession() throws RepositoryException {
+ return
this.executionContext.getSessionFactory().createSession(this.repositoryName +
"/" + this.workspaceName);
+ }
+
+ protected String getMimeType( URL file ) {
+ String filename = file.getPath().toLowerCase();
+ if (filename.endsWith(".java")) return "text/x-java-source";
+ throw new SystemFailureException("Unknown mime type for " + file);
+ }
+
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/UserInterface.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/UserInterface.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/UserInterface.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.sequencer.java;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * @author Randall Hauch
+ */
+public interface UserInterface {
+
+ public URL getFileToUpload() throws IllegalArgumentException, IOException;
+
+ public String getRepositoryPath( String defaultPath ) throws
IllegalArgumentException, IOException;
+
+ public void displaySearchResults( List<JavaInfo> javaInfos ) throws
IOException;
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/jackrabbitConfig.xml
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/jackrabbitConfig.xml
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/jackrabbitConfig.xml 2008-08-25
23:56:33 UTC (rev 466)
@@ -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/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/java-source-artifact.cnd
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/java-source-artifact.cnd
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/java-source-artifact.cnd 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,230 @@
+/*
+ * 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:annotationDeclaration,
java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:modifierName (string) 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:identifierName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation,
java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:normalAnnotationName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - java:markerAnnotationName (string) mandatory
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ - java:singleElementAnnotationNam
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+/**
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long',
'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type (''void')
+ */
+[java:primitiveType] > nt:unstructured
+ - java:primitiveTypeDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:primitiveTypeName (string) mandatory
+ + java:primitiveVariable (java:variable) = java:variable
+
+ [java:variable] > nt:unstructured
+ - java:variableName (string)
+
+/**
+ * Reference type (TODO to enhance)
+ */
+[java:referenceType] > nt:unstructured
+ - java:ReferenceDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:referenceName (string) mandatory
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:referenceType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:referenceType) mandatory
+ - java:methodName (string) mandatory
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:constructorDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:constructorName (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
+ - java:packageKeyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - java:singleTypeImportkeyword (string) mandatory
+ < 'import'
+ - java:singleImportName (string) mandatory
+
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - java:onDemandImportKeyword (string) mandatory
+ < 'import'
+ - java:onDemandImportName (string) mandatory
+
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) =
java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) =
java:typeImportOnDemandDeclaration
+
+
+/**
+ * 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 (java:modifierDeclaration) = java:modifierDeclaration
+ - java:normalClassName (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:unitType (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/log4j.properties
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/log4j.properties
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/log4j.properties 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,17 @@
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Set up the default logging to be INFO level, then override specific units
+log4j.logger.org.jboss.dna=INFO
+log4j.logger.org.jboss.dna.tests.integration.jackrabbit.JackrabbitMySqlStressTest=DEBUG
+
+# Jackrabbit logging
+log4j.logger.org.apache.jackrabbit=WARN, stdout
+log4j.logger.org.apache.derby=INFO, stdout
+
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/JavaSequencingClientTest.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/JavaSequencingClientTest.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/JavaSequencingClientTest.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,86 @@
+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.net.URL;
+import org.jboss.dna.common.util.FileUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class JavaSequencingClientTest {
+
+ private URL javaSourceUrl;
+
+ private JavaSequencingClient client;
+
+ @Before
+ public void beforeEach() throws Exception {
+
+ // Get the URL of source (MySource.java), that have to be sequencing
+ this.javaSourceUrl =
FileUtil.convertFileToURL("workspace/project1/src/org/acme/MySource.java");
+
+ // create the sequencing client
+ client = new JavaSequencingClient();
+
+ // the repository
+ client.setWorkingDirectory("target/repositoryData");
+
+ // for our content repository, we need a configuration file
+
client.setJackrabbitConfigPath("src/main/resources/jackrabbitConfig.xml");
+
+ // after all tests we have to deleted the local content repository
+ FileUtil.delete("target/repositoryData");
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ client.shutdownDnaServices();
+ client.shutdownRepository();
+ FileUtil.delete("target/repositoryData");
+ }
+
+ @Test
+ public void shouldFindCompilationUnitSource() {
+ assertThat(this.javaSourceUrl, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldStartupAndShutdownRepository() throws Exception {
+ client.startRepository();
+ client.shutdownRepository();
+
+ }
+
+ @Test
+ public void shouldStartupAndShutdownRepositoryAndSequencingService() throws Exception
{
+ client.startRepository();
+ client.startDnaServices();
+ client.shutdownDnaServices();
+ client.shutdownRepository();
+ }
+
+ @Test
+ public void shouldUploadAndSequenceJavaSourceFile() throws Exception {
+ client.setUserInterface(new MockUserInterface(this.javaSourceUrl,
"/a/b/MySource.java", 1));
+ client.startRepository();
+ client.startDnaServices();
+ client.uploadFile();
+
+ // Use a trick to wait until the sequencing has been done by sleeping (to give
the sequencing time to start)
+ // and to then shut down the DNA services (which will block until all sequencing
has been completed) ...
+ Thread.sleep(1000);
+ client.shutdownDnaServices();
+
+ // The sequencers should have run, so perform the search.
+ // The mock user interface checks the results.
+ // TODO
+ client.search();
+ assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
+ }
+
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/MockUserInterface.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/MockUserInterface.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/test/java/org/jboss/dna/sequencer/java/MockUserInterface.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,72 @@
+/*
+ * 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.junit.Assert.assertThat;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * @author Randall Hauch
+ * @author Serge Pagop
+ *
+ */
+public class MockUserInterface implements UserInterface {
+
+ private final String repositoryPath;
+ private final URL fileToUpload;
+ private final int numberOfSearchResults;
+
+ public MockUserInterface( URL fileToUpload,
+ String repositoryPath,
+ int numSearchResults ) {
+ this.repositoryPath = repositoryPath;
+ this.fileToUpload = fileToUpload;
+ this.numberOfSearchResults = numSearchResults;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void displaySearchResults( List<JavaInfo> infos ) {
+ assertThat(infos.size(), is(this.numberOfSearchResults));
+ for (JavaInfo info : infos) {
+ System.out.println("Java Info: " + info);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URL getFileToUpload() {
+ return this.fileToUpload;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRepositoryPath( String defaultPath ) {
+ return this.repositoryPath != null ? this.repositoryPath : defaultPath;
+ }
+
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/MySource.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/MySource.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/MySource.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -0,0 +1,94 @@
+/*
+ * 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;
+import java.util.*;
+
+/**
+ * @author Serge Pagop
+ */
+@MyClassAnnotation
+public class MySource {
+
+ private int i, j;
+ private static double a;
+ private List<String> l;
+ private A<Integer> o;
+ private X x;
+
+ MySource() {
+ }
+ public MySource(int i, int j) {
+ this.i = i;
+ this.j = j;
+ }
+
+
+ public int getI() {
+ return this.i;
+ }
+
+ public void setI( int i ) {
+ this.i = i;
+ }
+
+ public void setJ( int j ) {
+ this.j = j;
+ }
+
+ public void doSomething(int p1, double p2) {
+ l = new ArrayList<String>();
+ l.add("N1");
+ }
+
+ // nested class
+ class A<E> {
+ E e;
+
+ A( E e ) {
+ this.e = e;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.e);
+ }
+
+ class B<T> {
+ T t;
+
+ B( T t ) {
+ this.t = t;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.t);
+ }
+ }
+ }
+
+ class X {
+
+ }
+}
Added:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -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/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -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/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/package-info.java
===================================================================
---
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/package-info.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/workspace/project1/src/org/acme/package-info.java 2008-08-25
23:56:33 UTC (rev 466)
@@ -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;
+