[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model ...
Robert Stryker
rawblem at gmail.com
Thu Jul 27 02:34:03 EDT 2006
User: rawb
Date: 06/07/27 02:34:03
Modified: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model
ServerProcessLog.java DescriptorModel.java
Added: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model
SimpleTreeItem.java
Log:
Implemented xpath editor in properties view. Other changes made to fascilitate this implementation (added to DescriptorModel, etc). Also fixed bugs, re-added classpath to server configuration so user can customize.
Revision Changes Path
1.7 +8 -41 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/ServerProcessLog.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ServerProcessLog.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/ServerProcessLog.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- ServerProcessLog.java 10 Jul 2006 15:44:23 -0000 1.6
+++ ServerProcessLog.java 27 Jul 2006 06:34:03 -0000 1.7
@@ -33,7 +33,7 @@
public class ServerProcessLog {
- public static class ProcessLogEvent {
+ public static class ProcessLogEvent extends SimpleTreeItem {
public static final int SERVER_ROOT = 0;
public static final int SERVER_CONSOLE = 1;
@@ -44,8 +44,6 @@
public static final int ADD_END = 1;
- private HashMap properties = new HashMap();
- private ArrayList children = new ArrayList();
private ProcessLogEvent parent;
private int eventType;
@@ -53,6 +51,7 @@
private boolean complete = false;
public ProcessLogEvent(int eventType) {
+ super(null, null);
this.eventType = eventType;
this.date = new Date().getTime();
}
@@ -72,15 +71,6 @@
event.setParent(this);
}
- public void addChild(ProcessLogEvent event) {
- addChild(event, ADD_END);
- }
-
-
- public ProcessLogEvent addChild(int eventType) {
- return addChild(eventType, ADD_END);
- }
-
public ProcessLogEvent addChild(int eventType, int location) {
ProcessLogEvent e = new ProcessLogEvent(eventType);
addChild(e, location);
@@ -88,10 +78,6 @@
}
- public void setParent(ProcessLogEvent parent) {
- this.parent = parent;
- }
-
public void addChildren(ProcessLogEvent[] kids) {
for( int i = 0; i < kids.length; i++ ) {
addChild(kids[i]);
@@ -108,16 +94,12 @@
if( getParent() instanceof ProcessLogEventRoot )
return (ProcessLogEventRoot)getParent();
- return getParent().getRoot();
+ if( getParent() instanceof ProcessLogEvent ) {
+ return ((ProcessLogEvent)getParent()).getRoot();
}
-
- public void deleteChildren() {
- children.clear();
+ return null;
}
- public void deleteChild(ProcessLogEvent o) {
- children.remove(o);
- }
public void accept(IProcessLogVisitor visitor) {
boolean ret = visitor.visit(this);
@@ -138,26 +120,10 @@
this.eventType = eventType;
}
- public ProcessLogEvent getParent() {
- return parent;
- }
-
public long getDate() {
return this.date;
}
- public void setProperty( Object key, Object val ) {
- properties.put(key, val);
- }
-
- public Object getProperty(Object key) {
- return properties.get(key);
- }
-
- public HashMap getProperties() {
- return properties;
- }
-
public boolean isComplete() {
return complete;
}
@@ -192,6 +158,7 @@
this.server = ServerCore.findServer(serverID);
this.serverID = serverID;
}
+
/**
* One of my children has changed and I should alert someone
* who might care.
1.4 +324 -25 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DescriptorModel.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- DescriptorModel.java 10 Jul 2006 15:44:42 -0000 1.3
+++ DescriptorModel.java 27 Jul 2006 06:34:03 -0000 1.4
@@ -22,16 +22,27 @@
package org.jboss.ide.eclipse.as.core.model;
import java.io.File;
+import java.io.FileOutputStream;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import org.dom4j.Attribute;
import org.dom4j.Document;
+import org.dom4j.Node;
+import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.Server;
import org.jboss.ide.eclipse.as.core.JBossServerCore;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
@@ -53,6 +64,8 @@
*/
public class DescriptorModel {
+
+ /* Static Portion */
private static DescriptorModel model = null;
public static DescriptorModel getDefault() {
@@ -62,6 +75,8 @@
return model;
}
+
+ /* Member variables / methods */
private HashMap map;
public DescriptorModel() {
@@ -88,44 +103,31 @@
}
- /*
- * MUST BE FIXED, or rather, actually implemented
- */
public class ServerDescriptorModel {
private String serverId;
- private long lastChecked;
private String configPath;
+ private HashMap pathToDocument;
+ private HashMap pathToLastRead;
+
public ServerDescriptorModel(String id) {
this.serverId = id;
ServerAttributeHelper helper = getJBossServer().getAttributeHelper();
configPath = helper.getConfigurationPath();
-
- }
-
- public int getJNDIPort() {
- try {
- String jbossServicePath = configPath + File.separator + "conf" +
- File.separator + "jboss-service.xml";
- URL jbossServiceURL = new File(jbossServicePath).toURL();
- SAXReader reader = new SAXReader();
- Document document = reader.read(jbossServiceURL);
- List l = document.selectNodes("/server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']");
- if( l.size() == 1 ) {
- DefaultElement el = (DefaultElement)l.get(0);
- int jndi = Integer.parseInt(el.getText());
- return jndi;
- }
- } catch( Exception e ) {
-
- }
- return 1099;
+ pathToDocument = new HashMap();
+ pathToLastRead = new HashMap();
}
public JBossServer getJBossServer() {
return JBossServerCore.getServer(ServerCore.findServer(serverId));
}
+
+ /**
+ * Discover all descriptors in the configuration
+ * @return
+ */
+
private File[] getAllDescriptors() {
ArrayList list = new ArrayList();
File config = new File(configPath);
@@ -147,7 +149,304 @@
}
}
}
+
+
+ private static final String IGNORED_DESCRIPTOR_FOLDERS = "_IGNORED_DESCRIPTOR_FOLDERS_";
+
+ /*
+ * Do preference stuff here to see if the directory is ignored.
+ */
+ private boolean isIgnoredDirectory(File f) {
+ boolean found = false;
+ List ignored = Arrays.asList(getIgnoredDirectories());
+ while( f != null && !found ) {
+ if( ignored.contains(f.getAbsoluteFile()))
+ return true;
+ f = f.getParentFile();
+ }
+ return false;
+ }
+
+ public String[] getIgnoredDirectories() {
+ List list = ((Server)getJBossServer().getAttributeHelper().getServer()).getAttribute(IGNORED_DESCRIPTOR_FOLDERS, new ArrayList());
+ String[] ignoredDirs = (String[]) list.toArray(new String[list.size()]);
+ return ignoredDirs;
+ }
+
+ private Document getDocument(String path) {
+ // First get last time loaded.
+ if( !isCurrent(path)) {
+ loadDocument(path);
+ }
+ return (Document)pathToDocument.get(path);
+ }
+
+ private boolean isCurrent( String path ) {
+ if( pathToLastRead.get(path) == null ) return false;
+ if( !(pathToLastRead.get(path) instanceof Long)) return false;
+ if( pathToDocument.get(path) == null ) return false;
+ long lastModified = ((Long)pathToLastRead.get(path)).longValue();
+ File f = new File(path);
+ if( f.lastModified() > lastModified ) return false;
+
+ return true;
+ }
+
+ private void loadDocument(String path) {
+ try {
+ File file = new File(path);
+ long lastModified = file.lastModified();
+ URL url = new File(path).toURL();
+ SAXReader reader = new SAXReader(false);
+ reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ Document document = reader.read(url);
+
+ // add to maps
+ pathToDocument.put(path, document);
+ pathToLastRead.put(path, new Long(lastModified));
+ } catch( Exception e ) {
+ ASDebug.p("file " + path + ", Exception: " + e.getMessage(), this);
+ }
+ }
+
+ /**
+ * Searches in the given file for the given xpath
+ * @param path
+ * @param xpath
+ * @return A list of DefaultElements
+ */
+ public List getXPathFromFile(String path, String xpath) {
+ Document d = getDocument(path);
+ if( d == null ) return new ArrayList();
+ return d.selectNodes(xpath);
+ }
+
+ /**
+ * Searches all descriptors for the provided xpath
+ * @param xpath
+ * @return A list of file / DefaultElement pairs
+ */
+ public XPathTreeItem[] getXPath(String xpath) {
+ return getXPath(xpath, null);
+ }
+
+ public XPathTreeItem[] getXPath(String xpath, String attributeName) {
+ return getXPath(xpath, attributeName, true);
+ }
+
+ public XPathTreeItem[] getXPath(String xpath, String attributeName, boolean filter ) {
+ return getXPath(xpath, attributeName, filter, true);
+ }
+
+ public XPathTreeItem[] getXPath(String xpath, String attributeName, boolean filter, boolean refresh ) {
+ if( refresh )
+ refreshDescriptors(new NullProgressMonitor());
+
+ ArrayList list = new ArrayList();
+ Set documentPathSet = pathToDocument.keySet();
+ Iterator i = documentPathSet.iterator();
+ String p;
+ List tmp;
+ XPathTreeItem newItem;
+ while(i.hasNext()) {
+ p = (String)i.next();
+
+ if( !filter || !isIgnoredDirectory(new File(p))) {
+ tmp = getXPathFromFile(p, xpath);
+ if( tmp.size() > 0 ) {
+ if( attributeName == null ) {
+ newItem = new XPathTreeItem(null, new File(p), tmp);
+ } else {
+ newItem = new XPathTreeItem(null, new File(p), tmp, attributeName);
+ }
+ list.add(newItem);
+ }
+ }
+ }
+ return (XPathTreeItem[]) list.toArray(new XPathTreeItem[list.size()]);
+ }
+
+
+
+ public class XPathTreeItem extends SimpleTreeItem {
+ public XPathTreeItem(SimpleTreeItem parent, File data, List nodes) {
+ super(parent, data);
+ addXPathsAsChildren(nodes);
+ }
+
+ public XPathTreeItem(SimpleTreeItem parent, File data, List nodes, String attribute) {
+ super(parent, data);
+ addXPathsAsChildren(nodes, attribute);
+ }
+
+ public File getFile() {
+ return ((File)getData());
+ }
+
+// just add the list of nodes as children
+ private void addXPathsAsChildren(List nodes) {
+ Iterator i = nodes.iterator();
+ int z = 0;
+ while(i.hasNext()) {
+ Node o = (Node)i.next();
+ addChild(new XPathTreeItem2(this, o, z++));
+ }
+ }
+
+// just add the list of nodes as children with an attribute
+ private void addXPathsAsChildren(List nodes, String attribute) {
+ Iterator i = nodes.iterator();
+ int z = 0;
+ while(i.hasNext()) {
+ Node o = (Node)i.next();
+ addChild(new XPathTreeItem2(this, o, attribute, z++));
+ }
+ }
+
+
+ }
+
+ public class XPathTreeItem2 extends SimpleTreeItem {
+ // which match inside the file am i?
+ private int index;
+ private String attribute;
+ private boolean hasAttribute, isDirty;
+
+ public XPathTreeItem2(XPathTreeItem parent, Node data, int index) {
+ super(parent, data);
+ this.index = index;
+ hasAttribute = false;
+ isDirty = false;
+ }
+ public XPathTreeItem2(XPathTreeItem parent, Node data, String attribute, int index) {
+ super(parent, data);
+ this.index = index;
+ this.attribute = attribute;
+ hasAttribute = true;
+ isDirty = false;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public boolean hasAttribute() {
+ return hasAttribute;
+ }
+ public boolean isDirty() {
+ return isDirty;
+ }
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public String getAttributeValue() {
+ if( getData() instanceof DefaultElement ) {
+ return ((DefaultElement)getData()).attributeValue(attribute);
+ }
+ return "";
+ }
+
+ public Document getDocument() {
+ if( getData() instanceof DefaultElement ) {
+ return ((DefaultElement)getData()).getDocument();
+ }
+ return null;
+ }
+
+ public String getText() {
+ if( getData() instanceof DefaultElement ) {
+ if( !hasAttribute()) {
+ return ((DefaultElement)getData()).getText();
+ } else {
+ Attribute att = ((DefaultElement)getData()).attribute(attribute);
+ return att.getValue();
+ }
+ }
+ return "";
+ }
+
+ public void setText(String newValue) {
+ if( getData() instanceof DefaultElement ) {
+ if( !hasAttribute()) {
+ ((DefaultElement)getData()).setText(newValue);
+ } else {
+ ((DefaultElement)getData()).attribute(attribute).setValue(newValue);
+ }
+ isDirty = true;
+ }
+ }
+
+ public String elementAsXML() {
+ DefaultElement element = ((DefaultElement)getData());
+ return ((DefaultElement)getData()).asXML();
+ }
+
+ public void saveDescriptor() {
+ if( getParent() instanceof XPathTreeItem ) {
+ try {
+ File outFile = ((XPathTreeItem)getParent()).getFile();
+ FileOutputStream os = new FileOutputStream(outFile);
+
+ Document doc = ((DefaultElement)getData()).getDocument();
+
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ XMLWriter writer = new XMLWriter(os, outformat);
+ writer.write(doc);
+ writer.flush();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void reloadDescriptorFromDisk() {
+ if( getParent() instanceof XPathTreeItem ) {
+ try {
+ loadDocument(((XPathTreeItem)getParent()).getFile().getAbsolutePath());
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ }
}
+ public void refreshDescriptors(IProgressMonitor monitor) {
+ File[] files = getAllDescriptors();
+ monitor.beginTask("Refresh", files.length);
+ for( int i = 0; i < files.length; i++ ) {
+ getDocument(files[i].getAbsolutePath());
+ monitor.worked(1);
+ }
+ monitor.done();
+ }
+ public void refreshDescriptorsClean(IProgressMonitor monitor) {
+ pathToDocument.clear();
+ pathToLastRead.clear();
+ refreshDescriptors(monitor);
+ }
+
+ /**
+ * JNDI specific
+ * @return
+ */
+ public int getJNDIPort() {
+ try {
+ String jbossServicePath = configPath + File.separator + "conf" +
+ File.separator + "jboss-service.xml";
+ String xpath = "/server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']";
+ List l = getXPathFromFile(jbossServicePath, xpath);
+ if( l.size() > 0 ) {
+ DefaultElement el = (DefaultElement)l.get(0);
+ int jndi = Integer.parseInt(el.getText());
+
+ return jndi;
+ }
+ } catch( Exception e ) {
+ }
+ return 1099;
+ }
+ }
}
1.1 date: 2006/07/27 06:34:03; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/SimpleTreeItem.java
Index: SimpleTreeItem.java
===================================================================
package org.jboss.ide.eclipse.as.core.model;
import java.util.ArrayList;
import java.util.HashMap;
import org.jboss.ide.eclipse.as.core.model.ServerProcessLog.ProcessLogEvent;
public class SimpleTreeItem {
protected ArrayList children;
protected HashMap properties;
protected SimpleTreeItem parent;
protected Object data;
public SimpleTreeItem(SimpleTreeItem parent, Object data) {
children = new ArrayList();
properties = new HashMap();
this.data = data;
this.parent = parent;
if( parent != null ) parent.addChild(this);
}
public SimpleTreeItem[] getChildren2() {
SimpleTreeItem[] arr = new SimpleTreeItem[children.size()];
children.toArray(arr);
return arr;
}
public SimpleTreeItem getParent() {
return parent;
}
public void addChild(SimpleTreeItem item) {
if( !children.contains(item)) {
children.add(item);
item.setParent(this);
}
}
public void addChild(int loc, SimpleTreeItem item) {
children.add(loc, item);
}
public void deleteChildren() {
children.clear();
}
public void deleteChild(SimpleTreeItem o) {
children.remove(o);
}
public void setProperty( Object key, Object val ) {
properties.put(key, val);
}
public Object getProperty(Object key) {
return properties.get(key);
}
public HashMap getProperties() {
return properties;
}
public void setParent(SimpleTreeItem parent) {
this.parent = parent;
}
public Object getData() {
return this.data;
}
public void setData(Object data) {
this.data = data;
}
public void addChildren(SimpleTreeItem[] kids) {
for( int i = 0; i < kids.length; i++ ) {
addChild(kids[i]);
}
}
}
More information about the jboss-cvs-commits
mailing list