diff options
author | pdobrev | 2008-02-13 08:16:06 +0000 |
---|---|---|
committer | pdobrev | 2008-02-13 08:16:06 +0000 |
commit | c248e73d19e5f75d73903992aee4caedda0f1438 (patch) | |
tree | 059fd3eaacf5260a5a9010eb1f46eee8be3cbe5c /bundles/org.eclipse.equinox.wireadmin | |
parent | e858db978ae8a6238b7495fc470318978f2a1c51 (diff) | |
download | rt.equinox.bundles-c248e73d19e5f75d73903992aee4caedda0f1438.tar.gz rt.equinox.bundles-c248e73d19e5f75d73903992aee4caedda0f1438.tar.xz rt.equinox.bundles-c248e73d19e5f75d73903992aee4caedda0f1438.zip |
remove old content because of graduation of the new version
Diffstat (limited to 'bundles/org.eclipse.equinox.wireadmin')
20 files changed, 0 insertions, 2037 deletions
diff --git a/bundles/org.eclipse.equinox.wireadmin/.classpath b/bundles/org.eclipse.equinox.wireadmin/.classpath index 751c8f2e5..acad1c227 100644 --- a/bundles/org.eclipse.equinox.wireadmin/.classpath +++ b/bundles/org.eclipse.equinox.wireadmin/.classpath @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> diff --git a/bundles/org.eclipse.equinox.wireadmin/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.wireadmin/META-INF/MANIFEST.MF deleted file mode 100644 index ab535c006..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.equinox.wireadmin -Bundle-Name: %bundleName -Bundle-Vendor: %bundleVendor -Bundle-Copyright: %bundleCopyright -Bundle-Version: 1.0.0.qualifier -Bundle-Activator: org.eclipse.equinox.wireadmin.Activator -Bundle-Localization: plugin -Import-Package: org.eclipse.osgi.framework.eventmgr, - org.osgi.framework;version="1.1", - org.osgi.service.log;version="1.2", - org.osgi.service.prefs;version="1.0", - org.osgi.service.wireadmin;version="1.0", - org.osgi.util.tracker;version="1.2", - org.eclipse.osgi.util -Export-Package: org.eclipse.equinox.wireadmin;x-internal=true -Import-Service: org.osgi.service.log.LogService, org.osgi.service.prefs -Export-Service: org.osgi.service.wireadmin.WireAdmin diff --git a/bundles/org.eclipse.equinox.wireadmin/about.html b/bundles/org.eclipse.equinox.wireadmin/about.html deleted file mode 100644 index 3989f53a6..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>May 11, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.wireadmin/build.properties b/bundles/org.eclipse.equinox.wireadmin/build.properties deleted file mode 100644 index d855c169e..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/build.properties +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -# Copyright (c) 2005 IBM Corporation. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = META-INF/,\ - plugin*.properties,\ - about.html,\ - . -source.. = src/ -output.. = bin/ diff --git a/bundles/org.eclipse.equinox.wireadmin/plugin.properties b/bundles/org.eclipse.equinox.wireadmin/plugin.properties deleted file mode 100644 index 7eff0861a..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/plugin.properties +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################### -# Copyright (c) 2005 IBM Corporation. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bundleVendor = Eclipse.org -bundleName = Wire Admin Service -bundleCopyright = Copyright (c) IBM Corp. 2003, 2005 diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Activator.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Activator.java deleted file mode 100644 index 8513f27d4..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Activator.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.osgi.framework.*; -import org.osgi.service.prefs.PreferencesService; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class Activator implements BundleActivator, ServiceTrackerCustomizer { - - private String wireadminString = "org.osgi.service.wireadmin.WireAdmin"; //$NON-NLS-1$ - private WireAdmin wireadmin; - private ServiceRegistration wireadminReg; - private PreferencesService preferencesService; - private BundleContext context; - private ServiceTracker prefsTracker; - - /** - * @see BundleActivator#start(BundleContext) - */ - public void start(BundleContext context_) throws Exception { - - this.context = context_; - prefsTracker = new ServiceTracker(context, PreferencesService.class.getName(), this); - prefsTracker.open(); - } - - /** - * @see BundleActivator#stop(BundleContext) - */ - public void stop(BundleContext context_) throws Exception { - if(wireadminReg != null) - { - wireadminReg.unregister(); - wireadmin.destroy(); - } - - } - - public Object addingService(ServiceReference reference) { - prefsTracker.close(); - if (preferencesService == null) { - preferencesService = (PreferencesService) context.getService(reference); - registerWireAdminService(); - return preferencesService; - } - return null; //we don't want to track a service we are not using - } - - public void modifiedService(ServiceReference reference, Object service) { //do nothing - - } - - public void removedService(ServiceReference reference, Object service) { - if (service == preferencesService) { - preferencesService = null; - wireadminReg.unregister(); - } - context.ungetService(reference); - } - - public void registerWireAdminService() { - wireadmin = new WireAdmin(context); - wireadminReg = context.registerService(wireadminString, wireadmin, null); - wireadmin.setServiceReference(wireadminReg.getReference()); - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumerCustomizer.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumerCustomizer.java deleted file mode 100644 index 9a2ca949c..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumerCustomizer.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.wireadmin.Consumer; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ConsumerCustomizer implements ServiceTrackerCustomizer { - - protected Wire wire; - protected BundleContext context; - - public ConsumerCustomizer(BundleContext context, Wire wire) { - this.wire = wire; - this.context = context; - } - - /** - * @see ServiceTrackerCustomizer#addingService(ServiceReference) - */ - public Object addingService(ServiceReference reference) { - Consumer service = (Consumer) context.getService(reference); - synchronized (wire) { - wire.setConsumer(service, reference); - - return (service); - } - } - - /** - * @see ServiceTrackerCustomizer#modifiedService(ServiceReference, Object) - */ - public void modifiedService(ServiceReference reference, Object service) { - synchronized (wire) { - //our flavors and other properties may have changed - wire.setConsumerProperties(reference); - } - } - - /** - * @see ServiceTrackerCustomizer#removedService(ServiceReference, Object) - */ - public void removedService(ServiceReference reference, Object service) { - synchronized (wire) { - wire.removeConsumer(); - context.ungetService(reference); - } - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumersCustomizer.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumersCustomizer.java deleted file mode 100644 index 26a5f5871..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ConsumersCustomizer.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.osgi.framework.*; -import org.osgi.service.wireadmin.Consumer; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ConsumersCustomizer implements ServiceTrackerCustomizer { - - protected BundleContext context; - protected WireAdmin wireAdmin; - - public ConsumersCustomizer(BundleContext context, WireAdmin wireAdmin) { - this.context = context; - this.wireAdmin = wireAdmin; - } - - /** - * @see ServiceTrackerCustomizer#addingService(ServiceReference) - */ - public Object addingService(ServiceReference reference) { - Consumer service = (Consumer) context.getService(reference); - String pid = (String) reference.getProperty("service.pid"); //$NON-NLS-1$ - - try { - //if a wire contains this producer, the wire notify it - if (wireAdmin.getWires(wireAdmin.consumerFilter + pid + ")") == null) { //$NON-NLS-1$ - wireAdmin.notifyConsumer(service, pid); - } - } catch (InvalidSyntaxException ex) { - ex.printStackTrace(); - } - return (service); - } - - /** - * @see ServiceTrackerCustomizer#modifiedService(ServiceReference, Object) - */ - public void modifiedService(ServiceReference reference, Object service) { - //do nothing - } - - /** - * @see ServiceTrackerCustomizer#removedService(ServiceReference, Object) - */ - public void removedService(ServiceReference reference, Object service) { - - context.ungetService(reference); - } -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ExternalMessages.properties b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ExternalMessages.properties deleted file mode 100644 index 0143995d3..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ExternalMessages.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2002, 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -BACKING_STORE_READ_EXCEPTION=WireAdmin is unable to read its data from backing store {0} -WIREADMIN_UNREGISTERED_EXCEPTION=The WireAdmin Service has been unregistered {0} -WIREADMIN_EVENT_DISPATCH_ERROR=Error dispatching WireAdmin Events {0} -WIREADMIN_KEYS_CASE_INSENSITIVE_MATCH=Property keys can not be case insensitive matches diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogMessages.properties b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogMessages.properties deleted file mode 100644 index e29ba01e2..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogMessages.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2002, 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -Unknown_Log_level=Unknown Log Level -Info=Log Info -Warning=Log Warning -Error=Log Error diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTracker.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTracker.java deleted file mode 100644 index cd7f72524..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTracker.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 1998, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.io.PrintStream; -import java.text.DateFormat; -import java.util.Calendar; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; -import org.osgi.util.tracker.ServiceTracker; - -/** - * LogTracker class. This class encapsulates the LogService - * and handles all issues such as the service coming and going. - */ - -public class LogTracker extends ServiceTracker implements LogService { - /** LogService interface class name */ - protected final static String clazz = "org.osgi.service.log.LogService"; //$NON-NLS-1$ - - /** PrintStream to use if LogService is unavailable */ - protected PrintStream out; - - /** Calendar and DateFormat to user if LogService is unavailable */ - private static Calendar calendar; - private static DateFormat dateFormat; - private String timestamp; - - /** - * Create new LogTracker. - * - * @param context BundleContext of parent bundle. - * @param out Default PrintStream to use if LogService is unavailable. - */ - public LogTracker(BundleContext context, PrintStream out) { - super(context, clazz, null); - this.out = out; - calendar = Calendar.getInstance(); - dateFormat = DateFormat.getDateTimeInstance(); - open(); - } - - /* - * ---------------------------------------------------------------------- - * LogService Interface implementation - * ---------------------------------------------------------------------- - */ - - public void log(int level, String message) { - log(null, level, message, null); - } - - public void log(int level, String message, Throwable exception) { - log(null, level, message, exception); - } - - public void log(ServiceReference reference, int level, String message) { - log(reference, level, message, null); - } - - public synchronized void log(ServiceReference reference, int level, String message, Throwable exception) { - ServiceReference[] references = getServiceReferences(); - - if (references != null) { - int size = references.length; - - for (int i = 0; i < size; i++) { - LogService service = (LogService) getService(references[i]); - if (service != null) { - try { - service.log(reference, level, message, exception); - } catch (Exception e) { - //do nothing - } - } - } - - return; - } - - noLogService(level, message, exception, reference); - } - - /** - * The LogService is not available so we write the message to a PrintStream. - * - * @param level Logging level - * @param message Log message. - * @param throwable Log exception or null if none. - * @param reference ServiceReference associated with message or null if none. - */ - protected void noLogService(int level, String message, Throwable throwable, ServiceReference reference) { - if (out != null) { - synchronized (out) { - // Bug #113286. If no log service present and messages are being - // printed to stdout, prepend message with a timestamp. - timestamp = dateFormat.format(calendar.getTime()); - out.print(timestamp + " "); //$NON-NLS-1$ - - switch (level) { - case LOG_DEBUG : { - out.print("Debug: "); //$NON-NLS-1$ - - break; - } - case LOG_INFO : { - out.print(LogTrackerMsg.Info); - - break; - } - case LOG_WARNING : { - out.print(LogTrackerMsg.Warning); - - break; - } - case LOG_ERROR : { - out.print(LogTrackerMsg.Error); - - break; - } - default : { - out.print("["); //$NON-NLS-1$ - out.print(LogTrackerMsg.Unknown_Log_level); - out.print("]: "); //$NON-NLS-1$ - - break; - } - } - - out.println(message); - - if (reference != null) { - out.println(reference); - } - - if (throwable != null) { - throwable.printStackTrace(out); - } - } - } - } -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTrackerMsg.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTrackerMsg.java deleted file mode 100644 index 56f51a175..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/LogTrackerMsg.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.eclipse.osgi.util.NLS; - -public class LogTrackerMsg extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.equinox.wireadmin.LogMessages"; //$NON-NLS-1$ - - public static String Unknown_Log_level; - public static String Info; - public static String Warning; - public static String Error; - - static { - // initialize resource bundles - NLS.initializeMessages(BUNDLE_NAME, LogTrackerMsg.class); - } -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducerCustomizer.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducerCustomizer.java deleted file mode 100644 index ed6b3bfd5..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducerCustomizer.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.wireadmin.Producer; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ProducerCustomizer implements ServiceTrackerCustomizer { - - protected Wire wire; - protected BundleContext context; - - public ProducerCustomizer(BundleContext context, Wire wire) { - this.wire = wire; - this.context = context; - } - - /** - * @see ServiceTrackerCustomizer#addingService(ServiceReference) - */ - public Object addingService(ServiceReference reference) { - Object service = context.getService(reference); - wire.setProducer((Producer) service, reference); - return (service); - } - - /** - * @see ServiceTrackerCustomizer#modifiedService(ServiceReference, Object) - */ - public void modifiedService(ServiceReference reference, Object service) { - //the producer flavor filters may have changed - wire.setProducerProperties(reference); - } - - /** - * @see ServiceTrackerCustomizer#removedService(ServiceReference, Object) - */ - public void removedService(ServiceReference reference, Object service) { - wire.removeProducer(); - context.ungetService(reference); - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducersCustomizer.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducersCustomizer.java deleted file mode 100644 index 3b8af292d..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ProducersCustomizer.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.osgi.framework.*; -import org.osgi.service.wireadmin.Producer; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ProducersCustomizer implements ServiceTrackerCustomizer { - - protected BundleContext context; - protected WireAdmin wireAdmin; - - public ProducersCustomizer(BundleContext context, WireAdmin wireAdmin) { - this.context = context; - this.wireAdmin = wireAdmin; - } - - /** - * @see ServiceTrackerCustomizer#addingService(ServiceReference) - */ - public Object addingService(ServiceReference reference) { - Producer service = (Producer) context.getService(reference); - String pid = (String) reference.getProperty("service.pid"); //$NON-NLS-1$ - - try { - //if a wire contains this producer, the wire notifies it - if (wireAdmin.getWires(wireAdmin.producerFilter + pid + ")") == null) { //$NON-NLS-1$ - wireAdmin.notifyProducer(service, pid); - } - } catch (InvalidSyntaxException ex) { - ex.printStackTrace(); - } - - return (service); - } - - /** - * @see ServiceTrackerCustomizer#modifiedService(ServiceReference, Object) - */ - public void modifiedService(ServiceReference reference, Object service) { - //do nothing - } - - /** - * @see ServiceTrackerCustomizer#removedService(ServiceReference, Object) - */ - public void removedService(ServiceReference reference, Object service) { - - context.ungetService(reference); - } -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ReadOnlyDictionary.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ReadOnlyDictionary.java deleted file mode 100644 index f5331605d..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/ReadOnlyDictionary.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.util.*; - -public class ReadOnlyDictionary extends Hashtable { - - /** - * Serial Version UID - */ - private static final long serialVersionUID = 2878360633574220743L; - private Dictionary dictionary; - - public ReadOnlyDictionary(Dictionary dictionary) { - this.dictionary = dictionary; - } - - public Object put(Object key, Object value) { - return (null); - } - - public void clear() { - //??? Do I need to throw an exception - } - - public Enumeration elements() { - return dictionary.elements(); - } - - public boolean equals(Object object) { - //??? - What should we really do here - if (object instanceof ReadOnlyDictionary) { - return super.equals(object); - } - return dictionary.equals(object); - } - - public Object get(Object key) { - return dictionary.get(key); - } - - public int hashCode() { - //??? is this right - return dictionary.hashCode(); - } - - public boolean isEmpty() { - return dictionary.isEmpty(); - } - - public Enumeration keys() { - return dictionary.keys(); - } - - public Object remove(Object key) { - //??? - throw exception??? - return (null); - } - - public int size() { - return dictionary.size(); - } - - public String toString() { - return dictionary.toString(); - } -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Wire.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Wire.java deleted file mode 100644 index 7c0f47656..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/Wire.java +++ /dev/null @@ -1,490 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.util.*; -import org.osgi.framework.*; -import org.osgi.service.wireadmin.*; -import org.osgi.util.tracker.ServiceTracker; - -public class Wire implements org.osgi.service.wireadmin.Wire { - - protected boolean valid = false; - protected boolean connected = false; - - protected ServiceTracker consumerTracker; - protected ServiceTracker producerTracker; - - protected Producer producer = null; - protected Consumer consumer = null; - - protected Class[] flavors = null; - protected Class[] producerFlavors = null; - - protected Object lastValue; - protected long lastTime = -1; - - protected Dictionary properties; - protected WireAdmin wireadmin; - - private String pid; - private String producerPID; - private String consumerPID; - - private boolean producerFilterExists; - private Filter wireFilter; - - protected Wire(String pid, String producerPID, String consumerPID, Dictionary props, WireAdmin wireadmin) { - this.pid = pid; - this.producerPID = producerPID; - this.consumerPID = consumerPID; - - this.wireadmin = wireadmin; - setProperties(props); - - String consumerFilterString = "(&(objectClass=org.osgi.service.wireadmin.Consumer)(service.pid=" + consumerPID + "))";//$NON-NLS-1$ //$NON-NLS-2$ - String producerFilterString = "(&(objectClass=org.osgi.service.wireadmin.Producer)(service.pid=" + producerPID + "))";//$NON-NLS-1$ //$NON-NLS-2$ - Filter consumerFilter = null; - Filter producerFilter = null; - wireFilter = (Filter) properties.get(WireConstants.WIREADMIN_FILTER); - try { - consumerFilter = wireadmin.context.createFilter(consumerFilterString); - producerFilter = wireadmin.context.createFilter(producerFilterString); - } catch (InvalidSyntaxException ex) { - ex.printStackTrace();//FIXME - } - - ConsumerCustomizer consumerCustomizer = new ConsumerCustomizer(wireadmin.context, this); - ProducerCustomizer producerCustomizer = new ProducerCustomizer(wireadmin.context, this); - - consumerTracker = new ServiceTracker(wireadmin.context, consumerFilter, consumerCustomizer); - producerTracker = new ServiceTracker(wireadmin.context, producerFilter, producerCustomizer); - - valid = true; - } - - /** - * Return the state of this <tt>Wire</tt> object. - * - * <p>A connected <tt>Wire</tt> must always be disconnected before - * becoming invalid. - * - * @return <tt>false</tt> if this <tt>Wire</tt> is invalid because it - * has been deleted via {@link WireAdmin#deleteWire}; - * <tt>true</tt> otherwise. - */ - /** - * Return the state of this <tt>Wire</tt> object. - * - * <p>A connected <tt>Wire</tt> must always be disconnected before - * becoming invalid. - * - * @return <tt>false</tt> if this <tt>Wire</tt> is invalid because it - * has been deleted via {@link WireAdmin#deleteWire}; - * <tt>true</tt> otherwise. - */ - public boolean isValid() { - return (valid); - } - - /** - * Return the connection state of this <tt>Wire</tt> object. - * - * <p>A <tt>Wire</tt> is connected after the Wire Admin service receives - * notification that the <tt>Producer</tt> service and - * the <tt>Consumer</tt> service for this <tt>Wire</tt> object are both registered. - * This method will return <tt>true</tt> prior to notifying the <tt>Producer</tt> - * and <tt>Consumer</tt> services via calls - * to their respective <tt>consumersConnected</tt> and <tt>producersConnected</tt> - * methods. - * <p>A <tt>WireAdminEvent</tt> of type {@link WireAdminEvent#WIRE_CONNECTED} - * must be broadcast by the Wire Admin service when - * the <tt>Wire</tt> becomes connected. - * - * <p>A <tt>Wire</tt> object - * is disconnected when either the <tt>Consumer</tt> or <tt>Producer</tt> - * service is unregistered or the <tt>Wire</tt> object is deleted. - * <p>A <tt>WireAdminEvent</tt> of type {@link WireAdminEvent#WIRE_DISCONNECTED} - * must be broadcast by the Wire Admin service when - * the <tt>Wire</tt> becomes disconnected. - * - * @return <tt>true</tt> if both the <tt>Producer</tt> and <tt>Consumer</tt> - * for this <tt>Wire</tt> object are connected to the <tt>Wire</tt> object; - * <tt>false</tt> otherwise. - */ - - public boolean isConnected() { - return (connected); - } - - /** - * Return the list of data types understood by the - * <tt>Consumer</tt> service connected to this <tt>Wire</tt> object. Note that - * subclasses of the classes in this list are allowed as well. - * - * <p>The list is the value of the {@link Consumer#WIREADMIN_CONSUMER_FLAVORS} - * service property of the - * <tt>Consumer</tt> service object connected to this object. If no such - * property was registered, this method must return null. - * - * @return An array containing the list of classes understood by the - * <tt>Consumer</tt> service or <tt>null</tt> if the <tt>Consumer</tt> object is - * not currently a registered service, or the <tt>Wire</tt> has been disconnected, - * or the consumer did not register a {@link #WIREADMIN_CONSUMER_FLAVORS} property. - */ - public Class[] getFlavors() { - return (flavors); - } - - protected void setConsumerProperties(ServiceReference consumerReference) { - if (consumerReference != null) { - try { - flavors = (Class[]) consumerReference.getProperty(WireConstants.WIREADMIN_CONSUMER_FLAVORS); - } catch (ClassCastException ex) { - // log error??? - } - } - } - - /** - * Update the value. - * - * <p>This methods is called by the <tt>Producer</tt> service to - * notify the <tt>Consumer</tt> service connected to this <tt>Wire</tt> object - * of an updated value. - * <p>If the properties of this <tt>Wire</tt> object contain a - * {@link Constants#WIREADMIN_FILTER} property, - * then filtering is performed on this <tt>Wire</tt>. - * If the <tt>Producer</tt> service connected to this <tt>Wire</tt> - * object was registered with the service - * property {@link Constants#WIREADMIN_PRODUCER_FILTERS}, the - * <tt>Producer</tt> service will perform the filter the value according to the rules specified - * for the filter. Otherwise, this <tt>Wire</tt> object - * will filter the value according to the rules specified for the filter. - * <p>If no filtering is done, or the filter indicates the updated value should - * be delivered to the <tt>Consumer</tt> service, then - * this <tt>Wire</tt> object must call - * the {@link Consumer#updated} method with the updated value. - * If this <tt>Wire</tt> object is not connected, then the <tt>Consumer</tt> - * service must not be called. - * - * <p>A <tt>WireAdminEvent</tt> of type {@link WireAdminEvent#WIRE_TRACE} - * must be broadcast by the Wire Admin service after - * the <tt>Consumer</tt> service has been successfully called. - * - * @param value The updated value. The value should be an instance of - * one of the types returned by {@link #getFlavors}. - * @see Constants#WIREADMIN_FILTER - */ - //FIXME -- wire filter - public void update(Object value) { - wireadmin.checkAlive(); - synchronized (this) { - int length = flavors.length; - boolean correctFlavors = false; - for (int i = 0; i < length; i++) { - if (flavors[i].isInstance(value)) { - correctFlavors = true; - break; - } - } - if (!correctFlavors) { - return; - } - if (consumer != null) { - //if the producer filter property is set, the producer will do the filtering - //FIXME - check conditions correctly - if (producerFilterExists || wireFilter == null) { - try { - consumer.updated(this, value); - lastValue = value; - //lastTime = time; - wireadmin.eventProducer.generateEvent(WireAdminEvent.WIRE_TRACE, this, null); - } catch (Exception ex) { - wireadmin.eventProducer.generateEvent(WireAdminEvent.CONSUMER_EXCEPTION, this, ex); - } - } else { - long time = Calendar.getInstance().getTime().getTime(); - //get object properties - Hashtable valueProps = new Hashtable(10); - valueProps.put(WireConstants.WIREVALUE_CURRENT, value); - valueProps.put(WireConstants.WIREVALUE_PREVIOUS, lastValue); - valueProps.put(WireConstants.WIREVALUE_ELAPSED, new Long(time - lastTime)); //???LONG??? - try { - // value-lastValue; - if (value instanceof Short) { - int result = ((Short) value).shortValue() - ((Short) lastValue).shortValue(); - valueProps.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Integer(result)); - if (result < 0) { - result = result * -1; - } - valueProps.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Integer(result)); - } - if (value instanceof Integer) { - int result = ((Integer) value).intValue() - ((Integer) lastValue).intValue(); - valueProps.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Integer(result)); - if (result < 0) { - result = result * -1; - } - valueProps.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Integer(result)); - } - if (value instanceof Long) { - long result = ((Long) value).longValue() - ((Long) lastValue).longValue(); - valueProps.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Long(result)); - if (result < 0) { - result = result * -1; - } - valueProps.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Long(result)); - } - if (value instanceof Double) { - long result = ((Long) value).longValue() - ((Long) lastValue).longValue(); - valueProps.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Long(result)); - if (result < 0) { - result = result * -1; - } - valueProps.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Long(result)); - } - } catch (NumberFormatException ex) { - //we don't have two numeric values so do nothing - } - } - } - } - } - - /** - * Poll for an updated value. - * - * <p>This methods is normally called by the <tt>Consumer</tt> service to - * request an updated value from the <tt>Producer</tt> service - * connected to this <tt>Wire</tt> object. - * This <tt>Wire</tt> object will call - * the {@link Producer#polled} method to obtain an updated value. - * If this <tt>Wire</tt> object is not connected, then the <tt>Producer</tt> - * service must not be called. - * - * <p>A <tt>WireAdminEvent</tt> of type {@link WireAdminEvent#WIRE_TRACE} - * must be broadcast by the Wire Admin service after - * the <tt>Producer</tt> service has been successfully called. - * - * @return An updated value whose type should be one of the types - * returned by {@link #getFlavors} or <tt>null</tt> if - * the <tt>Wire</tt> object is not connected, - * the <tt>Producer</tt> service threw an exception, or - * the <tt>Producer</tt> service returned a value which is not an instance of - * one of the types returned by {@link #getFlavors}. - */ - public synchronized Object poll() { - wireadmin.checkAlive(); - if (producer != null) { - try { - synchronized (this) { - Object value = producer.polled(this); - wireadmin.eventProducer.generateEvent(WireAdminEvent.WIRE_TRACE, this, null); - if (checkFlavor(value)) { - lastValue = value; - return (value); - } - return (null); - } - } catch (Exception ex) { - wireadmin.eventProducer.generateEvent(WireAdminEvent.PRODUCER_EXCEPTION, this, ex); - return (null); - } - } - return (null); - - } - - /** - * Return the last value sent through this <tt>Wire</tt> object. - * - * <p>The returned value is the most recent, valid value passed to the - * {@link #update} method or returned by the {@link #poll} method - * of this object. If filtering is applied by the <tt>Wire</tt> object, - * this is still the value as set by the <tt>Producer</tt> service. - * - * @return The last value passed though this <tt>Wire</tt> object - * or <tt>null</tt> if no valid values have been passed. - */ - - public Object getLastValue() { - return (lastValue); - } - - /** - * Return the wire properties for this <tt>Wire</tt> object. - * - * @return The properties for this <tt>Wire</tt> object. - * The returned <tt>Dictionary</tt> must be read only. - */ - - public Dictionary getProperties() { - return (new ReadOnlyDictionary(properties)); - } - - protected void connect() { - connected = true; - wireadmin.notifyConsumer(consumer, consumerPID); - wireadmin.notifyProducer(producer, producerPID); - - //send event - wireadmin.eventProducer.generateEvent(WireAdminEvent.WIRE_CONNECTED, this, null); - } - - protected void disconnect() { - connected = false; - wireadmin.notifyConsumer(consumer, consumerPID); - wireadmin.notifyProducer(producer, producerPID); - - //send event - wireadmin.eventProducer.generateEvent(WireAdminEvent.WIRE_DISCONNECTED, this, null); - } - - protected void destroy() { - if (consumer != null) { - removeConsumer(); - } - if (producer != null) { - removeProducer(); - } - consumerTracker.close(); - producerTracker.close(); - valid = false; - } - - protected void setConsumer(Consumer consumer, ServiceReference reference) { - this.consumer = consumer; - setConsumerProperties(reference); - if (producer != null) { - connect(); - } - } - - protected void setProducer(Producer producer, ServiceReference reference) { - this.producer = producer; - setProducerProperties(reference); - if (consumer != null) { - connect(); - } - } - - protected void setProducerProperties(ServiceReference reference) { - producerFlavors = (Class[]) reference.getProperty(WireConstants.WIREADMIN_PRODUCER_FLAVORS); - //TODO - this method need to be completed - //String[] keys = reference.getPropertyKeys(); - //need to find out if WIREADMIN_PRODUCER_FILTERS key exists - if (reference.getProperty(WireConstants.WIREADMIN_PRODUCER_FILTERS) != null) { - producerFilterExists = true; - } - /* - for(int i=0;i<keys.length;i++) - { - if(keys[i] == (WireConstants.WIREADMIN_PRODUCER_FILTERS)) - { - producerFilterExists = true; - return; - } - } */ - } - - protected void removeProducer() { - producerFilterExists = false; - producerFlavors = null; - - if (connected) { - //The consumer is now "not connected" by this wire - disconnect(); - } - producer = null; - } - - protected void removeConsumer() { - - if (connected) { - disconnect(); - } - consumer = null; - flavors = null; - } - - protected String getPid() { - return pid; - } - - private boolean checkFlavor(Object value) { - if (flavors == null) { - return (true); - } - for (int i = 0; i < flavors.length; i++) { - if (value.getClass().isInstance(flavors[i])) { - return (true); - } - } - return (false); - } - - /** - * Return the calculated scope of this <tt>Wire</tt> object. - * - * The purpose of the <tt>Wire</tt> object's scope is to allow a Producer - * and/or Consumer service to produce/consume different types - * over a single <tt>Wire</tt> object (this was deemed necessary for efficiency - * reasons). Both the Consumer service and the - * Producer service must set an array of scope names (their scope) with - * the service registration property <tt>WIREADMIN_PRODUCER_SCOPE</tt>, or <tt>WIREADMIN_CONSUMER_SCOPE</tt> when they can - * produce multiple types. If a Producer service can produce different types, it should set this property - * to the array of scope names it can produce, the Consumer service - * must set the array of scope names it can consume. The scope of a <tt>Wire</tt> - * object is defined as the intersection of permitted scope names of the - * Producer service and Consumer service. - * <p>If neither the Consumer, or the Producer service registers scope names with its - * service registration, then the <tt>Wire</tt> object's scope must be <tt>null</tt>. - * <p>The <tt>Wire</tt> object's scope must not change when a Producer or Consumer services - * modifies its scope. - * <p>A scope name is permitted for a Producer service when the registering bundle has - * <tt>WirePermission[PRODUCE]</tt>, and for a Consumer service when - * the registering bundle has <tt>WirePermission[CONSUME]</tt>.<p> - * If either Consumer service or Producer service has not set a <tt>WIREADMIN_*_SCOPE</tt> property, then - * the returned value must be <tt>null</tt>.<p> - * If the scope is set, the <tt>Wire</tt> object must enforce the scope names when <tt>Envelope</tt> objects are - * used as a parameter to update or returned from the <tt>poll</tt> method. The <tt>Wire</tt> object must then - * remove all <tt>Envelope</tt> objects with a scope name that is not permitted. - * - * @return A list of permitted scope names or null if the Produce or Consumer service has set no scope names. - */ - public String[] getScope() { - return null; - } - - /** - * Return true if the given name is in this <tt>Wire</tt> object's scope. - * - * @param name The scope name - * @return true if the name is listed in the permitted scope names - */ - public boolean hasScope(String name) { - return false; - } - - protected void setProperties(Dictionary newprops) { - newprops.put(WireConstants.WIREADMIN_PID, pid); - newprops.put(WireConstants.WIREADMIN_PRODUCER_PID, producerPID); - newprops.put(WireConstants.WIREADMIN_CONSUMER_PID, consumerPID); - properties = newprops; - } - - protected void init() { - consumerTracker.open(); - producerTracker.open(); - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdmin.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdmin.java deleted file mode 100644 index b3912b623..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdmin.java +++ /dev/null @@ -1,432 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; -import org.osgi.service.prefs.PreferencesService; -import org.osgi.service.wireadmin.Consumer; -import org.osgi.service.wireadmin.Producer; -import org.osgi.service.wireadmin.WireAdminEvent; -import org.osgi.service.wireadmin.WireConstants; -import org.osgi.util.tracker.ServiceTracker; - -public class WireAdmin implements org.osgi.service.wireadmin.WireAdmin { - - protected Vector wires; - - protected BundleContext context; - - protected LogTracker log; - - protected WireAdminEventProducer eventProducer; - - protected ServiceReference reference; - - protected WireAdminStore wireAdminStore; - - protected int lastPid; - - private boolean alive = false; - - protected ServiceTracker producerTracker; - - protected ServiceTracker consumerTracker; - - protected final String consumerFilter = "(" + WireConstants.WIREADMIN_CONSUMER_PID + "="; //$NON-NLS-1$ //$NON-NLS-2$ - - protected final String producerFilter = "(" + WireConstants.WIREADMIN_PRODUCER_PID + "="; //$NON-NLS-1$ //$NON-NLS-2$ - - protected PreferencesService preferencesService; - - public WireAdmin(BundleContext context) { - this.context = context; - initWireAdmin(); - } - - /** - * Create a new <tt>Wire</tt> object that connects a <tt>Producer</tt> - * service to a <tt>Consumer</tt> service. - * - * The <tt>Producer</tt> service and <tt>Consumer</tt> service do not - * have to be registered when the the <tt>Wire</tt> object is created. - * - * <p> - * The <tt>Wire</tt> configuration data is persistently stored. All - * <tt>Wire</tt> connections are reestablished when the <tt>WireAdmin</tt> - * service is registered. A <tt>Wire</tt> connection can be removed by - * using the {@link #deleteWire} method. - * - * <p> - * The <tt>Wire</tt> object's properties must have case insensitive - * <tt>String</tt> objects as keys (like the Framework). However, the case - * of the key must be preserved. The type of the value of the property must - * be one of the following: - * - * <pre> - * type = basetype - * | vector | arrays - * basetype = String | Integer | Long - * | Float | Double | Byte - * | Short | BigInteger - * | BigDecimal | Character - * | Boolean - * primitive = long | int | short - * | char | byte | double | float - * arrays = primitive '[]' | basetype '[]' - * vector = Vector of basetype - * </pre> - * - * <p> - * The <tt>WireAdmin</tt> service must automatically add the following - * <tt>Wire</tt> properties: - * <ul> - * <li> {@link #WIREADMIN_PID} set to the value of the wire's persistent - * identity (PID). This value is generated by the <tt>WireAdmin</tt> - * service when a <tt>Wire</tt> object is created. </li> - * <li> {@link #WIREADMIN_PRODUCER_PID} set to the value of - * <tt>Producer</tt> service's PID. </li> - * <li> {@link #WIREADMIN_CONSUMER_PID} set to the value of - * <tt>Consumer</tt> service's PID. </li> - * </ul> - * If the <tt>properties</tt> argument already contains any of these keys, - * then the supplied values are replaced with the values assigned by the - * <tt>WireAdmin</tt> service. - * - * <p> - * The Wire Admin service must generate a {@link #WIREADMIN_CREATED} event - * after the new <tt>Wire</tt> object becomes available from - * {@link #getWires}. - * - * @param producerPID - * The "service.pid" of the <tt>Producer</tt> service - * to be connected to the <tt>Wire</tt>. - * @param consumerPID - * The "service.pid" of the <tt>Consumer</tt> service - * to be connected to the <tt>Wire</tt>. - * @param properties - * The <tt>Wire</tt> object's properties. This argument may be - * <tt>null</tt> if the caller does not wish to define any - * <tt>Wire</tt> object's properties. - * @return The <tt>Wire</tt> object for this connection. - * @throws java.lang.IllegalArgumentException - * If <tt>properties</tt> contains case variants of the same - * key name. - */ - public synchronized org.osgi.service.wireadmin.Wire createWire( - String producerPID, String consumerPID, Dictionary properties) { - checkAlive(); - // generate PID - lastPid++; - String pid = String.valueOf(lastPid); - if (consumerPID == null || producerPID == null) { - throw new IllegalArgumentException(); - } - if (properties == null) { - properties = new Hashtable(10); - } else { - checkProperties(properties); - } - Wire wire = createWire(pid, producerPID, consumerPID, properties); - try { - wireAdminStore.addWire(wire, properties); - } catch (Exception ex) { - log.log(LogService.LOG_ERROR, - WireAdminMsg.BACKING_STORE_READ_EXCEPTION, ex); - } - - eventProducer.generateEvent(WireAdminEvent.WIRE_CREATED, wire, null); - return (wire); - } - - protected Wire createWire(String pid, String producerPID, - String consumerPID, Dictionary properties) { - Wire wire = new Wire(pid, producerPID, consumerPID, properties, this); - wires.addElement(wire); - wire.init(); - return (wire); - } - - /** - * Disconnect a <tt>Producer</tt> service from a <tt>Consumer</tt> - * service. - * - * <p> - * The connection between a <tt>Producer</tt> service and a - * <tt>Consumer</tt> service is removed. The persistently stored - * configuration data for the <tt>Wire</tt> object is destroyed. The - * <tt>Wire</tt> object's method {@link Wire#isValid} will return - * <tt>false</tt> after it is destroyed. - * - * <p> - * The Wire Admin service must generate a {@link #WIREADMIN_DELETED} event - * after the <tt>Wire</tt> object becomes invalid. - * - * @param wire - * The <tt>Wire</tt> object which is to be disconnected. - */ - public void deleteWire(org.osgi.service.wireadmin.Wire wire) { - checkAlive(); - wires.removeElement(wire); - ((org.eclipse.equinox.wireadmin.Wire) wire).destroy(); - try { - wireAdminStore.removeWire((Wire) wire); - } catch (Exception ex) { - log.log(LogService.LOG_ERROR, WireAdminMsg.BACKING_STORE_READ_EXCEPTION, - ex); - } - eventProducer.generateEvent(WireAdminEvent.WIRE_DELETED, wire, null); - } - - /** - * Update the properties of a <tt>Wire</tt> object. - * - * The persistently stored configuration data for the <tt>Wire</tt> object - * is updated with the new properties and then the <tt>Consumer</tt> and - * <tt>Producer</tt> services will be called with the respective - * {@link Consumer#producersConnected} and - * {@link Producer#consumersConnected} methods. methods.. - * - * <p> - * The Wire Admin service must generate a {@link #WIREADMIN_UPDATED} event - * after the new <tt>properties</tt> become available from the - * <tt>Wire</tt> object. - * - * @param wire - * The <tt>Wire</tt> object which is to be updated. - * @param properties - * The new <tt>Wire</tt> object's properties or <tt>null</tt> - * if no properties are required. - */ - - public void updateWire(org.osgi.service.wireadmin.Wire wire, - Dictionary properties) { - checkAlive(); - checkProperties(properties); - if (!wire.isValid()) { - return; - } - ((org.eclipse.equinox.wireadmin.Wire) wire).setProperties(properties); - try { - wireAdminStore.updateWire((Wire) wire, properties); - } catch (Exception ex) { - log.log(LogService.LOG_ERROR, WireAdminMsg.BACKING_STORE_READ_EXCEPTION, - ex); - } - try { - Consumer consumer = ((org.eclipse.equinox.wireadmin.Wire) wire).consumer; - Wire[] wireArray = new Wire[wires.size()]; - wires.copyInto(wireArray); - if (consumer != null) { - consumer.producersConnected(wireArray); - } - Producer producer = ((org.eclipse.equinox.wireadmin.Wire) wire).producer; - if (producer != null) { - producer.consumersConnected(wireArray); - } - eventProducer - .generateEvent(WireAdminEvent.WIRE_UPDATED, wire, null); - } catch (Exception ex) { - // ??? - log.log(LogService.LOG_ERROR, WireAdminMsg.BACKING_STORE_READ_EXCEPTION, - ex); - } - - } - - /** - * Return the <tt>Wire</tt> objects that match the given <tt>filter</tt>. - * - * <p> - * The list of available <tt>Wire</tt> objects is matched against the - * specified <tt>filter</tt>. <tt>Wire</tt> objects which match the - * <tt>filter</tt> are returned. These <tt>Wire</tt> objects are not - * necessarily connected. The Wire Admin service should not return invalid - * <tt>Wire</tt> objects, but it is possible that a <tt>Wire</tt> object - * is deleted after it was placed in the list. - * - * <p> - * The filter matches against the <tt>Wire</tt> object's properties - * including {@link Constants#WIREADMIN_PRODUCER_PID}, - * {@link Constants#WIREADMIN_CONSUMER_PID} and - * {@link Constants#WIREADMIN_PID}. - * - * @param filter - * Filter string to select <tt>Wire</tt> objects or - * <tt>null</tt> to select all <tt>Wire</tt> objects. - * @return An array of <tt>Wire</tt> objects which match the - * <tt>filter</tt> or <tt>null</tt> if no <tt>Wire</tt> - * objects match the <tt>filter</tt>. - * @throws org.osgi.framework.InvalidSyntaxException - * If the specified <tt>filter</tt> has an invalid syntax. - * @see "org.osgi.framework.Filter" - */ - public org.osgi.service.wireadmin.Wire[] getWires(String filterString) - throws InvalidSyntaxException { - checkAlive(); - return getWires(filterString, false); - - } - - protected Wire[] getConnectedWires(String filterString) - throws InvalidSyntaxException { - return getWires(filterString, true); - } - - protected Wire[] getWires(String filterString, boolean connected) - throws InvalidSyntaxException { - Vector returnedWires; - synchronized (this) { - if (filterString == null) { - returnedWires = wires; - } - - else { - Filter filter = context.createFilter(filterString); // We do - // this - // first so - // an - // InvalidSyntaxException will be - // thrown even if there are no wires - // present. - returnedWires = new Vector(); - for (int i = 0; i < wires.size(); i++) { - Wire wire = (Wire) wires.elementAt(i); - if (filter.match(wire.properties)) { - if (!connected || wire.isConnected()) { - returnedWires.addElement(wire); - } - } - } - } - int size = returnedWires.size(); - if (size == 0) { - return (null); - } - Wire[] wireArray = new Wire[size]; - returnedWires.copyInto(wireArray); - return (wireArray); - } - } - - protected void setServiceReference(ServiceReference reference) { - if (this.reference == null) { - this.reference = reference; - - eventProducer = new WireAdminEventProducer(reference, context, log, - this); - } - } - - protected void destroy() { - alive = false; - wires = null; - eventProducer.close(); - producerTracker.close(); - consumerTracker.close(); - } - - protected void checkAlive() { - if (!alive) { - throw (new IllegalStateException( - WireAdminMsg.WIREADMIN_UNREGISTERED_EXCEPTION)); - } - - } - - protected void notifyProducer(Producer producer, String pid) { - org.osgi.service.wireadmin.Wire[] wireArray = null; - try { - wireArray = getConnectedWires(producerFilter + pid + ")"); //$NON-NLS-1$ - } catch (InvalidSyntaxException ex) { - ex.printStackTrace(); - } - - try { - producer.consumersConnected(wireArray); - } catch (Exception ex) { - eventProducer.generateEvent(WireAdminEvent.PRODUCER_EXCEPTION, - null, ex); - } - - } - - protected void notifyConsumer(Consumer consumer, String pid) { - org.osgi.service.wireadmin.Wire[] wireArray = null; - try { - wireArray = getConnectedWires(consumerFilter + pid + ")"); //$NON-NLS-1$ - } catch (InvalidSyntaxException ex) { - ex.printStackTrace(); - } - - try { - consumer.producersConnected(wireArray); - } catch (Exception ex) { - eventProducer.generateEvent(WireAdminEvent.CONSUMER_EXCEPTION, - null, ex); - } - - } - - private void checkProperties(Dictionary properties) { - Enumeration e = properties.keys(); - Vector keys = new Vector(properties.size()); - while (e.hasMoreElements()) { - String key = null; - try { - key = (String) e.nextElement(); - } catch (ClassCastException ex) { - throw new IllegalArgumentException( - WireAdminMsg.WIREADMIN_PROP_KEY_MUST_BE_STRING); - } - key = key.toUpperCase(); - if (keys.contains(key)) { - throw new IllegalArgumentException( - WireAdminMsg.WIREADMIN_KEYS_CASE_INSENSITIVE_MATCH); - } - keys.add(key); - } - } - - private void initWireAdmin() { - wires = new Vector(10); - - log = new LogTracker(context, System.out); - wireAdminStore = new WireAdminStore(context, this, log, - preferencesService); - - try { - wireAdminStore.init(preferencesService); - } catch (Exception ex) { - log.log(LogService.LOG_ERROR, WireAdminMsg.BACKING_STORE_READ_EXCEPTION, - ex); - } - consumerTracker = new ServiceTracker(context, Consumer.class.getName(), - new ConsumersCustomizer(context, this)); - consumerTracker.open(); - - producerTracker = new ServiceTracker(context, Producer.class.getName(), - new ProducersCustomizer(context, this)); - producerTracker.open(); - - alive = true; - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminEventProducer.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminEventProducer.java deleted file mode 100644 index e1f0563d2..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminEventProducer.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.util.Vector; -import org.eclipse.osgi.framework.eventmgr.*; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; -import org.osgi.service.wireadmin.*; -import org.osgi.service.wireadmin.Wire; -import org.osgi.util.tracker.ServiceTracker; - -/* - * WireAdminEventProducer is responsible for sending out WireAdminEvents - * to all WireAdminListeners. - */ - -public class WireAdminEventProducer extends ServiceTracker implements EventDispatcher { - - protected ServiceReference ref; - static protected final String wireAdminListenerClass = "org.osgi.service.wireadmin.WireAdminListener"; //$NON-NLS-1$ - protected Vector eventQueue; - protected LogService log; - protected BundleContext context; - - protected WireAdmin wireAdmin; - - /** List of WireAdminListeners */ - protected EventListeners listeners; - /** EventManager for event delivery. */ - protected EventManager eventManager; - - protected WireAdminEventProducer(ServiceReference ref, BundleContext context, LogService log, WireAdmin wireAdmin) { - super(context, wireAdminListenerClass, null); - this.ref = ref; - this.context = context; - this.log = log; - this.wireAdmin = wireAdmin; - eventManager = new EventManager("WireAdmin Event Dispatcher"); //$NON-NLS-1$ - listeners = new EventListeners(); - - open(); - - } - - public void close() { - super.close(); - listeners.removeAllListeners(); - eventManager.close(); - wireAdmin = null; - } - - protected void generateEvent(int type, Wire wire, Throwable t) { - if (wireAdmin != null) { - WireAdminEvent event = new WireAdminEvent(wireAdmin.reference, type, wire, t); - - /* queue to hold set of listeners */ - ListenerQueue queue = new ListenerQueue(eventManager); - - /* add set of WireAdminListeners to queue */ - queue.queueListeners(listeners, this); - - /* dispatch event to set of listeners */ - queue.dispatchEventAsynchronous(0, event); - } - } - - /** - * A service is being added to the <tt>ServiceTracker</tt> object. - * - * <p>This method is called before a service which matched - * the search parameters of the <tt>ServiceTracker</tt> object is - * added to it. This method should return the - * service object to be tracked for this <tt>ServiceReference</tt> object. - * The returned service object is stored in the <tt>ServiceTracker</tt> object - * and is available from the <tt>getService</tt> and <tt>getServices</tt> - * methods. - * - * @param reference Reference to service being added to the <tt>ServiceTracker</tt> object. - * @return The service object to be tracked for the - * <tt>ServiceReference</tt> object or <tt>null</tt> if the <tt>ServiceReference</tt> object should not - * be tracked. - */ - public Object addingService(ServiceReference reference) { - - Object service = super.addingService(reference); - setMask(reference, service); - - return (service); - } - - /** - * A service tracked by the <tt>ServiceTracker</tt> object has been removed. - * - * <p>This method is called after a service is no longer being tracked - * by the <tt>ServiceTracker</tt> object. - * - * @param reference Reference to service that has been removed. - * @param service The service object for the removed service. - */ - public void removedService(ServiceReference reference, Object service) { - listeners.removeListener(service); - - super.removedService(reference, service); - } - - /** - * This method is the call back that is called once for each listener. - * This method must cast the EventListener object to the appropriate listener - * class for the event type and call the appropriate listener method. - * - * @param listener This listener must be cast to the appropriate listener - * class for the events created by this source and the appropriate listener method - * must then be called. - * @param listenerObject This is the optional object that was passed to - * ListenerList.addListener when the listener was added to the ListenerList. - * @param eventAction This value was passed to the EventQueue object via one of its - * dispatchEvent* method calls. It can provide information (such - * as which listener method to call) so that this method - * can complete the delivery of the event to the listener. - * @param eventObject This object was passed to the EventQueue object via one of its - * dispatchEvent* method calls. This object was created by the event source and - * is passed to this method. It should contain all the necessary information (such - * as what event object to pass) so that this method - * can complete the delivery of the event to the listener. - */ - public void dispatchEvent(Object listener, Object maskObject, int eventAction, Object eventObject) { - ServiceReference wireAdminRef = wireAdmin.reference; - - WireAdminListener wal = (WireAdminListener) listener; - - try { - WireAdminEvent event = (WireAdminEvent) eventObject; - { - int mask = ((Integer) maskObject).intValue(); - int type = event.getType(); - if ((type & mask) != type) { - return; - } - } - wal.wireAdminEvent(event); - - } catch (Throwable t) { - log.log(wireAdminRef, LogService.LOG_WARNING, WireAdminMsg.WIREADMIN_EVENT_DISPATCH_ERROR, t); - } - - } - - /** - * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(ServiceReference, Object) - */ - public void modifiedService(ServiceReference reference, Object service) { - listeners.removeListener(service); - setMask(reference, service); - super.modifiedService(reference, service); - } - - private void setMask(ServiceReference reference, Object service) { - Integer mask = null; - try { - mask = (Integer) reference.getProperty(WireConstants.WIREADMIN_EVENTS); - } catch (ClassCastException ex) { - return; //mask was not of type Integer - } - listeners.addListener(service, mask); - - } - -} diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminMsg.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminMsg.java deleted file mode 100644 index 608983018..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminMsg.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import org.eclipse.osgi.util.NLS; - -public class WireAdminMsg extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.equinox.wireadmin.ExternalMessages"; //$NON-NLS-1$ - - public static String BACKING_STORE_READ_EXCEPTION; - public static String WIREADMIN_UNREGISTERED_EXCEPTION; - public static String WIREADMIN_EVENT_DISPATCH_ERROR; - public static String WIREADMIN_PROP_KEY_MUST_BE_STRING; - public static String WIREADMIN_KEYS_CASE_INSENSITIVE_MATCH; - - static { - // initialize resource bundles - NLS.initializeMessages(BUNDLE_NAME, WireAdminMsg.class); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminStore.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminStore.java deleted file mode 100644 index 9491315e7..000000000 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/wireadmin/WireAdminStore.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.wireadmin; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.*; -import java.util.*; -import org.osgi.framework.BundleContext; -import org.osgi.service.log.LogService; -import org.osgi.service.prefs.*; -import org.osgi.service.wireadmin.WireConstants; - -/* - * WireAdminStore is responsible for managing the persistence data of the wireadmin - * service. It uses the PersistenceNode service as its underlying storage. - */ - -public class WireAdminStore { - - static protected final String persistenceUserName = "WireAdmin"; //$NON-NLS-1$ - static protected final String lastPidString = "lastPid"; //$NON-NLS-1$ - static protected final String defaultLastPid = "1"; //$NON-NLS-1$ - - protected BundleContext context; - protected WireAdmin wireadmin; - protected LogService log; - protected Preferences rootNode; - protected PreferencesService preferencesService; - - protected WireAdminStore(BundleContext context, WireAdmin wireadmin, LogService log, PreferencesService preferencesService) { - this.context = context; - this.wireadmin = wireadmin; - this.log = log; - } - - protected void init(PreferencesService preferencesService_) throws BackingStoreException { - this.preferencesService = preferencesService_; - } - - protected void addWire(final Wire wire, final Dictionary properties) throws BackingStoreException { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - String pid = wire.getPid(); - rootNode.put(lastPidString, pid); - Preferences node = rootNode.node(pid); - storeProperties(properties, node); - - /* Enumeration enum = properties.keys(); - - while(enum.hasMoreElements()) - { - String key = (String)enum.nextElement(); - String value = (String)properties.get(key); - node.put(key,value); - } - */ - rootNode.flush(); - return (null); - } - }); - } catch (PrivilegedActionException ex) { - //log.log(log.LOG_ERROR,Text.BACKING_STORE_WRITE_EXCEPTION,ex); - throw ((BackingStoreException) ex.getException()); - } - } - - protected void removeWire(final Wire wire) throws BackingStoreException { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Preferences node = rootNode.node(wire.getPid()); - node.removeNode(); - rootNode.node("").flush(); //$NON-NLS-1$ - return (null); - } - }); - } catch (PrivilegedActionException ex) { - //log.log(log.LOG_ERROR,Text.BACKING_STORE_WRITE_EXCEPTION,ex); - throw ((BackingStoreException) ex.getException()); - } - } - - protected void loadWires() throws BackingStoreException { - synchronized (this) { - wireadmin.lastPid = Integer.parseInt(rootNode.get(lastPidString, defaultLastPid)); - String[] children = rootNode.node("").childrenNames(); //$NON-NLS-1$ - for (int i = 0; i < children.length; i++) { - loadWire(rootNode.node(children[i])); - } - } - } - - protected void loadWire(Preferences node) throws BackingStoreException { - String pid = node.name(); - Hashtable properties = loadProperties(node); - /* String[] keys = node.keys(); - for(int i=0;i<keys.length;i++) - { - String value = (String)node.get(keys[i],null); - properties.put(keys[i],value); - } */ - String consumerPid = (String) properties.get(WireConstants.WIREADMIN_CONSUMER_PID); - String producerPid = (String) properties.get(WireConstants.WIREADMIN_PRODUCER_PID); - wireadmin.createWire(pid, producerPid, consumerPid, properties); - } - - protected void updateWire(final Wire wire, final Dictionary properties) throws BackingStoreException { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - String pid = wire.getPid(); - Preferences node = rootNode.node(pid); - node.clear(); - storeProperties(properties, node); - - /*Enumeration enum = properties.keys(); - while(enum.hasMoreElements()) - { - String key = (String)enum.nextElement(); - String value = (String)properties.get(key); - node.put(key,value); - } - */ - node.flush(); - return (null); - } - }); - } catch (PrivilegedActionException ex) { - //log.log(log.LOG_ERROR,Text.BACKING_STORE_WRITE_EXCEPTION,ex); - throw ((BackingStoreException) ex.getException()); - } - } - - protected void destroy() { - try { - rootNode.flush(); - } catch (BackingStoreException ex) { - //log.log(log.LOG_ERROR,Text.BACKING_STORE_WRITE_EXCEPTION,ex); - } - } - - protected void storeProperties(Dictionary properties, Preferences node) throws BackingStoreException { - Enumeration e = properties.keys(); - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - Object value = properties.get(key); - if (value instanceof Vector) { - storeVector(node.node("Vector/" + key), (Vector) value); //$NON-NLS-1$ - } else { - Preferences childNode = node.node("basetype/" + value.getClass().getName()); //$NON-NLS-1$ - childNode.put(key, String.valueOf(value)); - } - - //node.put(key,value); - } - node.flush(); - } - - private void storeVector(Preferences node, Vector vector) { - Enumeration e = vector.elements(); - while (e.hasMoreElements()) { - Object value = e.nextElement(); - node.put(value.getClass().getName(), String.valueOf(value)); - } - } - - private Hashtable loadProperties(Preferences node) throws BackingStoreException { - Hashtable props = new Hashtable(15); - if (node.nodeExists("Vector")) { //$NON-NLS-1$ - loadVectors(node.node("Vector"), props); //$NON-NLS-1$ - } - if (node.nodeExists("basetype")) { //$NON-NLS-1$ - loadBaseTypes(node.node("basetype"), props); //$NON-NLS-1$ - } - return props; - } - - private void loadVectors(Preferences node, Hashtable props) throws BackingStoreException { - String[] children = node.childrenNames(); - for (int j = 0; j < children.length; j++) { - Preferences vectorNode = node.node(children[j]); - String keys[] = vectorNode.keys(); - Vector vector = new Vector(keys.length); - for (int i = 0; i < keys.length; i++) { - String value = node.get(keys[i], null); - vector.add(getValue(keys[i], value)); - - } - props.put(children[j], vector); - } - } - - private void loadBaseTypes(Preferences node, Hashtable props) throws BackingStoreException { - String[] children = node.childrenNames(); - for (int j = 0; j < children.length; j++) { - Preferences childNode = node.node(children[j]); - String keys[] = childNode.keys(); - for (int i = 0; i < keys.length; i++) { - props.put(keys[i], getValue(children[j], childNode.get(keys[i], null))); - } - } - } - - private Object getValue(String className, String value) { - //Float does not have a zero-arguement constructor - if (className.equals(Float.class.getName())) { - return Float.valueOf(value); - } else if (className.equals(Boolean.class.getName())) { - return Boolean.valueOf(value); - } - try { - Class clazz = Class.forName(className); - Object object = clazz.newInstance(); - Method method = clazz.getDeclaredMethod("valueOf", new Class[] {Object.class}); //$NON-NLS-1$ - return (method.invoke(object, new Object[] {value})); - - } catch (ClassNotFoundException ex) { - ex.printStackTrace(); - } catch (IllegalAccessException ex1) { - ex1.printStackTrace(); - } catch (InstantiationException ex2) { - - ex2.printStackTrace(); - } catch (NoSuchMethodException ex3) { - ex3.printStackTrace(); - } catch (InvocationTargetException ex4) { - ex4.printStackTrace(); - } - return null; - } - -} |