SLING-2624 : Improving Jackrabbit integration with OSGi Service Registry. Minor cosmetics
authorCarsten Ziegeler <cziegeler@apache.org>
Tue, 23 Oct 2012 09:54:37 +0000 (09:54 +0000)
committerCarsten Ziegeler <cziegeler@apache.org>
Tue, 23 Oct 2012 09:54:37 +0000 (09:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1401228 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/jcr/jackrabbit/base/config/OsgiBeanFactory.java

index f55cd45..3ec4e08 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.sling.jcr.jackrabbit.base.config;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -92,7 +93,7 @@ public class OsgiBeanFactory implements BeanFactory, ServiceTrackerCustomizer {
         this.tracker = new ServiceTracker(bundleContext, filter, this);
     }
 
-    public void initialize(InputSource configSource) throws IOException, ConfigurationException {
+    public void initialize(final InputSource configSource) throws ConfigurationException {
         determineDependencies(configSource);
         createClassNameMappings();
         tracker.open();
@@ -192,19 +193,26 @@ public class OsgiBeanFactory implements BeanFactory, ServiceTrackerCustomizer {
         }
     }
 
-    private void determineDependencies(InputSource source) throws ConfigurationException, IOException {
-        Properties p = new Properties();
+    private void determineDependencies(final InputSource source) throws ConfigurationException {
+        final Properties p = new Properties();
         p.putAll(System.getProperties());
         p.setProperty(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE, "/fake/path");
-        RepositoryConfigurationParser parser = new RepositoryConfigurationParser(p);
+
+        final RepositoryConfigurationParser parser = new RepositoryConfigurationParser(p);
         parser.setConfigVisitor(new DepFinderBeanConfigVisitor());
 
         try {
             parser.parseRepositoryConfig(source);
         } finally {
-            InputStream is = source.getByteStream();
+            // close source
+            final InputStream is = source.getByteStream();
             if (is != null) {
-                is.close();
+                try { is.close(); } catch (final IOException ignore) {}
+            } else {
+                final Reader r = source.getCharacterStream();
+                if ( r != null ) {
+                    try { r.close(); } catch (final IOException ignore) {}
+                }
             }
         }