Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 67552 invoked from network); 1 Dec 2009 18:45:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Dec 2009 18:45:31 -0000 Received: (qmail 49564 invoked by uid 500); 1 Dec 2009 18:45:31 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 49485 invoked by uid 500); 1 Dec 2009 18:45:31 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 49475 invoked by uid 99); 1 Dec 2009 18:45:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 18:45:31 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 18:45:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 913BC23889CF; Tue, 1 Dec 2009 18:45:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r885861 - in /incubator/aries/trunk/util/src/main/java/org/apache/aries/util: FragmentBuilder.java tracker/AriesBundleTrackerCustomizer.java tracker/BundleTrackerFactory.java Date: Tue, 01 Dec 2009 18:45:08 -0000 To: aries-commits@incubator.apache.org From: linsun@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091201184508.913BC23889CF@eris.apache.org> Author: linsun Date: Tue Dec 1 18:45:08 2009 New Revision: 885861 URL: http://svn.apache.org/viewvc?rev=885861&view=rev Log: format change only Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/FragmentBuilder.java incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/BundleTrackerFactory.java Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/FragmentBuilder.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/FragmentBuilder.java?rev=885861&r1=885860&r2=885861&view=diff ============================================================================== --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/FragmentBuilder.java (original) +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/FragmentBuilder.java Tue Dec 1 18:45:08 2009 @@ -36,161 +36,166 @@ import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -public class FragmentBuilder -{ - private List importPackages = new ArrayList(); - private List exportPackages = new ArrayList(); - private Bundle hostBundle; - private String nameExtension; - private String fragmentName; - private Map files = new HashMap(); - - public FragmentBuilder(Bundle host, String extension) - { - hostBundle = host; - nameExtension = extension; - - // make sure we have an initial '.' - if (!!!nameExtension.startsWith(".")) - nameExtension = "."+nameExtension; - } - - public void setName(String name) { - fragmentName = name; - } - - public void addImports(String ... imports) { - importPackages.addAll(Arrays.asList(imports)); - } - - public void addExports(String ... imports) { - exportPackages.addAll(Arrays.asList(imports)); - } - - public void addImportsFromExports(Bundle exportBundle) { - String exportString = (String) exportBundle.getHeaders().get( - Constants.EXPORT_PACKAGE); - - if (exportString != null) { - String exportVersion = exportBundle.getVersion().toString(); - String bundleConstraint = - Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=\"" + exportBundle.getSymbolicName() + "\""; - String bundleVersionConstraint = - Constants.BUNDLE_VERSION_ATTRIBUTE + "=\"[" + exportVersion + "," + exportVersion + "]\""; - - for (String export : exportString.split("\\s*,\\s*")) { - importPackages.add(convertExportToImport(export, bundleConstraint, bundleVersionConstraint)); - } - } - } - - /** - * Filter out directives in the export statement - * @param exportStatement - * @return - */ - private String convertExportToImport(String exportStatement, String bundleConstraint, String bundleVersionConstraint) - { - StringBuffer result = new StringBuffer(); - - for (String fragment : exportStatement.split("\\s*;\\s*")) { - int pos = fragment.indexOf('='); - - // similar to fragment.contains(":=") but looks for the first '=' and checks whether this is part of ':=' - // in this way we will not be fooled by attributes like a="something:=strange" - if (!!!(pos > 0 && fragment.charAt(pos-1) == ':')) { - result.append(fragment); +public class FragmentBuilder { + private List importPackages = new ArrayList(); + private List exportPackages = new ArrayList(); + private Bundle hostBundle; + private String nameExtension; + private String fragmentName; + private Map files = new HashMap(); + + public FragmentBuilder(Bundle host, String extension) { + hostBundle = host; + nameExtension = extension; + + // make sure we have an initial '.' + if (!!!nameExtension.startsWith(".")) + nameExtension = "." + nameExtension; + } + + public void setName(String name) { + fragmentName = name; + } + + public void addImports(String... imports) { + importPackages.addAll(Arrays.asList(imports)); + } + + public void addExports(String... imports) { + exportPackages.addAll(Arrays.asList(imports)); + } + + public void addImportsFromExports(Bundle exportBundle) { + String exportString = (String) exportBundle.getHeaders().get( + Constants.EXPORT_PACKAGE); + + if (exportString != null) { + String exportVersion = exportBundle.getVersion().toString(); + String bundleConstraint = Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + + "=\"" + exportBundle.getSymbolicName() + "\""; + String bundleVersionConstraint = Constants.BUNDLE_VERSION_ATTRIBUTE + + "=\"[" + exportVersion + "," + exportVersion + "]\""; + + for (String export : exportString.split("\\s*,\\s*")) { + importPackages.add(convertExportToImport(export, + bundleConstraint, bundleVersionConstraint)); + } + } + } + + /** + * Filter out directives in the export statement + * + * @param exportStatement + * @return + */ + private String convertExportToImport(String exportStatement, + String bundleConstraint, String bundleVersionConstraint) { + StringBuffer result = new StringBuffer(); + + for (String fragment : exportStatement.split("\\s*;\\s*")) { + int pos = fragment.indexOf('='); + + // similar to fragment.contains(":=") but looks for the first '=' + // and checks whether this is part of ':=' + // in this way we will not be fooled by attributes like + // a="something:=strange" + if (!!!(pos > 0 && fragment.charAt(pos - 1) == ':')) { + result.append(fragment); + result.append(';'); + } + } + + result.append(bundleConstraint); result.append(';'); - } + result.append(bundleVersionConstraint); + + return result.toString(); + } + + public void addFile(String path, byte[] content) { + files.put(path, content); + } + + public Bundle install(BundleContext ctx) throws IOException, + BundleException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + JarOutputStream jos = null; + + try { + jos = new JarOutputStream(baos, makeManifest()); + addFileContent(jos); + } finally { + if (jos != null) + jos.close(); + baos.close(); + } + + byte[] inMemoryJar = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(inMemoryJar); + + return ctx.installBundle(getFragmentSymbolicName(), bais); + } + + private void addFileContent(JarOutputStream jos) throws IOException { + for (Map.Entry entry : files.entrySet()) { + jos.putNextEntry(new JarEntry(entry.getKey())); + jos.write(entry.getValue()); + } + } + + public String getFragmentSymbolicName() { + return hostBundle.getSymbolicName() + nameExtension; + } + + private Manifest makeManifest() { + String commonVersion = hostBundle.getVersion().toString(); + String fragmentHost = hostBundle.getSymbolicName() + ";" + + Constants.BUNDLE_VERSION_ATTRIBUTE + "=\"" + commonVersion + + "\""; + + Manifest m = new Manifest(); + Attributes manifestAttributes = m.getMainAttributes(); + manifestAttributes.putValue( + Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + manifestAttributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifestAttributes.putValue(Constants.BUNDLE_SYMBOLICNAME, + getFragmentSymbolicName()); + if (fragmentName != null) + manifestAttributes.putValue(Constants.BUNDLE_NAME, fragmentName); + manifestAttributes.putValue(Constants.BUNDLE_VERSION, commonVersion); + manifestAttributes.putValue(Constants.BUNDLE_VENDOR, "IBM"); + manifestAttributes.putValue(Constants.FRAGMENT_HOST, fragmentHost); + + addImportsAndExports(manifestAttributes); + + return m; + } + + private void addImportsAndExports(Attributes attrs) { + if (!!!importPackages.isEmpty()) { + attrs.putValue(Constants.IMPORT_PACKAGE, joinStrings( + importPackages, ',')); + } + + if (!!!exportPackages.isEmpty()) { + attrs.putValue(Constants.EXPORT_PACKAGE, joinStrings( + exportPackages, ',')); + } + } + + private String joinStrings(List strs, char separator) { + StringBuilder result = new StringBuilder(); + boolean first = true; + for (String str : strs) { + if (first) + first = false; + else + result.append(separator); + + result.append(str); + } + + return result.toString(); } - - result.append(bundleConstraint); - result.append(';'); - result.append(bundleVersionConstraint); - - return result.toString(); - } - - public void addFile(String path, byte[] content) { - files.put(path, content); - } - - public Bundle install(BundleContext ctx) throws IOException, BundleException - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JarOutputStream jos = null; - - try { - jos = new JarOutputStream(baos, makeManifest()); - addFileContent(jos); - } - finally { - if (jos != null) jos.close(); - baos.close(); - } - - byte[] inMemoryJar = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(inMemoryJar); - - return ctx.installBundle(getFragmentSymbolicName(), bais); - } - - private void addFileContent(JarOutputStream jos) throws IOException - { - for (Map.Entry entry : files.entrySet()) { - jos.putNextEntry(new JarEntry(entry.getKey())); - jos.write(entry.getValue()); - } - } - - public String getFragmentSymbolicName() - { - return hostBundle.getSymbolicName() + nameExtension; - } - - private Manifest makeManifest() - { - String commonVersion = hostBundle.getVersion().toString(); - String fragmentHost = hostBundle.getSymbolicName() + ";"+Constants.BUNDLE_VERSION_ATTRIBUTE+"=\"" + commonVersion + "\""; - - Manifest m = new Manifest(); - Attributes manifestAttributes = m.getMainAttributes(); - manifestAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); - manifestAttributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); - manifestAttributes.putValue(Constants.BUNDLE_SYMBOLICNAME, getFragmentSymbolicName()); - if (fragmentName != null) - manifestAttributes.putValue(Constants.BUNDLE_NAME, fragmentName); - manifestAttributes.putValue(Constants.BUNDLE_VERSION, commonVersion); - manifestAttributes.putValue(Constants.BUNDLE_VENDOR, "IBM"); - manifestAttributes.putValue(Constants.FRAGMENT_HOST, fragmentHost); - - addImportsAndExports(manifestAttributes); - - return m; - } - - private void addImportsAndExports(Attributes attrs) { - if (!!!importPackages.isEmpty()) { - attrs.putValue(Constants.IMPORT_PACKAGE, joinStrings(importPackages, ',')); - } - - if (!!!exportPackages.isEmpty()) { - attrs.putValue(Constants.EXPORT_PACKAGE, joinStrings(exportPackages, ',')); - } - } - - private String joinStrings(List strs, char separator) { - StringBuilder result = new StringBuilder(); - boolean first = true; - for (String str : strs) { - if (first) - first = false; - else - result.append(separator); - - result.append(str); - } - - return result.toString(); - } } Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java?rev=885861&r1=885860&r2=885861&view=diff ============================================================================== --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java (original) +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java Tue Dec 1 18:45:08 2009 @@ -27,52 +27,60 @@ import org.osgi.util.tracker.BundleTracker; import org.osgi.util.tracker.BundleTrackerCustomizer; -public abstract class AriesBundleTrackerCustomizer implements BundleTrackerCustomizer { - - public AriesBundleTrackerCustomizer() { - } - - public Object addingBundle(Bundle b, BundleEvent event) - { - customizedProcessBundle(b, event, Bundle.STARTING | Bundle.STOPPING); - return null; - } - - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) - { - // we are only interested in uninstalled bundle state for composite bundles - // as we need to remove the bt off the bt factory - if (event.getType() == BundleEvent.STOPPING) { - customizedProcessBundle(b, event, 0); +public abstract class AriesBundleTrackerCustomizer implements + BundleTrackerCustomizer { + + public AriesBundleTrackerCustomizer() { + } + + public Object addingBundle(Bundle b, BundleEvent event) { + customizedProcessBundle(b, event, Bundle.STARTING | Bundle.STOPPING); + return null; + } + + public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) { + // we are only interested in uninstalled bundle state for composite + // bundles + // as we need to remove the bt off the bt factory + if (event.getType() == BundleEvent.STOPPING) { + customizedProcessBundle(b, event, 0); + } + } + + public void removedBundle(Bundle b, BundleEvent event, Object arg2) { } - } - public void removedBundle(Bundle b, BundleEvent event, Object arg2) - { - } - - protected void customizedProcessBundle(Bundle b, BundleEvent event, int stateMask) { - if (b instanceof CompositeBundle) { - // check if the compositeBundle is already tracked in the BundleTrackerFactory - String bundleScope = b.getSymbolicName() + "_" + b.getVersion().toString(); - List btList = BundleTrackerFactory.getBundleTrackerList(bundleScope); - - if (event.getType() == BundleEvent.STOPPING) { - // if CompositeBundle is being stopped, let's remove the bundle tracker(s) associated with the composite bundle - if (btList != null) { - // unregister the bundlescope off the factory and close bundle trackers - BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope); + protected void customizedProcessBundle(Bundle b, BundleEvent event, + int stateMask) { + if (b instanceof CompositeBundle) { + // check if the compositeBundle is already tracked in the + // BundleTrackerFactory + String bundleScope = b.getSymbolicName() + "_" + + b.getVersion().toString(); + List btList = BundleTrackerFactory + .getBundleTrackerList(bundleScope); + + if (event.getType() == BundleEvent.STOPPING) { + // if CompositeBundle is being stopped, let's remove the bundle + // tracker(s) associated with the composite bundle + if (btList != null) { + // unregister the bundlescope off the factory and close + // bundle trackers + BundleTrackerFactory + .unregisterAndCloseBundleTracker(bundleScope); + } + } else if (event.getType() == BundleEvent.STARTING) { + // let's process each of the bundle in the CompositeBundle + CompositeBundle cb = (CompositeBundle) b; + BundleContext compositeBundleContext = cb + .getCompositeFramework().getBundleContext(); + + // let's track each of the bundle in the CompositeBundle + BundleTracker bt = new BundleTracker(compositeBundleContext, + stateMask, this); + bt.open(); + BundleTrackerFactory.registerBundleTracker(bundleScope, bt); + } } - } else if (event.getType() == BundleEvent.STARTING) { - // let's process each of the bundle in the CompositeBundle - CompositeBundle cb = (CompositeBundle)b; - BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext(); - - // let's track each of the bundle in the CompositeBundle - BundleTracker bt = new BundleTracker(compositeBundleContext, stateMask, this); - bt.open(); - BundleTrackerFactory.registerBundleTracker(bundleScope, bt); - } } - } } Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/BundleTrackerFactory.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/BundleTrackerFactory.java?rev=885861&r1=885860&r2=885861&view=diff ============================================================================== --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/BundleTrackerFactory.java (original) +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/BundleTrackerFactory.java Tue Dec 1 18:45:08 2009 @@ -29,69 +29,78 @@ /** * this is the factory for BundleTracker */ -public class BundleTrackerFactory -{ - private static ConcurrentHashMap> btMap = new ConcurrentHashMap>(); +public class BundleTrackerFactory { + private static ConcurrentHashMap> btMap = new ConcurrentHashMap>(); - /** - * get bundle tracker based on bundle name and version - * @param bundleScope composite bundle's - SymbolicName_Version - * @return the list of bundle tracker associated with the bundle scope - */ - public static List getBundleTrackerList(String bundleScope) - { - return (List) btMap.get(bundleScope); - } - - /** - * get bundle tracker based on composite bundle's symbolicName and version - * @param bundleSymbolicName composite bundle's symbolicName - * @param bundleVersion composite bundle's version - * @return the list of bundle tracker associated with the bundle scope - */ - public static List getBundleTrackerList(String symbolicName, Version version) - { - return (List) btMap.get(symbolicName + "_" + version.toString()); - } + /** + * get bundle tracker based on bundle name and version + * + * @param bundleScope + * composite bundle's - SymbolicName_Version + * @return the list of bundle tracker associated with the bundle scope + */ + public static List getBundleTrackerList(String bundleScope) { + return (List) btMap.get(bundleScope); + } + + /** + * get bundle tracker based on composite bundle's symbolicName and version + * + * @param bundleSymbolicName + * composite bundle's symbolicName + * @param bundleVersion + * composite bundle's version + * @return the list of bundle tracker associated with the bundle scope + */ + public static List getBundleTrackerList(String symbolicName, + Version version) { + return (List) btMap.get(symbolicName + "_" + + version.toString()); + } + + /** + * get all bundle tracker registered in this factory + * + * @return + */ + public static Collection> getAllBundleTracker() { + return btMap.values(); + } + + /** + * register the bundle tracker + * + * @param bundleScope + * composite bundle's SymbolicName_Version + * @param bt + * the bundle tracker to be registered + */ + public static void registerBundleTracker(String bundleScope, + BundleTracker bt) { + List list = btMap.get(bundleScope); + if (list == null) { + list = new ArrayList(); + } + list.add(bt); + btMap.putIfAbsent(bundleScope, list); + } - /** - * get all bundle tracker registered in this factory - * @return - */ - public static Collection> getAllBundleTracker() - { - return btMap.values(); - } - - /** - * register the bundle tracker - * @param bundleScope composite bundle's SymbolicName_Version - * @param bt the bundle tracker to be registered - */ - public static void registerBundleTracker(String bundleScope, BundleTracker bt) - { - List list = btMap.get(bundleScope); - if (list == null) { - list = new ArrayList(); - } - list.add(bt); - btMap.putIfAbsent(bundleScope, list); - } - - /** - * unregister and close the bundle tracker(s) associated with composite bundle's - SymbolicName_Version - * @param bundleScope composite bundle's - SymbolicName_Version - */ - public static void unregisterAndCloseBundleTracker(String bundleScope) - { - List list = btMap.get(bundleScope); - if (list == null) { - return; - } else { - for (BundleTracker bt : list) { - bt.close(); - } + /** + * unregister and close the bundle tracker(s) associated with composite + * bundle's - SymbolicName_Version + * + * @param bundleScope + * composite bundle's - SymbolicName_Version + */ + public static void unregisterAndCloseBundleTracker(String bundleScope) { + List list = btMap.get(bundleScope); + if (list == null) { + return; + } else { + for (BundleTracker bt : list) { + bt.close(); + } + } + btMap.remove(bundleScope); } - btMap.remove(bundleScope); - } } \ No newline at end of file