Author: rhauch
Date: 2008-09-17 19:03:19 -0400 (Wed, 17 Sep 2008)
New Revision: 532
Added:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java
trunk/docs/examples/gettingstarted/sequencers/workspace/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java
Removed:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/
Modified:
trunk/docs/examples/gettingstarted/pom.xml
trunk/docs/examples/gettingstarted/sequencers/pom.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java
Log:
DNA-222 Create Getting Started example application for repositories
Refactored the java sequencer example project so that it's included in the
'sequencer' example. Most of the code was duplicated, and this makes the Getting
Started document much easier to understand as well, since all sequencing code is in the
one example.
Modified: trunk/docs/examples/gettingstarted/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/pom.xml 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
@@ -10,7 +10,7 @@
<modules>
<module>sequencers</module>
- <module>dna-example-java-sequencer</module>
+ <module>repositories</module>
</modules>
<properties>
@@ -36,6 +36,11 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
+ <artifactId>dna-jcr</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
<artifactId>dna-maven-classloader</artifactId>
<version>${dna-version}</version>
</dependency>
@@ -44,6 +49,27 @@
<artifactId>dna-sequencer-images</artifactId>
<version>${dna-version}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-java</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-inmemory</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-jbosscache</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-federation</artifactId>
+ <version>${dna-version}</version>
+ <scope>runtime</scope>
+ </dependency>
<!-- Logging (require SLF4J API for compiling, but use Log4J and its SLF4J
binding for testing) -->
<dependency>
<groupId>org.slf4j</groupId>
@@ -109,6 +135,12 @@
<version>4.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.5</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: trunk/docs/examples/gettingstarted/sequencers/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/pom.xml 2008-09-17 22:56:29 UTC (rev
531)
+++ trunk/docs/examples/gettingstarted/sequencers/pom.xml 2008-09-17 23:03:19 UTC (rev
532)
@@ -44,6 +44,12 @@
<version>${dna-version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-java</artifactId>
+ <version>${dna-version}</version>
+ <scope>runtime</scope>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for
testing)
-->
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml 2008-09-17
22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml 2008-09-17
23:03:19 UTC (rev 532)
@@ -23,6 +23,11 @@
<include>*.mp3</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>workspace/</directory>
+ <outputDirectory/>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ </fileSet>
</fileSets>
<files>
<file>
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -27,7 +27,6 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;
-import java.util.Map;
import org.jboss.dna.repository.sequencers.SequencingService;
/**
@@ -173,27 +172,22 @@
return path;
}
- public void displaySearchResults( List<MediaInfo> medias ) {
+ public void displaySearchResults( List<ContentInfo> contentInfos ) {
System.out.println();
- if (medias.isEmpty()) {
+ if (contentInfos.isEmpty()) {
System.out.println("No results were found.");
System.out.println();
return;
}
- if (medias.size() == 1) {
- System.out.println("1 image was found:");
+ if (contentInfos.size() == 1) {
+ System.out.println("1 result was found:");
} else {
- System.out.println("" + medias.size() + " images were
found:");
+ System.out.println("" + contentInfos.size() + " results were
found:");
}
int counter = 1;
- for (MediaInfo media : medias) {
- System.out.println(" Media " + counter++);
- System.out.println(" Name: " + media.getName());
- System.out.println(" Path: " + media.getPath());
- System.out.println(" Type: " + media.getMediaType());
- for (Map.Entry<Object, Object> entry :
media.getProperties().entrySet()) {
- System.out.println(" " + entry.getKey() + ": " +
entry.getValue());
- }
+ for (ContentInfo info : contentInfos) {
+ System.out.println(" " + info.getInfoType() + " " +
counter++);
+ System.out.println(info.toString());
}
System.out.println();
}
Added:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -0,0 +1,73 @@
+/*
+ * 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.example.dna.sequencers;
+
+import java.util.Map;
+import java.util.Properties;
+import net.jcip.annotations.Immutable;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class ContentInfo {
+
+ private final Properties properties = new Properties();
+ private final String name;
+ private final String path;
+
+ protected ContentInfo( String path,
+ String name,
+ Properties props ) {
+ this.name = name;
+ this.path = path;
+ if (props != null) this.properties.putAll(props);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
+
+ public Properties getProperties() {
+ return this.properties;
+ }
+
+ public String getInfoType() {
+ return this.getClass().getSimpleName().replaceAll("Info$",
"");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " +
entry.getValue() + "\n");
+ }
+ return sb.toString();
+ }
+
+}
Added:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.example.dna.sequencers;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import net.jcip.annotations.Immutable;
+
+/**
+ * @author Serge Pagop
+ * @author Randall Hauch
+ */
+@Immutable
+public class JavaInfo extends ContentInfo {
+
+ private final Map<String, List<Properties>> javaElements;
+ private final String type;
+
+ protected JavaInfo( String path,
+ String name,
+ String type,
+ Map<String, List<Properties>> javaElements ) {
+ super(path, name, null);
+ this.type = type;
+ this.javaElements = javaElements != null ? new TreeMap<String,
List<Properties>>(javaElements) : new TreeMap<String,
List<Properties>>();
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ /**
+ * @return javaElements
+ */
+ public Map<String, List<Properties>> getJavaElements() {
+ return javaElements;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ sb.append(" Type: " + getType() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " +
entry.getValue() + "\n");
+ }
+ for (Map.Entry<String, List<Properties>> javaElement :
getJavaElements().entrySet()) {
+ sb.append("\n ------ " + javaElement.getKey() + "
------\n");
+ for (Properties props : javaElement.getValue()) {
+ for (Map.Entry<Object, Object> entry : props.entrySet()) {
+ if (!entry.getKey().equals("jcr:primaryType")) {
+ sb.append(" " + entry.getKey() + " => "
+ entry.getValue() + "\n");
+ }
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+}
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -23,53 +23,38 @@
import java.util.Map;
import java.util.Properties;
+import net.jcip.annotations.Immutable;
/**
* @author Randall Hauch
*/
-public class MediaInfo {
+@Immutable
+public class MediaInfo extends ContentInfo {
- private final Properties properties = new Properties();
- private final String name;
- private final String path;
private final String mediaType;
- protected MediaInfo( String path, String name, String mediaType, Properties props )
{
- this.name = name;
- this.path = path;
+ protected MediaInfo( String path,
+ String name,
+ String mediaType,
+ Properties props ) {
+ super(path, name, props);
this.mediaType = mediaType;
- if (props != null) this.properties.putAll(props);
}
- public String getName() {
- return this.name;
- }
-
- public String getPath() {
- return this.path;
- }
-
public String getMediaType() {
return this.mediaType;
}
- public Properties getProperties() {
- return this.properties;
- }
-
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (Map.Entry<Object, Object> entry : this.properties.entrySet()) {
-
sb.append(entry.getKey()).append("=>").append(entry.getValue());
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ sb.append(" Type: " + getMediaType() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " +
entry.getValue() + "\n");
}
- return this.name + " (at " + this.path + ") of type \""
+ this.mediaType + "\" with properties {" + sb.toString() + "}";
+ return sb.toString();
}
}
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import javax.jcr.Credentials;
import javax.jcr.Node;
@@ -253,6 +255,14 @@
SequencerConfig mp3SequencerConfig = new SequencerConfig(name, desc,
classname, classpath, mp3PathExpressions);
this.sequencingService.addSequencer(mp3SequencerConfig);
+ // Set up the MP3 sequencer ...
+ name = "Java Sequencer";
+ desc = "Sequences java files to extract the characteristics of the java
sources";
+ classname = "org.jboss.dna.sequencer.java.JavaMetadataSequencer";
+ String[] javaPathExpressions = {"//(*.java[*])/jcr:content[@jcr:data]
=> /compilationUnits/$1"};
+ SequencerConfig javaSequencerConfig = new SequencerConfig(name, desc,
classname, classpath, javaPathExpressions);
+ 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());
@@ -330,10 +340,10 @@
*/
public void search() throws Exception {
// Use JCR to search the repository for image metadata ...
- List<MediaInfo> medias = new ArrayList<MediaInfo>();
+ List<ContentInfo> infos = new ArrayList<ContentInfo>();
Session session = createSession();
try {
- // Find the image node ...
+ // Find the node ...
Node root = session.getRootNode();
if (root.hasNode("images") || root.hasNode("mp3s")) {
@@ -344,7 +354,7 @@
for (NodeIterator iter = mediasNode.getNodes(); iter.hasNext();) {
Node mediaNode = iter.nextNode();
if (mediaNode.hasNode("image:metadata")) {
- medias.add(extractMediaInfo("image:metadata",
"image", mediaNode));
+ infos.add(extractMediaInfo("image:metadata",
"image", mediaNode));
}
}
}
@@ -354,18 +364,118 @@
for (NodeIterator iter = mediasNode.getNodes(); iter.hasNext();) {
Node mediaNode = iter.nextNode();
if (mediaNode.hasNode("mp3:metadata")) {
- medias.add(extractMediaInfo("mp3:metadata",
"mp3", mediaNode));
+ infos.add(extractMediaInfo("mp3:metadata",
"mp3", mediaNode));
}
}
}
+ } else if (root.hasNode("compilationUnits")) {
+ Map<String, List<Properties>> tree = new TreeMap<String,
List<Properties>>();
+ // Find the compilation unit node ...
+ List<Properties> javaElements;
+ if (root.hasNode("compilationUnits")) {
+ Node javaSourcesNode = root.getNode("compilationUnits");
+ for (NodeIterator i = javaSourcesNode.getNodes(); i.hasNext();) {
+
+ Node javaSourceNode = i.nextNode();
+
+ if (javaSourceNode.hasNodes()) {
+ Node javaCompilationUnit =
javaSourceNode.getNodes().nextNode();
+ // package informations
+
+ javaElements = new ArrayList<Properties>();
+ try {
+ Node javaPackageDeclarationNode =
javaCompilationUnit.getNode("java:package/java:packageDeclaration");
+
javaElements.add(extractJavaInfo(javaPackageDeclarationNode));
+ tree.put("Class package", javaElements);
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+
+ // import informations
+ javaElements = new ArrayList<Properties>();
+ try {
+ for (NodeIterator singleImportIterator =
javaCompilationUnit.getNode("java:import/java:importDeclaration/java:singleImport").getNodes();
singleImportIterator.hasNext();) {
+ Node javasingleTypeImportDeclarationNode =
singleImportIterator.nextNode();
+
javaElements.add(extractJavaInfo(javasingleTypeImportDeclarationNode));
+ }
+ tree.put("Class single Imports",
javaElements);
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+
+ javaElements = new ArrayList<Properties>();
+ try {
+ for (NodeIterator javaImportOnDemandIterator =
javaCompilationUnit.getNode("java:import/java:importDeclaration/java:importOnDemand").getNodes();
javaImportOnDemandIterator.hasNext();) {
+ Node javaImportOnDemandtDeclarationNode =
javaImportOnDemandIterator.nextNode();
+
javaElements.add(extractJavaInfo(javaImportOnDemandtDeclarationNode));
+ }
+ tree.put("Class on demand imports",
javaElements);
+
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+ // class head informations
+ javaElements = new ArrayList<Properties>();
+ Node javaNormalDeclarationClassNode =
javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration");
+
javaElements.add(extractJavaInfo(javaNormalDeclarationClassNode));
+ tree.put("Class head information", javaElements);
+
+ // field member informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaFieldTypeIterator =
javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:field/java:fieldType").getNodes();
javaFieldTypeIterator.hasNext();) {
+ Node rootFieldTypeNode =
javaFieldTypeIterator.nextNode();
+ if
(rootFieldTypeNode.hasNode("java:primitiveType")) {
+ Node javaPrimitiveTypeNode =
rootFieldTypeNode.getNode("java:primitiveType");
+
javaElements.add(extractJavaInfo(javaPrimitiveTypeNode));
+ // more informations
+ }
+
+ if
(rootFieldTypeNode.hasNode("java:simpleType")) {
+ Node javaSimpleTypeNode =
rootFieldTypeNode.getNode("java:simpleType");
+
javaElements.add(extractJavaInfo(javaSimpleTypeNode));
+ }
+ if
(rootFieldTypeNode.hasNode("java:parameterizedType")) {
+ Node javaParameterizedType =
rootFieldTypeNode.getNode("java:parameterizedType");
+
javaElements.add(extractJavaInfo(javaParameterizedType));
+ }
+ if
(rootFieldTypeNode.hasNode("java:arrayType")) {
+ Node javaArrayType =
rootFieldTypeNode.getNode("java:arrayType[2]");
+ javaElements.add(extractJavaInfo(javaArrayType));
+ }
+ }
+ tree.put("Class field members", javaElements);
+
+ // constructor informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaConstructorIterator =
javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:constructor").getNodes();
javaConstructorIterator.hasNext();) {
+ Node javaConstructor =
javaConstructorIterator.nextNode();
+ javaElements.add(extractJavaInfo(javaConstructor));
+ }
+ tree.put("Class constructors", javaElements);
+
+ // method informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaMethodIterator =
javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:method").getNodes();
javaMethodIterator.hasNext();) {
+ Node javaMethod = javaMethodIterator.nextNode();
+ javaElements.add(extractJavaInfo(javaMethod));
+ }
+ tree.put("Class member functions", javaElements);
+
+ JavaInfo javaInfo = new
JavaInfo(javaCompilationUnit.getPath(), javaCompilationUnit.getName(),
+ "java source",
tree);
+ infos.add(javaInfo);
+ }
+ }
+ }
+
}
} finally {
session.logout();
}
// Display the search results ...
- this.userInterface.displaySearchResults(medias);
+ this.userInterface.displaySearchResults(infos);
}
private MediaInfo extractMediaInfo( String metadataNodeName,
@@ -402,6 +512,29 @@
}
/**
+ * Extract informations from a specific node.
+ *
+ * @param node - node, that contains informations.
+ * @return a properties of keys/values.
+ * @throws RepositoryException
+ * @throws IllegalStateException
+ * @throws ValueFormatException
+ */
+ private Properties extractJavaInfo( Node node ) throws ValueFormatException,
IllegalStateException, RepositoryException {
+ if (node.hasProperties()) {
+ Properties properties = new Properties();
+ for (PropertyIterator propertyIter = node.getProperties();
propertyIter.hasNext();) {
+ Property property = propertyIter.nextProperty();
+ String name = property.getName();
+ String stringValue = property.getValue().getString();
+ properties.put(name, stringValue);
+ }
+ return properties;
+ }
+ return null;
+ }
+
+ /**
* Utility method to create a new JCR session from the execution context's {@link
SessionFactory}.
*
* @return the session
@@ -422,6 +555,7 @@
if (filename.endsWith(".jpeg")) return "image/jpeg";
if (filename.endsWith(".ras")) return "image/x-cmu-raster";
if (filename.endsWith(".mp3")) return "audio/mpeg";
+ if (filename.endsWith(".java")) return "text/x-java-source";
throw new SystemFailureException("Unknown mime type for " + file);
}
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -34,5 +34,5 @@
public String getRepositoryPath( String defaultPath ) throws
IllegalArgumentException, IOException;
- public void displaySearchResults( List<MediaInfo> images ) throws IOException;
+ public void displaySearchResults( List<ContentInfo> contentInfo ) throws
IOException;
}
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2008-09-17
23:03:19 UTC (rev 532)
@@ -3,6 +3,8 @@
<
mix='http://www.jcp.org/jcr/mix/1.0'>
<
image='http://jboss.org/dna/images/1.0'>
<
mp3='http://jboss.org/dna/mp3/1.0'>
+<java='http://www.jboss.org/dna/java/1.0'>
+
// ----------------------------------------------------------
// JCR Pre-defined Mixin Types that are not loaded by default
// ----------------------------------------------------------
@@ -32,6 +34,10 @@
- image:physicalWidthInches (long)
- image:physicalHeightInches (long)
+// -------------------
+// DNA MP3 Sequencer
+// -------------------
+
/**
* Node type that defines the metadata for an MP3 audio file
*/
@@ -42,4 +48,217 @@
- mp3:year (long)
- mp3:comment (string)
+// -------------------
+// DNA Java Sequencer
+// -------------------
+/**
+ * Node types that define metadata for a Java source file
+ */
+/**
+ * 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:arrayType, java:simpleType, java:qualifiedType,
java:wildcardType, java:parameterizedType)
+
+/**
+ * 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) mandatory
+
+/**
+ * java:arrayType
+ */
+[java:arrayType] > nt:unstructured
+ - java:arrayTypeDescription (string)
+ + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:arrayTypeName (string) mandatory
+ + java:arrayTypeVariable (java:variable) = java:variable
+
+[java:simpleType] > nt:unstructured
+ - java:simpleTypeDescription (string)
+ + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:simpleTypeName (string) mandatory
+ + java:simpleTypeVariable (java:variable) = java:variable
+
+[java:qualifiedType] > nt:unstructured
+ - java:qualifiedTypeDescription (string)
+ + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:qualifiedTypeName (string) mandatory
+ + java:qualifiedTypeVariable (java:variable) = java:variable
+
+[java:wildcardType] > nt:unstructured
+ - java:wildcardTypeDescription (string)
+ + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:wildcardTypeName (string) mandatory
+ + java:wildcardTypeVariable (java:variable) = java:variable
+
+[java:parameterizedType] > nt:unstructured
+ - java:parameterizedTypeDescription (string)
+ + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:parameterizedTypeName (string) mandatory
+ + java:parameterizedTypeVariable (java:variable) = java:variable
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType,
java:wildcardType, java:parameterizedType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:arrayType, java:simpleType,
java:qualifiedType, java:wildcardType, java:parameterizedType) 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 // TODO
+
+[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:unitType (java:classDeclaration, java:interfaceDeclaration)
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -46,10 +46,11 @@
/**
* {@inheritDoc}
*/
- public void displaySearchResults( List<MediaInfo> images ) {
- assertThat(images.size(), is(this.numberOfSearchResults));
- for (MediaInfo image : images) {
- System.out.println("Image: " + image);
+ public void displaySearchResults( List<ContentInfo> infos ) {
+ assertThat(infos.size(), is(this.numberOfSearchResults));
+ for (ContentInfo info : infos) {
+ System.out.println("Info: ");
+ System.out.println(info);
}
}
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java 2008-09-17
22:56:29 UTC (rev 531)
+++
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -24,6 +24,9 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.dna.common.util.FileUtil;
import org.junit.After;
@@ -39,14 +42,18 @@
private URL pictImageUrl;
private URL jpegImageUrl;
private URL mp3Url;
+ private URL javaSourceUrl;
private SequencingClient client;
@Before
- public void beforeEach() {
+ public void beforeEach() throws MalformedURLException {
this.pngImageUrl =
Thread.currentThread().getContextClassLoader().getResource("caution.png");
this.pictImageUrl =
Thread.currentThread().getContextClassLoader().getResource("caution.pict");
this.jpegImageUrl =
Thread.currentThread().getContextClassLoader().getResource("caution.jpg");
this.mp3Url =
Thread.currentThread().getContextClassLoader().getResource("sample1.mp3");
+ // Get the URL of source (MySource.java), that have to be sequencing
+ this.javaSourceUrl =
FileUtil.convertFileToURL("workspace/project1/src/org/acme/MySource.java");
+
client = new SequencingClient();
client.setWorkingDirectory("target/repositoryData");
client.setJackrabbitConfigPath("src/main/resources/jackrabbitConfig.xml");
@@ -159,4 +166,35 @@
assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
}
+ @Test
+ public void shouldFindCompilationUnitSource() throws IOException {
+ assertThat(this.javaSourceUrl, is(notNullValue()));
+ InputStream stream = this.javaSourceUrl.openStream();
+ try {
+ byte[] buffer = new byte[1024];
+ while (stream.read(buffer) != -1) {
+ }
+ } finally {
+ stream.close();
+ }
+ }
+
+ @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.
+ client.search();
+ assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1L));
+ }
+
}
Added:
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -0,0 +1,111 @@
+/*
+ * 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;
+ private int[] ia;
+ private Object[] oa;
+ private Collection[] ca;
+
+ MySource() {
+ }
+
+ public MySource( int i,
+ int j,
+ Object o ) {
+ 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,
+ Object o ) {
+ l = new ArrayList<String>();
+ l.add("N1");
+ }
+
+ private double doSomething2( Object[] oa,
+ int[] ia ) {
+ System.out.println("genial");
+ }
+
+ public Object doSomething3() {
+ return null;
+ }
+
+ // 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 {
+
+ }
+}
+
\ No newline at end of file
Added:
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -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/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -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/sequencers/workspace/project1/src/org/acme/package-info.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java
(rev 0)
+++
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java 2008-09-17
23:03:19 UTC (rev 532)
@@ -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;
+