I put the override processing afterward to keep it together logically as a unit. It's certainly more efficient to tie it into the initial list build, at the cost of mixing the two concerns of building a list, and finding overrides for items on a list.
I guess if we're happy that the approach of building the list isnt likely to change, or that if it does it will do so in a manner that remains close enough the the current, then I'm fine with moving the override check into addEntry/addEntries. (or rather into a method invoked from both). The concern would be mainly that if the list building is modified to call a new 'addXXX' method, that such a change would need to also invoke the 'checkOverride' method. Regards, Ozzy On Wed, Oct 21, 2009 at 5:02 PM, Guillaume Nodet <[email protected]> wrote: > Wouldn't it be nicer to do that on the fly in the addEntry / > addEntries method instead of iterating after the list has been built ? > > On Wed, Oct 21, 2009 at 16:24, <[email protected]> wrote: > > Author: ozzy > > Date: Wed Oct 21 14:24:37 2009 > > New Revision: 828032 > > > > URL: http://svn.apache.org/viewvc?rev=828032&view=rev > > Log: > > ARIES-25 allow Blueprint extender to find blueprint XML within bundle > private storage. > > > > Modified: > > > > incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java > > > > Modified: > incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java > > URL: > http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=828032&r1=828031&r2=828032&view=diff > > > ============================================================================== > > --- > incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java > (original) > > +++ > incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java > Wed Oct 21 14:24:37 2009 > > @@ -18,12 +18,15 @@ > > */ > > package org.apache.aries.blueprint.container; > > > > +import java.io.File; > > +import java.net.MalformedURLException; > > import java.net.URL; > > import java.util.ArrayList; > > import java.util.Collections; > > import java.util.Comparator; > > import java.util.Enumeration; > > import java.util.HashMap; > > +import java.util.Iterator; > > import java.util.List; > > import java.util.Map; > > import java.util.concurrent.Executors; > > @@ -38,8 +41,8 @@ > > import org.osgi.framework.BundleContext; > > import org.osgi.framework.BundleEvent; > > import org.osgi.framework.Constants; > > -import org.osgi.framework.SynchronousBundleListener; > > import org.osgi.framework.ServiceReference; > > +import org.osgi.framework.SynchronousBundleListener; > > import org.osgi.service.blueprint.container.BlueprintContainer; > > import org.osgi.service.blueprint.container.BlueprintEvent; > > import org.slf4j.Logger; > > @@ -172,6 +175,18 @@ > > } > > } > > > > + private String getFilePart(URL url) > > + { > > + String path = url.getPath(); > > + int index = path.lastIndexOf('/'); > > + return path.substring(index+1); > > + } > > + > > + private String cachePath(Bundle bundle, String filePath) > > + { > > + return bundle.getSymbolicName() + "/" + bundle.getVersion() + "/" > + filePath; > > + } > > + > > private void checkBundle(Bundle bundle) { > > LOGGER.debug("Scanning bundle {} for blueprint application", > bundle.getSymbolicName()); > > try { > > @@ -202,7 +217,45 @@ > > addEntry(bundle, name, pathList); > > } > > } > > - } > > + } > > + > > + //Override bundle specified blueprint XML with > > + //XML already in the private storage. > > + Iterator<Object> pathIter = pathList.iterator(); > > + List<Object> overridden = new > ArrayList<Object>(); > > + while (pathIter.hasNext()) { > > + Object path = pathIter.next(); > > + if (path instanceof URL) { > > + URL url = (URL) path; > > + File privateDataVersion = > context.getDataFile(cachePath( > > + bundle, > "OSGI-INF/blueprint/" + getFilePart(url))); > > + if (privateDataVersion != null && > privateDataVersion.exists()) { > > + try { > > + > overridden.add(privateDataVersion.toURL()); > > + > pathIter.remove(); > > + } catch > (MalformedURLException e) { > > + > LOGGER.error("Unexpected URL Conversion Issue", e); > > + } > > + } > > + } else if (path instanceof String) { > > + String s = (String) path; > > + File privateDataVersion = > context.getDataFile(cachePath( > > + bundle, s)); > > + if (privateDataVersion != null > && privateDataVersion.exists()) { > > + try { > > + > overridden.add(privateDataVersion.toURL()); > > + > pathIter.remove(); > > + } catch > (MalformedURLException e) { > > + > LOGGER.error("Unexpected URL Conversion Issue", e); > > + } > > + } > > + } else { > > + throw new > IllegalArgumentException("Unexpected path type: " > > + + > path.getClass()); > > + } > > + } > > + pathList.addAll(overridden); > > + > > if (!pathList.isEmpty()) { > > LOGGER.debug("Found blueprint application in bundle {} > with paths: {}", bundle.getSymbolicName(), pathList); > > // Check compatibility > > > > > > > > > > -- > Cheers, > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > ------------------------ > Open Source SOA > http://fusesource.com >
