[MOBY-guts] biomoby commit
Eddie Kawas
kawas at pub.open-bio.org
Fri Sep 30 14:44:58 UTC 2005
kawas
Fri Sep 30 10:44:58 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared
In directory pub.open-bio.org:/tmp/cvs-serv6357/org/biomoby/client/ui/graphical/applets/shared
Modified Files:
Construct.java MobyTree.java
Log Message:
modified the code so that an arbitrary tree can be created using any rdf document and a property to base the tree on.
This was done mainly for a student project that will create web forms that pop up these trees based on rdf.
moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared Construct.java,1.2,1.3 MobyTree.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java 2005/08/29 22:59:35 1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/Construct.java 2005/09/30 14:44:58 1.3
@@ -1,15 +1,11 @@
package org.biomoby.client.ui.graphical.applets.shared;
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
-import org.biomoby.client.ui.graphical.servlet.jresources.RESOURCE;
-
import com.hp.hpl.jena.mem.ModelMem;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Statement;
@@ -120,4 +116,72 @@
return homes;
}
+
+ /**
+ *
+ * PRE: none.<p>
+ * POST: A Hashmap containing object names as keys and their relationships,<p>
+ * in an array, as the value.
+ * @param property the property to build the tree from RDF
+ * @return returns a hashmap containing the object name as the key
+ * and an arraylist of children as the value.
+ */
+ public HashMap createHomes(String property) {
+ HashMap homes = new HashMap(); // (key=parent,val=household)
+ try {
+ // create an empty model
+ Model model = new ModelMem();
+
+ InputStream in = new URL(url).openStream();
+
+ // read the RDF/XML data
+ model.read(new InputStreamReader(in), "");
+ StmtIterator iter;
+ Statement stmt;
+
+ iter = model.listStatements();
+ while (iter.hasNext()) {
+ stmt = (Statement) iter.next();
+
+ String sub = stmt.getSubject().getURI();
+ String obj = stmt.getObject().toString();
+ if (sub != null)
+ sub = sub.substring(sub.indexOf("#") + 1, sub.length());
+ if (obj!= null)
+ obj = obj.substring(obj.indexOf("#") + 1, obj.length());
+
+ if (stmt.getPredicate().getURI().indexOf(property) > 0) {
+ //System.out.println(obj);
+ // we have the relationship that we want in the tree
+ if (homes.containsKey(obj)) {
+ // hash contains the home -> get the home and add child to household
+ Household h = (Household)homes.get(obj);
+ ArrayList ch = h.getChildren();
+ ch.add(sub);
+ h.setChildren(ch);
+ if (DEBUG) {
+ System.out.println(h.toString());
+ }
+ homes.put(obj,h);
+ } else {
+ // hash doesn't have the parent, so add the parent and child to a new household
+ ArrayList ch = new ArrayList();
+ ch.add(sub); // add the child
+ Household h = new Household(obj, ch);
+ if (DEBUG) {
+ //System.out.println("New Parent: " + obj + " child: " + sub);
+ System.out.println(h.toString());
+ }
+ homes.put(obj,h);
+ }
+ } // hashmap is created
+
+ }
+
+ } catch (Exception e) {
+ System.err.println("Failed: " + e.getMessage()+"\n" + e.getStackTrace());
+ }
+
+ return homes;
+ }
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java 2005/06/02 15:48:54 1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/applets/shared/MobyTree.java 2005/09/30 14:44:58 1.3
@@ -67,6 +67,29 @@
JScrollPane scrollPane = new JScrollPane(tree);
add(scrollPane);
}
+
+ /**
+ * A moby tree is constructed with the root node labeled as 'name'<p>
+ * and the material for the tree taken from the RDF located at <p>
+ * the url rdf. The tree is created by looking for the property property<p>
+ * @param canEdit - if true then nodes in tree can be edited, otherwise they cannot.
+ * @param rdf - the url of the RDF describing Moby Objects, Services, Service Types, and Namespaces
+ * @param name - the name of the root node in the tree.
+ * @param property - the property to parse the rdf document and base a tree on
+ */
+ public MobyTree(boolean canEdit, String rdf, String name, String property) {
+
+ // create the layout
+ super(new GridLayout(1, 0));
+ this.canEdit = canEdit;
+ this.rdf = rdf;
+ this.name = name;
+ reload(canEdit, name, property);
+
+
+ JScrollPane scrollPane = new JScrollPane(tree);
+ add(scrollPane);
+ }
private void reload(boolean canEdit, String name) {
// hashmap contains all the children of the root object
@@ -82,6 +105,23 @@
tree.setShowsRootHandles(true);
}
+
+ /*
+ *
+ * create a tree based on property instead of subClassOf
+ */
+ private void reload(boolean canEdit, String name, String property) {
+ // hashmap contains all the children of the root object
+ this.hashmap = new Construct(rdf).createHomes(property);
+ rootNode = new DefaultMutableTreeNode(name);
+ treeModel = new DefaultTreeModel(rootNode);
+ treeModel.addTreeModelListener(new MobyTreeModelListener());
+ tree = new JTree(treeModel);
+ tree.setEditable(canEdit);
+ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setShowsRootHandles(true);
+
+ }
/**
* PRE: None.<p>
More information about the MOBY-guts
mailing list