You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2014/11/27 16:14:40 UTC
svn commit: r1642172 [3/4] - in /felix/trunk/connect: ./
src/main/java/org/apache/felix/connect/
src/main/java/org/apache/felix/connect/felix/framework/
src/main/java/org/apache/felix/connect/felix/framework/capabilityset/
src/main/java/org/apache/feli...
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/CapabilitySet.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/CapabilitySet.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/CapabilitySet.java Thu Nov 27 15:14:39 2014
@@ -31,33 +31,34 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
+import org.osgi.resource.Capability;
+
import org.apache.felix.connect.felix.framework.util.StringComparator;
-import org.osgi.framework.wiring.BundleCapability;
-public class CapabilitySet
+public class CapabilitySet<T extends Capability>
{
- private final Map<String, Map<Object, Set<BundleCapability>>> m_indices;
- private final Set<BundleCapability> m_capSet = new HashSet<BundleCapability>();
+ private final Map<String, Map<Object, Set<T>>> m_indices;
+ private final Set<T> m_capSet = new HashSet<T>();
public CapabilitySet(List<String> indexProps, boolean caseSensitive)
{
m_indices = (caseSensitive)
- ? new TreeMap<String, Map<Object, Set<BundleCapability>>>()
- : new TreeMap<String, Map<Object, Set<BundleCapability>>>(
- new StringComparator(false));
+ ? new TreeMap<String, Map<Object, Set<T>>>()
+ : new TreeMap<String, Map<Object, Set<T>>>(
+ new StringComparator(false));
for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
{
m_indices.put(
- indexProps.get(i), new HashMap<Object, Set<BundleCapability>>());
+ indexProps.get(i), new HashMap<Object, Set<T>>());
}
}
- public void addCapability(BundleCapability cap)
+ public void addCapability(T cap)
{
m_capSet.add(cap);
// Index capability.
- for (Entry<String, Map<Object, Set<BundleCapability>>> entry : m_indices.entrySet())
+ for (Entry<String, Map<Object, Set<T>>> entry : m_indices.entrySet())
{
Object value = cap.getAttributes().get(entry.getKey());
if (value != null)
@@ -67,7 +68,7 @@ public class CapabilitySet
value = convertArrayToList(value);
}
- Map<Object, Set<BundleCapability>> index = entry.getValue();
+ Map<Object, Set<T>> index = entry.getValue();
if (value instanceof Collection)
{
@@ -86,22 +87,22 @@ public class CapabilitySet
}
private void indexCapability(
- Map<Object, Set<BundleCapability>> index, BundleCapability cap, Object capValue)
+ Map<Object, Set<T>> index, T cap, Object capValue)
{
- Set<BundleCapability> caps = index.get(capValue);
+ Set<T> caps = index.get(capValue);
if (caps == null)
{
- caps = new HashSet<BundleCapability>();
+ caps = new HashSet<T>();
index.put(capValue, caps);
}
caps.add(cap);
}
- public void removeCapability(BundleCapability cap)
+ public void removeCapability(T cap)
{
if (m_capSet.remove(cap))
{
- for (Entry<String, Map<Object, Set<BundleCapability>>> entry : m_indices.entrySet())
+ for (Entry<String, Map<Object, Set<T>>> entry : m_indices.entrySet())
{
Object value = cap.getAttributes().get(entry.getKey());
if (value != null)
@@ -111,7 +112,7 @@ public class CapabilitySet
value = convertArrayToList(value);
}
- Map<Object, Set<BundleCapability>> index = entry.getValue();
+ Map<Object, Set<T>> index = entry.getValue();
if (value instanceof Collection)
{
@@ -131,9 +132,9 @@ public class CapabilitySet
}
private void deindexCapability(
- Map<Object, Set<BundleCapability>> index, BundleCapability cap, Object value)
+ Map<Object, Set<T>> index, T cap, Object value)
{
- Set<BundleCapability> caps = index.get(value);
+ Set<T> caps = index.get(value);
if (caps != null)
{
caps.remove(cap);
@@ -144,18 +145,18 @@ public class CapabilitySet
}
}
- public Set<BundleCapability> match(SimpleFilter sf, boolean obeyMandatory)
+ public Set<T> match(SimpleFilter sf, boolean obeyMandatory)
{
- Set<BundleCapability> matches = match(m_capSet, sf);
- return matches;
- /* return (obeyMandatory)
+ Set<T> matches = match(m_capSet, sf);
+ return /* (obeyMandatory)
? matchMandatory(matches, sf)
- : matches;*/
+ : */ matches;
}
- private Set<BundleCapability> match(Set<BundleCapability> caps, SimpleFilter sf)
+ @SuppressWarnings("unchecked")
+ private Set<T> match(Set<T> caps, SimpleFilter sf)
{
- Set<BundleCapability> matches = new HashSet<BundleCapability>();
+ Set<T> matches = new HashSet<T>();
if (sf.getOperation() == SimpleFilter.MATCH_ALL)
{
@@ -179,9 +180,9 @@ public class CapabilitySet
// Evaluate each subfilter against the remaining capabilities.
// For OR we calculate the union of each subfilter.
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
- for (int i = 0; i < sfs.size(); i++)
+ for (SimpleFilter sf1 : sfs)
{
- matches.addAll(match(caps, sfs.get(i)));
+ matches.addAll(match(caps, sf1));
}
}
else if (sf.getOperation() == SimpleFilter.NOT)
@@ -190,17 +191,17 @@ public class CapabilitySet
// For OR we calculate the union of each subfilter.
matches.addAll(caps);
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
- for (int i = 0; i < sfs.size(); i++)
+ for (SimpleFilter sf1 : sfs)
{
- matches.removeAll(match(caps, sfs.get(i)));
+ matches.removeAll(match(caps, sf1));
}
}
else
{
- Map<Object, Set<BundleCapability>> index = m_indices.get(sf.getName());
+ Map<Object, Set<T>> index = m_indices.get(sf.getName());
if ((sf.getOperation() == SimpleFilter.EQ) && (index != null))
{
- Set<BundleCapability> existingCaps = index.get(sf.getValue());
+ Set<T> existingCaps = index.get(sf.getValue());
if (existingCaps != null)
{
matches.addAll(existingCaps);
@@ -209,9 +210,8 @@ public class CapabilitySet
}
else
{
- for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
+ for (T cap : caps)
{
- BundleCapability cap = it.next();
Object lhs = cap.getAttributes().get(sf.getName());
if (lhs != null)
{
@@ -227,12 +227,13 @@ public class CapabilitySet
return matches;
}
- /* public static boolean matches(BundleCapability cap, SimpleFilter sf)
- {
- return matchesInternal(cap, sf) && matchMandatory(cap, sf);
- }
-*/
- private static boolean matchesInternal(BundleCapability cap, SimpleFilter sf)
+ /* public static boolean matches(BundleCapability cap, SimpleFilter sf)
+ {
+ return matchesInternal(cap, sf) && matchMandatory(cap, sf);
+ }
+ */
+ @SuppressWarnings("unchecked")
+ private boolean matchesInternal(T cap, SimpleFilter sf)
{
boolean matched = true;
@@ -268,9 +269,9 @@ public class CapabilitySet
// Evaluate each subfilter against the remaining capabilities.
// For OR we calculate the union of each subfilter.
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
- for (int i = 0; i < sfs.size(); i++)
+ for (SimpleFilter sf1 : sfs)
{
- matched = !(matchesInternal(cap, sfs.get(i)));
+ matched = !(matchesInternal(cap, sf1));
}
}
else
@@ -286,12 +287,13 @@ public class CapabilitySet
return matched;
}
- /* private static Set<BundleCapability> matchMandatory(
- Set<BundleCapability> caps, SimpleFilter sf)
+ /*
+ private Set<T> matchMandatory(
+ Set<T> caps, SimpleFilter sf)
{
- for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
+ for (Iterator<T> it = caps.iterator(); it.hasNext(); )
{
- BundleCapability cap = it.next();
+ T cap = it.next();
if (!matchMandatory(cap, sf))
{
it.remove();
@@ -300,12 +302,12 @@ public class CapabilitySet
return caps;
}
- private static boolean matchMandatory(BundleCapability cap, SimpleFilter sf)
+ private boolean matchMandatory(T cap, SimpleFilter sf)
{
Map<String, Object> attrs = cap.getAttributes();
for (Entry<String, Object> entry : attrs.entrySet())
{
- if (((BundleCapability) cap).isAttributeMandatory(entry.getKey())
+ if (((T) cap).isAttributeMandatory(entry.getKey())
&& !matchMandatoryAttrbute(entry.getKey(), sf))
{
return false;
@@ -314,7 +316,7 @@ public class CapabilitySet
return true;
}
- private static boolean matchMandatoryAttrbute(String attrName, SimpleFilter sf)
+ private boolean matchMandatoryAttrbute(String attrName, SimpleFilter sf)
{
if ((sf.getName() != null) && sf.getName().equals(attrName))
{
@@ -336,8 +338,9 @@ public class CapabilitySet
return false;
}*/
- private static final Class<?>[] STRING_CLASS = new Class[] { String.class };
+ private static final Class<?>[] STRING_CLASS = new Class[]{String.class};
+ @SuppressWarnings("unchecked")
private static boolean compare(Object lhs, Object rhsUnknown, int op)
{
if (lhs == null)
@@ -382,66 +385,42 @@ public class CapabilitySet
switch (op)
{
case SimpleFilter.EQ:
- try
- {
- return (((Comparable) lhs).compareTo(rhs) == 0);
- }
- catch (Exception ex)
- {
- return false;
- }
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) == 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.GTE:
- try
- {
- return (((Comparable) lhs).compareTo(rhs) >= 0);
- }
- catch (Exception ex)
- {
- return false;
- }
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) >= 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.LTE:
- try
- {
- return (((Comparable) lhs).compareTo(rhs) <= 0);
- }
- catch (Exception ex)
- {
- return false;
- }
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) <= 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.APPROX:
- return compareApproximate(((Comparable) lhs), rhs);
+ return compareApproximate(lhs, rhs);
case SimpleFilter.SUBSTRING:
- return SimpleFilter.compareSubstring((List<String>) rhs, (String) lhs);
+ return SimpleFilter.compareSubstring((List<String>) rhs, (String) lhs);
default:
- throw new RuntimeException(
+ throw new RuntimeException(
"Unknown comparison operator: " + op);
}
}
- // Booleans do not implement comparable, so special case them.
- else if (lhs instanceof Boolean)
- {
- Object rhs;
- try
- {
- rhs = coerceType(lhs, (String) rhsUnknown);
- }
- catch (Exception ex)
- {
- return false;
- }
- switch (op)
- {
- case SimpleFilter.EQ:
- case SimpleFilter.GTE:
- case SimpleFilter.LTE:
- case SimpleFilter.APPROX:
- return (lhs.equals(rhs));
- default:
- throw new RuntimeException(
- "Unknown comparison operator: " + op);
- }
- }
// If the LHS is not a comparable or boolean, check if it is an
// array. If so, convert it to a list so we can treat it as a
@@ -455,9 +434,9 @@ public class CapabilitySet
// of the collection until a match is found.
if (lhs instanceof Collection)
{
- for (Iterator iter = ((Collection) lhs).iterator(); iter.hasNext();)
+ for (Object o : ((Collection) lhs))
{
- if (compare(iter.next(), rhsUnknown, op))
+ if (compare(o, rhsUnknown, op))
{
return true;
}
@@ -467,7 +446,7 @@ public class CapabilitySet
}
// Spec says SUBSTRING is false for all types other than string.
- if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String))
+ if (op == SimpleFilter.SUBSTRING)
{
return false;
}
@@ -489,19 +468,19 @@ public class CapabilitySet
if (rhs instanceof String)
{
return removeWhitespace((String) lhs)
- .equalsIgnoreCase(removeWhitespace((String) rhs));
+ .equalsIgnoreCase(removeWhitespace((String) rhs));
}
else if (rhs instanceof Character)
{
return Character.toLowerCase(((Character) lhs))
- == Character.toLowerCase(((Character) rhs));
+ == Character.toLowerCase(((Character) rhs));
}
return lhs.equals(rhs);
}
private static String removeWhitespace(String s)
{
- StringBuffer sb = new StringBuffer(s.length());
+ StringBuilder sb = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++)
{
if (!Character.isWhitespace(s.charAt(i)))
@@ -523,14 +502,14 @@ public class CapabilitySet
// Try to convert the RHS type to the LHS type by using
// the string constructor of the LHS class, if it has one.
- Object rhs = null;
+ Object rhs;
try
{
// The Character class is a special case, since its constructor
// does not take a string, so handle it separately.
if (lhs instanceof Character)
{
- rhs = new Character(rhsString.charAt(0));
+ rhs = rhsString.charAt(0);
}
else
{
@@ -541,16 +520,16 @@ public class CapabilitySet
}
Constructor ctor = lhs.getClass().getConstructor(STRING_CLASS);
ctor.setAccessible(true);
- rhs = ctor.newInstance(new Object[] { rhsString });
+ rhs = ctor.newInstance(rhsString);
}
}
catch (Exception ex)
{
throw new Exception(
- "Could not instantiate class "
- + lhs.getClass().getName()
- + " from string constructor with argument '"
- + rhsString + "' because " + ex);
+ "Could not instantiate class "
+ + lhs.getClass().getName()
+ + " from string constructor with argument '"
+ + rhsString + "' because " + ex);
}
return rhs;
@@ -561,14 +540,13 @@ public class CapabilitySet
* array of primitive wrapper objects. This method simplifies processing
* LDAP filters since the special case of primitive arrays can be ignored.
*
- * @param array
- * An array of primitive types.
+ * @param array An array of primitive types.
* @return An corresponding array using pritive wrapper objects.
- **/
- private static List convertArrayToList(Object array)
+ */
+ private static List<Object> convertArrayToList(Object array)
{
int len = Array.getLength(array);
- List list = new ArrayList(len);
+ List<Object> list = new ArrayList<Object>(len);
for (int i = 0; i < len; i++)
{
list.add(Array.get(array, i));
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/SimpleFilter.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/SimpleFilter.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/SimpleFilter.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/SimpleFilter.java Thu Nov 27 15:14:39 2014
@@ -60,6 +60,7 @@ public class SimpleFilter
return m_op;
}
+ @SuppressWarnings("unchecked")
public String toString()
{
String s = null;
@@ -84,8 +85,7 @@ public class SimpleFilter
s = "(" + m_name + ">=" + toEncodedString(m_value) + ")";
break;
case SUBSTRING:
- s = "(" + m_name + "=" + unparseSubstring((List<String>) m_value)
- + ")";
+ s = "(" + m_name + "=" + unparseSubstring((List<String>) m_value) + ")";
break;
case PRESENT:
s = "(" + m_name + "=*)";
@@ -97,19 +97,19 @@ public class SimpleFilter
return s;
}
- private static String toString(List list)
+ private static String toString(List<?> list)
{
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < list.size(); i++)
+ StringBuilder sb = new StringBuilder();
+ for (Object aList : list)
{
- sb.append(list.get(i).toString());
+ sb.append(aList.toString());
}
return sb.toString();
}
private static String toDecodedString(String s, int startIdx, int endIdx)
{
- StringBuffer sb = new StringBuffer(endIdx - startIdx);
+ StringBuilder sb = new StringBuilder(endIdx - startIdx);
boolean escaped = false;
for (int i = 0; i < (endIdx - startIdx); i++)
{
@@ -133,7 +133,7 @@ public class SimpleFilter
if (o instanceof String)
{
String s = (String) o;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
@@ -150,6 +150,7 @@ public class SimpleFilter
return o.toString();
}
+ @SuppressWarnings("unchecked")
public static SimpleFilter parse(String filter)
{
int idx = skipWhitespace(filter, 0);
@@ -166,7 +167,7 @@ public class SimpleFilter
}
SimpleFilter sf = null;
- List stack = new ArrayList();
+ List<Object> stack = new ArrayList<Object>();
boolean isEscaped = false;
while (idx < filter.length())
{
@@ -192,7 +193,7 @@ public class SimpleFilter
}
else
{
- stack.add(0, new Integer(idx));
+ stack.add(0, idx);
}
}
else if (filter.charAt(idx) == '|')
@@ -206,7 +207,7 @@ public class SimpleFilter
}
else
{
- stack.add(0, new Integer(idx));
+ stack.add(0, idx);
}
}
else if (filter.charAt(idx) == '!')
@@ -220,12 +221,12 @@ public class SimpleFilter
}
else
{
- stack.add(0, new Integer(idx));
+ stack.add(0, idx);
}
}
else
{
- stack.add(0, new Integer(idx));
+ stack.add(0, idx);
}
}
else if (!isEscaped && (filter.charAt(idx) == ')'))
@@ -233,36 +234,28 @@ public class SimpleFilter
Object top = stack.remove(0);
if (top instanceof SimpleFilter)
{
- if (!stack.isEmpty()
- && (stack.get(0) instanceof SimpleFilter))
+ if (!stack.isEmpty() && (stack.get(0) instanceof SimpleFilter))
{
- ((List) ((SimpleFilter) stack.get(0)).m_value).add(top);
+ ((List<Object>) ((SimpleFilter) stack.get(0)).m_value).add(top);
}
else
{
sf = (SimpleFilter) top;
}
}
- else if (!stack.isEmpty()
- && (stack.get(0) instanceof SimpleFilter))
+ else if (!stack.isEmpty() && (stack.get(0) instanceof SimpleFilter))
{
- ((List) ((SimpleFilter) stack.get(0)).m_value)
- .add(SimpleFilter.subfilter(filter,
- ((Integer) top).intValue(), idx));
+ ((List<Object>) ((SimpleFilter) stack.get(0)).m_value)
+ .add(SimpleFilter.subfilter(filter, (Integer) top, idx));
}
else
{
- sf = SimpleFilter.subfilter(filter,
- ((Integer) top).intValue(), idx);
+ sf = SimpleFilter.subfilter(filter, (Integer) top, idx);
}
}
- else if (!isEscaped && (filter.charAt(idx) == '\\'))
- {
- isEscaped = true;
- }
else
{
- isEscaped = false;
+ isEscaped = !isEscaped && (filter.charAt(idx) == '\\');
}
idx = skipWhitespace(filter, idx + 1);
@@ -270,15 +263,14 @@ public class SimpleFilter
if (sf == null)
{
- throw new IllegalArgumentException("Missing closing parenthesis: "
- + filter);
+ throw new IllegalArgumentException("Missing closing parenthesis: " + filter);
}
return sf;
}
private static SimpleFilter subfilter(String filter, int startIdx,
- int endIdx)
+ int endIdx)
{
final String opChars = "=<>~";
@@ -307,7 +299,7 @@ public class SimpleFilter
startIdx = skipWhitespace(filter, attrEndIdx);
// Determine the operator type.
- int op = -1;
+ int op;
switch (filter.charAt(startIdx))
{
case '=':
@@ -372,8 +364,8 @@ public class SimpleFilter
public static List<String> parseSubstring(String value)
{
- List<String> pieces = new ArrayList();
- StringBuffer ss = new StringBuffer();
+ List<String> pieces = new ArrayList<String>();
+ StringBuilder ss = new StringBuilder();
// int kind = SIMPLE; // assume until proven otherwise
boolean wasStar = false; // indicates last piece was a star
boolean leftstar = false; // track if the initial piece is a star
@@ -383,7 +375,7 @@ public class SimpleFilter
// We assume (sub)strings can contain leading and trailing blanks
boolean escaped = false;
- loop: for (;;)
+ for (; ; )
{
if (idx >= value.length())
{
@@ -401,7 +393,7 @@ public class SimpleFilter
// the string "" (!=null)
}
ss.setLength(0);
- break loop;
+ break;
}
// Read the next character and account for escapes.
@@ -460,7 +452,7 @@ public class SimpleFilter
public static String unparseSubstring(List<String> pieces)
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (int i = 0; i < pieces.size(); i++)
{
if (i > 0)
@@ -495,7 +487,7 @@ public class SimpleFilter
int index = 0;
- loop: for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
String piece = pieces.get(i);
@@ -506,7 +498,7 @@ public class SimpleFilter
if (!s.startsWith(piece))
{
result = false;
- break loop;
+ break;
}
}
@@ -514,15 +506,8 @@ public class SimpleFilter
// string ends with it.
if (i == len - 1)
{
- if (s.endsWith(piece))
- {
- result = true;
- }
- else
- {
- result = false;
- }
- break loop;
+ result = s.endsWith(piece);
+ break;
}
// If this is neither the first or last piece, then
@@ -533,7 +518,7 @@ public class SimpleFilter
if (index < 0)
{
result = false;
- break loop;
+ break;
}
}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/EventDispatcher.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/EventDispatcher.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/EventDispatcher.java Thu Nov 27 15:14:39 2014
@@ -20,10 +20,16 @@ package org.apache.felix.connect.felix.f
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.EventListener;
import java.util.EventObject;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -36,27 +42,23 @@ import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.hooks.bundle.EventHook;
+import org.osgi.framework.hooks.service.EventListenerHook;
import org.osgi.framework.hooks.service.ListenerHook;
import org.osgi.framework.launch.Framework;
import org.apache.felix.connect.felix.framework.ServiceRegistry;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
public class EventDispatcher
{
private final ServiceRegistry m_registry;
- private Map<BundleContext, List<ListenerInfo>> m_fwkListeners = Collections.EMPTY_MAP;
- private Map<BundleContext, List<ListenerInfo>> m_bndlListeners = Collections.EMPTY_MAP;
- private Map<BundleContext, List<ListenerInfo>> m_syncBndlListeners = Collections.EMPTY_MAP;
- private Map<BundleContext, List<ListenerInfo>> m_svcListeners = Collections.EMPTY_MAP;
+ private Map<BundleContext, List<ListenerInfo>> m_fwkListeners = Collections.emptyMap();
+ private Map<BundleContext, List<ListenerInfo>> m_bndlListeners = Collections.emptyMap();
+ private Map<BundleContext, List<ListenerInfo>> m_syncBndlListeners = Collections.emptyMap();
+ private Map<BundleContext, List<ListenerInfo>> m_svcListeners = Collections.emptyMap();
// A single thread is used to deliver events for all dispatchers.
private static Thread m_thread = null;
- private final static String m_threadLock = new String("thread lock");
+ private final static String m_threadLock = "thread lock";
private static int m_references = 0;
private static volatile boolean m_stopping = false;
// List of requests.
@@ -66,7 +68,7 @@ public class EventDispatcher
private static final boolean m_sync = "true".equalsIgnoreCase(System
.getProperty("org.apache.felix.connect.events.sync"));
-
+
public EventDispatcher(ServiceRegistry registry)
{
m_registry = registry;
@@ -153,6 +155,7 @@ public class EventDispatcher
}
catch (InterruptedException ex)
{
+ // Ignore
}
}
}
@@ -167,8 +170,7 @@ public class EventDispatcher
}
else if (!clazz.isInstance(l))
{
- throw new IllegalArgumentException(
- "Listener not of type " + clazz.getName());
+ throw new IllegalArgumentException("Listener not of type " + clazz.getName());
}
// See if we can simply update the listener, if so then
@@ -192,7 +194,7 @@ public class EventDispatcher
// Bundle context is no longer valid, so just return.
}
- Map<BundleContext, List<ListenerInfo>> listeners = null;
+ Map<BundleContext, List<ListenerInfo>> listeners;
Object acc = null;
if (clazz == FrameworkListener.class)
@@ -231,7 +233,7 @@ public class EventDispatcher
// Add listener.
ListenerInfo info =
- new ListenerInfo(bc.getBundle(), bc, clazz, l, filter, acc, false);
+ new ListenerInfo(bc.getBundle(), bc, clazz, l, filter, acc, false);
listeners = addListenerInfo(listeners, info);
if (clazz == FrameworkListener.class)
@@ -258,7 +260,7 @@ public class EventDispatcher
}
public ListenerHook.ListenerInfo removeListener(
- BundleContext bc, Class clazz, EventListener l)
+ BundleContext bc, Class clazz, EventListener l)
{
ListenerHook.ListenerInfo returnInfo = null;
@@ -270,13 +272,13 @@ public class EventDispatcher
else if (!clazz.isInstance(l))
{
throw new IllegalArgumentException(
- "Listener not of type " + clazz.getName());
+ "Listener not of type " + clazz.getName());
}
// Lock the object to remove the listener.
synchronized (this)
{
- Map<BundleContext, List<ListenerInfo>> listeners = null;
+ Map<BundleContext, List<ListenerInfo>> listeners;
if (clazz == FrameworkListener.class)
{
@@ -311,8 +313,8 @@ public class EventDispatcher
{
ListenerInfo info = infos.get(i);
if (info.getBundleContext().equals(bc)
- && (info.getListenerClass() == clazz)
- && (info.getListener() == l))
+ && (info.getListenerClass() == clazz)
+ && (info.getListener() == l))
{
// For service listeners, we must return some info about
// the listener for the ListenerHook callback.
@@ -405,19 +407,19 @@ public class EventDispatcher
{
ListenerInfo info = infos.get(i);
if (info.getBundleContext().equals(bc)
- && (info.getListenerClass() == clazz)
- && (info.getListener() == l))
+ && (info.getListenerClass() == clazz)
+ && (info.getListener() == l))
{
// The spec says to update the filter in this case.
Filter oldFilter = info.getParsedFilter();
ListenerInfo newInfo = new ListenerInfo(
- info.getBundle(),
- info.getBundleContext(),
- info.getListenerClass(),
- info.getListener(),
- filter,
- info.getSecurityContext(),
- info.isRemoved());
+ info.getBundle(),
+ info.getBundleContext(),
+ info.getListenerClass(),
+ info.getListener(),
+ filter,
+ info.getSecurityContext(),
+ info.isRemoved());
m_svcListeners = updateListenerInfo(m_svcListeners, i, newInfo);
return oldFilter;
}
@@ -429,15 +431,14 @@ public class EventDispatcher
}
/**
- * Returns all existing service listener information into a collection of
+ * Returns all existing service listener information into a List of
* ListenerHook.ListenerInfo objects. This is used the first time a listener
* hook is registered to synchronize it with the existing set of listeners.
*
* @return Returns all existing service listener information into a
- * collection of ListenerHook.ListenerInfo objects
- *
+ * List of ListenerHook.ListenerInfo objects
*/
- public Collection<ListenerHook.ListenerInfo> getAllServiceListeners()
+ public List<ListenerHook.ListenerInfo> getAllServiceListeners()
{
List<ListenerHook.ListenerInfo> listeners = new ArrayList<ListenerHook.ListenerInfo>();
synchronized (this)
@@ -453,7 +454,7 @@ public class EventDispatcher
public void fireFrameworkEvent(FrameworkEvent event)
{
// Take a snapshot of the listener array.
- Map<BundleContext, List<ListenerInfo>> listeners = null;
+ Map<BundleContext, List<ListenerInfo>> listeners;
synchronized (this)
{
listeners = m_fwkListeners;
@@ -466,8 +467,8 @@ public class EventDispatcher
public void fireBundleEvent(BundleEvent event)
{
// Take a snapshot of the listener array.
- Map<BundleContext, List<ListenerInfo>> listeners = null;
- Map<BundleContext, List<ListenerInfo>> syncListeners = null;
+ Map<BundleContext, List<ListenerInfo>> listeners;
+ Map<BundleContext, List<ListenerInfo>> syncListeners;
synchronized (this)
{
listeners = m_bndlListeners;
@@ -477,14 +478,13 @@ public class EventDispatcher
// Create a whitelist of bundle context for bundle listeners,
// if we have hooks.
Set<BundleContext> whitelist = createWhitelistFromHooks(event, event.getBundle(),
- listeners, syncListeners, org.osgi.framework.hooks.bundle.EventHook.class);
+ listeners.keySet(), syncListeners.keySet());
// If we have a whitelist, then create copies of only the whitelisted
// listeners.
if (whitelist != null)
{
- Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>();
+ Map<BundleContext, List<ListenerInfo>> copy = new HashMap<BundleContext, List<ListenerInfo>>();
for (BundleContext bc : whitelist)
{
List<ListenerInfo> infos = listeners.get(bc);
@@ -507,26 +507,81 @@ public class EventDispatcher
}
// Fire synchronous bundle listeners immediately on the calling thread.
- fireEventImmediately(
- this, Request.BUNDLE_EVENT, syncListeners, event, null);
+ fireEventImmediately(this, Request.BUNDLE_EVENT, syncListeners, event, null);
// The spec says that asynchronous bundle listeners do not get events
// of types STARTING, STOPPING, or LAZY_ACTIVATION.
if ((event.getType() != BundleEvent.STARTING)
- && (event.getType() != BundleEvent.STOPPING)
- && (event.getType() != BundleEvent.LAZY_ACTIVATION))
+ && (event.getType() != BundleEvent.STOPPING)
+ && (event.getType() != BundleEvent.LAZY_ACTIVATION))
{
// Fire asynchronous bundle listeners on a separate thread.
- fireEventAsynchronously(
- this, Request.BUNDLE_EVENT, listeners, event);
+ fireEventAsynchronously(this, Request.BUNDLE_EVENT, listeners, event);
}
}
- public void fireServiceEvent(
- final ServiceEvent event, final Dictionary oldProps, final Framework felix)
+ private <T> Set<BundleContext> createWhitelistFromHooks(
+ BundleEvent event,
+ Bundle bundle,
+ Set<BundleContext> listeners1,
+ Set<BundleContext> listeners2)
+ {
+ if (bundle == null)
+ {
+ return null;
+ }
+ // Create a whitelist of bundle context, if we have hooks.
+ Set<BundleContext> whitelist = null;
+ Set<ServiceReference<EventHook>> hooks = m_registry.getHooks(EventHook.class);
+ if ((hooks != null) && !hooks.isEmpty())
+ {
+ whitelist = new HashSet<BundleContext>();
+ whitelist.addAll(listeners1);
+ whitelist.addAll(listeners2);
+
+ int originalSize = whitelist.size();
+ ShrinkableCollection<BundleContext> shrinkable = new ShrinkableCollection<BundleContext>(whitelist);
+ for (ServiceReference<EventHook> sr : hooks)
+ {
+ try
+ {
+ EventHook eh = m_registry.getService(bundle, sr);
+ if (eh != null)
+ {
+ try
+ {
+ eh.event(event, shrinkable);
+ }
+ catch (Throwable th)
+ {
+ System.out.println("Problem invoking bundle hook");
+ th.printStackTrace();
+ }
+ finally
+ {
+ m_registry.ungetService(bundle, sr);
+ }
+ }
+ }
+ catch (Throwable th)
+ {
+ // If we can't get the hook, then ignore it.
+ }
+ }
+ // If the whitelist hasn't changed, then null it to avoid having
+ // to do whitelist lookups during event delivery.
+ if (originalSize == whitelist.size())
+ {
+ whitelist = null;
+ }
+ }
+ return whitelist;
+ }
+
+ public void fireServiceEvent(final ServiceEvent event, final Dictionary<String, ?> oldProps, final Framework felix)
{
// Take a snapshot of the listener array.
- Map<BundleContext, List<ListenerInfo>> listeners = null;
+ Map<BundleContext, List<ListenerInfo>> listeners;
synchronized (this)
{
listeners = m_svcListeners;
@@ -536,72 +591,52 @@ public class EventDispatcher
listeners = filterListenersUsingHooks(event, felix, listeners);
// Fire all service events immediately on the calling thread.
- fireEventImmediately(
- this, Request.SERVICE_EVENT, listeners, event, oldProps);
+ fireEventImmediately(this, Request.SERVICE_EVENT, listeners, event, oldProps);
}
-// TODO: OSGi R4.3 - This is ugly and inefficient.
private Map<BundleContext, List<ListenerInfo>> filterListenersUsingHooks(
- ServiceEvent event, Framework felix, Map<BundleContext, List<ListenerInfo>> listeners)
+ ServiceEvent event, Framework felix, Map<BundleContext, List<ListenerInfo>> listeners)
{
+ if (felix == null)
+ {
+ return listeners;
+ }
+
Set<ServiceReference<org.osgi.framework.hooks.service.EventHook>> ehs =
- m_registry.getHooks(org.osgi.framework.hooks.service.EventHook.class);
- if ((ehs != null) && !ehs.isEmpty())
+ m_registry.getHooks(org.osgi.framework.hooks.service.EventHook.class);
+ Set<ServiceReference<EventListenerHook>> elhs =
+ m_registry.getHooks(EventListenerHook.class);
+
+ if ((ehs == null || ehs.isEmpty()) && (elhs == null || elhs.isEmpty()))
{
- // Create a whitelist of bundle context for bundle listeners,
- // if we have hooks.
- Set<BundleContext> whitelist = createWhitelistFromHooks(event, felix,
- listeners, null, org.osgi.framework.hooks.service.EventHook.class);
+ return listeners;
+ }
- // If we have a whitelist, then create copies of only the whitelisted
- // listeners.
- if (whitelist != null)
- {
- Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>();
- for (BundleContext bc : whitelist)
- {
- copy.put(bc, listeners.get(bc));
- }
- listeners = copy;
- }
+ // Create a shrinkable copy of the map
+ Map<BundleContext, List<ListenerInfo>> shrinkableMap = new HashMap<BundleContext, List<ListenerInfo>>();
+ for (Entry<BundleContext, List<ListenerInfo>> entry : listeners.entrySet())
+ {
+ List<ListenerInfo> shrinkableList =
+ new ShrinkableList<ListenerInfo>(
+ new ArrayList<ListenerInfo>(entry.getValue()));
+ shrinkableMap.put(entry.getKey(), shrinkableList);
}
+ shrinkableMap = new ShrinkableMap<BundleContext, List<ListenerInfo>>(shrinkableMap);
- Set<ServiceReference<org.osgi.framework.hooks.service.EventListenerHook>> elhs =
- m_registry.getHooks(org.osgi.framework.hooks.service.EventListenerHook.class);
- if ((elhs != null) && !elhs.isEmpty())
+ // Go through service EventHook
+ if (ehs != null && !ehs.isEmpty())
{
- // Create shrinkable map with shrinkable collections.
- Map<BundleContext, Collection<ListenerHook.ListenerInfo>> shrinkableMap =
- new HashMap<BundleContext, Collection<ListenerHook.ListenerInfo>>();
- for (Entry<BundleContext, List<ListenerInfo>> entry : listeners.entrySet())
- {
- Collection shrinkableCollection =
- new ShrinkableCollection(new ArrayList(entry.getValue()));
- shrinkableMap.put(
- entry.getKey(),
- (Collection<ListenerHook.ListenerInfo>) shrinkableCollection);
- }
- shrinkableMap =
- new ShrinkableMap<BundleContext, Collection<ListenerHook.ListenerInfo>>(shrinkableMap);
- for (ServiceReference<org.osgi.framework.hooks.service.EventListenerHook> sr : elhs)
+ Set<BundleContext> shrink = shrinkableMap.keySet();
+ for (ServiceReference<org.osgi.framework.hooks.service.EventHook> sr : ehs)
{
- if (felix != null)
+ try
{
- org.osgi.framework.hooks.service.EventListenerHook elh = null;
- try
- {
- elh = m_registry.getService(felix, sr);
- }
- catch (Exception ex)
- {
- // If we can't get the hook, then ignore it.
- }
- if (elh != null)
+ org.osgi.framework.hooks.service.EventHook eh = m_registry.getService(felix, sr);
+ if (eh != null)
{
try
{
- elh.event(event, shrinkableMap);
+ eh.event(event, shrink);
}
catch (Throwable th)
{
@@ -614,77 +649,29 @@ public class EventDispatcher
}
}
}
- }
-// TODO: OSGi R4.3 - Should check and only do this if there was a change.
-// Also, it is inefficient to have to create new lists for the values.
- Map<BundleContext, List<ListenerInfo>> newMap =
- new HashMap<BundleContext, List<ListenerInfo>>();
- for (Entry entry : shrinkableMap.entrySet())
- {
- if (!((Collection) entry.getValue()).isEmpty())
+ catch (Throwable th)
{
- newMap.put((BundleContext) entry.getKey(),
- new ArrayList<ListenerInfo>((Collection) entry.getValue()));
+ // Ignore
}
}
- listeners = newMap;
}
- return listeners;
- }
-
- private <T> Set<BundleContext> createWhitelistFromHooks(
- EventObject event, Bundle bundle,
- Map<BundleContext, List<ListenerInfo>> listeners1,
- Map<BundleContext, List<ListenerInfo>> listeners2,
- Class<T> hookClass)
- {
- // Create a whitelist of bundle context, if we have hooks.
- Set<BundleContext> whitelist = null;
- Set<ServiceReference<T>> hooks = m_registry.getHooks(hookClass);
- if ((hooks != null) && !hooks.isEmpty())
+ // Go through EventListenerHook
+ if (elhs != null && !elhs.isEmpty())
{
- whitelist = new HashSet<BundleContext>();
- for (Entry<BundleContext, List<ListenerInfo>> entry : listeners1.entrySet())
+ @SuppressWarnings("unchecked")
+ Map<BundleContext, Collection<ListenerHook.ListenerInfo>> shrink =
+ (Map<BundleContext, Collection<ListenerHook.ListenerInfo>>) (Map) shrinkableMap;
+ for (ServiceReference<EventListenerHook> sr : elhs)
{
- whitelist.add(entry.getKey());
- }
- if (listeners2 != null)
- {
- for (Entry<BundleContext, List<ListenerInfo>> entry : listeners2.entrySet())
- {
- whitelist.add(entry.getKey());
- }
- }
-
- int originalSize = whitelist.size();
- ShrinkableCollection<BundleContext> shrinkable =
- new ShrinkableCollection<BundleContext>(whitelist);
- for (ServiceReference<T> sr : hooks)
- {
- if (bundle != null)
+ try
{
- T eh = null;
- try
- {
- eh = m_registry.getService(bundle, sr);
- }
- catch (Exception ex)
- {
- // If we can't get the hook, then ignore it.
- }
- if (eh != null)
+ EventListenerHook elh = m_registry.getService(felix, sr);
+ if (elh != null)
{
try
{
- if (eh instanceof org.osgi.framework.hooks.service.EventHook)
- {
- ((org.osgi.framework.hooks.service.EventHook) eh).event((ServiceEvent) event, shrinkable);
- }
- else if (eh instanceof org.osgi.framework.hooks.bundle.EventHook)
- {
- ((org.osgi.framework.hooks.bundle.EventHook) eh).event((BundleEvent) event, shrinkable);
- }
+ elh.event(event, shrink);
}
catch (Throwable th)
{
@@ -693,31 +680,28 @@ public class EventDispatcher
}
finally
{
- m_registry.ungetService(bundle, sr);
+ m_registry.ungetService(felix, sr);
}
}
}
- }
- // If the whitelist hasn't changed, then null it to avoid having
- // to do whitelist lookups during event delivery.
- if (originalSize == whitelist.size())
- {
- whitelist = null;
+ catch (Throwable th)
+ {
+ // Ignore
+ }
}
}
- return whitelist;
+
+ return shrinkableMap;
}
private static void fireEventAsynchronously(
- EventDispatcher dispatcher, int type,
- Map<BundleContext, List<ListenerInfo>> listeners,
- EventObject event)
+ EventDispatcher dispatcher, int type,
+ Map<BundleContext, List<ListenerInfo>> listeners,
+ EventObject event)
{
if (!m_sync)
{
- // TODO: should possibly check this within thread lock, seems to be
- // ok
- // though without
+ // TODO: should possibly check this within thread lock, seems to be ok though without
// If dispatch thread is stopped, then ignore dispatch request.
if (m_stopping || m_thread == null)
{
@@ -725,7 +709,7 @@ public class EventDispatcher
}
// First get a request from the pool or create one if necessary.
- Request req = null;
+ Request req;
synchronized (m_requestPool)
{
if (m_requestPool.size() > 0)
@@ -760,9 +744,9 @@ public class EventDispatcher
}
private static void fireEventImmediately(
- EventDispatcher dispatcher, int type,
- Map<BundleContext, List<ListenerInfo>> listeners,
- EventObject event, Dictionary oldProps)
+ EventDispatcher dispatcher, int type,
+ Map<BundleContext, List<ListenerInfo>> listeners,
+ EventObject event, Dictionary<String, ?> oldProps)
{
if (!listeners.isEmpty())
{
@@ -788,19 +772,17 @@ public class EventDispatcher
}
else if (type == Request.SERVICE_EVENT)
{
- invokeServiceListenerCallback(
- bundle, l, filter, acc, event, oldProps);
+ invokeServiceListenerCallback(bundle, l, filter, acc, event, oldProps);
}
}
catch (Throwable th)
{
if ((type != Request.FRAMEWORK_EVENT)
- || (((FrameworkEvent) event).getType() != FrameworkEvent.ERROR))
+ || (((FrameworkEvent) event).getType() != FrameworkEvent.ERROR))
{
System.out.println("EventDispatcher: Error during dispatch.");
th.printStackTrace();
- dispatcher.fireFrameworkEvent(
- new FrameworkEvent(FrameworkEvent.ERROR, bundle, th));
+ dispatcher.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.ERROR, bundle, th));
}
}
}
@@ -809,13 +791,12 @@ public class EventDispatcher
}
private static void invokeFrameworkListenerCallback(
- Bundle bundle, final EventListener l, final EventObject event)
+ Bundle bundle, final EventListener l, final EventObject event)
{
// The spec says only active bundles receive asynchronous events,
// but we will include starting bundles too otherwise
// it is impossible to see everything.
- if ((bundle.getState() == Bundle.STARTING)
- || (bundle.getState() == Bundle.ACTIVE))
+ if ((bundle.getState() == Bundle.STARTING) || (bundle.getState() == Bundle.ACTIVE))
{
((FrameworkListener) l).frameworkEvent((FrameworkEvent) event);
@@ -823,7 +804,7 @@ public class EventDispatcher
}
private static void invokeBundleListenerCallback(
- Bundle bundle, final EventListener l, final EventObject event)
+ Bundle bundle, final EventListener l, final EventObject event)
{
// A bundle listener is either synchronous or asynchronous.
// If the bundle listener is synchronous, then deliver the
@@ -831,25 +812,25 @@ public class EventDispatcher
// ACTIVE. If the listener is asynchronous, then deliver the
// event only to bundles that are STARTING or ACTIVE.
if (((SynchronousBundleListener.class.isAssignableFrom(l.getClass()))
- && ((bundle.getState() == Bundle.STARTING)
- || (bundle.getState() == Bundle.STOPPING)
- || (bundle.getState() == Bundle.ACTIVE)))
- || ((bundle.getState() == Bundle.STARTING)
- || (bundle.getState() == Bundle.ACTIVE)))
+ && ((bundle.getState() == Bundle.STARTING)
+ || (bundle.getState() == Bundle.STOPPING)
+ || (bundle.getState() == Bundle.ACTIVE)))
+ || ((bundle.getState() == Bundle.STARTING)
+ || (bundle.getState() == Bundle.ACTIVE)))
{
((BundleListener) l).bundleChanged((BundleEvent) event);
}
}
private static void invokeServiceListenerCallback(Bundle bundle,
- final EventListener l, Filter filter, Object acc,
- final EventObject event, final Dictionary oldProps)
+ final EventListener l, Filter filter, Object acc,
+ final EventObject event, final Dictionary<String, ?> oldProps)
{
// Service events should be delivered to STARTING,
// STOPPING, and ACTIVE bundles.
if ((bundle.getState() != Bundle.STARTING)
- && (bundle.getState() != Bundle.STOPPING)
- && (bundle.getState() != Bundle.ACTIVE))
+ && (bundle.getState() != Bundle.STOPPING)
+ && (bundle.getState() != Bundle.ACTIVE))
{
return;
}
@@ -864,12 +845,11 @@ public class EventDispatcher
{
// Dispatch according to the filter.
boolean matched = (filter == null)
- || filter.match(((ServiceEvent) event).getServiceReference());
+ || filter.match(((ServiceEvent) event).getServiceReference());
if (matched)
{
- ((ServiceListener) l)
- .serviceChanged((ServiceEvent) event);
+ ((ServiceListener) l).serviceChanged((ServiceEvent) event);
}
// We need to send an MODIFIED_ENDMATCH event if the listener
// matched previously.
@@ -878,8 +858,8 @@ public class EventDispatcher
if (filter.match(oldProps))
{
final ServiceEvent se = new ServiceEvent(
- ServiceEvent.MODIFIED_ENDMATCH,
- ((ServiceEvent) event).getServiceReference());
+ ServiceEvent.MODIFIED_ENDMATCH,
+ ((ServiceEvent) event).getServiceReference());
((ServiceListener) l).serviceChanged(se);
}
@@ -888,11 +868,11 @@ public class EventDispatcher
}
private static Map<BundleContext, List<ListenerInfo>> addListenerInfo(
- Map<BundleContext, List<ListenerInfo>> listeners, ListenerInfo info)
+ Map<BundleContext, List<ListenerInfo>> listeners, ListenerInfo info)
{
// Make a copy of the map, since we will be mutating it.
Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>(listeners);
+ new HashMap<BundleContext, List<ListenerInfo>>(listeners);
// Remove the affected entry and make a copy so we can modify it.
List<ListenerInfo> infos = copy.remove(info.getBundleContext());
if (infos == null)
@@ -911,32 +891,32 @@ public class EventDispatcher
}
private static Map<BundleContext, List<ListenerInfo>> updateListenerInfo(
- Map<BundleContext, List<ListenerInfo>> listeners, int idx,
- ListenerInfo info)
+ Map<BundleContext, List<ListenerInfo>> listeners, int idx,
+ ListenerInfo info)
{
// Make a copy of the map, since we will be mutating it.
Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>(listeners);
+ new HashMap<BundleContext, List<ListenerInfo>>(listeners);
// Remove the affected entry and make a copy so we can modify it.
List<ListenerInfo> infos = copy.remove(info.getBundleContext());
if (infos != null)
{
- infos = new ArrayList<ListenerInfo>(infos);
+ List<ListenerInfo> copylist = new ArrayList<ListenerInfo>(infos);
// Update the new listener info.
- infos.set(idx, info);
+ copylist.set(idx, info);
// Put the listeners back into the copy of the map and return it.
- copy.put(info.getBundleContext(), infos);
+ copy.put(info.getBundleContext(), copylist);
return copy;
}
return listeners;
}
private static Map<BundleContext, List<ListenerInfo>> removeListenerInfo(
- Map<BundleContext, List<ListenerInfo>> listeners, BundleContext bc, int idx)
+ Map<BundleContext, List<ListenerInfo>> listeners, BundleContext bc, int idx)
{
// Make a copy of the map, since we will be mutating it.
Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>(listeners);
+ new HashMap<BundleContext, List<ListenerInfo>>(listeners);
// Remove the affected entry and make a copy so we can modify it.
List<ListenerInfo> infos = copy.remove(bc);
if (infos != null)
@@ -955,11 +935,11 @@ public class EventDispatcher
}
private static Map<BundleContext, List<ListenerInfo>> removeListenerInfos(
- Map<BundleContext, List<ListenerInfo>> listeners, BundleContext bc)
+ Map<BundleContext, List<ListenerInfo>> listeners, BundleContext bc)
{
// Make a copy of the map, since we will be mutating it.
Map<BundleContext, List<ListenerInfo>> copy =
- new HashMap<BundleContext, List<ListenerInfo>>(listeners);
+ new HashMap<BundleContext, List<ListenerInfo>>(listeners);
// Remove the affected entry and return the copy.
copy.remove(bc);
return copy;
@@ -967,11 +947,10 @@ public class EventDispatcher
/**
* This is the dispatching thread's main loop.
- *
*/
private static void run()
{
- Request req = null;
+ Request req;
while (true)
{
// Lock the request list so we can try to get a
@@ -1012,8 +991,8 @@ public class EventDispatcher
// the invoked method shields us from exceptions by
// catching Throwables when it invokes callbacks.
fireEventImmediately(
- req.m_dispatcher, req.m_type, req.m_listeners,
- req.m_event, null);
+ req.m_dispatcher, req.m_type, req.m_listeners,
+ req.m_event, null);
// Put dispatch request in cache.
synchronized (m_requestPool)
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerInfo.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerInfo.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerInfo.java Thu Nov 27 15:14:39 2014
@@ -19,6 +19,7 @@
package org.apache.felix.connect.felix.framework.util;
import java.util.EventListener;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -36,8 +37,8 @@ public class ListenerInfo implements Lis
private final boolean m_removed;
public ListenerInfo(
- Bundle bundle, BundleContext context, Class listenerClass, EventListener listener,
- Filter filter, Object acc, boolean removed)
+ Bundle bundle, BundleContext context, Class listenerClass, EventListener listener,
+ Filter filter, Object acc, boolean removed)
{
// Technically, we could get the bundle from the bundle context, but
// there are some corner cases where the bundle context might become
@@ -121,10 +122,10 @@ public class ListenerInfo implements Lis
ListenerInfo other = (ListenerInfo) obj;
return (other.m_bundle == m_bundle)
- && (other.m_context == m_context)
- && (other.m_listenerClass == m_listenerClass)
- && (other.m_listener == m_listener)
- && (m_filter == null ? other.m_filter == null : m_filter.equals(other.m_filter));
+ && (other.m_context == m_context)
+ && (other.m_listenerClass == m_listenerClass)
+ && (other.m_listener == m_listener)
+ && (m_filter == null ? other.m_filter == null : m_filter.equals(other.m_filter));
}
@Override
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/MapToDictionary.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/MapToDictionary.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/MapToDictionary.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/MapToDictionary.java Thu Nov 27 15:14:39 2014
@@ -18,20 +18,23 @@
*/
package org.apache.felix.connect.felix.framework.util;
-import java.util.*;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Map;
/**
* This is a simple class that implements a <tt>Dictionary</tt> from a
* <tt>Map</tt>. The resulting dictionary is immutable.
- **/
-public class MapToDictionary extends Dictionary
+ */
+public class MapToDictionary<K, V> extends Dictionary<K, V>
{
/**
* Map source.
- **/
- private Map m_map = null;
+ */
+ private Map<K, V> m_map = null;
- public MapToDictionary(Map map)
+ public MapToDictionary(Map<K, V> map)
{
if (map == null)
{
@@ -40,12 +43,12 @@ public class MapToDictionary extends Dic
m_map = map;
}
- public Enumeration elements()
+ public Enumeration<V> elements()
{
return Collections.enumeration(m_map.values());
}
- public Object get(Object key)
+ public V get(Object key)
{
return m_map.get(key);
}
@@ -55,17 +58,17 @@ public class MapToDictionary extends Dic
return m_map.isEmpty();
}
- public Enumeration keys()
+ public Enumeration<K> keys()
{
return Collections.enumeration(m_map.keySet());
}
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
throw new UnsupportedOperationException();
}
- public Object remove(Object key)
+ public V remove(Object key)
{
throw new UnsupportedOperationException();
}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableCollection.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableCollection.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableCollection.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableCollection.java Thu Nov 27 15:14:39 2014
@@ -18,13 +18,14 @@
*/
package org.apache.felix.connect.felix.framework.util;
+import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
/**
* A collection wrapper that only permits clients to shrink the collection.
-**/
-public class ShrinkableCollection<T> implements Collection<T>
+ */
+public class ShrinkableCollection<T> extends AbstractCollection<T>
{
private final Collection<T> m_delegate;
@@ -33,80 +34,16 @@ public class ShrinkableCollection<T> imp
m_delegate = delegate;
}
- public boolean add(T o)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends T> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clear()
- {
- m_delegate.clear();
- }
-
- public boolean contains(Object o)
- {
- return m_delegate.contains(o);
- }
-
- public boolean containsAll(Collection<?> c)
- {
- return m_delegate.containsAll(c);
- }
-
@Override
- public boolean equals(Object o)
- {
- return m_delegate.equals(o);
- }
-
- @Override
- public int hashCode()
- {
- return m_delegate.hashCode();
- }
-
- public boolean isEmpty()
- {
- return m_delegate.isEmpty();
- }
-
- public Iterator iterator()
+ public Iterator<T> iterator()
{
return m_delegate.iterator();
}
- public boolean remove(Object o)
- {
- return m_delegate.remove(o);
- }
-
- public boolean removeAll(Collection<?> c)
- {
- return m_delegate.removeAll(c);
- }
-
- public boolean retainAll(Collection<?> c)
- {
- return m_delegate.retainAll(c);
- }
-
+ @Override
public int size()
{
return m_delegate.size();
}
- public Object[] toArray()
- {
- return m_delegate.toArray();
- }
-
- public <A> A[] toArray(A[] a)
- {
- return m_delegate.toArray(a);
- }
}
Copied: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableList.java (from r1641786, felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Attribute.java)
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableList.java?p2=felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableList.java&p1=felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Attribute.java&r1=1641786&r2=1642172&rev=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Attribute.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableList.java Thu Nov 27 15:14:39 2014
@@ -16,38 +16,39 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.connect.felix.framework.capabilityset;
+package org.apache.felix.connect.felix.framework.util;
-public class Attribute
+import java.util.AbstractList;
+import java.util.List;
+
+/**
+ * A collection wrapper that only permits clients to shrink the collection.
+ */
+public class ShrinkableList<T> extends AbstractList<T>
{
- private final String m_name;
- private final Object m_value;
- private final boolean m_isMandatory;
+ private final List<T> m_delegate;
- public Attribute(String name, Object value, boolean isMandatory)
+ public ShrinkableList(List<T> delegate)
{
- m_name = name;
- m_value = value;
- m_isMandatory = isMandatory;
+ m_delegate = delegate;
}
- public String getName()
+ @Override
+ public T get(int index)
{
- return m_name;
+ return m_delegate.get(index);
}
- public Object getValue()
+ @Override
+ public int size()
{
- return m_value;
+ return m_delegate.size();
}
- public boolean isMandatory()
+ @Override
+ public T remove(int index)
{
- return m_isMandatory;
+ return m_delegate.remove(index);
}
- public String toString()
- {
- return m_name + "=" + m_value;
- }
-}
\ No newline at end of file
+}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableMap.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableMap.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableMap.java Thu Nov 27 15:14:39 2014
@@ -18,11 +18,11 @@
*/
package org.apache.felix.connect.felix.framework.util;
-import java.util.Collection;
+import java.util.AbstractMap;
import java.util.Map;
import java.util.Set;
-public class ShrinkableMap<K, V> implements Map<K, V>
+public class ShrinkableMap<K, V> extends AbstractMap<K, V>
{
private final Map<K, V> m_delegate;
@@ -31,63 +31,10 @@ public class ShrinkableMap<K, V> impleme
m_delegate = delegate;
}
- public int size()
- {
- return m_delegate.size();
- }
-
- public boolean isEmpty()
- {
- return m_delegate.isEmpty();
- }
-
- public boolean containsKey(Object o)
- {
- return m_delegate.containsKey(o);
- }
-
- public boolean containsValue(Object o)
- {
- return m_delegate.containsValue(o);
- }
-
- public V get(Object o)
- {
- return m_delegate.get(o);
- }
-
- public V put(K k, V v)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public V remove(Object o)
- {
- return m_delegate.remove(o);
- }
-
- public void putAll(Map<? extends K, ? extends V> map)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public void clear()
- {
- m_delegate.clear();
- }
-
- public Set<K> keySet()
- {
- return m_delegate.keySet();
- }
-
- public Collection<V> values()
- {
- return m_delegate.values();
- }
-
+ @Override
public Set<Entry<K, V>> entrySet()
{
return m_delegate.entrySet();
}
+
}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringComparator.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringComparator.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringComparator.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringComparator.java Thu Nov 27 15:14:39 2014
@@ -20,7 +20,7 @@ package org.apache.felix.connect.felix.f
import java.util.Comparator;
-public class StringComparator implements Comparator
+public class StringComparator implements Comparator<String>
{
private final boolean m_isCaseSensitive;
@@ -29,15 +29,16 @@ public class StringComparator implements
m_isCaseSensitive = b;
}
- public int compare(Object o1, Object o2)
+ @Override
+ public int compare(String o1, String o2)
{
if (m_isCaseSensitive)
{
- return o1.toString().compareTo(o2.toString());
+ return o1.compareTo(o2);
}
else
{
- return o1.toString().compareToIgnoreCase(o2.toString());
+ return o1.compareToIgnoreCase(o2);
}
}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringMap.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringMap.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringMap.java Thu Nov 27 15:14:39 2014
@@ -18,7 +18,10 @@
*/
package org.apache.felix.connect.felix.framework.util;
-import java.util.*;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
/**
* Simple utility class that creates a map for string-based keys. This map can
@@ -26,10 +29,10 @@ import java.util.*;
* for the key. Any keys put into this map will be converted to a
* <tt>String</tt> using the <tt>toString()</tt> method, since it is only
* intended to compare strings.
- **/
-public class StringMap implements Map
+ */
+public class StringMap<T> implements Map<String, T>
{
- private TreeMap m_map;
+ private TreeMap<String, T> m_map;
public StringMap()
{
@@ -38,10 +41,10 @@ public class StringMap implements Map
public StringMap(boolean caseSensitive)
{
- m_map = new TreeMap(new StringComparator(caseSensitive));
+ m_map = new TreeMap<String, T>(new StringComparator(caseSensitive));
}
- public StringMap(Map map, boolean caseSensitive)
+ public StringMap(Map<? extends String, ? extends T> map, boolean caseSensitive)
{
this(caseSensitive);
putAll(map);
@@ -56,72 +59,83 @@ public class StringMap implements Map
{
if (isCaseSensitive() != b)
{
- TreeMap map = new TreeMap(new StringComparator(b));
+ TreeMap<String, T> map = new TreeMap<String, T>(new StringComparator(b));
map.putAll(m_map);
m_map = map;
}
}
+ @Override
public int size()
{
return m_map.size();
}
+ @Override
public boolean isEmpty()
{
return m_map.isEmpty();
}
+ @Override
public boolean containsKey(Object arg0)
{
return m_map.containsKey(arg0);
}
+ @Override
public boolean containsValue(Object arg0)
{
return m_map.containsValue(arg0);
}
- public Object get(Object arg0)
+ @Override
+ public T get(Object arg0)
{
return m_map.get(arg0);
}
- public Object put(Object key, Object value)
+ @Override
+ public T put(String key, T value)
{
- return m_map.put(key.toString(), value);
+ return m_map.put(key, value);
}
- public void putAll(Map map)
+ @Override
+ public void putAll(Map<? extends String, ? extends T> map)
{
- for (Iterator it = map.entrySet().iterator(); it.hasNext();)
+ for (Entry<? extends String, ? extends T> entry : map.entrySet())
{
- Map.Entry entry = (Map.Entry) it.next();
put(entry.getKey(), entry.getValue());
}
}
- public Object remove(Object arg0)
+ @Override
+ public T remove(Object arg0)
{
return m_map.remove(arg0);
}
+ @Override
public void clear()
{
m_map.clear();
}
- public Set keySet()
+ @Override
+ public Set<String> keySet()
{
return m_map.keySet();
}
- public Collection values()
+ @Override
+ public Collection<T> values()
{
return m_map.values();
}
- public Set entrySet()
+ @Override
+ public Set<Entry<String, T>> entrySet()
{
return m_map.entrySet();
}
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/Util.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/Util.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/Util.java Thu Nov 27 15:14:39 2014
@@ -36,7 +36,7 @@ public class Util
{
/**
* The default name used for the default configuration properties file.
- **/
+ */
private static final String DEFAULT_PROPERTIES_FILE = "default.properties";
public static String getDefaultProperty(String name)
@@ -66,7 +66,9 @@ public class Util
try
{
if (is != null)
+ {
is.close();
+ }
}
catch (IOException ex2)
{
@@ -83,7 +85,7 @@ public class Util
* Converts a module identifier to a bundle identifier. Module IDs are
* typically <tt><bundle-id>.<revision></tt>; this method
* returns only the portion corresponding to the bundle ID.
- **/
+ */
public static long getBundleIdFromModuleId(String id)
{
try
@@ -102,7 +104,7 @@ public class Util
* Converts a module identifier to a bundle identifier. Module IDs are
* typically <tt><bundle-id>.<revision></tt>; this method
* returns only the portion corresponding to the revision.
- **/
+ */
public static int getModuleRevisionFromModuleId(String id)
{
try
@@ -196,13 +198,11 @@ public class Util
* from the service object's class loader, but from the class loaders of any
* interfaces it implements and the class loaders of all super classes.
* </p>
- *
- * @param svcObj
- * the class that is the root of the search.
- * @param name
- * the name of the class to load.
+ *
+ * @param svcObj the class that is the root of the search.
+ * @param name the name of the class to load.
* @return the loaded class or <tt>null</tt> if it could not be loaded.
- **/
+ */
public static Class loadClassUsingClass(Class clazz, String name)
{
Class loadedClass = null;
@@ -248,16 +248,14 @@ public class Util
* This method determines if the requesting bundle is able to cast the
* specified service reference based on class visibility rules of the
* underlying modules.
- *
- * @param requester
- * The bundle requesting the service.
- * @param ref
- * The service in question.
+ *
+ * @param requester The bundle requesting the service.
+ * @param ref The service in question.
* @return <tt>true</tt> if the requesting bundle is able to case the
- * service object to a known type.
- **/
+ * service object to a known type.
+ */
public static boolean isServiceAssignable(Bundle requester,
- ServiceReference ref)
+ ServiceReference ref)
{
// Boolean flag.
boolean allow = true;
@@ -280,22 +278,22 @@ public class Util
return allow;
}
- private static final byte encTab[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
+ private static final byte encTab[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x2b, 0x2f };
+ 0x39, 0x2b, 0x2f};
- private static final byte decTab[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ private static final byte decTab[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
-1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
- 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1};
public static String base64Encode(String s) throws IOException
{
@@ -304,12 +302,10 @@ public class Util
/**
* Encode a raw byte array to a Base64 String.
- *
- * @param in
- * Byte array to encode.
- * @param len
- * Length of Base64 lines. 0 means no line breaks.
- **/
+ *
+ * @param in Byte array to encode.
+ * @param len Length of Base64 lines. 0 means no line breaks.
+ */
public static String encode(byte[] in, int len) throws IOException
{
ByteArrayOutputStream baos = null;
@@ -409,23 +405,18 @@ public class Util
* as nested variable placeholders, which are substituted from inner most to
* outer most. Configuration properties override system properties.
* </p>
- *
- * @param val
- * The string on which to perform property substitution.
- * @param currentKey
- * The key of the property being evaluated used to detect cycles.
- * @param cycleMap
- * Map of variable references used to detect nested cycles.
- * @param configProps
- * Set of configuration properties.
+ *
+ * @param val The string on which to perform property substitution.
+ * @param currentKey The key of the property being evaluated used to detect cycles.
+ * @param cycleMap Map of variable references used to detect nested cycles.
+ * @param configProps Set of configuration properties.
* @return The value of the specified string after system property
- * substitution.
- * @throws IllegalArgumentException
- * If there was a syntax error in the property placeholder
- * syntax or a recursive variable reference.
- **/
+ * substitution.
+ * @throws IllegalArgumentException If there was a syntax error in the property placeholder
+ * syntax or a recursive variable reference.
+ */
public static String substVars(String val, String currentKey, Map cycleMap,
- Properties configProps) throws IllegalArgumentException
+ Properties configProps) throws IllegalArgumentException
{
// If there is currently no cycle map, then create
// one for detecting cycles for this invocation.
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/VersionRange.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/VersionRange.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/VersionRange.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/VersionRange.java Thu Nov 27 15:14:39 2014
@@ -30,7 +30,7 @@ public class VersionRange
Version.emptyVersion, true, null, true);
public VersionRange(Version low, boolean isLowInclusive, Version high,
- boolean isHighInclusive)
+ boolean isHighInclusive)
{
m_floor = low;
m_isFloorInclusive = isLowInclusive;
Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/BundleDescriptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/BundleDescriptor.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/BundleDescriptor.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/BundleDescriptor.java Thu Nov 27 15:14:39 2014
@@ -18,21 +18,34 @@
*/
package org.apache.felix.connect.launch;
-import java.net.URL;
import java.util.Map;
+import org.apache.felix.connect.Revision;
+
public class BundleDescriptor
{
private final ClassLoader m_loader;
- private final URL m_url;
+ private final String m_url;
private final Map<String, String> m_headers;
+ private final Revision m_revision;
+ private final Map<Class, Object> m_services;
+
+ public BundleDescriptor(ClassLoader loader, String url,
+ Map<String, String> headers)
+ {
+ this(loader, url, headers, null, null);
+ }
- public BundleDescriptor(ClassLoader loader, URL url,
- Map<String, String> headers)
+ public BundleDescriptor(ClassLoader loader, String url,
+ Map<String, String> headers,
+ Revision revision,
+ Map<Class, Object> services)
{
m_loader = loader;
m_url = url;
m_headers = headers;
+ m_revision = revision;
+ m_services = services;
}
public ClassLoader getClassLoader()
@@ -40,18 +53,28 @@ public class BundleDescriptor
return m_loader;
}
- public URL getUrl()
+ public String getUrl()
{
return m_url;
}
public String toString()
{
- return m_url.toExternalForm();
+ return m_url;
}
public Map<String, String> getHeaders()
{
return m_headers;
}
+
+ public Revision getRevision()
+ {
+ return m_revision;
+ }
+
+ public Map<Class, Object> getServices()
+ {
+ return m_services;
+ }
}