[dna-commits] DNA SVN: r492 - in trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main: resources and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue Sep 2 19:51:05 EDT 2008


Author: spagop
Date: 2008-09-02 19:51:05 -0400 (Tue, 02 Sep 2008)
New Revision: 492

Modified:
   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/resources/java-source-artifact.cnd
Log:
fixed a bug and enhance the sequence output to be more readable

Modified: 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	2008-09-02 23:49:42 UTC (rev 491)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/ConsoleInput.java	2008-09-02 23:51:05 UTC (rev 492)
@@ -28,6 +28,7 @@
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import org.jboss.dna.repository.sequencers.SequencingService;
 
 /**
@@ -189,9 +190,17 @@
             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());
+            for (Map.Entry<String, List<Properties>> javaElement : javaInfo.getJavaElements().entrySet()) {
+                System.out.println("\n------ " + javaElement.getKey() + " ------\n");
+                for (Properties props : javaElement.getValue()) {
+                    for (Map.Entry<Object, Object> entry : props.entrySet()) {
+                        if (!entry.getKey().equals("jcr:primaryType")) {
+                            System.out.println(entry.getKey() + " => "+ entry.getValue());
+                        }
+                    }
+                }
             }
+            
         }
         System.out.println();
     }

Modified: 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	2008-09-02 23:49:42 UTC (rev 491)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaInfo.java	2008-09-02 23:51:05 UTC (rev 492)
@@ -21,28 +21,30 @@
  */
 package org.jboss.dna.sequencer.java;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
+import java.util.TreeMap;
 
 /**
  * @author Serge Pagop
- *
  */
 public class JavaInfo {
-    
-    private final  Multimap<String, String> map =  new ArrayListMultimap<String, String>();
-    
+
+    private final Map<String, List<Properties>> javaElements = new TreeMap<String, List<Properties>>();
+
     private final String name;
     private final String path;
     private final String type;
 
-    protected JavaInfo( String path, String name, String type, Multimap<String, String> map) {
+    protected JavaInfo( String path,
+                        String name,
+                        String type,
+                        Map<String, List<Properties>> javaElements ) {
         this.name = name;
         this.path = path;
         this.type = type;
-        if (map != null) this.map.putAll(map);
+        if (javaElements != null) this.javaElements.putAll(javaElements);
     }
 
     public String getName() {
@@ -57,28 +59,31 @@
         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(", ");
+
+        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()).append(" => ").append(entry.getValue());
+                        sb.append("; ");
+                    }
+                }
             }
         }
-        return this.name + " (at " + this.path + ") of type \"" + this.type + "\" with properties {" + sb.toString() + "}";
+
+        return this.name + " (at " + this.path + ") of type \"" + this.type + "\" with elements \n{\n" + sb.toString()
+               + " \n}\n";
     }
 
     /**
-     * @return map
+     * @return javaElements
      */
-    public Multimap<String, String> getMap() {
-        return map;
+    public Map<String, List<Properties>> getJavaElements() {
+        return javaElements;
     }
 
 }

Modified: 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	2008-09-02 23:49:42 UTC (rev 491)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/java/org/jboss/dna/sequencer/java/JavaSequencingClient.java	2008-09-02 23:51:05 UTC (rev 492)
@@ -25,15 +25,9 @@
 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;
@@ -46,7 +40,6 @@
 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;
@@ -60,9 +53,6 @@
 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
@@ -76,8 +66,6 @@
     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);
@@ -335,44 +323,88 @@
      */
     public void search() throws Exception {
         // Use JCR to search the repository for image meta data ...
+        Map<String, List<Properties>> tree = new TreeMap<String, List<Properties>>();
         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;
+            JavaInfo javaInfo;
+            List<Properties> javaElements;
             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);
+
+                    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(extractInfo(javaPackageDeclarationNode));
+                            tree.put("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(extractInfo(javasingleTypeImportDeclarationNode));
                             }
-                            // import infos
-                            if (javaCompilationUnit.hasNode("java:import")) {
-                                // single type import
-                                Node javaImport = javaCompilationUnit.getNode("java:import")
-                                    .getNode("java:importDeclaration");
-                                extractInfo(javaImport, multimap);
+                            tree.put("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(extractInfo(javaImportOnDemandtDeclarationNode));
                             }
-                            // 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);
+                            tree.put("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(extractInfo(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(extractInfo(javaPrimitiveTypeNode));
+                                // more informations
                             }
-                            javaInfo = new JavaInfo(javaCompilationUnit.getPath(), javaCompilationUnit.getName(), "java:compilationUnit", multimap);
-                            javaInfos.add(javaInfo);
+
+                            if (rootFieldTypeNode.hasNode("java:simpleType")) {
+                                Node javaSimpleTypeNode = rootFieldTypeNode.getNode("java:simpleType");
+                                javaElements.add(extractInfo(javaSimpleTypeNode));
+                            }
+                            if (rootFieldTypeNode.hasNode("java:parameterizedType")) {
+                                Node javaParameterizedType = rootFieldTypeNode.getNode("java:parameterizedType");
+                                javaElements.add(extractInfo(javaParameterizedType));
+                            }
                         }
+                        tree.put("Class field members", javaElements);
+
+                        // constructor informations
+
+                        // method informations
+                        javaInfo = new JavaInfo(javaCompilationUnit.getPath(), javaCompilationUnit.getName(), "java source", tree);
+                        javaInfos.add(javaInfo);
                     }
                 }
             }
@@ -380,7 +412,7 @@
         } finally {
             session.logout();
         }
-         
+
         // Display the search results ...
         this.userInterface.displaySearchResults(javaInfos);
     }
@@ -389,30 +421,23 @@
      * Extract informations from a specific node.
      * 
      * @param node - node, that contains informations.
-     * @param multimap - a google collection, that support duplicate keys.
-     * @throws RepositoryException 
+     * @return a properties of keys/values.
+     * @throws RepositoryException
      * @throws IllegalStateException
      * @throws ValueFormatException
      */
-    private void extractInfo( Node node,
-                              Multimap<String, String> multimap )
-        throws ValueFormatException, IllegalStateException, RepositoryException {
+    private Properties extractInfo( Node node ) throws ValueFormatException, IllegalStateException, RepositoryException {
         if (node.hasProperties()) {
-            int index = 1;
+            Properties properties = new Properties();
             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);
-                }
+                properties.put(name, stringValue);
             }
+            return properties;
         }
-        if (node.hasNodes()) {
-            for (NodeIterator iterator = node.getNodes(); iterator.hasNext();) {
-                extractInfo(iterator.nextNode(), multimap);
-            }
-        }
+        return null;
     }
 
     /**

Modified: 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	2008-09-02 23:49:42 UTC (rev 491)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/src/main/resources/java-source-artifact.cnd	2008-09-02 23:51:05 UTC (rev 492)
@@ -230,7 +230,7 @@
  + java:method (java:methodDeclaration) = java:methodDeclaration multiple
  + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
  
-[java:enumDeclaration] > nt:unstructured
+[java:enumDeclaration] > nt:unstructured // TODO
  
 [java:classDeclaration] > nt:unstructured
  + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration




More information about the dna-commits mailing list