incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
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 GMT
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<String> importPackages = new ArrayList<String>();
-  private List<String> exportPackages = new ArrayList<String>();
-  private Bundle hostBundle;
-  private String nameExtension;
-  private String fragmentName;
-  private Map<String,byte[]> files = new HashMap<String, byte[]>();
-  
-  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<String> importPackages = new ArrayList<String>();
+    private List<String> exportPackages = new ArrayList<String>();
+    private Bundle hostBundle;
+    private String nameExtension;
+    private String fragmentName;
+    private Map<String, byte[]> files = new HashMap<String, byte[]>();
+
+    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<String, byte[]> 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<String> 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<String, byte[]> 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<String> 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<BundleTracker> 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<BundleTracker> 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<String, List<BundleTracker>> btMap = new ConcurrentHashMap<String,
List<BundleTracker>>();
+public class BundleTrackerFactory {
+    private static ConcurrentHashMap<String, List<BundleTracker>> btMap = new
ConcurrentHashMap<String, List<BundleTracker>>();
 
-  /**
-   * 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<BundleTracker> getBundleTrackerList(String bundleScope)
-  {
-    return (List<BundleTracker>) 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<BundleTracker> getBundleTrackerList(String symbolicName, Version
version)
-  {
-    return (List<BundleTracker>) 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<BundleTracker> getBundleTrackerList(String bundleScope) {
+        return (List<BundleTracker>) 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<BundleTracker> getBundleTrackerList(String symbolicName,
+            Version version) {
+        return (List<BundleTracker>) btMap.get(symbolicName + "_"
+                + version.toString());
+    }
+
+    /**
+     * get all bundle tracker registered in this factory
+     * 
+     * @return
+     */
+    public static Collection<List<BundleTracker>> 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<BundleTracker> list = btMap.get(bundleScope);
+        if (list == null) {
+            list = new ArrayList<BundleTracker>();
+        }
+        list.add(bt);
+        btMap.putIfAbsent(bundleScope, list);
+    }
 
-  /**
-   * get all bundle tracker registered in this factory
-   * @return
-   */
-  public static Collection<List<BundleTracker>> 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<BundleTracker> list = btMap.get(bundleScope);
-    if (list == null) {
-      list = new ArrayList<BundleTracker>();
-    } 
-    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<BundleTracker> 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<BundleTracker> 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



Mime
View raw message