You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2010/12/23 10:25:37 UTC
svn commit: r1052206 - in
/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly:
Activator.java ClientWeavingHook.java
Author: davidb
Date: Thu Dec 23 09:25:37 2010
New Revision: 1052206
URL: http://svn.apache.org/viewvc?rev=1052206&view=rev
Log:
Small cleanup.
Modified:
incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java
incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java?rev=1052206&r1=1052205&r2=1052206&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java Thu Dec 23 09:25:37 2010
@@ -55,12 +55,6 @@ public class Activator implements Bundle
private final ConcurrentMap<Bundle, Map<ConsumerRestriction, List<BundleDescriptor>>> consumerRestrictions =
new ConcurrentHashMap<Bundle, Map<ConsumerRestriction, List<BundleDescriptor>>>();
-
-// private final ConcurrentMap<Bundle, Collection<String>> consumerProviders =
-// new ConcurrentHashMap<Bundle, Collection<String>>();
-//
-// private final ConcurrentMap<Bundle, Map<Map<String, Map<String, Map<Integer, Map<String, String>>>>, List<BundleDescriptor>>> consumerRestrictions =
-// new ConcurrentHashMap<Bundle, Map<Map<String, Map<String, Map<Integer, Map<String, String>>>>, List<BundleDescriptor>>>();
public synchronized void start(BundleContext context) throws Exception {
bundleContext = context;
@@ -141,24 +135,6 @@ public class Activator implements Bundle
}
}
- /* public void registerConsumerBundle(Bundle consumer, Collection<String> spiProviders, String className, String methodName, Map<Integer, String> argRestrictions) {
- if (spiProviders != null)
- consumerProviders.put(consumer, spiProviders);
-
- if (className != null) {
- Map<String, Map<String, Map<Integer, String>>> restrictions = new HashMap<String, Map<String, Map<Integer, String>>>();
- Map<String, Map<Integer, String>> restriction = null;
- if (methodName != null) {
- restriction = new HashMap<String, Map<Integer,String>>();
- restriction.put(methodName, argRestrictions);
- }
- restrictions.put(className, restriction);
- // TODO consumerRestrictions.put(consumer, restrictions);
- }
- if (argRestrictions != null)
- consumerArgRestrictions.put(consumer, argRestrictions);
- } */
-
public Collection<Bundle> findConsumerRestrictions(Bundle consumer, String className, String methodName,
Map<Pair<Integer, String>, String> args) {
Map<ConsumerRestriction, List<BundleDescriptor>> restrictions = consumerRestrictions.get(consumer);
@@ -173,36 +149,6 @@ public class Activator implements Bundle
}
return Collections.emptySet();
- /*
- ConsumerRestriction consumerRestriction = new ConsumerRestriction(className, methodName, args);
-
- Map<Map<String, Map<String, Map<Integer, Map<String, String>>>>, List<BundleDescriptor>> res =
- consumerRestrictions.get(consumer);
- if (res == null) {
- return null;
- }
-
- Map<String, Map<String, Map<Integer, Map<String, String>>>> classNameMap =
- new HashMap<String, Map<String,Map<Integer,Map<String,String>>>>();
- Map<String, Map<Integer, Map<String, String>>> methodNameMap =
- new HashMap<String, Map<Integer,Map<String,String>>>();
- methodNameMap.put(methodName, args);
- classNameMap.put(className, methodNameMap);
- List<BundleDescriptor> bundles = res.get(classNameMap);
- if (bundles != null) {
- return getBundles(bundles);
- }
- return null;//... process wildcarding ...
- */
-// List<Bundle> result = new ArrayList<Bundle>();
-// for (String allowedBundle : findComsumerRestrictions2(consumer, argIdx)) {
-// for (Bundle b : bundleContext.getBundles()) {
-// if (b.getSymbolicName().equals(allowedBundle)) {
-// result.add(b);
-// }
-// }
-// }
-// return result;
}
private Collection<Bundle> getBundles(List<BundleDescriptor> descriptors) {
@@ -223,25 +169,5 @@ public class Activator implements Bundle
return bundles;
}
- /*
- private Collection<String> findComsumerRestrictions2(Bundle consumer, int argIdx) {
- Collection<String> providers = consumerProviders.get(consumer);
- Map<Integer, String> argRestrictions = consumerRestrictions.get(consumer);
-
- if (providers != null) {
- if (argRestrictions != null) {
- // Clone providers because we're going to modify it...
- providers = new ArrayList<String>(providers);
- providers.retainAll(Collections.singleton(argRestrictions.get(argIdx)));
- }
- return providers;
- } else {
- if (argRestrictions != null) {
- return Collections.singleton(argRestrictions.get(argIdx));
- }
- return null;
- }
- } */
-
// TODO unRegisterConsumerBundle();
}
Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java?rev=1052206&r1=1052205&r2=1052206&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java Thu Dec 23 09:25:37 2010
@@ -54,7 +54,7 @@ public class ClientWeavingHook implement
if (consumerHeader != null) {
Activator.activator.log(LogService.LOG_DEBUG, "Weaving class " + wovenClass.getClassName());
- WeavingData wd = parseHeader(consumerBundle, consumerHeader);
+ WeavingData wd = processHeader(consumerBundle, consumerHeader);
ClassReader cr = new ClassReader(wovenClass.getBytes());
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
@@ -91,19 +91,10 @@ public class ClientWeavingHook implement
* @param consumerHeader the <tt>SPI-Consumer</tt> header.
* @return an instance of the {@link WeavingData} class.
*/
- private WeavingData parseHeader(Bundle consumerBundle, String consumerHeader) {
+ private WeavingData processHeader(Bundle consumerBundle, String consumerHeader) {
List<BundleDescriptor> allowedBundles = new ArrayList<BundleDescriptor>();
for (PathElement element : HeaderParser.parseHeader(consumerHeader)) {
- /* This map has the following structure:
- * ClassName -> MethodName -> Argument# -> ArgClassName -> ArgValue
- * Anything except from the ClassName and MethodName can be null which means any
- * value is allowed there.
- */
- /* Map<String, Map<String, Map<Integer, Map<String, String>>>> restrictions =
- new HashMap<String, Map<String,Map<Integer,Map<String,String>>>>();
- Map<String, Map<Integer, Map<String, String>>> methods =
- new HashMap<String, Map<Integer,Map<String,String>>>(); */
Set<ConsumerRestriction> restrictions = new HashSet<ConsumerRestriction>();
MethodRestriction methodRestriction = null;
String name = element.getName().trim();
@@ -128,14 +119,8 @@ public class ClientWeavingHook implement
int idx = s.indexOf('[');
int end = s.indexOf(idx, ']');
if (idx > 0 && end > idx) {
-// Map<String, String> argVals = new HashMap<String, String>();
-// argVals.put(s.substring(0, idx), s.substring(idx + 1, end));
-// args.put(argNumber, argVals);
argRestrictions.addRestriction(argNumber, s.substring(0, idx), s.substring(idx + 1, end));
} else {
-// Map<String, String> argVals = new HashMap<String, String>();
-// argVals.put(s, null);
-// args.put(argNumber, argVals);
argRestrictions.addRestriction(argNumber, s);
}
argNumber++;
@@ -144,30 +129,17 @@ public class ClientWeavingHook implement
String[] classNames = classes.split(",");
for (int i = 0; i < classNames.length; i++) {
argRestrictions.addRestriction(i, classNames[i]);
-// Map<String, String> argTypes = new HashMap<String, String>();
-// argTypes.put(classNames[i], null);
-// args.put(i, argTypes);
}
}
}
}
- // methods.put(methodName, args);
-
methodRestriction = new MethodRestriction(methodName, argRestrictions);
} else {
methodName = name.substring(hashIdx + 1);
- // methods.put(methodName, null);
methodRestriction = new MethodRestriction(methodName);
}
} else {
if ("true".equalsIgnoreCase(name)) {
- /*
- Map<Integer, Map<String, String>> args = new HashMap<Integer, Map<String,String>>();
- Map<String, String> argTypes = new HashMap<String, String>();
- argTypes.put(Class.class.getName(), null);
- args.put(1, argTypes);
- methods.put(methodName, args);
- */
className = ServiceLoader.class.getName();
methodName = "load";
ArgRestrictions argRestrictions = new ArgRestrictions();
@@ -179,7 +151,6 @@ public class ClientWeavingHook implement
}
ConsumerRestriction restriction = new ConsumerRestriction(className, methodRestriction);
restrictions.add(restriction);
- // restrictions.put(className, methods);
String bsn = element.getAttribute("bundle");
if (bsn != null) {
@@ -203,9 +174,10 @@ public class ClientWeavingHook implement
// Activator.activator.log(LogService.LOG_INFO, "Weaving " + className + "#" + methodName + " from bundle " +
// consumerBundle.getSymbolicName() + " to " + (allowedBundles.size() == 0 ? " any provider" : allowedBundles));
- Activator.activator.registerConsumerBundle(consumerBundle, restrictions, allowedBundles.size() == 0 ? null : allowedBundles);
-
+ Activator.activator.registerConsumerBundle(consumerBundle, restrictions,
+ allowedBundles.size() == 0 ? null : allowedBundles);
String[] argClasses = restriction.getMethodRestriction(methodName).getArgClasses();
+
// TODO support more than one definition
return new WeavingData(className, methodName, argClasses);
}