diff options
author | Thomas Watson | 2007-11-12 21:06:36 +0000 |
---|---|---|
committer | Thomas Watson | 2007-11-12 21:06:36 +0000 |
commit | 8f20d697789e472c742e0700aa5d2bd486a0c6d3 (patch) | |
tree | 6e173b1306a2414c4caac259059018c87e4a0d91 /bundles/org.eclipse.equinox.useradmin | |
parent | 336c76142d4c6fe28906228dfc2496cfb52dcce4 (diff) | |
download | rt.equinox.bundles-8f20d697789e472c742e0700aa5d2bd486a0c6d3.tar.gz rt.equinox.bundles-8f20d697789e472c742e0700aa5d2bd486a0c6d3.tar.xz rt.equinox.bundles-8f20d697789e472c742e0700aa5d2bd486a0c6d3.zip |
Diffstat (limited to 'bundles/org.eclipse.equinox.useradmin')
9 files changed, 194 insertions, 39 deletions
diff --git a/bundles/org.eclipse.equinox.useradmin/.classpath b/bundles/org.eclipse.equinox.useradmin/.classpath index 1fa3e6803..866a165d0 100644 --- a/bundles/org.eclipse.equinox.useradmin/.classpath +++ b/bundles/org.eclipse.equinox.useradmin/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/OSGi%Minimum-1.1"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.useradmin/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.useradmin/.settings/org.eclipse.jdt.core.prefs index f31f25003..ae4c9fce7 100644 --- a/bundles/org.eclipse.equinox.useradmin/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.useradmin/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Tue Aug 21 11:27:47 CDT 2007 +#Mon Nov 12 12:45:03 CST 2007 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -8,9 +8,9 @@ org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.3 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -62,7 +62,6 @@ org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled org.eclipse.jdt.core.compiler.problem.unusedImport=error diff --git a/bundles/org.eclipse.equinox.useradmin/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.useradmin/META-INF/MANIFEST.MF index a047bc4a9..b935b8b28 100644 --- a/bundles/org.eclipse.equinox.useradmin/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.useradmin/META-INF/MANIFEST.MF @@ -1,18 +1,20 @@ Bundle-ManifestVersion: 2 Bundle-Vendor: %bundleVendor -Bundle-Version: 1.0.100.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.eclipse.equinox.useradmin.Activator Bundle-Copyright: %bundleCopyright Bundle-SymbolicName: org.eclipse.equinox.useradmin Import-Service: org.osgi.service.log.LogService Bundle-Name: %bundleName Export-Service: org.osgi.service.useradmin.UserAdmin -Import-Package: org.eclipse.osgi.framework.eventmgr; version="1.1", +Import-Package: org.eclipse.osgi.framework.eventmgr;version="1.1", + org.eclipse.osgi.util, org.osgi.framework;version="1.1", + org.osgi.service.event;version="1.0", org.osgi.service.log;version="1.0", org.osgi.service.prefs;version="1.0", org.osgi.service.useradmin;version="1.0", - org.osgi.util.tracker;version="1.1", - org.eclipse.osgi.util + org.osgi.util.tracker;version="1.1" Export-Package: org.eclipse.equinox.useradmin;x-internal:=true Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.1 diff --git a/bundles/org.eclipse.equinox.useradmin/build.properties b/bundles/org.eclipse.equinox.useradmin/build.properties index 873261924..3da785a7f 100644 --- a/bundles/org.eclipse.equinox.useradmin/build.properties +++ b/bundles/org.eclipse.equinox.useradmin/build.properties @@ -9,7 +9,7 @@ # IBM Corporation - initial API and implementation ############################################################################### bin.includes = META-INF/,\ - plugin*.properties,\ + plugin.properties,\ about.html,\ . src.includes = about.html diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/Activator.java b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/Activator.java index a17241901..046417a3a 100644 --- a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/Activator.java +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/Activator.java @@ -32,11 +32,12 @@ public class Activator implements BundleActivator, ServiceFactory, ServiceTracke protected PreferencesService prefs; protected BundleContext context; protected ServiceTracker prefsTracker; + protected UserAdminEventAdapter eventAdapter; + + public Activator() { + //a public constructor is required for a BundleActivator + } - public Activator() { - //a public constructor is required for a BundleActivator - } - /** * Required by BundleActivator Interface. */ @@ -44,24 +45,31 @@ public class Activator implements BundleActivator, ServiceFactory, ServiceTracke this.context = context_; prefsTracker = new ServiceTracker(context, PreferencesService.class.getName(), this); prefsTracker.open(); + + eventAdapter = new UserAdminEventAdapter(context_); + eventAdapter.start(); } /** * Required by BundleActivator Interface. */ public void stop(BundleContext context_) throws Exception { + if (eventAdapter != null) { + eventAdapter.stop(); + eventAdapter = null; + } + prefsTracker.close(); - unregisterUserAdminService(); + unregisterUserAdminService(); } - public Object getService(Bundle bundle, ServiceRegistration registration_) { userAdmin.setServiceReference(registration_.getReference()); return userAdmin; } public void ungetService(Bundle bundle, ServiceRegistration registration_, Object service) { - //do nothing + //do nothing } public Object addingService(ServiceReference reference) { @@ -78,7 +86,7 @@ public class Activator implements BundleActivator, ServiceFactory, ServiceTracke } public void modifiedService(ServiceReference reference, Object service) { - // do nothing + // do nothing } public void removedService(ServiceReference reference, Object service) { @@ -89,7 +97,6 @@ public class Activator implements BundleActivator, ServiceFactory, ServiceTracke context.ungetService(reference); } - /** * Register the UserAdmin service. */ @@ -104,10 +111,9 @@ public class Activator implements BundleActivator, ServiceFactory, ServiceTracke registration = context.registerService(userAdminClazz, this, properties); userAdmin.setServiceReference(registration.getReference()); } - + protected void unregisterUserAdminService() { - if(registration != null) - { + if (registration != null) { registration.unregister(); registration = null; userAdmin.destroy(); diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogMessages.properties b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogMessages.properties index e2cd481a9..6a2f70673 100644 --- a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogMessages.properties +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2001, 2006 IBM Corporation and others. +# Copyright (c) 2001, 2007 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 @@ -9,7 +9,9 @@ # IBM Corporation - initial API and implementation ############################################################################### # NLS_MESSAGEFORMAT_ALL + Unknown_Log_level=Unknown Log Level Info=Log Info Warning=Log Warning Error=Log Error +Debug=Log Debug diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTracker.java b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTracker.java index 61ec2ef70..8a9213128 100644 --- a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTracker.java +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1998, 2006 IBM Corporation and others. + * Copyright (c) 1998, 2007 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 @@ -11,8 +11,9 @@ package org.eclipse.equinox.useradmin; import java.io.PrintStream; -import java.text.DateFormat; import java.util.Calendar; +import java.util.Date; + import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; @@ -28,12 +29,7 @@ public class LogTracker extends ServiceTracker implements LogService { 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; + private final PrintStream out; /** * Create new LogTracker. @@ -44,9 +40,6 @@ public class LogTracker extends ServiceTracker implements LogService { public LogTracker(BundleContext context, PrintStream out) { super(context, clazz, null); this.out = out; - calendar = Calendar.getInstance(); - dateFormat = DateFormat.getDateTimeInstance(); - open(); } /* @@ -78,7 +71,8 @@ public class LogTracker extends ServiceTracker implements LogService { if (service != null) { try { service.log(reference, level, message, exception); - } catch (Exception e) { // do nothing + } catch (Exception e) { + // TODO: consider printing to System Error } } } @@ -102,12 +96,12 @@ public class LogTracker extends ServiceTracker implements LogService { 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()); + String timestamp = getDate(new Date()); out.print(timestamp + " "); //$NON-NLS-1$ switch (level) { case LOG_DEBUG : { - out.print("Debug: "); //$NON-NLS-1$ + out.print(LogTrackerMsg.Debug); break; } @@ -147,4 +141,34 @@ public class LogTracker extends ServiceTracker implements LogService { } } } + + // from EclipseLog to avoid using DateFormat -- see bug 149892#c10 + private String getDate(Date date) { + Calendar c = Calendar.getInstance(); + c.setTime(date); + StringBuffer sb = new StringBuffer(); + appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-'); + appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-'); + appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' '); + appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':'); + appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':'); + appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.'); + appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb); + return sb.toString(); + } + + private StringBuffer appendPaddedInt(int value, int pad, StringBuffer buffer) { + pad = pad - 1; + if (pad == 0) + return buffer.append(Integer.toString(value)); + int padding = (int) Math.pow(10, pad); + if (value >= padding) + return buffer.append(Integer.toString(value)); + while (padding > value && padding > 1) { + buffer.append('0'); + padding = padding / 10; + } + buffer.append(value); + return buffer; + } } diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTrackerMsg.java b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTrackerMsg.java index 17626e57b..452640f55 100644 --- a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTrackerMsg.java +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/LogTrackerMsg.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -19,6 +19,7 @@ public class LogTrackerMsg extends NLS { public static String Info; public static String Warning; public static String Error; + public static String Debug; static { // initialize resource bundles diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/UserAdminEventAdapter.java b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/UserAdminEventAdapter.java new file mode 100644 index 000000000..a69bfb3bd --- /dev/null +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/useradmin/UserAdminEventAdapter.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 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.useradmin; + +import java.util.Hashtable; +import org.osgi.framework.*; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.useradmin.*; +import org.osgi.service.useradmin.Role; +import org.osgi.util.tracker.ServiceTracker; + +public class UserAdminEventAdapter implements UserAdminListener { + // constants for Event topic substring + public static final String TOPIC = "org/osgi/service/useradmin/UserAdmin"; //$NON-NLS-1$ + public static final char TOPIC_SEPARATOR = '/'; + public static final String EVENT = "event"; //$NON-NLS-1$ + + public static final String SERVICE = "service"; //$NON-NLS-1$ + public static final String SERVICE_ID = "service.id"; //$NON-NLS-1$ + public static final String SERVICE_OBJECTCLASS = "service.objectClass"; //$NON-NLS-1$ + public static final String SERVICE_PID = "service.pid"; //$NON-NLS-1$ + + public static final String ROLE_CREATED = "ROLE_CREATED"; //$NON-NLS-1$ + public static final String ROLE_CHANGED = "ROLE_CHANGED"; //$NON-NLS-1$ + public static final String ROLE_REMOVED = "ROLE_REMOVED"; //$NON-NLS-1$ + // constants for Event properties + public static final String ROLE = "role"; //$NON-NLS-1$ + public static final String ROLE_NAME = "role.name"; //$NON-NLS-1$ + public static final String ROLE_TYPE = "role.type"; //$NON-NLS-1$ + + private BundleContext context; + private ServiceRegistration userAdminRegistration; + private ServiceTracker eventAdminTracker; + + public UserAdminEventAdapter(BundleContext context) { + this.context = context; + } + + public void start() throws Exception { + Hashtable props = new Hashtable(3); + userAdminRegistration = context.registerService(UserAdminListener.class.getName(), this, props); + + eventAdminTracker = new ServiceTracker(context, EventAdmin.class.getName(), null); + eventAdminTracker.open(); + } + + public void stop() throws Exception { + if (eventAdminTracker != null) { + eventAdminTracker.close(); + eventAdminTracker = null; + } + if (userAdminRegistration != null) { + userAdminRegistration.unregister(); + userAdminRegistration = null; + } + this.context = null; + } + + public void roleChanged(UserAdminEvent event) { + EventAdmin eventAdmin = eventAdminTracker == null ? null : ((EventAdmin) eventAdminTracker.getService()); + if (eventAdmin != null) { + String typename = null; + switch (event.getType()) { + case UserAdminEvent.ROLE_CREATED : + typename = ROLE_CREATED; + break; + case UserAdminEvent.ROLE_CHANGED : + typename = ROLE_CHANGED; + break; + case UserAdminEvent.ROLE_REMOVED : + typename = ROLE_REMOVED; + break; + default : + return; + } + String topic = TOPIC + TOPIC_SEPARATOR + typename; + Hashtable properties = new Hashtable(); + ServiceReference ref = event.getServiceReference(); + if (ref == null) { + throw new RuntimeException("UserAdminEvent's getServiceReference() returns null."); //$NON-NLS-1$ + } + putServiceReferenceProperties(properties, ref); + Role role = event.getRole(); + if (role == null) { + throw new RuntimeException("UserAdminEvent's getRole() returns null."); //$NON-NLS-1$ + } + if (role != null) { + properties.put(ROLE, role); + properties.put(ROLE_NAME, role.getName()); + properties.put(ROLE_TYPE, new Integer(role.getType())); + } + properties.put(EVENT, event); + Event convertedEvent = new Event(topic, properties); + eventAdmin.postEvent(convertedEvent); + } + } + + public void putServiceReferenceProperties(Hashtable properties, ServiceReference ref) { + properties.put(SERVICE, ref); + properties.put(SERVICE_ID, ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)); + Object o = ref.getProperty(org.osgi.framework.Constants.SERVICE_PID); + if ((o != null) && (o instanceof String)) { + properties.put(SERVICE_PID, o); + } + Object o2 = ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS); + if ((o2 != null) && (o2 instanceof String[])) { + properties.put(SERVICE_OBJECTCLASS, o2); + } + } + +}
\ No newline at end of file |