diff options
Diffstat (limited to 'bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi')
15 files changed, 208 insertions, 200 deletions
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java index c464f07fb..b9443df43 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java @@ -338,7 +338,7 @@ public class Debug { Method[] methods = t.getClass().getMethods(); int size = methods.length; - Class throwable = Throwable.class; + Class<?> throwable = Throwable.class; for (int i = 0; i < size; i++) { Method method = methods[i]; diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java index b1f89c984..de13dcd70 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java @@ -64,7 +64,7 @@ class EclipseDebugTrace implements DebugTrace { /** The value written to the trace file if a null object is being traced */ private final static String NULL_VALUE = "<null>"; //$NON-NLS-1$ /** */ - private final static SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); + private final static SecureAction secureAction = AccessController.doPrivileged(SecureAction.createSecureAction()); /** A lock object used to synchronize access to the trace file */ private final static Object writeLock = new Object(); @@ -117,7 +117,7 @@ class EclipseDebugTrace implements DebugTrace { * @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled * @param traceClass The class that the client is using to perform trace API calls */ - EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions, final Class traceClass) { + EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions, final Class<?> traceClass) { this.traceClass = traceClass != null ? traceClass.getName() : null; this.debugOptions = debugOptions; diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java index 445ad49f8..7c245f649 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java @@ -14,7 +14,6 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.*; -import java.util.Map.Entry; import org.eclipse.osgi.framework.internal.core.FrameworkProperties; import org.eclipse.osgi.service.debug.*; import org.osgi.framework.*; @@ -28,7 +27,7 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; * * @since 3.1 */ -public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustomizer { +public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustomizer<DebugOptionsListener, DebugOptionsListener> { private static final String OSGI_DEBUG = "osgi.debug"; //$NON-NLS-1$ private static final String OSGI_DEBUG_VERBOSE = "osgi.debug.verbose"; //$NON-NLS-1$ @@ -44,13 +43,13 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom /** The default name of the .options file if loading when the -debug command-line argument is used */ private static final String OPTIONS = ".options"; //$NON-NLS-1$ /** A cache of all of the bundles <code>DebugTrace</code> in the format <key,value> --> <bundle name, DebugTrace> */ - protected final static Map debugTraceCache = new HashMap(); + protected final static Map<String, DebugTrace> debugTraceCache = new HashMap<String, DebugTrace>(); /** The File object to store messages. This value may be null. */ protected File outFile = null; /** Is verbose debugging enabled? Changing this value causes a new tracing session to start. */ protected boolean verboseDebug = true; private volatile BundleContext context; - private volatile ServiceTracker listenerTracker; + private volatile ServiceTracker<DebugOptionsListener, DebugOptionsListener> listenerTracker; /** * Internal constructor to create a <code>FrameworkDebugOptions</code> singleton object. @@ -96,15 +95,14 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom e.printStackTrace(System.out); } // trim off all the blanks since properties files don't do that. - for (Iterator i = options.keySet().iterator(); i.hasNext();) { - Object key = i.next(); + for (Object key : options.keySet()) { options.put(key, ((String) options.get(key)).trim()); } } public void start(BundleContext bc) { this.context = bc; - listenerTracker = new ServiceTracker(bc, DebugOptionsListener.class.getName(), this); + listenerTracker = new ServiceTracker<DebugOptionsListener, DebugOptionsListener>(bc, DebugOptionsListener.class.getName(), this); listenerTracker.open(); } @@ -126,6 +124,7 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom return FrameworkDebugOptions.singleton; } + @SuppressWarnings("deprecation") private static URL buildURL(String spec, boolean trailingSlash) { if (spec == null) return null; @@ -194,13 +193,14 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom } } - public Map getOptions() { - Properties snapShot = new Properties(); + @SuppressWarnings({"unchecked", "rawtypes"}) + public Map<String, String> getOptions() { + Map<String, String> snapShot = new HashMap<String, String>(); synchronized (lock) { if (options != null) - snapShot.putAll(options); + snapShot.putAll((Map) options); else if (disabledOptions != null) - snapShot.putAll(disabledOptions); + snapShot.putAll((Map) disabledOptions); } return snapShot; } @@ -215,10 +215,10 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom synchronized (lock) { if (options != null) { optionsArray = new String[options.size()]; - final Iterator entrySetIterator = options.entrySet().iterator(); + final Iterator<Map.Entry<Object, Object>> entrySetIterator = options.entrySet().iterator(); int i = 0; while (entrySetIterator.hasNext()) { - Map.Entry entry = (Map.Entry) entrySetIterator.next(); + Map.Entry<Object, Object> entry = entrySetIterator.next(); optionsArray[i] = ((String) entry.getKey()) + "=" + ((String) entry.getValue()); //$NON-NLS-1$ i++; } @@ -292,17 +292,18 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom return null; } - public void setOptions(Map ops) { + @SuppressWarnings("cast") + public void setOptions(Map<String, String> ops) { if (ops == null) throw new IllegalArgumentException("The options must not be null."); //$NON-NLS-1$ Properties newOptions = new Properties(); - for (Iterator entries = ops.entrySet().iterator(); entries.hasNext();) { - Entry entry = (Entry) entries.next(); + for (Iterator<Map.Entry<String, String>> entries = ops.entrySet().iterator(); entries.hasNext();) { + Map.Entry<String, String> entry = entries.next(); if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) throw new IllegalArgumentException("Option keys and values must be of type String: " + entry.getKey() + "=" + entry.getValue()); //$NON-NLS-1$ //$NON-NLS-2$ - newOptions.put(entry.getKey(), ((String) entry.getValue()).trim()); + newOptions.put(entry.getKey(), entry.getValue().trim()); } - Set fireChangesTo = null; + Set<String> fireChangesTo = null; synchronized (lock) { if (options == null) { @@ -310,9 +311,9 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom // no events to fire return; } - fireChangesTo = new HashSet(); + fireChangesTo = new HashSet<String>(); // first check for removals - for (Iterator keys = options.keySet().iterator(); keys.hasNext();) { + for (Iterator<Object> keys = options.keySet().iterator(); keys.hasNext();) { String key = (String) keys.next(); if (!newOptions.containsKey(key)) { String symbolicName = getSymbolicName(key); @@ -321,8 +322,8 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom } } // now check for changes to existing values - for (Iterator newEntries = newOptions.entrySet().iterator(); newEntries.hasNext();) { - Entry entry = (Entry) newEntries.next(); + for (Iterator<Map.Entry<Object, Object>> newEntries = newOptions.entrySet().iterator(); newEntries.hasNext();) { + Map.Entry<Object, Object> entry = newEntries.next(); String existingValue = (String) options.get(entry.getKey()); if (!entry.getValue().equals(existingValue)) { String symbolicName = getSymbolicName((String) entry.getKey()); @@ -334,8 +335,8 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom options = newOptions; } if (fireChangesTo != null) - for (Iterator iChanges = fireChangesTo.iterator(); iChanges.hasNext();) - optionsChanged((String) iChanges.next()); + for (Iterator<String> iChanges = fireChangesTo.iterator(); iChanges.hasNext();) + optionsChanged(iChanges.next()); } /* @@ -404,11 +405,11 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom * (non-Javadoc) * @see org.eclipse.osgi.service.debug.DebugOptions#createTrace(java.lang.String, java.lang.Class) */ - public final DebugTrace newDebugTrace(String bundleSymbolicName, Class traceEntryClass) { + public final DebugTrace newDebugTrace(String bundleSymbolicName, Class<?> traceEntryClass) { DebugTrace debugTrace = null; synchronized (FrameworkDebugOptions.debugTraceCache) { - debugTrace = (DebugTrace) FrameworkDebugOptions.debugTraceCache.get(bundleSymbolicName); + debugTrace = FrameworkDebugOptions.debugTraceCache.get(bundleSymbolicName); if (debugTrace == null) { debugTrace = new EclipseDebugTrace(bundleSymbolicName, FrameworkDebugOptions.singleton, traceEntryClass); FrameworkDebugOptions.debugTraceCache.put(bundleSymbolicName, debugTrace); @@ -469,7 +470,7 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom return; // do not use the service tracker because that is only used to call all listeners initially when they are registered // here we only want the services with the specified name. - ServiceReference[] listenerRefs = null; + ServiceReference<?>[] listenerRefs = null; try { listenerRefs = bc.getServiceReferences(DebugOptionsListener.class.getName(), "(" + DebugOptions.LISTENER_SYMBOLICNAME + "=" + bundleSymbolicName + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } catch (InvalidSyntaxException e) { @@ -491,17 +492,17 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom } } - public Object addingService(ServiceReference reference) { - DebugOptionsListener listener = (DebugOptionsListener) context.getService(reference); + public DebugOptionsListener addingService(ServiceReference<DebugOptionsListener> reference) { + DebugOptionsListener listener = context.getService(reference); listener.optionsChanged(this); return listener; } - public void modifiedService(ServiceReference reference, Object service) { + public void modifiedService(ServiceReference<DebugOptionsListener> reference, DebugOptionsListener service) { // nothing } - public void removedService(ServiceReference reference, Object service) { + public void removedService(ServiceReference<DebugOptionsListener> reference, DebugOptionsListener service) { context.ungetService(reference); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java index cc9fa78ba..71b83cebf 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java @@ -27,7 +27,7 @@ public class CopyOnWriteIdentityMap<K, V> implements Map<K, V> { /** * The empty array singleton instance. */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") private static final Entry[] emptyArray = new Entry[0]; /** diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventDispatcher.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventDispatcher.java index 3e6f3cb18..18327d402 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventDispatcher.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventDispatcher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2008 IBM Corporation and others. + * Copyright (c) 2003, 2010 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,7 +19,7 @@ package org.eclipse.osgi.framework.eventmgr; * </p> * @since 3.1 */ -public interface EventDispatcher { +public interface EventDispatcher<K, V, E> { /** * This method is called once for each listener. * This method must cast the event listener object to the appropriate listener @@ -45,5 +45,5 @@ public interface EventDispatcher { * can complete the delivery of the event to the listener. * This is typically the actual event object. */ - public void dispatchEvent(Object eventListener, Object listenerObject, int eventAction, Object eventObject); + public void dispatchEvent(K eventListener, V listenerObject, int eventAction, E eventObject); } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventListeners.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventListeners.java index fee66aeb5..431e4be94 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventListeners.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventListeners.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2008 IBM Corporation and others. + * Copyright (c) 2003, 2010 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,6 +11,7 @@ package org.eclipse.osgi.framework.eventmgr; +import java.util.Map; import java.util.Set; /** @@ -24,8 +25,8 @@ import java.util.Set; * @deprecated As of 3.5. Replaced by CopyOnWriteIdentityMap. * @noextend This class is not intended to be subclassed by clients. */ -public class EventListeners { - private final CopyOnWriteIdentityMap list = new CopyOnWriteIdentityMap(); +public class EventListeners<K, V> { + private final CopyOnWriteIdentityMap<K, V> list = new CopyOnWriteIdentityMap<K, V>(); /** * Creates an empty listener list. @@ -55,7 +56,7 @@ public class EventListeners { * when the listener is to be called. This may be null * @throws IllegalArgumentException If listener is null. */ - public void addListener(Object listener, Object listenerObject) { + public void addListener(K listener, V listenerObject) { list.put(listener, listenerObject); } @@ -66,7 +67,7 @@ public class EventListeners { * @param listener This is the listener object to be removed from the list. * @throws IllegalArgumentException If listener is null. */ - public void removeListener(Object listener) { + public void removeListener(V listener) { list.remove(listener); } @@ -83,7 +84,7 @@ public class EventListeners { * Get the entry Set from the internal CopyOnWriteIdentityMap. * @return The entry Set. */ - Set entrySet() { + Set<Map.Entry<K, V>> entrySet() { return list.entrySet(); } } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventManager.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventManager.java index 2dc7188c7..9e371ee34 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventManager.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/EventManager.java @@ -13,7 +13,8 @@ package org.eclipse.osgi.framework.eventmgr; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.*; +import java.util.Map; +import java.util.Set; /** * This class is the central class for the Event Manager. Each @@ -104,7 +105,7 @@ public class EventManager { * EventThread for asynchronous dispatch of events. * Access to this field must be protected by a synchronized region. */ - private EventThread thread; + private EventThread<?, ?, ?> thread; /** * Once closed, an attempt to create a new EventThread will result in an @@ -185,22 +186,25 @@ public class EventManager { * @return EventThread to use for dispatching events asynchronously for * this EventManager. */ - synchronized EventThread getEventThread() { + synchronized <K, V, E> EventThread<K, V, E> getEventThread() { if (closed) { throw new IllegalStateException(); } if (thread == null) { /* if there is no thread, then create a new one */ - thread = (EventThread) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - EventThread t = new EventThread(threadGroup, threadName); + thread = AccessController.doPrivileged(new PrivilegedAction<EventThread<K, V, E>>() { + public EventThread<K, V, E> run() { + EventThread<K, V, E> t = new EventThread<K, V, E>(threadGroup, threadName); return t; } }); /* start the new thread */ thread.start(); } - return thread; + + @SuppressWarnings("unchecked") + EventThread<K, V, E> result = (EventThread<K, V, E>) thread; + return result; } /** @@ -217,18 +221,17 @@ public class EventManager { * @param eventObject This object was created by the event source and * is passed to this method. This is passed on to the call back object. */ - static void dispatchEvent(Set/*<Map.Entry<Object,Object>>*/listeners, EventDispatcher dispatcher, int eventAction, Object eventObject) { - for (Iterator iter = listeners.iterator(); iter.hasNext();) { /* iterate over the list of listeners */ - Map.Entry listener = (Map.Entry) iter.next(); - Object eventListener = listener.getKey(); - Object listenerObject = listener.getValue(); + static <K, V, E> void dispatchEvent(Set<Map.Entry<K, V>> listeners, EventDispatcher<K, V, E> dispatcher, int eventAction, E eventObject) { + for (Map.Entry<K, V> listener : listeners) { /* iterate over the list of listeners */ + final K eventListener = listener.getKey(); + final V listenerObject = listener.getValue(); try { /* Call the EventDispatcher to complete the delivery of the event. */ dispatcher.dispatchEvent(eventListener, listenerObject, eventAction, eventObject); } catch (Throwable t) { /* Consume and ignore any exceptions thrown by the listener */ if (DEBUG) { - System.out.println("Exception in " + listener.getKey()); //$NON-NLS-1$ + System.out.println("Exception in " + eventListener); //$NON-NLS-1$ t.printStackTrace(); } } @@ -239,7 +242,7 @@ public class EventManager { * This package private class is used for asynchronously dispatching events. */ - static class EventThread extends Thread { + static class EventThread<K, V, E> extends Thread { private static int nextThreadNumber; /** @@ -247,17 +250,17 @@ public class EventManager { * represents the items which are placed on the asynch dispatch queue. * This class is private. */ - private static class Queued { + private static class Queued<K, V, E> { /** listener list for this event */ - final Set/*<Map.Entry<Object,Object>>*/listeners; + final Set<Map.Entry<K, V>> listeners; /** dispatcher of this event */ - final EventDispatcher dispatcher; + final EventDispatcher<K, V, E> dispatcher; /** action for this event */ final int action; /** object for this event */ - final Object object; + final E object; /** next item in event queue */ - Queued next; + Queued<K, V, E> next; /** * Constructor for event queue item @@ -267,7 +270,7 @@ public class EventManager { * @param a Action for this event * @param o Object for this event */ - Queued(Set/*<Map.Entry<Object,Object>>*/l, EventDispatcher d, int a, Object o) { + Queued(Set<Map.Entry<K, V>> l, EventDispatcher<K, V, E> d, int a, E o) { listeners = l; dispatcher = d; action = a; @@ -277,9 +280,9 @@ public class EventManager { } /** item at the head of the event queue */ - private Queued head; + private Queued<K, V, E> head; /** item at the tail of the event queue */ - private Queued tail; + private Queued<K, V, E> tail; /** if false the thread must terminate */ private volatile boolean running; @@ -330,7 +333,7 @@ public class EventManager { public void run() { try { while (true) { - Queued item = getNextEvent(); + Queued<K, V, E> item = getNextEvent(); if (item == null) { return; } @@ -363,12 +366,12 @@ public class EventManager { * @param a Action for this event * @param o Object for this event */ - synchronized void postEvent(Set/*<Map.Entry<Object,Object>>*/l, EventDispatcher d, int a, Object o) { + synchronized void postEvent(Set<Map.Entry<K, V>> l, EventDispatcher<K, V, E> d, int a, E o) { if (!isAlive()) { /* If the thread is not alive, throw an exception */ throw new IllegalStateException(); } - Queued item = new Queued(l, d, a, o); + Queued<K, V, E> item = new Queued<K, V, E>(l, d, a, o); if (head == null) /* if the queue was empty */ { @@ -391,7 +394,7 @@ public class EventManager { * @return The Queued removed from the top of the queue or null * if the thread has been requested to stop. */ - private synchronized Queued getNextEvent() { + private synchronized Queued<K, V, E> getNextEvent() { while (running && (head == null)) { try { wait(); @@ -404,7 +407,7 @@ public class EventManager { return null; } - Queued item = head; + Queued<K, V, E> item = head; head = item.next; if (head == null) { tail = null; diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/ListenerQueue.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/ListenerQueue.java index 0f63ecc18..6f1d7319d 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/ListenerQueue.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/eventmgr/ListenerQueue.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2009 IBM Corporation and others. + * Copyright (c) 2003, 2010 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,7 +11,8 @@ package org.eclipse.osgi.framework.eventmgr; -import java.util.*; +import java.util.Map; +import java.util.Set; import org.eclipse.osgi.framework.eventmgr.EventManager.EventThread; /** @@ -33,7 +34,7 @@ import org.eclipse.osgi.framework.eventmgr.EventManager.EventThread; * added to the list. * @since 3.1 */ -public class ListenerQueue { +public class ListenerQueue<K, V, E> { /** * EventManager with which this queue is associated. */ @@ -41,7 +42,7 @@ public class ListenerQueue { /** * A list of listener lists. */ - private final Map /*<Set<Map.Entry<Object,Object>>,EventDispatcher>*/queue; + private final Map<Set<Map.Entry<K, V>>, EventDispatcher<K, V, E>> queue; /** * Once the listener queue has been used to dispatch an event, @@ -62,7 +63,7 @@ public class ListenerQueue { } this.manager = manager; - queue = new CopyOnWriteIdentityMap(); + queue = new CopyOnWriteIdentityMap<Set<Map.Entry<K, V>>, EventDispatcher<K, V, E>>(); readOnly = false; } @@ -79,7 +80,7 @@ public class ListenerQueue { * @throws IllegalStateException If called after one of the dispatch methods has been called. * @deprecated As of 3.5. Replaced by {@link #queueListeners(Set, EventDispatcher)}. */ - public void queueListeners(EventListeners listeners, EventDispatcher dispatcher) { + public void queueListeners(EventListeners<K, V> listeners, EventDispatcher<K, V, E> dispatcher) { queueListeners(listeners.entrySet(), dispatcher); } @@ -97,7 +98,7 @@ public class ListenerQueue { * @throws IllegalStateException If called after one of the dispatch methods has been called. * @since 3.5 */ - public synchronized void queueListeners(Set/*<Map.Entry<Object,Object>>*/listeners, EventDispatcher dispatcher) { + public synchronized void queueListeners(Set<Map.Entry<K, V>> listeners, EventDispatcher<K, V, E> dispatcher) { if (readOnly) { throw new IllegalStateException(); } @@ -115,15 +116,14 @@ public class ListenerQueue { * @param eventAction This value is passed to the EventDispatcher. * @param eventObject This object is passed to the EventDispatcher. */ - public void dispatchEventAsynchronous(int eventAction, Object eventObject) { + public void dispatchEventAsynchronous(int eventAction, E eventObject) { synchronized (this) { readOnly = true; } - EventThread eventThread = manager.getEventThread(); + EventThread<K, V, E> eventThread = manager.getEventThread(); synchronized (eventThread) { /* synchronize on the EventThread to ensure no interleaving of posting to the event thread */ - for (Iterator iter = queue.entrySet().iterator(); iter.hasNext();) { /* iterate over the list of listener lists */ - Map.Entry entry = (Map.Entry) iter.next(); - eventThread.postEvent((Set) entry.getKey(), (EventDispatcher) entry.getValue(), eventAction, eventObject); + for (Map.Entry<Set<Map.Entry<K, V>>, EventDispatcher<K, V, E>> entry : queue.entrySet()) { /* iterate over the list of listener lists */ + eventThread.postEvent(entry.getKey(), entry.getValue(), eventAction, eventObject); } } } @@ -138,15 +138,14 @@ public class ListenerQueue { * @param eventAction This value is passed to the EventDispatcher. * @param eventObject This object is passed to the EventDispatcher. */ - public void dispatchEventSynchronous(int eventAction, Object eventObject) { + public void dispatchEventSynchronous(int eventAction, E eventObject) { synchronized (this) { readOnly = true; } // We can't guarantee any delivery order for synchronous events. // Attempts to do so result in deadly embraces. - for (Iterator iter = queue.entrySet().iterator(); iter.hasNext();) { /* iterate over the list of listener lists */ - Map.Entry entry = (Map.Entry) iter.next(); - EventManager.dispatchEvent((Set) entry.getKey(), (EventDispatcher) entry.getValue(), eventAction, eventObject); + for (Map.Entry<Set<Map.Entry<K, V>>, EventDispatcher<K, V, E>> entry : queue.entrySet()) { /* iterate over the list of listener lists */ + EventManager.dispatchEvent(entry.getKey(), entry.getValue(), eventAction, eventObject); } } } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/FrameworkProperties.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/FrameworkProperties.java index cb2878b0c..7cf733628 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/FrameworkProperties.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/FrameworkProperties.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Cognos Incorporated, IBM Corporation and others. + * Copyright (c) 2006, 2010 Cognos Incorporated, 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 @@ -85,7 +85,7 @@ public class FrameworkProperties { return properties; } - public static synchronized void setProperties(Map input) { + public static synchronized void setProperties(Map<String, String> input) { if (input == null) { // just use internal props; note that this will reuse a previous set of properties if they were set internalGetProperties("false"); //$NON-NLS-1$ @@ -93,8 +93,8 @@ public class FrameworkProperties { } properties = null; Properties toSet = internalGetProperties("false"); //$NON-NLS-1$ - for (Iterator keys = input.keySet().iterator(); keys.hasNext();) { - String key = (String) keys.next(); + for (Iterator<String> keys = input.keySet().iterator(); keys.hasNext();) { + String key = keys.next(); Object value = input.get(key); if (value instanceof String) { toSet.setProperty(key, (String) value); @@ -135,7 +135,7 @@ public class FrameworkProperties { public static String decode(String urlString) { //try to use Java 1.4 method if available try { - Class clazz = URLDecoder.class; + Class<? extends URLDecoder> clazz = URLDecoder.class; Method method = clazz.getDeclaredMethod("decode", new Class[] {String.class, String.class}); //$NON-NLS-1$ //first encode '+' characters, because URLDecoder incorrectly converts //them to spaces on certain class library implementations. diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java index 1f6ac61fc..1d6cba76c 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2010 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 @@ -126,7 +126,7 @@ public class ReliableFile { private File referenceFile; /** List of checksum file objects: File => specific ReliableFile generation */ - private static Hashtable cacheFiles = new Hashtable(20); + private static Hashtable<File, CacheInfo> cacheFiles = new Hashtable<File, CacheInfo>(20); private File inputFile = null; private File outputFile = null; @@ -193,7 +193,7 @@ public class ReliableFile { String[] files = parent.list(); if (files == null) return null; - ArrayList list = new ArrayList(defaultMaxGenerations); + List<Integer> list = new ArrayList<Integer>(defaultMaxGenerations); if (file.exists()) list.add(new Integer(0)); //base file exists for (int i = 0; i < files.length; i++) { @@ -263,7 +263,7 @@ public class ReliableFile { InputStream is = null; CacheInfo info; synchronized (cacheFiles) { - info = (CacheInfo) cacheFiles.get(file); + info = cacheFiles.get(file); long timeStamp = file.lastModified(); if (info == null || timeStamp != info.timeStamp) { try { @@ -354,7 +354,7 @@ public class ReliableFile { } try { - CacheInfo info = (CacheInfo) cacheFiles.get(inputFile); + CacheInfo info = cacheFiles.get(inputFile); appendChecksum = info.checksum; OutputStream os = new FileOutputStream(tmpFile); if (info.filetype == FILETYPE_NOSIGNATURE) { @@ -443,7 +443,7 @@ public class ReliableFile { // backup files. for (int idx = 0, count = generationCount - rmCount; idx < count; idx++) { File file = new File(parent, name + '.' + generations[idx]); - CacheInfo info = (CacheInfo) cacheFiles.get(file); + CacheInfo info = cacheFiles.get(file); if (info != null) { if (info.filetype == FILETYPE_CORRUPT) rmCount--; @@ -623,7 +623,7 @@ public class ReliableFile { if (!directory.isDirectory()) throw new IOException("Not a valid directory"); //$NON-NLS-1$ String files[] = directory.list(); - HashSet list = new HashSet(files.length / 2); + Set<String> list = new HashSet<String>(files.length / 2); for (int idx = 0; idx < files.length; idx++) { String file = files[idx]; int pos = file.lastIndexOf('.'); @@ -642,8 +642,8 @@ public class ReliableFile { } files = new String[list.size()]; int idx = 0; - for (Iterator iter = list.iterator(); iter.hasNext();) { - files[idx++] = (String) iter.next(); + for (Iterator<String> iter = list.iterator(); iter.hasNext();) { + files[idx++] = iter.next(); } return files; } @@ -695,7 +695,7 @@ public class ReliableFile { */ int getSignatureSize() throws IOException { if (inputFile != null) { - CacheInfo info = (CacheInfo) cacheFiles.get(inputFile); + CacheInfo info = cacheFiles.get(inputFile); if (info != null) { switch (info.filetype) { case FILETYPE_VALID : diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java index 400218d62..2e654b16c 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java @@ -30,8 +30,8 @@ public class SecureAction { private AccessControlContext controlContext; // This ClassLoader is used in loadSystemClass if System.getClassLoader() returns null - static final ClassLoader bootClassLoader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + static final ClassLoader bootClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { return new ClassLoader(Object.class.getClassLoader()) { /* boot class loader */}; } }); @@ -54,9 +54,9 @@ public class SecureAction { * </pre> * @return a privileged action object that can be used to construct a SecureAction object. */ - public static PrivilegedAction createSecureAction() { - return new PrivilegedAction() { - public Object run() { + public static PrivilegedAction<SecureAction> createSecureAction() { + return new PrivilegedAction<SecureAction>() { + public SecureAction run() { return new SecureAction(); } }; @@ -71,8 +71,8 @@ public class SecureAction { public String getProperty(final String property) { if (System.getSecurityManager() == null) return FrameworkProperties.getProperty(property); - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { return FrameworkProperties.getProperty(property); } }, controlContext); @@ -89,8 +89,8 @@ public class SecureAction { public String getProperty(final String property, final String def) { if (System.getSecurityManager() == null) return FrameworkProperties.getProperty(property, def); - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { return FrameworkProperties.getProperty(property, def); } }, controlContext); @@ -104,8 +104,8 @@ public class SecureAction { public Properties getProperties() { if (System.getSecurityManager() == null) return FrameworkProperties.getProperties(); - return (Properties) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Properties>() { + public Properties run() { return FrameworkProperties.getProperties(); } }, controlContext); @@ -122,8 +122,8 @@ public class SecureAction { if (System.getSecurityManager() == null) return new FileInputStream(file); try { - return (FileInputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws FileNotFoundException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<FileInputStream>() { + public FileInputStream run() throws FileNotFoundException { return new FileInputStream(file); } }, controlContext); @@ -146,8 +146,8 @@ public class SecureAction { if (System.getSecurityManager() == null) return new FileOutputStream(file.getAbsolutePath(), append); try { - return (FileOutputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws FileNotFoundException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<FileOutputStream>() { + public FileOutputStream run() throws FileNotFoundException { return new FileOutputStream(file.getAbsolutePath(), append); } }, controlContext); @@ -167,11 +167,11 @@ public class SecureAction { public long length(final File file) { if (System.getSecurityManager() == null) return file.length(); - return ((Long) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Long>() { + public Long run() { return new Long(file.length()); } - }, controlContext)).longValue(); + }, controlContext).longValue(); } /** @@ -185,8 +185,8 @@ public class SecureAction { if (System.getSecurityManager() == null) return file.getCanonicalPath(); try { - return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() { + public String run() throws IOException { return file.getCanonicalPath(); } }, controlContext); @@ -206,11 +206,11 @@ public class SecureAction { public boolean exists(final File file) { if (System.getSecurityManager() == null) return file.exists(); - return ((Boolean) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { + public Boolean run() { return file.exists() ? Boolean.TRUE : Boolean.FALSE; } - }, controlContext)).booleanValue(); + }, controlContext).booleanValue(); } /** @@ -222,11 +222,11 @@ public class SecureAction { public boolean isDirectory(final File file) { if (System.getSecurityManager() == null) return file.isDirectory(); - return ((Boolean) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { + public Boolean run() { return file.isDirectory() ? Boolean.TRUE : Boolean.FALSE; } - }, controlContext)).booleanValue(); + }, controlContext).booleanValue(); } /** @@ -238,11 +238,11 @@ public class SecureAction { public long lastModified(final File file) { if (System.getSecurityManager() == null) return file.lastModified(); - return ((Long) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Long>() { + public Long run() { return new Long(file.lastModified()); } - }, controlContext)).longValue(); + }, controlContext).longValue(); } /** @@ -254,8 +254,8 @@ public class SecureAction { public String[] list(final File file) { if (System.getSecurityManager() == null) return file.list(); - return (String[]) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<String[]>() { + public String[] run() { return file.list(); } }, controlContext); @@ -273,8 +273,8 @@ public class SecureAction { if (System.getSecurityManager() == null) return new ZipFile(file); try { - return (ZipFile) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<ZipFile>() { + public ZipFile run() throws IOException { return new ZipFile(file); } }, controlContext); @@ -309,8 +309,8 @@ public class SecureAction { if (System.getSecurityManager() == null) return new URL(protocol, host, port, file, handler); try { - return (URL) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws MalformedURLException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() { + public URL run() throws MalformedURLException { return new URL(protocol, host, port, file, handler); } }, controlContext); @@ -332,8 +332,8 @@ public class SecureAction { public Thread createThread(final Runnable target, final String name, final ClassLoader contextLoader) { if (System.getSecurityManager() == null) return createThread0(target, name, contextLoader); - return (Thread) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<Thread>() { + public Thread run() { return createThread0(target, name, contextLoader); } }, controlContext); @@ -353,11 +353,11 @@ public class SecureAction { * @param context the BundleContext * @return a service object */ - public Object getService(final ServiceReference reference, final BundleContext context) { + public <S> S getService(final ServiceReference<S> reference, final BundleContext context) { if (System.getSecurityManager() == null) return context.getService(reference); - return AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction<S>() { + public S run() { return context.getService(reference); } }, controlContext); @@ -370,12 +370,12 @@ public class SecureAction { * @return a Class * @throws ClassNotFoundException */ - public Class forName(final String name) throws ClassNotFoundException { + public Class<?> forName(final String name) throws ClassNotFoundException { if (System.getSecurityManager() == null) return Class.forName(name); try { - return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { + return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { + public Class<?> run() throws Exception { return Class.forName(name); } }, controlContext); @@ -393,14 +393,14 @@ public class SecureAction { * @return a Class * @throws ClassNotFoundException */ - public Class loadSystemClass(final String name) throws ClassNotFoundException { + public Class<?> loadSystemClass(final String name) throws ClassNotFoundException { if (System.getSecurityManager() == null) { ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); return (systemClassLoader != null) ? systemClassLoader.loadClass(name) : bootClassLoader.loadClass(name); } try { - return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { + return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { + public Class<?> run() throws Exception { ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); return (systemClassLoader != null) ? systemClassLoader.loadClass(name) : bootClassLoader.loadClass(name); } @@ -416,12 +416,12 @@ public class SecureAction { * Opens a ServiceTracker. Same as calling tracker.open() * @param tracker the ServiceTracker to open. */ - public void open(final ServiceTracker tracker) { + public void open(final ServiceTracker<?, ?> tracker) { if (System.getSecurityManager() == null) { tracker.open(); return; } - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { tracker.open(); return null; @@ -441,7 +441,7 @@ public class SecureAction { return; } try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws BundleException { bundle.start(options); return null; diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java index 9e6b3bd2e..9f9bc254f 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/debug/DebugOptions.java @@ -108,7 +108,7 @@ public interface DebugOptions { * @return a snapshot of the current options. * @since 3.6 */ - public Map /*<String, String>*/getOptions(); + public Map<String, String> getOptions(); /** * Sets the identified option to the identified value. If debug is @@ -134,7 +134,7 @@ public interface DebugOptions { * @param options the new set of options * @since 3.6 */ - public abstract void setOptions(Map /*<String, String>*/options); + public abstract void setOptions(Map<String, String> options); /** * Removes the identified option. If debug is not enabled then @@ -215,5 +215,5 @@ public interface DebugOptions { * @return A new or existing <code>DebugTrace</code> object for the specified plug-in ID * @since 3.5 */ - public abstract DebugTrace newDebugTrace(String bundleSymbolicName, Class traceEntryClass); + public abstract DebugTrace newDebugTrace(String bundleSymbolicName, Class<?> traceEntryClass); }
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java index 3ebfe71c1..baf06cda5 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java @@ -86,7 +86,7 @@ import org.eclipse.osgi.framework.util.SecureAction; public final class StorageManager { private static final int FILETYPE_STANDARD = 0; private static final int FILETYPE_RELIABLEFILE = 1; - private static final SecureAction secure = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); + private static final SecureAction secure = AccessController.doPrivileged(SecureAction.createSecureAction()); private static final boolean tempCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanTempFiles")).booleanValue(); //$NON-NLS-1$ private static final boolean openCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnOpen")).booleanValue(); //$NON-NLS-1$ private static final String MANAGER_FOLDER = ".manager"; //$NON-NLS-1$ @@ -320,7 +320,8 @@ public final class StorageManager { public String[] getManagedFiles() { if (!open) return null; - Set set = table.keySet(); + Set<Object> set = table.keySet(); + @SuppressWarnings("cast") String[] keys = (String[]) set.toArray(new String[set.size()]); String[] result = new String[keys.length]; for (int i = 0; i < keys.length; i++) @@ -494,7 +495,7 @@ public final class StorageManager { } } tableStamp = stamp; - for (Enumeration e = diskTable.keys(); e.hasMoreElements();) { + for (Enumeration<Object> e = diskTable.keys(); e.hasMoreElements();) { String file = (String) e.nextElement(); String value = diskTable.getProperty(file); if (value != null) { @@ -531,7 +532,7 @@ public final class StorageManager { updateTable(); Properties props = new Properties(); - for (Enumeration e = table.keys(); e.hasMoreElements();) { + for (Enumeration<Object> e = table.keys(); e.hasMoreElements();) { String file = (String) e.nextElement(); Entry entry = (Entry) table.get(file); String value; @@ -610,9 +611,9 @@ public final class StorageManager { //If we are here it is because we are the last instance running. After locking the table and getting its latest content, remove all the backup files and change the table updateTable(); - Collection managedFiles = table.entrySet(); - for (Iterator iter = managedFiles.iterator(); iter.hasNext();) { - Map.Entry fileEntry = (Map.Entry) iter.next(); + Collection<Map.Entry<Object, Object>> managedFiles = table.entrySet(); + for (Iterator<Map.Entry<Object, Object>> iter = managedFiles.iterator(); iter.hasNext();) { + Map.Entry<Object, Object> fileEntry = iter.next(); String fileName = (String) fileEntry.getKey(); Entry info = (Entry) fileEntry.getValue(); if (info.getFileType() == FILETYPE_RELIABLEFILE) { diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java index db3185ac7..f19cbd909 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java @@ -96,12 +96,12 @@ public class ManifestElement { /** * The table of attributes for the manifest element. */ - private Hashtable attributes; + private Hashtable<String, Object> attributes; /** * The table of directives for the manifest element. */ - private Hashtable directives; + private Hashtable<String, Object> directives; /** * Constructs an empty manifest element with no value or attributes. @@ -192,7 +192,7 @@ public class ManifestElement { * * @return the enumeration of attribute keys or null if none exist. */ - public Enumeration getKeys() { + public Enumeration<String> getKeys() { return getTableKeys(attributes); } @@ -245,7 +245,7 @@ public class ManifestElement { * * @return the enumeration of directive keys or <code>null</code> */ - public Enumeration getDirectiveKeys() { + public Enumeration<String> getDirectiveKeys() { return getTableKeys(directives); } @@ -262,7 +262,7 @@ public class ManifestElement { /* * Return the last value associated with the given key in the specified table. */ - private String getTableValue(Hashtable table, String key) { + private String getTableValue(Hashtable<String, Object> table, String key) { if (table == null) return null; Object result = table.get(key); @@ -271,15 +271,16 @@ public class ManifestElement { if (result instanceof String) return (String) result; - ArrayList valueList = (ArrayList) result; + @SuppressWarnings("unchecked") + List<String> valueList = (List<String>) result; //return the last value - return (String) valueList.get(valueList.size() - 1); + return valueList.get(valueList.size() - 1); } /* * Return the values associated with the given key in the specified table. */ - private String[] getTableValues(Hashtable table, String key) { + private String[] getTableValues(Hashtable<String, Object> table, String key) { if (table == null) return null; Object result = table.get(key); @@ -287,14 +288,15 @@ public class ManifestElement { return null; if (result instanceof String) return new String[] {(String) result}; - ArrayList valueList = (ArrayList) result; - return (String[]) valueList.toArray(new String[valueList.size()]); + @SuppressWarnings("unchecked") + List<String> valueList = (List<String>) result; + return valueList.toArray(new String[valueList.size()]); } /* * Return an enumeration of table keys for the specified table. */ - private Enumeration getTableKeys(Hashtable table) { + private Enumeration<String> getTableKeys(Hashtable<String, Object> table) { if (table == null) return null; return table.keys(); @@ -305,19 +307,20 @@ public class ManifestElement { * for this key, then create an array list from the current value (if necessary) and * append the new value to the end of the list. */ - private Hashtable addTableValue(Hashtable table, String key, String value) { + @SuppressWarnings("unchecked") + private Hashtable<String, Object> addTableValue(Hashtable<String, Object> table, String key, String value) { if (table == null) { - table = new Hashtable(7); + table = new Hashtable<String, Object>(7); } Object curValue = table.get(key); if (curValue != null) { - ArrayList newList; + List<String> newList; // create a list to contain multiple values - if (curValue instanceof ArrayList) { - newList = (ArrayList) curValue; + if (curValue instanceof List) { + newList = (List<String>) curValue; } else { - newList = new ArrayList(5); - newList.add(curValue); + newList = new ArrayList<String>(5); + newList.add((String) curValue); } newList.add(value); table.put(key, newList); @@ -342,13 +345,13 @@ public class ManifestElement { public static ManifestElement[] parseHeader(String header, String value) throws BundleException { if (value == null) return (null); - ArrayList headerElements = new ArrayList(10); + List<ManifestElement> headerElements = new ArrayList<ManifestElement>(10); Tokenizer tokenizer = new Tokenizer(value); parseloop: while (true) { String next = tokenizer.getString(";,"); //$NON-NLS-1$ if (next == null) throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR); - ArrayList headerValues = new ArrayList(); + List<String> headerValues = new ArrayList<String>(); StringBuffer headerValue = new StringBuffer(next); headerValues.add(next); @@ -381,7 +384,7 @@ public class ManifestElement { } } // found the header value create a manifestElement for it. - ManifestElement manifestElement = new ManifestElement(headerValue.toString(), (String[]) headerValues.toArray(new String[headerValues.size()])); + ManifestElement manifestElement = new ManifestElement(headerValue.toString(), headerValues.toArray(new String[headerValues.size()])); // now add any attributes/directives for the manifestElement. while (c == '=' || c == ':') { @@ -442,7 +445,7 @@ public class ManifestElement { if (size == 0) return (null); - ManifestElement[] result = (ManifestElement[]) headerElements.toArray(new ManifestElement[size]); + ManifestElement[] result = headerElements.toArray(new ManifestElement[size]); return (result); } @@ -470,14 +473,14 @@ public class ManifestElement { public static String[] getArrayFromList(String stringList, String separator) { if (stringList == null || stringList.trim().length() == 0) return new String[0]; - ArrayList list = new ArrayList(); + List<String> list = new ArrayList<String>(); StringTokenizer tokens = new StringTokenizer(stringList, separator); while (tokens.hasMoreTokens()) { String token = tokens.nextToken().trim(); if (token.length() != 0) list.add(token); } - return (String[]) list.toArray(new String[list.size()]); + return list.toArray(new String[list.size()]); } /** @@ -495,9 +498,9 @@ public class ManifestElement { * @throws IOException if an error occurs while reading the manifest * @return the map with the header/value pairs from the bundle manifest */ - public static Map parseBundleManifest(InputStream manifest, Map headers) throws IOException, BundleException { + public static Map<String, String> parseBundleManifest(InputStream manifest, Map<String, String> headers) throws IOException, BundleException { if (headers == null) - headers = new HashMap(); + headers = new HashMap<String, String>(); BufferedReader br; try { br = new BufferedReader(new InputStreamReader(manifest, "UTF8")); //$NON-NLS-1$ @@ -561,20 +564,20 @@ public class ManifestElement { } public String toString() { - Enumeration attrKeys = getKeys(); - Enumeration directiveKeys = getDirectiveKeys(); + Enumeration<String> attrKeys = getKeys(); + Enumeration<String> directiveKeys = getDirectiveKeys(); if (attrKeys == null && directiveKeys == null) return mainValue; StringBuffer result = new StringBuffer(mainValue); if (attrKeys != null) { while (attrKeys.hasMoreElements()) { - String key = (String) attrKeys.nextElement(); + String key = attrKeys.nextElement(); addValues(false, key, getAttributes(key), result); } } if (directiveKeys != null) { while (directiveKeys.hasMoreElements()) { - String key = (String) directiveKeys.nextElement(); + String key = directiveKeys.nextElement(); addValues(true, key, getDirectives(key), result); } } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java index 76ee19bb8..c7776d2ff 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java @@ -135,12 +135,12 @@ public abstract class NLS { * @param baseName the base name of a fully qualified message properties file. * @param clazz the class where the constants will exist */ - public static void initializeMessages(final String baseName, final Class clazz) { + public static void initializeMessages(final String baseName, final Class<?> clazz) { if (System.getSecurityManager() == null) { load(baseName, clazz); return; } - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { load(baseName, clazz); return null; @@ -244,7 +244,7 @@ public abstract class NLS { if (nlSuffixes == null) { //build list of suffixes for loading resource bundles String nl = Locale.getDefault().toString(); - ArrayList result = new ArrayList(4); + List<String> result = new ArrayList<String>(4); int lastSeparator; while (true) { result.add('_' + nl + EXTENSION); @@ -255,7 +255,7 @@ public abstract class NLS { } //add the empty suffix last (most general) result.add(EXTENSION); - nlSuffixes = (String[]) result.toArray(new String[result.size()]); + nlSuffixes = result.toArray(new String[result.size()]); } root = root.replace('.', '/'); String[] variants = new String[nlSuffixes.length]; @@ -264,7 +264,7 @@ public abstract class NLS { return variants; } - private static void computeMissingMessages(String bundleName, Class clazz, Map fieldMap, Field[] fieldArray, boolean isAccessible) { + private static void computeMissingMessages(String bundleName, Class<?> clazz, Map<Object, Object> fieldMap, Field[] fieldArray, boolean isAccessible) { // iterate over the fields in the class to make sure that there aren't any empty ones final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; final int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; @@ -297,7 +297,7 @@ public abstract class NLS { /* * Load the given resource bundle using the specified class loader. */ - static void load(final String bundleName, Class clazz) { + static void load(final String bundleName, Class<?> clazz) { long start = System.currentTimeMillis(); final Field[] fieldArray = clazz.getDeclaredFields(); ClassLoader loader = clazz.getClassLoader(); @@ -306,7 +306,7 @@ public abstract class NLS { //build a map of field names to Field objects final int len = fieldArray.length; - Map fields = new HashMap(len * 2); + Map<Object, Object> fields = new HashMap<Object, Object>(len * 2); for (int i = 0; i < len; i++) fields.put(fieldArray[i].getName(), fieldArray[i]); @@ -387,10 +387,10 @@ public abstract class NLS { private static final long serialVersionUID = 1L; private final String bundleName; - private final Map fields; + private final Map<Object, Object> fields; private final boolean isAccessible; - public MessagesProperties(Map fieldMap, String bundleName, boolean isAccessible) { + public MessagesProperties(Map<Object, Object> fieldMap, String bundleName, boolean isAccessible) { super(); this.fields = fieldMap; this.bundleName = bundleName; |