Author: rob.stryker(a)jboss.com
Date: 2007-07-18 20:48:10 -0400 (Wed, 18 Jul 2007)
New Revision: 2513
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/AntFileFilter.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XMLDocumentRepository.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathCategory.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathFileResult.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathModel.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathQuery.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/legacy/
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/legacy/DescriptorModel.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.40.default.ports.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.42.default.ports.properties
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/AbstractJBossServerRuntime.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerLaunchDefaults.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IDeployableServer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/stripped/DeployableServer.java
Log:
A significant update to the descriptor model.
First, caches many less objects.
Second, the API is cleaner IMO.
Still needs some work but nothing major I believe. Wanted to get it into svn to test and
make sure no build errors.
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2007-07-19
00:47:40 UTC (rev 2512)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2007-07-19
00:48:10 UTC (rev 2513)
@@ -23,6 +23,7 @@
Eclipse-LazyStart: true
Export-Package: org.jboss.ide.eclipse.as.core,
org.jboss.ide.eclipse.as.core.model,
+ org.jboss.ide.eclipse.as.core.model.descriptor,
org.jboss.ide.eclipse.as.core.packages,
org.jboss.ide.eclipse.as.core.packages.types,
org.jboss.ide.eclipse.as.core.publishers,
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -1,460 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.ide.eclipse.as.core.model;
-
-import java.io.File;
-import java.io.FileFilter;
-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 javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-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.DefaultAttribute;
-import org.dom4j.tree.DefaultElement;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
-
-public class DescriptorModel {
- /* Static Portion */
- private static DescriptorModel model = null;
-
- public static DescriptorModel getDefault() {
- if( model == null ) {
- model = new DescriptorModel();
- }
- return model;
- }
-
-
- /* Member variables / methods */
- private HashMap map;
-
- public DescriptorModel() {
- map = new HashMap();
- }
-
- public ServerDescriptorModel getServerModel(IPath configPath) {
- String key = configPath.toOSString();
- Object o = map.get(key);
- if( o == null ) {
- o = createEntity(configPath);
- }
- return (ServerDescriptorModel)o;
- }
-
- private ServerDescriptorModel createEntity(IPath configPath) {
- ServerDescriptorModel val = new ServerDescriptorModel(configPath.toOSString());
- map.put(configPath.toOSString(), val);
- return val;
- }
-
- public static class ServerDescriptorModel {
- private String configPath;
-
- private HashMap pathToDocument;
- private HashMap pathToLastRead;
-
- public ServerDescriptorModel(String configPath) {
- this.configPath = configPath;
- pathToDocument = new HashMap();
- pathToLastRead = new HashMap();
- }
-
- /**
- * Discover all descriptors in the configuration
- * @return
- */
-
- private File[] getAllDescriptors() {
- ArrayList list = new ArrayList();
- File config = new File(configPath);
- getAllDescriptorsRecurse(config, list);
- File[] ret = new File[list.size()];
- list.toArray(ret);
- return ret;
- }
-
- private void getAllDescriptorsRecurse(File parent, ArrayList collector) {
- if( parent.isDirectory() ) {
- File[] children = parent.listFiles();
- for( int i = 0; i < children.length; i++ ) {
- if( children[i].isDirectory()) {
- getAllDescriptorsRecurse(children[i], collector);
- } else if( children[i].getAbsolutePath().endsWith(".xml")) {
- collector.add(children[i]);
- }
- }
- }
- }
-
-
-
- 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();
-
- SAXParserFactory spf = SAXParserFactory.newInstance();
- SAXParser sp = spf.newSAXParser();
-
sp.getXMLReader().setFeature("http://apache.org/xml/features/nonvali...;,
false);
-
- SAXReader reader = new SAXReader(false);
- reader.setXMLReader(sp.getXMLReader());
- Document document = reader.read(url);
-
- // add to maps
- pathToDocument.put(path, document);
- pathToLastRead.put(path, new Long(lastModified));
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
-
- /**
- * 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) {
- try {
- Document d = getDocument(path);
- if( d == null ) return new ArrayList();
- return d.selectNodes(xpath);
- } catch( Exception e ) {
- return new ArrayList();
- }
- }
-
- /**
- * 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, null);
- }
-
- public XPathTreeItem[] getXPath(String xpath, String attributeName, FileFilter filter )
{
- return getXPath(xpath, attributeName, filter, true);
- }
-
- public XPathTreeItem[] getXPath(String xpath, String attributeName, FileFilter 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 == null || filter.accept(new File(p))) {
- tmp = getXPathFromFile(p, xpath);
- if( tmp.size() > 0 ) {
- if( attributeName == null || attributeName.equals("")) {
- newItem = new XPathTreeItem(null, new File(p), tmp);
- list.add(newItem);
- } else {
- // Remove any that match the path but not the attribute
- Iterator j = tmp.iterator();
- while( j.hasNext()) {
- DefaultElement el = (DefaultElement)j.next();
- if( el.attribute(attributeName) == null ) {
- j.remove();
- }
- }
- if( tmp.size() > 0 ) {
- 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() {
- try {
- if( getData() instanceof DefaultElement ) {
- if( !hasAttribute()) {
- return ((DefaultElement)getData()).getText();
- } else {
- Attribute att = ((DefaultElement)getData()).attribute(attribute);
- return att.getValue();
- }
- }
- } catch( NullPointerException npe ) {
- npe.printStackTrace();
- }
- 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() {
- return ((DefaultElement)getData()).asXML();
- }
-
- public String getElementName() {
- return ((DefaultElement)getData()).getName();
- }
-
- public String[] getElementChildrenNames() {
- DefaultElement element = ((DefaultElement)getData());
- List l = element.elements();
- DefaultElement child;
- ArrayList names = new ArrayList();
- for( Iterator i = l.iterator();i.hasNext();) {
- child = (DefaultElement)i.next();
- if( !names.contains(child.getName()))
- names.add(child.getName());
- }
- return (String[]) names.toArray(new String[names.size()]);
- }
- public String[] getElementAttributeNames() {
- DefaultElement element = ((DefaultElement)getData());
- List l = element.attributes();
- DefaultAttribute child;
- ArrayList names = new ArrayList();
- for( Iterator i = l.iterator();i.hasNext();) {
- child = (DefaultAttribute)i.next();
- if( !names.contains(child.getName()))
- names.add(child.getName());
- }
- return (String[]) names.toArray(new String[names.size()]);
- }
- public String[] getElementAttributeValues(String attName) {
- DefaultElement element = ((DefaultElement)getData());
- Attribute at = element.attribute(attName);
- return at == null ? new String[0] : new String[] {at.getValue()};
- }
-
- 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;
- }
-
- }
-}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/AntFileFilter.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/AntFileFilter.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/AntFileFilter.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,29 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+import org.apache.tools.ant.DirectoryScanner;
+
+public class AntFileFilter {
+ private String includes;
+ private String baseDir;
+ private boolean hasScanned;
+ private transient DirectoryScanner scanner;
+ public AntFileFilter(String baseDir, String includes) {
+ this.includes = includes == null ? "**/*.xml" : includes;
+ this.baseDir = baseDir;
+ this.scanner = new DirectoryScanner();
+ String includesList[] = this.includes.split(" ?, ?");
+ scanner.setBasedir(baseDir);
+ scanner.setIncludes(includesList);
+ }
+ public String getBaseDir() { return baseDir; }
+ public String getIncludes() { return includes; }
+ public void setIncludes(String includes) { this.includes = includes; }
+ public void setBaseDir(String baseDir) { this.baseDir = baseDir; }
+ public String[] getIncludedFiles() {
+ if( !hasScanned ) {
+ hasScanned = true;
+ scanner.scan();
+ }
+ return scanner.getIncludedFiles();
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XMLDocumentRepository.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XMLDocumentRepository.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XMLDocumentRepository.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,106 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.dom4j.Document;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+/**
+ * Parses and potentially stores descriptor files.
+ *
+ * @author rstryker
+ *
+ */
+public class XMLDocumentRepository {
+ private static XMLDocumentRepository instance = null;
+ public static XMLDocumentRepository getDefault() {
+ if( instance == null )
+ instance = new XMLDocumentRepository();
+ return instance;
+ }
+
+ private HashMap pathToDocument;
+ private HashMap pathToTimestamp;
+ private XMLDocumentRepository parent;
+
+ XMLDocumentRepository() {
+ pathToDocument = new HashMap();
+ pathToTimestamp = new HashMap();
+ }
+
+ public XMLDocumentRepository(XMLDocumentRepository parent) {
+ pathToDocument = new HashMap();
+ pathToTimestamp = new HashMap();
+ this.parent = parent;
+ }
+
+ public Document getDocument(String fullPath) {
+ return getDocument(fullPath, true);
+ }
+
+ public Document getDocument(String fullPath, boolean load) {
+ return getDocument(fullPath, load, true);
+ }
+
+ public Document getDocument(String fullPath, boolean load, boolean save) {
+ Document d = (Document)pathToDocument.get(fullPath);
+ if( d == null && load ) {
+ d = loadDocument(fullPath);
+ if( save ) {
+ pathToDocument.put(fullPath, d);
+ pathToTimestamp.put(fullPath, new Long(new File(fullPath).lastModified()));
+ }
+ }
+ return d;
+ }
+
+ public boolean refresh(String fullPath) {
+ if( new File(fullPath).lastModified() !=
((Long)pathToTimestamp.get(fullPath)).longValue()) {
+ pathToDocument.put(fullPath, loadDocument(fullPath));
+ pathToTimestamp.put(fullPath, new Long(new File(fullPath).lastModified()));
+ return true;
+ }
+ return false;
+ }
+
+ private Document loadDocument(String fullpath) {
+ try {
+ URL url = new File(fullpath).toURI().toURL();
+
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ SAXParser sp = spf.newSAXParser();
+
sp.getXMLReader().setFeature("http://apache.org/xml/features/nonvali...;,
false);
+
+ SAXReader reader = new SAXReader(false);
+ reader.setXMLReader(sp.getXMLReader());
+ Document document = reader.read(url);
+
+ return document;
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static void saveDocument(Document doc, String fullPath) {
+ try {
+ File outFile = new File(fullPath);
+ FileOutputStream os = new FileOutputStream(outFile);
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ XMLWriter writer = new XMLWriter(os, outformat);
+ writer.write(doc);
+ writer.flush();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathCategory.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathCategory.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathCategory.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,54 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+import java.util.HashMap;
+
+import org.jboss.ide.eclipse.as.core.server.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
+
+public class XPathCategory {
+ protected String name; // cannot include delimiter from the model, comma
+ protected JBossServer server;
+ protected HashMap children;
+
+ public XPathCategory(String name, JBossServer server) {
+ this.name = name;
+ this.server = server;
+ }
+
+ public String getName() { return this.name; }
+
+ public boolean queriesLoaded() {
+ return children != null;
+ }
+
+ public XPathQuery[] getQueries() {
+ if( children == null ) {
+ children = new HashMap();
+ XPathQuery[] queries = XPathModel.getDefault().loadQueries(this, server);
+ for( int i = 0; i < queries.length; i++ ) {
+ children.put(queries[i].getName(), queries[i]);
+ }
+ }
+ return (XPathQuery[]) children.values().toArray(new XPathQuery[children.size()]);
+ }
+
+ public XPathQuery getQuery(String name) {
+ return (XPathQuery)children.get(name);
+ }
+ public void addQuery(XPathQuery query) {
+ getQueries();
+ children.put(query.getName(), query);
+ query.setCategory(this);
+ }
+
+ public void removeQuery(XPathQuery query) {
+ getQueries();
+ children.remove(query.getName());
+ }
+
+ public void save() {
+ ServerAttributeHelper helper = server.getAttributeHelper();
+ XPathModel.getDefault().saveCategory(this, server, helper);
+ helper.save();
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathFileResult.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathFileResult.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathFileResult.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,162 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.Node;
+import org.dom4j.tree.DefaultAttribute;
+import org.dom4j.tree.DefaultElement;
+
+
+public class XPathFileResult {
+ protected XPathQuery query;
+ protected List nodeList;
+ protected String fileLoc;
+
+ protected XPathResultNode[] children;
+ public XPathFileResult(XPathQuery query, String fileLoc, List nodeList) {
+ this.query = query;
+ this.fileLoc = fileLoc;
+ this.nodeList = nodeList;
+ }
+
+ public String getFileLocation() {
+ return fileLoc;
+ }
+
+ public XPathQuery getQuery() {
+ return query;
+ }
+
+ public XPathResultNode[] getChildren() {
+ if( children == null ) {
+ ArrayList childList = new ArrayList();
+ Iterator i = nodeList.iterator();
+ int z = 0;
+ while(i.hasNext()) {
+ Node o = (Node)i.next();
+ childList.add(new XPathResultNode(o, query.getAttribute(), z++));
+ }
+ children = (XPathResultNode[]) childList.toArray(new
XPathResultNode[childList.size()]);
+ }
+ return children;
+ }
+
+ public class XPathResultNode {
+ protected Node node;
+ protected String attribute;
+ protected boolean hasAttribute;
+ protected int index;
+ protected Object val;
+ protected boolean dirty;
+ public XPathResultNode(Node node, String attribute, int index) {
+ this.node = node;
+ this.attribute = attribute;
+ this.index = index;
+ this.hasAttribute = attribute == null ? false : true;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public boolean hasAttribute() {
+ return hasAttribute;
+ }
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public String getAttributeValue() {
+ if( node instanceof DefaultElement ) {
+ return ((DefaultElement)node).attributeValue(attribute);
+ }
+ return "";
+ }
+
+ public Document getDocument() {
+ if( node instanceof DefaultElement ) {
+ return ((DefaultElement)node).getDocument();
+ }
+ return null;
+ }
+
+ public String getText() {
+ try {
+ if( node instanceof DefaultElement ) {
+ if( !hasAttribute()) {
+ return ((DefaultElement)node).getText();
+ } else {
+ Attribute att = ((DefaultElement)node).attribute(attribute);
+ return att.getValue();
+ }
+ }
+ } catch( NullPointerException npe ) {
+ }
+ return "";
+ }
+
+ public void setText(String newValue) {
+ if( node instanceof DefaultElement ) {
+ if( !hasAttribute()) {
+ ((DefaultElement)node).setText(newValue);
+ } else {
+ ((DefaultElement)node).attribute(attribute).setValue(newValue);
+ }
+ dirty = true;
+ }
+ }
+
+ public String elementAsXML() {
+ return ((DefaultElement)node).asXML();
+ }
+
+ public String getElementName() {
+ return ((DefaultElement)node).getName();
+ }
+
+ public String[] getElementChildrenNames() {
+ DefaultElement element = ((DefaultElement)node);
+ List l = element.elements();
+ DefaultElement child;
+ ArrayList names = new ArrayList();
+ for( Iterator i = l.iterator();i.hasNext();) {
+ child = (DefaultElement)i.next();
+ if( !names.contains(child.getName()))
+ names.add(child.getName());
+ }
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+ public String[] getElementAttributeNames() {
+ DefaultElement element = ((DefaultElement)node);
+ List l = element.attributes();
+ DefaultAttribute child;
+ ArrayList names = new ArrayList();
+ for( Iterator i = l.iterator();i.hasNext();) {
+ child = (DefaultAttribute)i.next();
+ if( !names.contains(child.getName()))
+ names.add(child.getName());
+ }
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+ public String[] getElementAttributeValues(String attName) {
+ DefaultElement element = ((DefaultElement)node);
+ Attribute at = element.attribute(attName);
+ return at == null ? new String[0] : new String[] {at.getValue()};
+ }
+ public boolean isDirty() {
+ return dirty;
+ }
+ public String getFileLocation() {
+ return fileLoc;
+ }
+ public void saveDescriptor() {
+ XMLDocumentRepository.saveDocument(node.getDocument(), fileLoc);
+ dirty = false;
+ }
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathModel.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathModel.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathModel.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,241 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+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.Properties;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.runtime.server.AbstractJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
+
+public class XPathModel {
+ public static final String EMPTY_STRING =
"org.jboss.ide.eclipse.as.core.model.descriptor.EmptyString";
+ private static final String DELIMITER = ",";
+ private static final String CATEGORY_LIST =
+ "org.jboss.ide.eclipse.as.core.model.descriptor.Categories";
+ private static final String QUERY_LIST =
+ "org.jboss.ide.eclipse.as.core.model.descriptor.QueryList";
+ private static final String QUERY =
+ "org.jboss.ide.eclipse.as.core.model.descriptor.Query";
+
+ public static XPathModel instance;
+ public static XPathModel getDefault() {
+ if( instance == null )
+ instance = new XPathModel();
+ return instance;
+ }
+
+ protected HashMap serverToCategories;
+ public XPathModel() {
+ serverToCategories = new HashMap();
+ }
+
+ public XPathQuery getQuery(JBossServer jbs, IPath path) {
+ XPathCategory cat = getCategory(jbs, path.segment(0));
+ if( cat != null )
+ return cat.getQuery(path.segment(1));
+ return null;
+ }
+
+ public ArrayList getCategoryCollection(JBossServer jbs) {
+ if( serverToCategories.get(jbs.getServer().getId()) == null ) {
+ ArrayList val = new ArrayList(Arrays.asList(load(jbs)));
+ if( val.size() == 0 ) {
+ val = loadDefaults(jbs);
+ serverToCategories.put(jbs.getServer().getId(), val);
+ save(jbs);
+ } else {
+ serverToCategories.put(jbs.getServer().getId(), val);
+ }
+ }
+ return (ArrayList)serverToCategories.get(jbs.getServer().getId());
+ }
+
+ public XPathCategory[] getCategories(JBossServer jbs) {
+ ArrayList val = getCategoryCollection(jbs);
+ return (XPathCategory[]) val.toArray(new XPathCategory[val.size()]);
+ }
+
+ public boolean containsCategory(JBossServer jbs, String name) {
+ return getCategory(jbs, name) == null ? false : true;
+ }
+
+ public XPathCategory getCategory(JBossServer jbs, String name) {
+ ArrayList list = getCategoryCollection(jbs);
+ Iterator i = list.iterator();
+ XPathCategory c;
+ while(i.hasNext()) {
+ c = (XPathCategory)i.next();
+ if( c.getName().equals(name))
+ return c;
+ }
+ return null;
+ }
+
+ public XPathCategory addCategory(JBossServer jbs, String name) {
+ if( !containsCategory(jbs, name)) {
+ XPathCategory c = new XPathCategory(name, jbs);
+ getCategoryCollection(jbs).add(c);
+ return c;
+ }
+ return getCategory(jbs, name);
+ }
+
+ public void addCategory(JBossServer jbs, XPathCategory category) {
+ if( !containsCategory(jbs, category.getName())) {
+ getCategoryCollection(jbs).add(category);
+ }
+ }
+
+ public void removeCategory(JBossServer jbs, String name) {
+ ArrayList list = getCategoryCollection(jbs);
+ Iterator i = list.iterator();
+ while(i.hasNext()) {
+ XPathCategory cat = (XPathCategory)i.next();
+ if( cat.getName().equals(name)) {
+ i.remove();
+ return;
+ }
+ }
+ }
+
+ /*
+ * Loading and saving is below
+ */
+ private XPathCategory[] load(JBossServer jbs) {
+ ServerAttributeHelper helper = jbs.getAttributeHelper();
+ String list = helper.getAttribute(CATEGORY_LIST, (String)null);
+ System.out.println("load " + CATEGORY_LIST + ", got " + list);
+ if( list == null )
+ return new XPathCategory[] {};
+ String[] byName = list.split(DELIMITER);
+ XPathCategory[] cats = new XPathCategory[byName.length];
+ for( int i = 0; i < byName.length; i++ ) {
+ cats[i] = new XPathCategory(byName[i], jbs);
+ }
+ return cats;
+ }
+
+ public void save(JBossServer jbs) {
+ if( !serverToCategories.containsKey(jbs.getServer().getId()))
+ return;
+
+ ServerAttributeHelper helper = jbs.getAttributeHelper();
+ XPathCategory[] categories = getCategories(jbs);
+ String list = "";
+ for( int i = 0; i < categories.length; i++ ) {
+ if( i != 0 )
+ list += DELIMITER;
+ list += categories[i].getName();
+ saveCategory(categories[i], jbs, helper);
+ }
+ helper.setAttribute(CATEGORY_LIST, list);
+ helper.save();
+ }
+
+ public void saveCategory(XPathCategory category, JBossServer jbs, ServerAttributeHelper
helper) {
+ if( category.queriesLoaded()) {
+ XPathQuery[] queries = category.getQueries();
+ String val = "";
+ for( int i = 0; i < queries.length; i++ ) {
+ if( i != 0 )
+ val += DELIMITER;
+ val += category.getName() + Path.SEPARATOR + queries[i].getName();
+ saveQuery(queries[i], category, jbs, helper);
+ }
+ helper.setAttribute(QUERY_LIST + "." + category.getName().replace('
', '_'), val);
+ System.out.println("save " + QUERY_LIST + "." + category.getName()
+ " with " + val);
+ }
+ }
+
+ private void saveQuery(XPathQuery query, XPathCategory category, JBossServer jbs,
ServerAttributeHelper helper) {
+ ArrayList list = new ArrayList();
+ list.add(query.getBaseDir());
+ list.add(query.getFilePattern() == null ? EMPTY_STRING : query.getFilePattern());
+ list.add(query.getXpathPattern() == null ? EMPTY_STRING : query.getXpathPattern());
+ list.add(query.getAttribute() == null ? EMPTY_STRING : query.getAttribute());
+ helper.setAttribute(QUERY + "." + category.getName().replace(' ',
'_') + Path.SEPARATOR + query.getName().replace(' ', '_'), list);
+ System.out.println("saved " + QUERY + "." + category.getName() +
Path.SEPARATOR + query.getName() + " with " + list);
+ }
+
+ public XPathQuery[] loadQueries(XPathCategory category, JBossServer jbs) {
+ ServerAttributeHelper helper = jbs.getAttributeHelper();
+ String list = helper.getAttribute(QUERY_LIST + "." +
category.getName().replace(' ', '_'), (String)null);
+ System.out.println("load " + QUERY_LIST + "." + category.getName()
+ " gets " + list);
+ if( list == null )
+ return new XPathQuery[] {};
+ String[] queriesByName = list.split(DELIMITER);
+ List queryAsStringValues;
+ ArrayList returnList = new ArrayList();
+ for( int i = 0; i < queriesByName.length; i++ ) {
+ queryAsStringValues = helper.getAttribute(QUERY + "." +
queriesByName[i].replace(' ', '_'), (List)null);
+ System.out.println("load " + QUERY + "." + queriesByName[i]);
+ if( queryAsStringValues != null ) {
+ try {
+ XPathQuery q =new
XPathQuery(queriesByName[i].substring(queriesByName[i].indexOf(Path.SEPARATOR)+1),
queryAsStringValues);
+ q.setCategory(category);
+ returnList.add(q);
+ } catch( Exception e ) {e.printStackTrace(); }
+ }
+ }
+ return (XPathQuery[]) returnList.toArray(new XPathQuery[returnList.size()]);
+ }
+
+
+
+ /*
+ * Loading the defaults for the server
+ * returns the category created
+ */
+ private static HashMap rtToPortsFile;
+ private static final String ATTRIBUTE_SUFFIX = "_ATTRIBUTE";
+ private static final String FILE_SUFFIX = "_FILE";
+ static {
+ rtToPortsFile = new HashMap();
+ rtToPortsFile.put("3.2", new
Path("properties").append("jboss.32.default.ports.properties"));
+ rtToPortsFile.put("4.0", new
Path("properties").append("jboss.40.default.ports.properties"));
+ rtToPortsFile.put("4.2", new
Path("properties").append("jboss.42.default.ports.properties"));
+ rtToPortsFile.put("5.0", new
Path("properties").append("jboss.50.default.ports.properties"));
+ }
+
+ protected ArrayList loadDefaults(JBossServer jbs) {
+ ArrayList retVal = new ArrayList();
+ String configFolder;
+ configFolder = jbs.getConfigDirectory(false); // do not check the launch config
+ AbstractJBossServerRuntime ajbsr = (AbstractJBossServerRuntime)
+ jbs.getServer().getRuntime().loadAdapter(AbstractJBossServerRuntime.class, new
NullProgressMonitor());
+ Path p = (Path)rtToPortsFile.get(ajbsr.getId());
+ URL url = FileLocator.find(JBossServerCorePlugin.getDefault().getBundle(), p, null);
+ Properties pr = new Properties();
+ try {
+ pr.load(url.openStream());
+ XPathCategory ports = new XPathCategory("Ports", jbs);
+ Iterator i = pr.keySet().iterator();
+ String name, xpath, attributeName, file;
+ XPathQuery query;
+ while(i.hasNext()) {
+ name = (String)i.next();
+ if( !name.endsWith(ATTRIBUTE_SUFFIX) && !name.endsWith(FILE_SUFFIX)) {
+ xpath = pr.getProperty(name);
+ attributeName = pr.getProperty(name+ATTRIBUTE_SUFFIX);
+ file = pr.getProperty(name + FILE_SUFFIX);
+ query = new XPathQuery(name.replace('_', ' '), configFolder, file,
xpath, attributeName);
+ ports.addQuery(query);
+ }
+ }
+ retVal.add(ports);
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return retVal;
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathQuery.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathQuery.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/descriptor/XPathQuery.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,150 @@
+package org.jboss.ide.eclipse.as.core.model.descriptor;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
+
+/**
+ * A simple value object to hold the XPath query data
+ * @author rstryker(a)redhat.com
+ *
+ */
+public class XPathQuery implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * XPath-important fields
+ */
+ protected String name;
+ protected String baseDir;
+ protected String filePattern;
+ protected String xpathPattern;
+ protected String attribute;
+
+ /*
+ * The filter, need not be saved on serialize
+ */
+ protected transient AntFileFilter filter;
+
+ /*
+ * The file results, need not be saved on serialize
+ */
+ protected transient XPathFileResult[] results;
+ protected transient XPathCategory category;
+ protected transient XMLDocumentRepository repository = null;
+
+ public XPathQuery(String name, List list) {
+ this.name = name;
+ this.baseDir = list.get(0).equals(XPathModel.EMPTY_STRING) ? null :
(String)list.get(0);
+ this.filePattern = list.get(1).equals(XPathModel.EMPTY_STRING) ? null :
(String)list.get(1);
+ this.xpathPattern = list.get(2).equals(XPathModel.EMPTY_STRING) ? null :
(String)list.get(2);
+ this.attribute = list.size() < 3 || list.get(3).equals(XPathModel.EMPTY_STRING) ?
null : (String)list.get(3);
+ }
+ public XPathQuery(String name, String baseDir, String filePattern, String xpathPattern,
String attribute) {
+ this.name = name;
+ this.baseDir = baseDir;
+ this.filePattern = filePattern;
+ this.xpathPattern = xpathPattern;
+ this.attribute = attribute;
+ this.results = null;
+ }
+ protected AntFileFilter getFilter() {
+ if( filter == null )
+ filter = new AntFileFilter(baseDir, filePattern);
+ return filter;
+ }
+ public void refresh() {
+ String[] files = getFilter().getIncludedFiles();
+ boolean changed = false;
+ for( int i = 0; i < files.length; i++ ) {
+ changed = changed || getRepository().refresh(new
Path(baseDir).append(files[i]).toOSString());
+ }
+ if( changed ) {
+ results = null;
+ }
+ }
+
+ public XPathFileResult[] getResults() {
+ if( results == null )
+ loadResults();
+ return results;
+ }
+
+ public boolean resultsLoaded() {
+ return results == null ? false : true;
+ }
+
+ protected void loadResults() {
+ String[] files = getFilter().getIncludedFiles();
+ String fileLoc;
+ ArrayList resultList = new ArrayList();
+ List nodeList;
+ for( int i = 0; i < files.length; i++ ) {
+ fileLoc = new Path(baseDir).append(files[i]).toOSString();
+ nodeList = getRepository().getDocument(fileLoc).selectNodes(xpathPattern);
+ if( nodeList.size() > 0 )
+ resultList.add(new XPathFileResult(this, fileLoc, nodeList));
+ }
+ results = (XPathFileResult[]) resultList.toArray(new
XPathFileResult[resultList.size()]);
+ }
+
+ public String getFirstResult() {
+ XPathFileResult[] fileResults = getResults();
+ if( fileResults.length > 0 ) {
+ XPathResultNode[] nodes = fileResults[0].getChildren();
+ if( nodes.length > 0 ) {
+ return nodes[0].getText();
+ }
+ }
+ return null;
+ }
+ /*
+ * Field Getters and setters
+ */
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getFilePattern() {
+ return filePattern;
+ }
+ public void setFilePattern(String filePattern) {
+ this.filePattern = filePattern;
+ }
+ public String getXpathPattern() {
+ return xpathPattern;
+ }
+ public void setXpathPattern(String xpathPattern) {
+ this.xpathPattern = xpathPattern;
+ }
+ public String getAttribute() {
+ return attribute;
+ }
+ public void setAttribute(String attribute) {
+ this.attribute = attribute;
+ }
+ public String getBaseDir() {
+ return baseDir;
+ }
+ public void setBaseDir(String baseDir) {
+ this.baseDir = baseDir;
+ }
+ public XPathCategory getCategory() {
+ return category;
+ }
+ public void setCategory(XPathCategory category) {
+ this.category = category;
+ }
+ public void setRepository(XMLDocumentRepository repo) {
+ this.repository = repo;
+ }
+ protected XMLDocumentRepository getRepository() {
+ return repository == null ? XMLDocumentRepository.getDefault() : repository;
+ }
+}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/legacy/DescriptorModel.java
(from rev 2202,
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/DescriptorModel.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/legacy/DescriptorModel.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/legacy/DescriptorModel.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,459 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ide.eclipse.as.core.model.legacy;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+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.DefaultAttribute;
+import org.dom4j.tree.DefaultElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
+
+public class DescriptorModel {
+ /* Static Portion */
+ private static DescriptorModel model = null;
+
+ public static DescriptorModel getDefault() {
+ if( model == null ) {
+ model = new DescriptorModel();
+ }
+ return model;
+ }
+
+
+ /* Member variables / methods */
+ private HashMap map;
+
+ public DescriptorModel() {
+ map = new HashMap();
+ }
+//
+// public ServerDescriptorModel getServerModel(IPath configPath) {
+// String key = configPath.toOSString();
+// Object o = map.get(key);
+// if( o == null ) {
+// o = createEntity(configPath);
+// }
+// return (ServerDescriptorModel)o;
+// }
+//
+// private ServerDescriptorModel createEntity(IPath configPath) {
+// ServerDescriptorModel val = new ServerDescriptorModel(configPath.toOSString());
+// map.put(configPath.toOSString(), val);
+// return val;
+// }
+//
+// public static class ServerDescriptorModel {
+// private String configPath;
+//
+// private HashMap pathToDocument;
+// private HashMap pathToLastRead;
+//
+// public ServerDescriptorModel(String configPath) {
+// this.configPath = configPath;
+// pathToDocument = new HashMap();
+// pathToLastRead = new HashMap();
+// }
+//
+// /**
+// * Discover all descriptors in the configuration
+// * @return
+// */
+//
+// private File[] getAllDescriptors() {
+// ArrayList list = new ArrayList();
+// File config = new File(configPath);
+// getAllDescriptorsRecurse(config, list);
+// File[] ret = new File[list.size()];
+// list.toArray(ret);
+// return ret;
+// }
+//
+// private void getAllDescriptorsRecurse(File parent, ArrayList collector) {
+// if( parent.isDirectory() ) {
+// File[] children = parent.listFiles();
+// for( int i = 0; i < children.length; i++ ) {
+// if( children[i].isDirectory()) {
+// getAllDescriptorsRecurse(children[i], collector);
+// } else if( children[i].getAbsolutePath().endsWith(".xml")) {
+// collector.add(children[i]);
+// }
+// }
+// }
+// }
+//
+//
+//
+// 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();
+//
+// SAXParserFactory spf = SAXParserFactory.newInstance();
+// SAXParser sp = spf.newSAXParser();
+//
sp.getXMLReader().setFeature("http://apache.org/xml/features/nonvali...;,
false);
+//
+// SAXReader reader = new SAXReader(false);
+// reader.setXMLReader(sp.getXMLReader());
+// Document document = reader.read(url);
+//
+// // add to maps
+// pathToDocument.put(path, document);
+// pathToLastRead.put(path, new Long(lastModified));
+// } catch( Exception e ) {
+// e.printStackTrace();
+// }
+// }
+//
+// /**
+// * 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) {
+// try {
+// Document d = getDocument(path);
+// if( d == null ) return new ArrayList();
+// return d.selectNodes(xpath);
+// } catch( Exception e ) {
+// return new ArrayList();
+// }
+// }
+//
+// /**
+// * 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, null);
+// }
+//
+// public XPathTreeItem[] getXPath(String xpath, String attributeName, FileFilter filter
) {
+// return getXPath(xpath, attributeName, filter, true);
+// }
+//
+// public XPathTreeItem[] getXPath(String xpath, String attributeName, FileFilter
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 == null || filter.accept(new File(p))) {
+// tmp = getXPathFromFile(p, xpath);
+// if( tmp.size() > 0 ) {
+// if( attributeName == null || attributeName.equals("")) {
+// newItem = new XPathTreeItem(null, new File(p), tmp);
+// list.add(newItem);
+// } else {
+// // Remove any that match the path but not the attribute
+// Iterator j = tmp.iterator();
+// while( j.hasNext()) {
+// DefaultElement el = (DefaultElement)j.next();
+// if( el.attribute(attributeName) == null ) {
+// j.remove();
+// }
+// }
+// if( tmp.size() > 0 ) {
+// 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() {
+// try {
+// if( getData() instanceof DefaultElement ) {
+// if( !hasAttribute()) {
+// return ((DefaultElement)getData()).getText();
+// } else {
+// Attribute att = ((DefaultElement)getData()).attribute(attribute);
+// return att.getValue();
+// }
+// }
+// } catch( NullPointerException npe ) {
+// npe.printStackTrace();
+// }
+// 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() {
+// return ((DefaultElement)getData()).asXML();
+// }
+//
+// public String getElementName() {
+// return ((DefaultElement)getData()).getName();
+// }
+//
+// public String[] getElementChildrenNames() {
+// DefaultElement element = ((DefaultElement)getData());
+// List l = element.elements();
+// DefaultElement child;
+// ArrayList names = new ArrayList();
+// for( Iterator i = l.iterator();i.hasNext();) {
+// child = (DefaultElement)i.next();
+// if( !names.contains(child.getName()))
+// names.add(child.getName());
+// }
+// return (String[]) names.toArray(new String[names.size()]);
+// }
+// public String[] getElementAttributeNames() {
+// DefaultElement element = ((DefaultElement)getData());
+// List l = element.attributes();
+// DefaultAttribute child;
+// ArrayList names = new ArrayList();
+// for( Iterator i = l.iterator();i.hasNext();) {
+// child = (DefaultAttribute)i.next();
+// if( !names.contains(child.getName()))
+// names.add(child.getName());
+// }
+// return (String[]) names.toArray(new String[names.size()]);
+// }
+// public String[] getElementAttributeValues(String attName) {
+// DefaultElement element = ((DefaultElement)getData());
+// Attribute at = element.attribute(attName);
+// return at == null ? new String[0] : new String[] {at.getValue()};
+// }
+//
+// 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;
+// }
+//
+// }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/AbstractJBossServerRuntime.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/AbstractJBossServerRuntime.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/AbstractJBossServerRuntime.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -28,7 +28,6 @@
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstallType;
import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy;
import org.eclipse.wst.server.core.model.RuntimeDelegate;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerLaunchDefaults.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerLaunchDefaults.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerLaunchDefaults.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -37,8 +37,6 @@
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
import org.jboss.ide.eclipse.as.core.runtime.IJBossServerLaunchDefaults;
import org.jboss.ide.eclipse.as.core.runtime.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
@@ -116,14 +114,7 @@
workingCopy.setAttribute(vmArgsKey + STOP_SUFFIX, getVMArgs());
- int jndiPort;
- try {
- String serverConfDir = getJBServer().getConfigDirectory(false);
- ServerDescriptorModel descriptorModel =
DescriptorModel.getDefault().getServerModel(new Path(serverConfDir));
- jndiPort = descriptorModel.getJNDIPort();
- } catch( Exception e ) {
- jndiPort = 1099;
- }
+ int jndiPort = getJBServer().getJNDIPort();
String host = server.getHost();
String twiddleArgs = "-s " + host + ":" + jndiPort + " -a
jmx/rmi/RMIAdaptor ";
@@ -156,7 +147,6 @@
IJBossServerRuntime rt = getRuntime();
if( rt != null ) {
return "--configuration=" + rt.getJBossConfiguration();
- //+ " --host=" + server.getHost();
}
return "";
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -41,10 +41,9 @@
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
import org.jboss.ide.eclipse.as.core.model.EventLogModel;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
+import org.jboss.ide.eclipse.as.core.model.legacy.DescriptorModel;
import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.JBossServerLaunchConfiguration;
import org.jboss.ide.eclipse.as.core.server.TwiddleLauncher;
@@ -86,10 +85,12 @@
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
ClassLoader twiddleLoader = getClassLoader();
if( twiddleLoader != null ) {
- String serverConfDir =
ServerConverter.getJBossServer(server).getConfigDirectory(false);
- ServerDescriptorModel descriptorModel =
DescriptorModel.getDefault().getServerModel(new Path(serverConfDir));
- int port = descriptorModel.getJNDIPort();
-
+ // TODO: FIX ME
+// String serverConfDir =
ServerConverter.getJBossServer(server).getConfigDirectory(false);
+// ServerDescriptorModel descriptorModel =
DescriptorModel.getDefault().getServerModel(new Path(serverConfDir));
+// int port = descriptorModel.getJNDIPort();
+ int port = 1099;
+
Thread.currentThread().setContextClassLoader(twiddleLoader);
Properties props = new Properties();
props.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
@@ -207,11 +208,7 @@
public class PollingSecurityException extends PollingException {
public PollingSecurityException(String msg) {super(msg);}
}
- public class PollingNamingException extends PollingException {
- public PollingNamingException(String msg) {super(msg);}
- }
-
public boolean getState() throws PollingException {
if( pollingException != null ) throw pollingException;
if( started == 0 ) return SERVER_DOWN;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -22,11 +22,12 @@
package org.jboss.ide.eclipse.as.core.server;
import java.io.File;
-import java.io.FileFilter;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -42,10 +43,8 @@
import org.eclipse.wst.server.core.model.IURLProvider;
import org.eclipse.wst.server.core.model.ServerDelegate;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem2;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathModel;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
import org.jboss.ide.eclipse.as.core.runtime.IJBossServerLaunchDefaults;
import org.jboss.ide.eclipse.as.core.runtime.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.runtime.server.ServerLaunchDefaults;
@@ -122,21 +121,13 @@
}
return new ServerAttributeHelper(getServer(), copy);
}
-
-
-
public String getConfigDirectory() {
return getConfigDirectory(true);
}
public String getDeployDirectory() {
return getDeployDirectory(true);
}
-
- public ServerDescriptorModel getDescriptorModel() {
- String configPath = getConfigDirectory();
- return DescriptorModel.getDefault().getServerModel(new Path(configPath));
- }
public String getConfigDirectory(boolean checkLaunchConfig) {
if( !checkLaunchConfig )
@@ -191,49 +182,52 @@
return new Path(p).toOSString();
}
+ private static final IPath JNDI_KEY = new
Path("Ports").append("JNDI");
+ private static final int JNDI_DEFAULT_PORT = 1099;
+ public int getJNDIPort() {
+ int port = findPort(JNDI_KEY);
+ return port == -1 ? JNDI_DEFAULT_PORT : port;
+ }
+ private static final IPath JBOSS_WEB_KEY = new
Path("Ports").append("JBoss Web");
+ public static final int JBOSS_WEB_DEFAULT_PORT = 8080;
+ public int getJBossWebPort() {
+ int port = findPort(JBOSS_WEB_KEY);
+ return port == -1 ? JBOSS_WEB_DEFAULT_PORT : port;
+ }
+
+ protected int findPort(IPath path) {
+ XPathQuery query = XPathModel.getDefault().getQuery(this, path);
+ String result = query.getFirstResult();
+ if( result != null ) {
+ try {
+ return Integer.parseInt(result);
+ } catch( Exception e ) {}
+ }
+ return -1;
+ }
+
public URL getModuleRootURL(IModule module) {
- try {
- if (module == null || module.loadAdapter(IWebModule.class,null)==null )
- return null;
-
- IWebModule webModule =(IWebModule)module.loadAdapter(IWebModule.class,null);
- String host = getServer().getHost();
- String url = "http://"+host; //$NON-NLS-1$
- int port = -1;
-
- ServerDescriptorModel sdm = DescriptorModel.getDefault().getServerModel(new
Path(getConfigDirectory()));
- FileFilter filter = new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.getAbsolutePath().endsWith("server.xml");
- }
- };
- XPathTreeItem[] items = sdm.getXPath(
- "//Server/Service[@name='jboss.web']/Connector[count((a)sslProtocol) = 0
and (count(@protocol) = 0 or @protocol = 'HTTP/1.1')]",
- "port", filter, false);
- if( items.length > 0 ) {
- try {
- port =
Integer.parseInt(((XPathTreeItem2)items[0].getChildren()[0]).getAttributeValue());
- } catch(Exception e) {}
- }
- if( port == -1 ) port = 8080;
- //port =ServerUtil.getMonitoredPort(getServer(), port, "web");
//$NON-NLS-1$
- if (port != 80)
- url += ":" + port; //$NON-NLS-1$
+ if (module == null || module.loadAdapter(IWebModule.class,null)==null )
+ return null;
+
+ IWebModule webModule =(IWebModule)module.loadAdapter(IWebModule.class,null);
+ String host = getServer().getHost();
+ String url = "http://"+host; //$NON-NLS-1$
+ int port = getJBossWebPort();
+ if (port != 80)
+ url += ":" + port; //$NON-NLS-1$
- url += "/"+webModule.getContextRoot(); //$NON-NLS-1$
+ url += "/"+webModule.getContextRoot(); //$NON-NLS-1$
- if (!url.endsWith("/")) //$NON-NLS-1$
- url += "/"; //$NON-NLS-1$
+ if (!url.endsWith("/")) //$NON-NLS-1$
+ url += "/"; //$NON-NLS-1$
+ try {
return new URL(url);
- } catch (Exception e) {
- return null;
- }
- }
-
-
+ } catch( MalformedURLException murle) { return null; }
+ }
}
\ No newline at end of file
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -48,7 +48,7 @@
public void stop(boolean force) {
int state = getServer().getServerState();
- if( force || process.isTerminated() || state == IServer.STATE_STOPPED) {
+ if( force || process == null || process.isTerminated() || state ==
IServer.STATE_STOPPED) {
forceStop();
return;
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -21,9 +21,6 @@
*/
package org.jboss.ide.eclipse.as.core.server;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -33,10 +30,13 @@
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem;
-import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
+/**
+ * This class just opens up the get and set attributes for a server,
+ * and provides saving mechanisms.
+ * @author rstryker(a)redhat.com
+ *
+ */
public class ServerAttributeHelper {
private ServerWorkingCopy wch;
@@ -71,10 +71,6 @@
wch.setAttribute(attributeName, value);
}
-
-
-
-
public String getAttribute(String attributeName, String defaultValue) {
return wch.getAttribute(attributeName, defaultValue);
}
@@ -95,8 +91,6 @@
return wch.getAttribute(attributeName, defaultValue);
}
-
-
public boolean isDirty() {
return wch.isDirty();
}
@@ -110,207 +104,5 @@
return save(false, new NullProgressMonitor());
} catch( Exception e ) {}
return null;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static final String PORTS_DEFAULT_CATEGORY = "Ports";
- public static final String XPATH_CATEGORIES = "_XPATH_CATEGORIES_";
- public static final String XPATH_CATEGORY2_PREFIX =
"_XPATH_CATEGORY2_PREFIX_";
- public static final String XPATH_PROPERTY_PREFIX = "_XPATH_PROPERTY_PREFIX_";
- public static final String PORT_CATEGORY_PREF_KEY = "_PORT_CATEGORY_NAME_";
-
- public String getDefaultPortCategoryName() {
- return wch.getAttribute(PORT_CATEGORY_PREF_KEY, PORTS_DEFAULT_CATEGORY);
- }
- public void setDefaultPortCategoryName(String s) {
- wch.setAttribute(PORT_CATEGORY_PREF_KEY, s);
- }
-
- public SimpleXPathPreferenceTreeItem getXPathPreferenceTree() {
- List categories = wch.getAttribute(XPATH_CATEGORIES, (List)null);
- if( categories == null ) {
- return getDefaultXPathPreferenceTree();
- }
- SimpleXPathPreferenceTreeItem model = new SimpleXPathPreferenceTreeItem(null,
XPATH_CATEGORIES);
- Iterator i = categories.iterator();
- while(i.hasNext()) {
- String categoryName = (String)i.next();
- SimpleXPathPreferenceTreeItem categoryItem = new SimpleXPathPreferenceTreeItem(model,
categoryName);
- String categoryListKey = XPATH_CATEGORY2_PREFIX + categoryName;
- List categoryElementsAsList = wch.getAttribute(categoryListKey, new ArrayList());
- Iterator j = categoryElementsAsList.iterator();
- while(j.hasNext()) {
- String xpathName = (String)j.next();
- String finalKey = XPATH_PROPERTY_PREFIX + categoryName + xpathName;
- List xpathItem = wch.getAttribute(finalKey, new ArrayList());
- if( xpathItem.size() == 2 ) {
- XPathPreferenceTreeItem xpi = new XPathPreferenceTreeItem(categoryItem,
- (String)xpathItem.get(0), (String)xpathItem.get(1));
- } else if( xpathItem.size() == 3 ) {
- XPathPreferenceTreeItem xpi = new XPathPreferenceTreeItem(categoryItem,
- (String)xpathItem.get(0), (String)xpathItem.get(1), (String)xpathItem.get(2));
- }
- }
- }
-
- return model;
- }
-
- private SimpleXPathPreferenceTreeItem getDefaultXPathPreferenceTree() {
- SimpleXPathPreferenceTreeItem model = new SimpleXPathPreferenceTreeItem(null,
XPATH_CATEGORIES);
-
- SimpleXPathPreferenceTreeItem ports = new SimpleXPathPreferenceTreeItem(model,
PORTS_DEFAULT_CATEGORY);
-
-
-
- XPathPreferenceTreeItem jndi = new XPathPreferenceTreeItem(ports,
- "JNDI",
"/server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']");
- XPathPreferenceTreeItem jndiRMI = new XPathPreferenceTreeItem(ports,
- "JNDI RMI",
"/server/mbean[@name='jboss:service=Naming']/attribute[@name='RmiPort']");
-
- XPathPreferenceTreeItem haJndiStub = new XPathPreferenceTreeItem(ports,
- "HA JNDI Stub",
"//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='Port']");
-
- XPathPreferenceTreeItem haJndiRMI = new XPathPreferenceTreeItem(ports,
- "HA JNDI RMI",
"//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='RmiPort']");
-
- XPathPreferenceTreeItem jrmpa = new XPathPreferenceTreeItem(ports,
- "JRMPA RMI Object",
"//server/mbean[@name='jboss:service=invoker,type=jrmpha']/attribute[@name='RMIObjectPort']");
-
- XPathPreferenceTreeItem clusterUDPMcast = new XPathPreferenceTreeItem(ports,
- "Cluster UDP MCast",
"//server/mbean[@name='jboss:service=${jboss.partition.name:DefaultPartition}']/attribute[@name='PartitionConfig']/Config/UDP",
"mcast_port");
-
- XPathPreferenceTreeItem webservices = new XPathPreferenceTreeItem(ports,
- "Web Services",
"//server/mbean[@name='jboss:service=WebService']/attribute[@name='Port']");
-
-// XPathPreferenceTreeItem hypersonic = new XPathPreferenceTreeItem(ports,
-// "HyperSonic",
"//server/mbean[@name='jboss:service=Hypersonic']/attribute[@name='Port']");
-
- XPathPreferenceTreeItem jrmpInvoker = new XPathPreferenceTreeItem(ports,
- "JRMP Invoker",
"//server/mbean[@name='jboss:service=invoker,type=jrmp']/attribute[@name='RMIObjectPort']");
-
- XPathPreferenceTreeItem pooledInvoker = new XPathPreferenceTreeItem(ports,
- "Pooled Invoker",
"//server/mbean[@name='jboss:service=invoker,type=pooled']/attribute[@name='ServerBindPort']");
-
-
-
-
- return model;
- }
-
- public void saveXPathPreferenceTree(SimpleTreeItem tree) {
-
- SimpleTreeItem[] children = tree.getChildren();
- SimpleTreeItem[] grandChildren;
- ArrayList categoryList = new ArrayList();
- ArrayList xpathNameList, itemAsList;
- XPathPreferenceTreeItem xpathPrefItem;
- HashMap map = new HashMap();
- for( int i = 0; i < children.length; i++ ) {
- xpathNameList = new ArrayList();
- String categoryName = (String)children[i].getData();
- categoryList.add(categoryName); // add "Ports"
-
- grandChildren = children[i].getChildren(); // list of xpaths under "Ports"
- for( int j = 0; j < grandChildren.length; j++ ) {
- xpathPrefItem = ((XPathPreferenceTreeItem)grandChildren[j]); // JNDI
- itemAsList = new ArrayList();
- itemAsList.add(xpathPrefItem.getName());
- itemAsList.add(xpathPrefItem.getXPath());
- itemAsList.add(xpathPrefItem.getAttributeName());
- xpathNameList.add(xpathPrefItem.getName());
- map.put(XPATH_PROPERTY_PREFIX + categoryName + xpathPrefItem.getName(), itemAsList);
- }
- map.put(XPATH_CATEGORY2_PREFIX + categoryName, xpathNameList);
- }
- map.put(XPATH_CATEGORIES, categoryList);
-
- Iterator i = map.keySet().iterator();
- while( i.hasNext()) {
- String key = (String)i.next();
- wch.setAttribute(key, (List)map.get(key));
- }
-
- }
-
- /* Just a label class */
- public static class SimpleXPathPreferenceTreeItem extends SimpleTreeItem {
- public SimpleXPathPreferenceTreeItem(SimpleTreeItem parent, Object data) {
- super(parent, data);
- }
- }
- public static class XPathPreferenceTreeItem extends SimpleXPathPreferenceTreeItem {
- private String name;
- private String elementXPath;
- private String attributeName = null;
-
- public XPathPreferenceTreeItem(SimpleTreeItem parent, String key, String value) {
- super(parent, null);
- this.name = key;
- this.elementXPath = value;
- }
-
- public XPathPreferenceTreeItem(SimpleTreeItem parent, String key,
- String value, String attributeName ) {
- this(parent, key, value);
- this.attributeName = attributeName;
- }
- public String getName() {
- return name;
- }
- public String getXPath() {
- return elementXPath;
- }
- public void setXPath(String value) {
- this.elementXPath = value;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getAttributeName() {
- return attributeName;
- }
- public void setAttributeName(String attName) {
- this.attributeName = attName;
- }
-
- // actually a forced refresh
- public void ensureLoaded(IDeployableServer jbServer) {
- String XPATH_PROPERTY_LOADED = "_XPATH_PROPERTY_LOADED_";
-
- String xpath = getXPath();
- String attribute = getAttributeName();
- XPathTreeItem[] items = new XPathTreeItem[0];
- if( attribute == null || attribute.equals("")) {
- items = jbServer.getDescriptorModel().getXPath(xpath);
- } else {
- items = jbServer.getDescriptorModel().getXPath(xpath, attribute);
- }
-
- if( getProperty(XPATH_PROPERTY_LOADED) != null ) {
- //deleteChildren();
- return;
- }
- for( int i = 0; i < items.length; i++ ) {
- addChild(items[i]);
- }
- setProperty(XPATH_PROPERTY_LOADED, new Boolean(true));
- }
-
- }
-
-
-
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IDeployableServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IDeployableServer.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IDeployableServer.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -22,7 +22,6 @@
package org.jboss.ide.eclipse.as.core.server.attributes;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
/**
@@ -34,5 +33,4 @@
public String getConfigDirectory();
public ServerAttributeHelper getAttributeHelper();
public IServer getServer();
- public ServerDescriptorModel getDescriptorModel();
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/stripped/DeployableServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/stripped/DeployableServer.java 2007-07-19
00:47:40 UTC (rev 2512)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/stripped/DeployableServer.java 2007-07-19
00:48:10 UTC (rev 2513)
@@ -3,14 +3,11 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.model.ServerDelegate;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
@@ -19,22 +16,37 @@
public static final String DEPLOY_DIRECTORY =
"org.jboss.ide.eclipse.as.core.server.stripped.deploy_directory";
public DeployableServer() {
- // TODO Auto-generated constructor stub
}
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.server.core.model.ServerDelegate#canModifyModules(org.eclipse.wst.server.core.IModule[],
org.eclipse.wst.server.core.IModule[])
+ */
public IStatus canModifyModules(IModule[] add, IModule[] remove) {
return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID,0, "OK",
null);
}
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.server.core.model.ServerDelegate#getChildModules(org.eclipse.wst.server.core.IModule[])
+ */
public IModule[] getChildModules(IModule[] module) {
// TODO Auto-generated method stub
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.server.core.model.ServerDelegate#getRootModules(org.eclipse.wst.server.core.IModule)
+ */
public IModule[] getRootModules(IModule module) throws CoreException {
return new IModule[] { module };
}
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.server.core.model.ServerDelegate#modifyModules(org.eclipse.wst.server.core.IModule[],
org.eclipse.wst.server.core.IModule[], org.eclipse.core.runtime.IProgressMonitor)
+ */
public void modifyModules(IModule[] add, IModule[] remove,
IProgressMonitor monitor) throws CoreException {
// TODO Auto-generated method stub
@@ -47,6 +59,10 @@
return getAttribute(DEPLOY_DIRECTORY, "");
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer#getAttributeHelper()
+ */
public ServerAttributeHelper getAttributeHelper() {
IServerWorkingCopy copy = getServerWorkingCopy();
if( copy == null ) {
@@ -59,10 +75,4 @@
public String getConfigDirectory() {
return getDeployDirectory();
}
-
- public ServerDescriptorModel getDescriptorModel() {
- return DescriptorModel.getDefault().getServerModel(new Path(getDeployDirectory()));
- }
-
-
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.40.default.ports.properties
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.40.default.ports.properties
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.40.default.ports.properties 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,15 @@
+JNDI=//server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']
+JNDI_FILE=**/jboss-service.xml
+JBoss_Web=//Server/Service[@name='jboss.web']/Connector[count((a)sslProtocol) = 0
and (count(@protocol) = 0 or @protocol = 'HTTP/1.1')]
+JBoss_Web_ATTRIBUTE=port
+JBoss_Web_FILE=**/*server.xml
+JNDI_RMI=//server/mbean[@name='jboss:service=Naming']/attribute[@name='RmiPort']
+HA_JNDI_STUB=//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='Port']
+HA_JNDI_RMI=//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='RmiPort']
+JRMPA_RMI_OBJECT=//server/mbean[@name='jboss:service=invoker,type=jrmpha']/attribute[@name='RMIObjectPort']
+CLUSTER_UDP_MCAST=//server/mbean[@name='jboss:service=${jboss.partition.name:DefaultPartition}']/attribute[@name='PartitionConfig']/Config/UDP
+CLUSTER_UDP_MCAST_ATTRIBUTE=mcast_port
+Web_Services=//server/mbean[@name='jboss:service=WebService']/attribute[@name='Port']
+Hypersonic=//server/mbean[@name='jboss:service=Hypersonic']/attribute[@name='Port']
+JRMP_Invoker=//server/mbean[@name='jboss:service=invoker,type=jrmp']/attribute[@name='RMIObjectPort']
+Pooled_Invoker=//server/mbean[@name='jboss:service=invoker,type=pooled']/attribute[@name='ServerBindPort']
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.42.default.ports.properties
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.42.default.ports.properties
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/properties/jboss.42.default.ports.properties 2007-07-19
00:48:10 UTC (rev 2513)
@@ -0,0 +1,20 @@
+# As much as possible, try to create file patterns that match
+# as few files as possible. Each matching file *WILL* be scanned
+# and cached, regardless of if there's a match.
+
+JNDI=//server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']
+JNDI_FILE=**/jboss-service.xml
+JBoss_Web=//Server/Service[@name='jboss.web']/Connector[count((a)sslProtocol) = 0
and (count(@protocol) = 0 or @protocol = 'HTTP/1.1')]
+JBoss_Web_ATTRIBUTE=port
+JBoss_Web_FILE=**/*server.xml
+JNDI_RMI=//server/mbean[@name='jboss:service=Naming']/attribute[@name='RmiPort']
+JNDI_RMI_FILE=**/jboss-service.xml
+Web_Services=//server/mbean[@name='jboss:service=WebService']/attribute[@name='Port']
+JRMP_Invoker=//server/mbean[@name='jboss:service=invoker,type=jrmp']/attribute[@name='RMIObjectPort']
+Pooled_Invoker=//server/mbean[@name='jboss:service=invoker,type=pooled']/attribute[@name='ServerBindPort']
+#HA_JNDI_STUB=//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='Port']
+#HA_JNDI_RMI=//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='RmiPort']
+#JRMPA_RMI_OBJECT=//server/mbean[@name='jboss:service=invoker,type=jrmpha']/attribute[@name='RMIObjectPort']
+#CLUSTER_UDP_MCAST=//server/mbean[@name='jboss:service=${jboss.partition.name:DefaultPartition}']/attribute[@name='PartitionConfig']/Config/UDP
+#CLUSTER_UDP_MCAST_ATTRIBUTE=mcast_port
+#Hypersonic=//server/mbean[@name='jboss:service=Hypersonic']/attribute[@name='Port']