Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 274980 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java (+14 lines)
Lines 24-27 Link Here
24
	public Attribute[] getElements() {
24
	public Attribute[] getElements() {
25
		return elements;
25
		return elements;
26
	}
26
	}
27
	
28
	public ModelObject[] getChildren() {
29
		return elements;
30
	}
31
32
	public void addChild(ModelObject o) {
33
		if (o instanceof Attribute) {
34
			// XXX very ineffective
35
			Attribute[] tmp = new Attribute[elements.length + 1];
36
			System.arraycopy(elements, 0, tmp, 0, elements.length);
37
			tmp[tmp.length - 1] = (Attribute) o;
38
			elements = tmp;
39
		}
40
	}
27
}
41
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java (+9 lines)
Lines 17-20 Link Here
17
	public void setModel(RegistryModel model) {
17
	public void setModel(RegistryModel model) {
18
		this.model = model;
18
		this.model = model;
19
	}
19
	}
20
	
21
22
	public void addChild(ModelObject obj) {
23
		// empty
24
	}
25
26
	public ModelObject[] getChildren() {
27
		return null;
28
	}
20
}
29
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java (-1 / +1 lines)
Lines 293-299 Link Here
293
	 *  
293
	 *  
294
	 * @param objects
294
	 * @param objects
295
	 */
295
	 */
296
	protected void fireModelChangeEvent(ModelChangeDelta[] delta) {
296
	synchronized protected void fireModelChangeEvent(ModelChangeDelta[] delta) {
297
		for (Iterator i = listeners.iterator(); i.hasNext();) {
297
		for (Iterator i = listeners.iterator(); i.hasNext();) {
298
			ModelChangeListener listener = (ModelChangeListener) i.next();
298
			ModelChangeListener listener = (ModelChangeListener) i.next();
299
			listener.modelChanged(delta);
299
			listener.modelChanged(delta);
(-)src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java (+14 lines)
Lines 143-146 Link Here
143
		}
143
		}
144
		return 0;
144
		return 0;
145
	}
145
	}
146
147
	public void addChild(ModelObject obj) {
148
		if (obj instanceof Property) {
149
			// XXX very ineffective
150
			Property[] tmp = new Property[properties.length + 1];
151
			System.arraycopy(properties, 0, tmp, 0, properties.length);
152
			tmp[tmp.length - 1] = (Property) obj;
153
			properties = tmp;
154
		}
155
	}
156
157
	public ModelObject[] getChildren() {
158
		return properties;
159
	}
146
}
160
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java (+3 lines)
Lines 20-25 Link Here
20
 */
20
 */
21
public class RegistryModelFactory {
21
public class RegistryModelFactory {
22
22
23
	public static final String LOCAL = "local"; //$NON-NLS-1$
24
	public static final String REMOTE = "remote"; //$NON-NLS-1$
25
23
	/**
26
	/**
24
	 * 
27
	 * 
25
	 * @param uri
28
	 * @param uri
(-)src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java (-1 / +22 lines)
Lines 13-19 Link Here
13
/**
13
/**
14
 * Delta model objects are of type IBundle, IService, IExtension, IExtensionPoint
14
 * Delta model objects are of type IBundle, IService, IExtension, IExtensionPoint
15
 */
15
 */
16
public class ModelChangeDelta {
16
public class ModelChangeDelta extends ModelObject {
17
17
18
	public static final int ADDED = 0;
18
	public static final int ADDED = 0;
19
	public static final int UPDATED = 1;
19
	public static final int UPDATED = 1;
Lines 25-33 Link Here
25
	public static final int RESOLVED = 7;
25
	public static final int RESOLVED = 7;
26
	public static final int UNRESOLVED = 8;
26
	public static final int UNRESOLVED = 8;
27
27
28
	// TODO SWITCH from HEAVY ModelChangeDelta carrying whole object, to LIGHT delta - name, type (Bundle/Service/Ext/ExtPt), id
28
	private ModelObject fObject;
29
	private ModelObject fObject;
29
	private int fFlag;
30
	private int fFlag;
30
31
32
	public ModelChangeDelta() {
33
		// empty
34
	}
35
31
	public ModelChangeDelta(ModelObject object, int flag) {
36
	public ModelChangeDelta(ModelObject object, int flag) {
32
		fObject = object;
37
		fObject = object;
33
		fFlag = flag;
38
		fFlag = flag;
Lines 40-43 Link Here
40
	public int getFlag() {
45
	public int getFlag() {
41
		return fFlag;
46
		return fFlag;
42
	}
47
	}
48
49
	public void addChild(ModelObject o) {
50
		setModelObject(o);
51
	}
52
53
	public ModelObject[] getChildren() {
54
		return new ModelObject[] {fObject};
55
	}
56
57
	public void setModelObject(ModelObject fObject) {
58
		this.fObject = fObject;
59
	}
60
61
	public void setFlag(int flag) {
62
		this.fFlag = flag;
63
	}
43
}
64
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java (-1 / +1 lines)
Lines 16-22 Link Here
16
16
17
public interface RegistryBackend {
17
public interface RegistryBackend {
18
18
19
	public void connect(IProgressMonitor monitor);
19
	public boolean connect(IProgressMonitor monitor);
20
20
21
	public void disconnect();
21
	public void disconnect();
22
22
(-)src/org/eclipse/pde/internal/runtime/registry/model/Extension.java (+14 lines)
Lines 119-122 Link Here
119
			return null;
119
			return null;
120
		return model.getBundle(contributor);
120
		return model.getBundle(contributor);
121
	}
121
	}
122
	
123
	public void addChild(ModelObject o) {
124
		if (o instanceof ConfigurationElement) {
125
			// XXX very ineffective
126
			ConfigurationElement[] tmp = new ConfigurationElement[configurationElements.length + 1];
127
			System.arraycopy(configurationElements, 0, tmp, 0, configurationElements.length);
128
			tmp[tmp.length - 1] = (ConfigurationElement) o;
129
			configurationElements = tmp;
130
		}
131
	}
132
133
	public ModelObject[] getChildren() {
134
		return configurationElements;
135
	}
122
}
136
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java (-2 / +7 lines)
Lines 32-44 Link Here
32
	/* (non-Javadoc)
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#connect()
33
	 * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#connect()
34
	 */
34
	 */
35
	public void connect(IProgressMonitor monitor) {
35
	public boolean connect(IProgressMonitor monitor) {
36
		if (monitor.isCanceled())
36
		if (monitor.isCanceled())
37
			return;
37
			return false;
38
38
39
		PDERuntimePlugin.getDefault().getBundleContext().addBundleListener(this);
39
		PDERuntimePlugin.getDefault().getBundleContext().addBundleListener(this);
40
		Platform.getExtensionRegistry().addListener(this);
40
		Platform.getExtensionRegistry().addListener(this);
41
		PDERuntimePlugin.getDefault().getBundleContext().addServiceListener(this);
41
		PDERuntimePlugin.getDefault().getBundleContext().addServiceListener(this);
42
43
		return true;
42
	}
44
	}
43
45
44
	/* (non-Javadoc)
46
	/* (non-Javadoc)
Lines 299-304 Link Here
299
			return null;
301
			return null;
300
		}
302
		}
301
303
304
		if (bundleEntry == null)
305
			return null;
306
302
		try {
307
		try {
303
			bundleEntry = FileLocator.resolve(bundleEntry);
308
			bundleEntry = FileLocator.resolve(bundleEntry);
304
		} catch (IOException e) { // do nothing
309
		} catch (IOException e) { // do nothing
(-)src/org/eclipse/pde/internal/runtime/registry/model/Property.java (+4 lines)
Lines 131-134 Link Here
131
		return name0.compareTo(name1);
131
		return name0.compareTo(name1);
132
	}
132
	}
133
133
134
	public String toString() {
135
		return "Property(\"" + name + "\", \"" + value + "\")";
136
	}
137
134
}
138
}
(-).settings/org.eclipse.jdt.core.prefs (-7 / +7 lines)
Lines 1-4 Link Here
1
#Mon Oct 13 14:57:59 CDT 2008
1
#Thu May 21 20:21:01 CEST 2009
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
3
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
4
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
4
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
Lines 8-24 Link Here
8
org.eclipse.jdt.core.circularClasspath=error
8
org.eclipse.jdt.core.circularClasspath=error
9
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
9
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
10
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
10
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
11
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
11
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
12
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
12
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
13
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
13
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
14
org.eclipse.jdt.core.compiler.compliance=1.4
14
org.eclipse.jdt.core.compiler.compliance=1.5
15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
16
org.eclipse.jdt.core.compiler.debug.localVariable=generate
16
org.eclipse.jdt.core.compiler.debug.localVariable=generate
17
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
17
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
18
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
18
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
19
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
19
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
20
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
20
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
22
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
22
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
23
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
23
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
24
org.eclipse.jdt.core.compiler.problem.deprecation=warning
24
org.eclipse.jdt.core.compiler.problem.deprecation=warning
Lines 26-32 Link Here
26
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
26
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
27
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
27
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
28
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
28
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
29
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
29
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
30
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
30
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
31
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
31
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
32
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
32
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
Lines 91-97 Link Here
91
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
91
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
92
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
92
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
93
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
93
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
94
org.eclipse.jdt.core.compiler.source=1.3
94
org.eclipse.jdt.core.compiler.source=1.5
95
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
95
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
96
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
96
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
97
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
97
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 18-26 Link Here
18
Export-Package: org.eclipse.pde.internal.runtime;x-internal:=true,
18
Export-Package: org.eclipse.pde.internal.runtime;x-internal:=true,
19
 org.eclipse.pde.internal.runtime.registry;x-internal:=true,
19
 org.eclipse.pde.internal.runtime.registry;x-internal:=true,
20
 org.eclipse.pde.internal.runtime.registry.model;x-internal:=true,
20
 org.eclipse.pde.internal.runtime.registry.model;x-internal:=true,
21
 org.eclipse.pde.internal.runtime.registry.remote.jmx;x-internal:=true,
21
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.spy;x-internal:=true,
22
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
23
 org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true,
23
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
24
 org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true,
24
 org.eclipse.pde.internal.runtime.spy.sections;x-internal:=true
25
 org.eclipse.pde.internal.runtime.spy.sections;x-internal:=true
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
26
Bundle-RequiredExecutionEnvironment: J2SE-1.5
26
Bundle-ActivationPolicy: lazy
27
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java (+21 lines)
Lines 11-18 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.runtime.registry;
12
package org.eclipse.pde.internal.runtime.registry;
13
13
14
import java.io.IOException;
14
import java.util.*;
15
import java.util.*;
15
import java.util.List;
16
import java.util.List;
17
import javax.management.JMException;
18
import javax.management.ObjectName;
16
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.action.*;
Lines 22-27 Link Here
22
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.pde.internal.runtime.*;
26
import org.eclipse.pde.internal.runtime.*;
24
import org.eclipse.pde.internal.runtime.registry.model.*;
27
import org.eclipse.pde.internal.runtime.registry.model.*;
28
import org.eclipse.pde.internal.runtime.registry.remote.jmx.JmxAgent;
29
import org.eclipse.pde.internal.runtime.registry.remote.jmx.JmxModel;
25
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.custom.BusyIndicator;
31
import org.eclipse.swt.custom.BusyIndicator;
27
import org.eclipse.swt.dnd.*;
32
import org.eclipse.swt.dnd.*;
Lines 158-163 Link Here
158
163
159
	private void initializeModel() {
164
	private void initializeModel() {
160
		model = RegistryModelFactory.getRegistryModel("local"); //$NON-NLS-1$
165
		model = RegistryModelFactory.getRegistryModel("local"); //$NON-NLS-1$
166
161
		fTreeViewer.setInput(model);
167
		fTreeViewer.setInput(model);
162
		listener = new RegistryBrowserModelChangeListener(RegistryBrowser.this);
168
		listener = new RegistryBrowserModelChangeListener(RegistryBrowser.this);
163
		model.addModelChangeListener(listener);
169
		model.addModelChangeListener(listener);
Lines 170-175 Link Here
170
			}
176
			}
171
		};
177
		};
172
		initializeModelJob.schedule();
178
		initializeModelJob.schedule();
179
		initializeJMXServer();
180
	}
181
182
	public void initializeJMXServer() {
183
		JmxAgent agent = new JmxAgent("localhost", 9999); //$NON-NLS-1$
184
		JmxModel jmxModel = new JmxModel(model);
185
		try {
186
			ObjectName jmxModelName = new ObjectName(agent.getDefaultDomain() + ":type=Bundles"); //$NON-NLS-1$
187
			agent.registryMBean(jmxModel, jmxModelName);
188
			agent.startConnectionServer();
189
		} catch (IOException e) {
190
			PDERuntimePlugin.log(e);
191
		} catch (JMException e) {
192
			PDERuntimePlugin.log(e);
193
		}
173
	}
194
	}
174
195
175
	public void init(IViewSite site, IMemento memento) throws PartInitException {
196
	public void init(IViewSite site, IMemento memento) throws PartInitException {
(-)src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxClient.java (+100 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.remote.jmx;
2
3
import java.io.IOException;
4
import java.util.Iterator;
5
import java.util.Set;
6
import javax.management.*;
7
import javax.management.remote.*;
8
9
public class JmxClient {
10
11
	protected JMXConnector jmxConnector = null;
12
	protected MBeanServerConnection mbServerConnection = null;
13
14
	public JmxClient() {
15
		this.createJMXConnector("localhost", 9999);
16
		try {
17
			this.setMbServerConnection(this.getJmxConnector().getMBeanServerConnection());
18
		} catch (IOException e) {
19
			// TODO Auto-generated catch block
20
			e.printStackTrace();
21
		}
22
	}
23
24
	public void startTestModelInit() {
25
		String domains[] = null;
26
		try {
27
			domains = this.getMbServerConnection().getDomains();
28
		} catch (IOException e) {
29
			// TODO Auto-generated catch block
30
			e.printStackTrace();
31
		}
32
		for (int i = 0; i < domains.length; i++) {
33
			System.out.println("\tDomain[" + i + "] = " + domains[i]);
34
		}
35
36
		Set<ObjectName> names = null;
37
		try {
38
			names = this.getMbServerConnection().queryNames(null, null);
39
		} catch (IOException e) {
40
			// TODO Auto-generated catch block
41
			e.printStackTrace();
42
		}
43
		for (Iterator<ObjectName> i = names.iterator(); i.hasNext();) {
44
			ObjectName objName = i.next();
45
			System.out.println("\tObjectName = " + objName);
46
			if (objName.getKeyProperty("type").equals("Bundles")) {
47
				this.getAttributes(objName, this);
48
			}
49
		}
50
	}
51
52
	private void getAttributes(ObjectName obj, JmxClient client) {
53
		try {
54
			/*TestClass tc = TestSerialize.deserialize(
55
					(String)client.getMbServerConnection().invoke(obj,
56
					"returnTest", null, null));
57
			System.out.println(tc.getId());*/
58
			System.out.println(client.getMbServerConnection().invoke(obj, "allBundles", null, null));
59
			System.out.println();
60
			System.out.println(client.getMbServerConnection().invoke(obj, "allServices", null, null));
61
			System.out.println();
62
			System.out.println(client.getMbServerConnection().invoke(obj, "allExtensionPoints", null, null));
63
		} catch (IOException e) {
64
			// TODO Auto-generated catch block
65
			e.printStackTrace();
66
		} catch (InstanceNotFoundException e) {
67
			// TODO Auto-generated catch block
68
			e.printStackTrace();
69
		} catch (MBeanException e) {
70
			// TODO Auto-generated catch block
71
			e.printStackTrace();
72
		} catch (ReflectionException e) {
73
			// TODO Auto-generated catch block
74
			e.printStackTrace();
75
		}
76
	}
77
78
	public MBeanServerConnection getMbServerConnection() {
79
		return mbServerConnection;
80
	}
81
82
	public void setMbServerConnection(MBeanServerConnection mbServerConnection) {
83
		this.mbServerConnection = mbServerConnection;
84
	}
85
86
	protected void createJMXConnector(String host, int port) {
87
		try {
88
			JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server");
89
			jmxConnector = JMXConnectorFactory.connect(url, null);
90
		} catch (IOException e) {
91
			// TODO Auto-generated catch block
92
			e.printStackTrace();
93
		}
94
	}
95
96
	public JMXConnector getJmxConnector() {
97
		return jmxConnector;
98
	}
99
100
}
(-)src/org/eclipse/pde/internal/runtime/registry/model/ModelSerializer.java (+356 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.model;
2
3
import java.util.*;
4
import org.xml.sax.Attributes;
5
import org.xml.sax.SAXException;
6
import org.xml.sax.helpers.DefaultHandler;
7
8
public class ModelSerializer {
9
10
	private static final String BUNDLE = "bundle"; //$NON-NLS-1$
11
	private static final String USING_BUNDLES = "usingBundles"; //$NON-NLS-1$
12
	private static final String CLASSES = "classes"; //$NON-NLS-1$
13
	private static final String EXTENSION_POINT_UNIQUE_IDENTIFIER = "extensionPointUniqueIdentifier"; //$NON-NLS-1$
14
	private static final String CONTRIBUTOR = "contributor"; //$NON-NLS-1$
15
	private static final String LABEL = "label"; //$NON-NLS-1$
16
	private static final String UNIQUE_IDENTIFIER = "uniqueIdentifier"; //$NON-NLS-1$
17
	private static final String NAMESPACE_IDENTIFIER = "namespaceIdentifier"; //$NON-NLS-1$
18
	private static final String IS_EXPORTED = "isExported"; //$NON-NLS-1$
19
	private static final String LIBRARY = "library"; //$NON-NLS-1$
20
	private static final String ID = "id"; //$NON-NLS-1$
21
	private static final String STATE = "state"; //$NON-NLS-1$
22
	private static final String VERSION = "version"; //$NON-NLS-1$
23
	private static final String IS_ENABLED = "isEnabled"; //$NON-NLS-1$
24
	private static final String LOCATION = "location"; //$NON-NLS-1$
25
	private static final String SYMBOLIC_NAME = "symbolicName"; //$NON-NLS-1$
26
	private static final String VALUE = "value"; //$NON-NLS-1$
27
	private static final String NAME = "name"; //$NON-NLS-1$
28
	private static final String FLAG = "flag"; //$NON-NLS-1$
29
30
	public static abstract class XMLHandler extends DefaultHandler {
31
32
		private Stack stack = new Stack();
33
34
		public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
35
			if (qName.equals("start")) //$NON-NLS-1$
36
				return;
37
38
			ModelObject o = create(qName);
39
			if (o == null)
40
				return;
41
42
			for (int i = 0; i < attributes.getLength(); i++) {
43
				set(o, attributes.getQName(i), attributes.getValue(i));
44
			}
45
46
			if (!(o instanceof ModelChangeDelta)) {
47
				((ModelObject) stack.peek()).addChild(o);
48
			}
49
50
			//System.out.println("push " + o); //XXX remove syso
51
			stack.push(o);
52
53
		}
54
55
		public void endElement(String uri, String localName, String qName) throws SAXException {
56
			if (qName.equals("start"))
57
				return;
58
59
			//System.out.print("pop "); //XXX remove syso
60
			ModelObject o = (ModelObject) stack.pop();
61
			//System.out.println(o); //XXX remove syso
62
63
			if (o instanceof ModelChangeDelta) {
64
				handleDelta((ModelChangeDelta) o);
65
			}
66
		}
67
68
		public abstract void handleDelta(ModelChangeDelta delta);
69
70
	}
71
72
	protected static void set(ModelObject o, String name, String value) {
73
		if (o instanceof Attribute) {
74
			Attribute attribute = (Attribute) o;
75
			if (NAME.equals(name)) {
76
				attribute.setName(value);
77
			} else if (VALUE.equals(name)) {
78
				attribute.setValue(value);
79
			}
80
81
		} else if (o instanceof Bundle) {
82
			Bundle bundle = (Bundle) o;
83
84
			if (SYMBOLIC_NAME.equals(name)) {
85
				bundle.setSymbolicName(value);
86
			} else if (LOCATION.equals(name)) {
87
				bundle.setLocation(value);
88
			} else if (IS_ENABLED.equals(name)) {
89
				bundle.setEnabled(Boolean.valueOf(value).booleanValue());
90
			} else if (VERSION.equals(name)) {
91
				bundle.setVersion(value);
92
			} else if (STATE.equals(name)) {
93
				bundle.setState(Integer.parseInt(value));
94
			} else if (ID.equals(name)) {
95
				bundle.setId(Long.parseLong(value));
96
			}
97
98
		} else if (o instanceof BundleLibrary) {
99
			BundleLibrary library = (BundleLibrary) o;
100
			if (LIBRARY.equals(name)) {
101
				library.setLibrary(value);
102
			}
103
104
		} else if (o instanceof BundlePrerequisite) {
105
			BundlePrerequisite prereq = (BundlePrerequisite) o;
106
			if (NAME.equals(name)) {
107
				prereq.setName(value);
108
			} else if (VERSION.equals(name)) {
109
				prereq.setVersion(value);
110
			} else if (IS_EXPORTED.equals(name)) {
111
				prereq.setExported(Boolean.valueOf(value).booleanValue());
112
			}
113
114
		} else if (o instanceof Extension) {
115
			Extension ext = (Extension) o;
116
			if (NAMESPACE_IDENTIFIER.equals(name)) {
117
				ext.setNamespaceIdentifier(value);
118
			} else if (LABEL.equals(name)) {
119
				ext.setLabel(value);
120
			} else if (EXTENSION_POINT_UNIQUE_IDENTIFIER.equals(name)) {
121
				ext.setExtensionPointUniqueIdentifier(value);
122
			} else if (CONTRIBUTOR.equals(name)) {
123
				ext.setContributor(Long.valueOf(value));
124
			}
125
126
		} else if (o instanceof ExtensionPoint) {
127
			ExtensionPoint extPt = (ExtensionPoint) o;
128
			if (LABEL.equals(name)) {
129
				extPt.setLabel(value);
130
			} else if (UNIQUE_IDENTIFIER.equals(name)) {
131
				extPt.setUniqueIdentifier(value);
132
			} else if (NAMESPACE_IDENTIFIER.equals(name)) {
133
				extPt.setNamespaceIdentifier(value);
134
			} else if (CONTRIBUTOR.equals(name)) {
135
				extPt.setContributor(Long.valueOf(value));
136
			}
137
138
		} else if (o instanceof ServiceRegistration) {
139
			ServiceRegistration service = (ServiceRegistration) o;
140
			if (ID.equals(name)) {
141
				service.setId(Long.parseLong(value));
142
			} else if (BUNDLE.equals(name)) {
143
				service.setBundle(value);
144
			} else if (USING_BUNDLES.equals(name)) {
145
				StringTokenizer st = new StringTokenizer(value, ",");
146
				List l = new ArrayList();
147
				while (st.hasMoreTokens()) {
148
					l.add(Long.valueOf(st.nextToken()));
149
				}
150
				long[] ids = new long[l.size()];
151
				for (int i = 0; i < l.size(); i++) {
152
					ids[i] = ((Long) l.get(i)).longValue();
153
				}
154
				service.setUsingBundles(ids);
155
			} else if (CLASSES.equals(name)) {
156
				StringTokenizer st = new StringTokenizer(value, ",");
157
				List l = new ArrayList();
158
				while (st.hasMoreTokens()) {
159
					l.add(st.nextToken());
160
				}
161
162
				ServiceName sn = new ServiceName((String[]) l.toArray(new String[l.size()]));
163
				service.setName(sn);
164
			}
165
		} else if (o instanceof Property) {
166
			Property property = (Property) o;
167
			if (NAME.equals(name)) {
168
				property.setName(value);
169
			} else if (VALUE.equals(name)) {
170
				property.setValue(value);
171
			}
172
173
		} else if (o instanceof ModelChangeDelta) {
174
			ModelChangeDelta delta = (ModelChangeDelta) o;
175
176
			if (FLAG.equals(name)) {
177
				delta.setFlag(Integer.parseInt(value));
178
			}
179
		}
180
	}
181
182
	protected static void addAttribute(StringBuffer sb, String name, String value) {
183
		if (value == null)
184
			return;
185
186
		sb.append(" ").append(name).append("=\"").append(getWritableString(value)).append("\"");
187
	}
188
189
	protected static void addAttributes(StringBuffer sb, ModelObject o) {
190
191
		if (o instanceof Attribute) {
192
			Attribute attribute = (Attribute) o;
193
			addAttribute(sb, NAME, attribute.getName());
194
			addAttribute(sb, VALUE, attribute.getValue());
195
196
		} else if (o instanceof Bundle) {
197
			Bundle bundle = (Bundle) o;
198
199
			addAttribute(sb, SYMBOLIC_NAME, bundle.getSymbolicName());
200
			addAttribute(sb, LOCATION, bundle.getLocation());
201
			addAttribute(sb, IS_ENABLED, Boolean.toString(bundle.isEnabled()));
202
			addAttribute(sb, VERSION, bundle.getVersion());
203
			addAttribute(sb, STATE, Integer.toString(bundle.getState()));
204
			addAttribute(sb, ID, Long.toString(bundle.getId()));
205
206
		} else if (o instanceof BundleLibrary) {
207
			BundleLibrary library = (BundleLibrary) o;
208
			addAttribute(sb, LIBRARY, library.getLibrary());
209
210
		} else if (o instanceof BundlePrerequisite) {
211
			BundlePrerequisite prereq = (BundlePrerequisite) o;
212
			addAttribute(sb, NAME, prereq.getName());
213
			addAttribute(sb, VERSION, prereq.getVersion());
214
			addAttribute(sb, IS_EXPORTED, Boolean.toString(prereq.isExported()));
215
216
		} else if (o instanceof Extension) {
217
			Extension ext = (Extension) o;
218
			addAttribute(sb, NAMESPACE_IDENTIFIER, ext.getNamespaceIdentifier());
219
			addAttribute(sb, LABEL, ext.getLabel());
220
			addAttribute(sb, EXTENSION_POINT_UNIQUE_IDENTIFIER, ext.getExtensionPointUniqueIdentifier());
221
			Long id = ext.getContributorId();
222
			if (id != null)
223
				addAttribute(sb, CONTRIBUTOR, id.toString());
224
225
		} else if (o instanceof ExtensionPoint) {
226
			ExtensionPoint extPt = (ExtensionPoint) o;
227
			addAttribute(sb, LABEL, extPt.getLabel());
228
			addAttribute(sb, UNIQUE_IDENTIFIER, extPt.getUniqueIdentifier());
229
			addAttribute(sb, NAMESPACE_IDENTIFIER, extPt.getNamespaceIdentifier());
230
			Long id = extPt.getContributorId();
231
			if (id != null)
232
				addAttribute(sb, CONTRIBUTOR, id.toString());
233
234
		} else if (o instanceof ServiceRegistration) {
235
			ServiceRegistration service = (ServiceRegistration) o;
236
			addAttribute(sb, ID, Long.toString(service.getId()));
237
			addAttribute(sb, BUNDLE, service.getBundle());
238
			addAttribute(sb, USING_BUNDLES, arrayToString(service.getUsingBundleIds()));
239
			addAttribute(sb, CLASSES, arrayToString(service.getName().getClasses()));
240
241
		} else if (o instanceof Property) {
242
			Property property = (Property) o;
243
			addAttribute(sb, NAME, property.getName());
244
			addAttribute(sb, VALUE, property.getValue());
245
246
		} else if (o instanceof ModelChangeDelta) {
247
			ModelChangeDelta delta = (ModelChangeDelta) o;
248
			addAttribute(sb, FLAG, Integer.toString(delta.getFlag()));
249
		}
250
	}
251
252
	private static String arrayToString(Object[] array) {
253
		StringBuffer sb = new StringBuffer();
254
		for (int i = 0; i < array.length; i++) {
255
			if (i > 0)
256
				sb.append(',');
257
			sb.append(array[i]);
258
		}
259
260
		return sb.toString();
261
	}
262
263
	private static String arrayToString(long[] array) {
264
		StringBuffer sb = new StringBuffer();
265
		for (int i = 0; i < array.length; i++) {
266
			if (i > 0)
267
				sb.append(',');
268
			sb.append(array[i]);
269
		}
270
271
		return sb.toString();
272
	}
273
274
	private static ModelObject create(String name) {
275
		if (Attribute.class.getName().equals(name)) {
276
			return new Attribute();
277
		} else if (Bundle.class.getName().equals(name)) {
278
			return new Bundle();
279
		} else if (BundleLibrary.class.getName().equals(name)) {
280
			return new BundleLibrary();
281
		} else if (BundlePrerequisite.class.getName().equals(name)) {
282
			return new BundlePrerequisite();
283
		} else if (ConfigurationElement.class.getName().equals(name)) {
284
			return new ConfigurationElement();
285
		} else if (Extension.class.getName().equals(name)) {
286
			return new Extension();
287
		} else if (ExtensionPoint.class.getName().equals(name)) {
288
			return new ExtensionPoint();
289
		} else if (ModelChangeDelta.class.getName().equals(name)) {
290
			return new ModelChangeDelta();
291
		} else if (ServiceRegistration.class.getName().equals(name)) {
292
			return new ServiceRegistration();
293
		} else if (Property.class.getName().equals(name)) {
294
			return new Property();
295
		}
296
297
		return null;
298
	}
299
300
	public static String serialize(ModelObject o) {
301
		return serialize(o, new StringBuffer());
302
	}
303
304
	// XXX From PDEXMLHelper
305
	private static String getWritableString(String source) {
306
		if (source == null)
307
			return ""; //$NON-NLS-1$
308
		StringBuffer buf = new StringBuffer();
309
		for (int i = 0; i < source.length(); i++) {
310
			char c = source.charAt(i);
311
			switch (c) {
312
				case '&' :
313
					buf.append("&amp;"); //$NON-NLS-1$
314
					break;
315
				case '<' :
316
					buf.append("&lt;"); //$NON-NLS-1$
317
					break;
318
				case '>' :
319
					buf.append("&gt;"); //$NON-NLS-1$
320
					break;
321
				case '\'' :
322
					buf.append("&apos;"); //$NON-NLS-1$
323
					break;
324
				case '\"' :
325
					buf.append("&quot;"); //$NON-NLS-1$
326
					break;
327
				default :
328
					buf.append(c);
329
					break;
330
			}
331
		}
332
		return buf.toString();
333
	}
334
335
	private static String serialize(ModelObject o, StringBuffer sb) {
336
		String className = o.getClass().getName();
337
		sb.append('<').append(className);
338
339
		addAttributes(sb, o);
340
341
		sb.append('>').append('\n');
342
343
		ModelObject[] children = o.getChildren();
344
345
		if (children != null) {
346
			for (int i = 0; i < children.length; i++) {
347
				if (children[i] != null)
348
					serialize(children[i], sb);
349
			}
350
		}
351
352
		sb.append("</").append(className).append('>').append('\n'); //$NON-NLS-1$
353
354
		return sb.toString();
355
	}
356
}
(-)src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModel.java (+40 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.remote.jmx;
2
3
import org.eclipse.pde.internal.runtime.registry.model.*;
4
5
public class JmxModel implements JmxModelMBean {
6
7
	private RegistryModel model;
8
9
	public JmxModel(RegistryModel model) {
10
		super();
11
		this.model = model;
12
	}
13
14
	public String allBundles() {
15
		Bundle[] bundles = model.getBundles();
16
		String result = ""; //$NON-NLS-1$
17
		for (int i = 0; i < bundles.length; i++) {
18
			result += ModelSerializer.serialize(bundles[i]);
19
		}
20
		return result;
21
	}
22
23
	public String allServices() {
24
		ServiceRegistration[] services = model.getServices();
25
		String result = ""; //$NON-NLS-1$
26
		for (int i = 0; i < services.length; i++) {
27
			result += ModelSerializer.serialize(services[i]);
28
		}
29
		return result;
30
	}
31
32
	public String allExtensionPoints() {
33
		ExtensionPoint[] exPoints = model.getExtensionPoints();
34
		String result = ""; //$NON-NLS-1$
35
		for (int i = 0; i < exPoints.length; i++) {
36
			result += ModelSerializer.serialize(exPoints[i]);
37
		}
38
		return result;
39
	}
40
}
(-)src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxAgent.java (+165 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.remote.jmx;
2
3
import java.io.IOException;
4
import java.lang.management.ManagementFactory;
5
import java.rmi.RemoteException;
6
import java.rmi.registry.LocateRegistry;
7
import java.rmi.registry.Registry;
8
import java.util.Map;
9
import java.util.Map.Entry;
10
import javax.management.*;
11
import javax.management.remote.*;
12
13
public class JmxAgent {
14
	private MBeanServer server = null;
15
	private JMXConnectorServer connectionServer = null;
16
	Registry registry = null;
17
	private boolean isDebug = true;
18
19
	public JmxAgent(String host, int port) {
20
		createMBeanServer();
21
		createRMIRegistry(port);
22
		createJMXConnectionServer(host, port);
23
	}
24
25
	private void createMBeanServer() {
26
		print("CREATE the MBeanServer"); //$NON-NLS-1$
27
		server = ManagementFactory.getPlatformMBeanServer();
28
	}
29
30
	private void createJMXConnectionServer(String host, int port) {
31
		try {
32
			JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
33
			connectionServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
34
		} catch (IOException e) {
35
			// TODO Auto-generated catch block
36
			e.printStackTrace();
37
		}
38
	}
39
40
	private void createRMIRegistry(int port) {
41
		try {
42
			registry = LocateRegistry.createRegistry(port);
43
		} catch (RemoteException e) {
44
			// TODO Auto-generated catch block
45
			e.printStackTrace();
46
		}
47
	}
48
49
	public String getDefaultDomain() {
50
51
		return server.getDefaultDomain();
52
	}
53
54
	public void startConnectionServer() throws IOException {
55
		connectionServer.start();
56
		print("connected"); //$NON-NLS-1$ 
57
	}
58
59
	public void stopConnectionServer() throws IOException {
60
		connectionServer.stop();
61
		print("disconnected"); //$NON-NLS-1$ 
62
	}
63
64
	public void registryMBean(Object mBean, Map<String, String> params) throws JMException {
65
		String paramString = ":"; //$NON-NLS-1$ 
66
		int i = 1;
67
		for (Entry<String, String> element : params.entrySet()) {
68
			paramString += element.getKey() + "=" + element.getValue(); //$NON-NLS-1$ 
69
			i++;
70
			if (params.size() > i)
71
				paramString += ","; //$NON-NLS-1$ 
72
		}
73
		ObjectName on = new ObjectName(server.getDefaultDomain() + paramString);
74
		server.registerMBean(mBean, on);
75
		print("registered: " + on.toString()); //$NON-NLS-1$ 
76
	}
77
78
	public void registryMBean(Object mBean, String params) throws JMException {
79
		ObjectName on = new ObjectName(server.getDefaultDomain() + ":" + params); //$NON-NLS-1$ 
80
		server.registerMBean(mBean, on);
81
		print("registered: " + on.toString()); //$NON-NLS-1$ 
82
	}
83
84
	public void registryMBean(Object mBean, ObjectName on) throws JMException {
85
		server.registerMBean(mBean, on);
86
		print("registered: " + on.toString()); //$NON-NLS-1$ 
87
	}
88
89
	public void printMBeanInfo(ObjectName objectName, String className) {
90
		print("information about: " + objectName.toString()); //$NON-NLS-1$ 
91
		MBeanInfo info = null;
92
		try {
93
			info = server.getMBeanInfo(objectName);
94
		} catch (Exception e) {
95
			print("Could not get MBeanInfo object for " + className); //$NON-NLS-1$ 
96
			e.printStackTrace();
97
			return;
98
		}
99
		print("classname: " + info.getClassName()); //$NON-NLS-1$ 
100
		print("description: " + info.getDescription()); //$NON-NLS-1$ 
101
102
		print("attributes: "); //$NON-NLS-1$ 
103
		MBeanAttributeInfo[] attrInfo = info.getAttributes();
104
		if (attrInfo.length > 0) {
105
			for (int i = 0; i < attrInfo.length; i++) {
106
				print("\tname: " + attrInfo[i].getName()); //$NON-NLS-1$ 
107
				print("\tdescription: " + attrInfo[i].getDescription()); //$NON-NLS-1$ 
108
				print("\ttype: " + attrInfo[i].getType()); //$NON-NLS-1$ 
109
				print("\treadable: " + attrInfo[i].isReadable()); //$NON-NLS-1$ 
110
				print("\twritable: " + attrInfo[i].isWritable()); //$NON-NLS-1$ 
111
				print("\n"); //$NON-NLS-1$ 
112
			}
113
		} else {
114
			print("no attributes\n"); //$NON-NLS-1$ 
115
		}
116
117
		print("constructors: "); //$NON-NLS-1$ 
118
		MBeanConstructorInfo[] constructorInfo = info.getConstructors();
119
		if (constructorInfo.length > 0) {
120
			for (int i = 0; i < constructorInfo.length; i++) {
121
				print("\tname: " + constructorInfo[i].getName()); //$NON-NLS-1$ 
122
				print("\tdescription: " + constructorInfo[i].getDescription()); //$NON-NLS-1$ 
123
				print("\tparameter number: " + constructorInfo[i].getSignature().length); //$NON-NLS-1$ 
124
				print("\n"); //$NON-NLS-1$ 
125
			}
126
		} else {
127
			print("no constructors\n"); //$NON-NLS-1$ 
128
		}
129
130
		print("operations: "); //$NON-NLS-1$ 
131
		MBeanOperationInfo[] opInfo = info.getOperations();
132
		if (opInfo.length > 0) {
133
			for (int i = 0; i < opInfo.length; i++) {
134
				print("\tname: " + opInfo[i].getName()); //$NON-NLS-1$ 
135
				print("\tdescription: " + opInfo[i].getDescription()); //$NON-NLS-1$ 
136
				print("\tparameter number: " + opInfo[i].getSignature().length); //$NON-NLS-1$ 
137
				print("\n"); //$NON-NLS-1$ 
138
			}
139
		} else {
140
			print("no operations\n"); //$NON-NLS-1$ 
141
		}
142
143
		print("notifications: "); //$NON-NLS-1$ 
144
		MBeanNotificationInfo[] notifInfo = info.getNotifications();
145
		if (notifInfo.length > 0) {
146
			for (int i = 0; i < notifInfo.length; i++) {
147
				print("\tname: " + notifInfo[i].getName()); //$NON-NLS-1$ 
148
				print("\tdescription: " + notifInfo[i].getDescription()); //$NON-NLS-1$ 
149
				String notifTypes[] = notifInfo[i].getNotifTypes();
150
				for (int j = 0; j < notifTypes.length; j++) {
151
					print("\t\ttype:" + notifTypes[j]); //$NON-NLS-1$ 
152
				}
153
				print("\n"); //$NON-NLS-1$ 
154
			}
155
		} else {
156
			print("no notifications\n"); //$NON-NLS-1$ 
157
		}
158
	}
159
160
	private void print(String s) {
161
		if (isDebug) {
162
			System.out.println(s);
163
		}
164
	}
165
}
(-)src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModelMBean.java (+10 lines)
Added Link Here
1
package org.eclipse.pde.internal.runtime.registry.remote.jmx;
2
3
4
public interface JmxModelMBean {
5
	public String allBundles();
6
7
	public String allServices();
8
9
	public String allExtensionPoints();
10
}

Return to bug 274980