felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r681469 - in /felix/trunk/bundlerepository: ./ src/main/java/org/apache/felix/bundlerepository/ src/main/java/org/apache/felix/bundlerepository/metadataparser/ src/test/java/org/apache/felix/bundlerepository/
Date Thu, 31 Jul 2008 20:19:22 GMT
Author: rickhall
Date: Thu Jul 31 13:19:21 2008
New Revision: 681469

URL: http://svn.apache.org/viewvc?rev=681469&view=rev
Log:
Applied patch (FELIX-482) to use logger instead of System.err.

Added:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java
  (with props)
Modified:
    felix/trunk/bundlerepository/pom.xml
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Activator.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/LocalRepositoryImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdminImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResolverImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/KXml2MetadataHandler.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/MetadataHandler.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlCommonHandler.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlMetadataHandler.java
    felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryImplTest.java

Modified: felix/trunk/bundlerepository/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/pom.xml?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/pom.xml (original)
+++ felix/trunk/bundlerepository/pom.xml Thu Jul 31 13:19:21 2008
@@ -45,6 +45,12 @@
       <artifactId>kxml2</artifactId>
       <version>2.2.2</version>
     </dependency>
+    <dependency>
+        <groupId>${pom.groupId}</groupId>
+        <artifactId>org.osgi.compendium</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <optional>true</optional>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -57,7 +63,7 @@
           <instructions>
             <Export-Package>org.osgi.service.obr</Export-Package>
             <Private-Package>org.kxml2.*,org.xmlpull.*;-split-package:=merge-first,org.apache.felix.bundlerepository.*</Private-Package>
-            <Import-Package>!javax.xml.parsers,!org.xml.sax,*</Import-Package>
+            <Import-Package>!javax.xml.parsers,!org.xml.sax,org.osgi.service.log; version="1.3.0";
resolution:=optional,*</Import-Package>
             <DynamicImport-Package>org.apache.felix.shell</DynamicImport-Package>
             <Bundle-Activator>${pom.artifactId}.Activator</Bundle-Activator>
             <Bundle-DocURL>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/</Bundle-DocURL>

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Activator.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Activator.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Activator.java
Thu Jul 31 13:19:21 2008
@@ -32,7 +32,7 @@
         m_context = context;
 
         // Register bundle repository service.
-        m_repoAdmin = new RepositoryAdminImpl(m_context);
+        m_repoAdmin = new RepositoryAdminImpl(m_context, new Logger(m_context));
         context.registerService(
             RepositoryAdmin.class.getName(),
             m_repoAdmin, null);

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/LocalRepositoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/LocalRepositoryImpl.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/LocalRepositoryImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/LocalRepositoryImpl.java
Thu Jul 31 13:19:21 2008
@@ -28,14 +28,16 @@
 public class LocalRepositoryImpl implements Repository
 {
     private BundleContext m_context = null;
+    private final Logger m_logger;
     private long m_currentTimeStamp = 0;
     private long m_snapshotTimeStamp = 0;
     private List m_localResourceList = new ArrayList();
     private BundleListener m_bundleListener = null;
 
-    public LocalRepositoryImpl(BundleContext context)
+    public LocalRepositoryImpl(BundleContext context, Logger logger)
     {
         m_context = context;
+        m_logger = logger;
         initialize();
     }
 
@@ -100,13 +102,13 @@
         {
             try
             {
-                m_localResourceList.add(new LocalResourceImpl(bundles[i]));
+                m_localResourceList.add(new LocalResourceImpl(bundles[i], m_logger));
             }
             catch (InvalidSyntaxException ex)
             {
                 // This should never happen since we are generating filters,
                 // but ignore the resource if it does occur.
-                System.err.println(ex);
+                m_logger.log(Logger.LOG_WARNING, ex.getMessage(), ex);
             }
         }
     }
@@ -115,12 +117,12 @@
     {
         private Bundle m_bundle = null;
 
-        LocalResourceImpl(Bundle bundle) throws InvalidSyntaxException
+        LocalResourceImpl(Bundle bundle, Logger logger) throws InvalidSyntaxException
         {
-            this(null, bundle);
+            this(null, bundle, logger);
         }
 
-        LocalResourceImpl(ResourceImpl resource, Bundle bundle)
+        LocalResourceImpl(ResourceImpl resource, Bundle bundle, Logger logger)
             throws InvalidSyntaxException
         {
             super(resource);

Added: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java?rev=681469&view=auto
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java
(added)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java
Thu Jul 31 13:19:21 2008
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.bundlerepository;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+import java.io.PrintStream;
+
+/**
+ * Internal logger to be used in order to avoid a manatory dependency on OSGi LogService.
+ * It first tries to log to a log service implementation if there is one available and then
fallback to System out/err
+ * in case there is no log service available.
+ * <p/>
+ * As OBR implementation (this bundle) logs only errors the strategy is to lookup the log
service on each log call.
+ * This can prove as not efficient on a more intensive ussage as for example debug logging,
case when a
+ * ServiceListener or ServiceTracker can be used.
+ */
+public class Logger
+{
+    public static final int LOG_ERROR = 1;
+    public static final int LOG_WARNING = 2;
+    public static final int LOG_INFO = 3;
+    public static final int LOG_DEBUG = 4;
+
+    /**
+     * Bundle context.
+     */
+    private final BundleContext m_context;
+    private boolean m_isLogClassPresent;
+
+    /**
+     * Constructor.
+     *
+     * @param bundleContext bundle context
+     */
+    Logger(BundleContext context)
+    {
+        m_context = context;
+        try
+        {
+            org.osgi.service.log.LogService.class.getName();
+            m_isLogClassPresent = true;
+        }
+        catch (NoClassDefFoundError ex)
+        {
+            m_isLogClassPresent = false;
+        }
+    }
+
+    /**
+     * @see LogService#log(int, String)
+     */
+    public void log(int level, String message)
+    {
+        log(level, message, null);
+    }
+
+    /**
+     * @see LogService#log(int, String, Throwable)
+     */
+    public void log(int level, String message, Throwable exception)
+    {
+        if (!m_isLogClassPresent || !_log(level, message, exception))
+        {
+            final PrintStream stream = getStream(level);
+            stream.println(message);
+            if (exception != null)
+            {
+                exception.printStackTrace(stream);
+            }
+
+        }
+    }
+
+    /**
+     * Lookup the OSGi LogService and if available use it.
+     */
+    private boolean _log(int level, String message, Throwable exception)
+    {
+        try
+        {
+            ServiceReference reference = null;
+            reference = m_context.getServiceReference(LogService.class.getName());
+            if (reference != null)
+            {
+                final LogService logService = (LogService) m_context.getService(reference);
+                if (logService != null)
+                {
+                    logService.log(level, message, exception);
+                    m_context.ungetService(reference);
+                    return true;
+                }
+            }
+        }
+        catch (NoClassDefFoundError e)
+        {
+            //ignore
+        }
+        return false;
+    }
+
+    /**
+     * Return the standard print streams to use depending on log level.
+     *
+     * @param level log level
+     * @return print stream corresponding to log level
+     */
+    private PrintStream getStream(int level)
+    {
+        switch (level)
+        {
+            case LOG_ERROR:
+                System.err.print("ERROR: ");
+                return System.err;
+            case LOG_WARNING:
+                System.err.print("WARNING: ");
+                return System.err;
+            case LOG_INFO:
+                System.out.print("INFO: ");
+                return System.out;
+            case LOG_DEBUG:
+                System.out.print("DEBUG: ");
+                return System.out;
+            default:
+                System.out.print("UNKNOWN: ");
+                return System.out;
+        }
+    }
+}
\ No newline at end of file

Propchange: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Logger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdminImpl.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdminImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdminImpl.java
Thu Jul 31 13:19:21 2008
@@ -39,6 +39,7 @@
 public class RepositoryAdminImpl implements RepositoryAdmin
 {
     static BundleContext m_context = null;
+    private final Logger m_logger;
     private List m_urlList = new ArrayList();
     private Map m_repoMap = new HashMap();
     private boolean m_initialized = false;
@@ -50,9 +51,10 @@
     public static final String REPOSITORY_URL_PROP = "obr.repository.url";
     public static final String EXTERN_REPOSITORY_TAG = "extern-repositories";
 
-    public RepositoryAdminImpl(BundleContext context)
+    public RepositoryAdminImpl(BundleContext context, Logger logger)
     {
         m_context = context;
+        m_logger = logger;
     }
 
     public Repository addRepository(URL url) throws Exception
@@ -70,7 +72,7 @@
         // If the repository URL is a duplicate, then we will just
         // replace the existing repository object with a new one,
         // which is effectively the same as refreshing the repository.
-        Repository repo = new RepositoryImpl(this, url, hopCount);
+        Repository repo = new RepositoryImpl(this, url, hopCount, m_logger);
         m_repoMap.put(url, repo);
         return repo;
     }
@@ -103,7 +105,7 @@
             initialize();
         }
 
-        return new ResolverImpl(m_context, this);
+        return new ResolverImpl(m_context, this, m_logger);
     }
 
     public synchronized Resource[] discoverResources(String filterExpr)
@@ -120,7 +122,10 @@
         }
         catch (InvalidSyntaxException ex)
         {
-            System.err.println(ex);
+            m_logger.log(
+                Logger.LOG_WARNING,
+                "Error while discovering resources for " + filterExpr,
+                ex);
             return new Resource[0];
         }
 
@@ -163,13 +168,17 @@
                 {
                     while (st.hasMoreTokens())
                     {
+                        final String token = st.nextToken();
                         try
                         {
-                            m_urlList.add(new URL(st.nextToken()));
+                            m_urlList.add(new URL(token));
                         }
                         catch (MalformedURLException ex)
                         {
-                            System.err.println("RepositoryAdminImpl: " + ex);
+                            m_logger.log(
+                                Logger.LOG_WARNING,
+                                "Repository url " + token + " cannot be used. Skipped.",
+                                ex);
                         }
                     }
                 }
@@ -184,7 +193,10 @@
                 }
                 catch (MalformedURLException ex)
                 {
-                    System.err.println("RepositoryAdminImpl: " + ex);
+                    m_logger.log(
+                        Logger.LOG_WARNING,
+                        "Default repository url " + DEFAULT_REPOSITORY_URL + " cannot be
used. Skipped.",
+                        ex);
                 }
             }
         }
@@ -196,7 +208,7 @@
             URL url = (URL) m_urlList.get(i);
             try
             {
-                Repository repo = new RepositoryImpl(this, url);
+                Repository repo = new RepositoryImpl(this, url, m_logger);
                 if (repo != null)
                 {
                     m_repoMap.put(url, repo);
@@ -204,8 +216,11 @@
             }
             catch (Exception ex)
             {
-                System.err.println("RepositoryAdminImpl: Exception creating repository -
" + ex);
-                System.err.println("RepositoryAdminImpl: Ignoring repository " + url);
+                m_logger.log(
+                    Logger.LOG_WARNING,
+                    "RepositoryAdminImpl: Exception creating repository " + url.toExternalForm()
+                        + ". Repository is skipped.",
+                    ex);
             }
         }
     }

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
Thu Jul 31 13:19:21 2008
@@ -46,6 +46,7 @@
     private String m_name = null;
     private long m_lastmodified = 0;
     private URL m_url = null;
+    private final Logger m_logger;
     private Resource[] m_resources = null;
     private Referral[] m_referrals = null;
     private RepositoryAdminImpl m_repoAdmin = null;
@@ -53,15 +54,18 @@
     // Reusable comparator for sorting resources by name.
     private ResourceComparator m_nameComparator = new ResourceComparator();
 
-    public RepositoryImpl(RepositoryAdminImpl repoAdmin, URL url) throws Exception
+    public RepositoryImpl(RepositoryAdminImpl repoAdmin, URL url, Logger logger)
+        throws Exception
     {
-        this(repoAdmin, url, Integer.MAX_VALUE);
+        this(repoAdmin, url, Integer.MAX_VALUE, logger);
     }
 
-    public RepositoryImpl(RepositoryAdminImpl repoAdmin, URL url, final int hopCount) throws
Exception
+    public RepositoryImpl(RepositoryAdminImpl repoAdmin, URL url, final int hopCount, Logger
logger)
+        throws Exception
     {
         m_repoAdmin = repoAdmin;
         m_url = url;
+        m_logger = logger;
         try
         {
             AccessController.doPrivileged(new PrivilegedExceptionAction()
@@ -219,7 +223,7 @@
             if (is != null)
             {
                 // Create the parser Kxml
-                XmlCommonHandler handler = new XmlCommonHandler();
+                XmlCommonHandler handler = new XmlCommonHandler(m_logger);
                 Object factory = new Object()
                 {
                     public RepositoryImpl newInstance()

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResolverImpl.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResolverImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResolverImpl.java
Thu Jul 31 13:19:21 2008
@@ -29,6 +29,7 @@
 {
     private BundleContext m_context = null;
     private RepositoryAdmin m_admin = null;
+    private final Logger m_logger;
     private LocalRepositoryImpl m_local = null;
     private Set m_addedSet = new HashSet();
     private Set m_resolveSet = new HashSet();
@@ -38,10 +39,11 @@
     private Map m_unsatisfiedMap = new HashMap();
     private boolean m_resolved = false;
 
-    public ResolverImpl(BundleContext context, RepositoryAdmin admin)
+    public ResolverImpl(BundleContext context, RepositoryAdmin admin, Logger logger)
     {
         m_context = context;
         m_admin = admin;
+        m_logger = logger;
     }
 
     public synchronized void add(Resource resource)
@@ -116,7 +118,7 @@
         {
             m_local.dispose();
         }
-        m_local = new LocalRepositoryImpl(m_context);
+        m_local = new LocalRepositoryImpl(m_context, m_logger);
 
         // Reset instance values.
         m_resolveSet.clear();
@@ -423,8 +425,7 @@
         // Must resolve if not already resolved.
         if (!m_resolved && !resolve())
         {
-            // TODO: OBR - Use logger if possible.
-            System.err.println("Resolver: Cannot resolve target resources.");
+            m_logger.log(Logger.LOG_ERROR, "Resolver: Cannot resolve target resources.");
             return;
         }
 
@@ -495,9 +496,10 @@
                     }
                     catch (Exception ex)
                     {
-                        // TODO: OBR - Use logger if possible.
-                        System.err.println("Resolver: Update error - " + Util.getBundleName(localResource.getBundle()));
-                        ex.printStackTrace(System.err);
+                        m_logger.log(
+                            Logger.LOG_ERROR,
+                            "Resolver: Update error - " + Util.getBundleName(localResource.getBundle()),
+                            ex);
                         return;
                     }
                 }
@@ -530,10 +532,10 @@
                 }
                 catch (Exception ex)
                 {
-                    // TODO: OBR - Use logger if possible.
-                    System.err.println("Resolver: Install error - "
-                        + deployResources[i].getSymbolicName());
-                    ex.printStackTrace(System.err);
+                    m_logger.log(
+                        Logger.LOG_ERROR,
+                        "Resolver: Install error - " + deployResources[i].getSymbolicName(),

+                        ex);
                     return;
                 }
             }
@@ -547,8 +549,10 @@
             }
             catch (BundleException ex)
             {
-                // TODO: OBR - Use logger if possible.
-                System.err.println("Resolver: Start error - " + ex);
+                m_logger.log(
+                    Logger.LOG_ERROR,
+                    "Resolver: Start error - " + ((Bundle) startList.get(i)).getSymbolicName(),
+                    ex);
             }
         }
     }
@@ -685,9 +689,8 @@
                     }
                 }
             }
-            return (Requirement[])
-                reqList.toArray(new Requirement[reqList.size()]);
+            return (Requirement[]) reqList.toArray(new Requirement[reqList.size()]);
         }
         return null;
     }
-}
+}
\ No newline at end of file

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/KXml2MetadataHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/KXml2MetadataHandler.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/KXml2MetadataHandler.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/KXml2MetadataHandler.java
Thu Jul 31 13:19:21 2008
@@ -21,6 +21,7 @@
 import java.io.*;
 
 import org.apache.felix.bundlerepository.metadataparser.kxmlsax.KXml2SAXParser;
+import org.apache.felix.bundlerepository.Logger;
 
 /**
  * handles the metadata in XML format
@@ -28,7 +29,9 @@
  */
 public class KXml2MetadataHandler extends MetadataHandler {
 
-	public KXml2MetadataHandler() {}
+	public KXml2MetadataHandler(Logger logger) {
+        super(logger);
+    }
 
 	/**
 	* Called to parse the InputStream and set bundle list and package hash map
@@ -39,4 +42,4 @@
 		parser = new KXml2SAXParser(br);
 		parser.parseXML(handler);
 	}
-}
+}
\ No newline at end of file

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/MetadataHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/MetadataHandler.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/MetadataHandler.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/MetadataHandler.java
Thu Jul 31 13:19:21 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.bundlerepository.metadataparser;
 
+import org.apache.felix.bundlerepository.Logger;
+
 import java.io.InputStream;
 import java.lang.reflect.Method;
 
@@ -29,8 +31,8 @@
 	 * constructor 
 	 *
 	 */
-	public MetadataHandler() {
-		handler = new XmlCommonHandler();
+	public MetadataHandler(Logger logger) {
+		handler = new XmlCommonHandler(logger);
 	}
 
 	/**
@@ -133,4 +135,4 @@
 	public final void setTrace(boolean trace) {
 		handler.setTrace(trace);
 	}
-}
+}
\ No newline at end of file

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlCommonHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlCommonHandler.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlCommonHandler.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlCommonHandler.java
Thu Jul 31 13:19:21 2008
@@ -23,6 +23,7 @@
 import java.util.*;
 
 import org.apache.felix.bundlerepository.metadataparser.kxmlsax.KXml2SAXHandler;
+import org.apache.felix.bundlerepository.Logger;
 import org.xml.sax.SAXException;
 
 
@@ -64,8 +65,9 @@
 	private StringBuffer currentText;
 
 	private Map context;
+    private final Logger m_logger;
 
-	private class XmlStackElement {
+    private class XmlStackElement {
 		
 		public final String qname;
 		public Object object;
@@ -151,8 +153,9 @@
 		}
 	}
 	
-	public XmlCommonHandler() {
-		elementStack = new Stack();
+	public XmlCommonHandler(Logger logger) {
+        m_logger = logger;
+        elementStack = new Stack();
 		pis = new HashMap();
 		missingPIExceptionFlag = false;
 		types = new HashMap();
@@ -269,7 +272,7 @@
 			try {
 				method.invoke(object, new Object[] { context });
 			} catch (InvocationTargetException e) {
-				e.getTargetException().printStackTrace(System.err);
+                m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 				throw e;
 			}
 		}
@@ -293,7 +296,7 @@
 			try {
 				method.invoke(object, null);
 			} catch (InvocationTargetException e) {
-				// e.getTargetException().printStackTrace(System.err);
+				// m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 				throw e.getTargetException();
 			}
 
@@ -319,7 +322,7 @@
 			try {
 				method.invoke(object, new Object[] { parent });
 			} catch (InvocationTargetException e) {
-				e.getTargetException().printStackTrace(System.err);
+				m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 				throw e;
 			}
 		}
@@ -352,9 +355,9 @@
 			try {
 				// enables to access to "unmuttable" method
 				type.newInstanceMethod.setAccessible(true);
-				obj = type.newInstanceMethod.invoke(type.instanceFactory, null);
-			} catch (Exception e) {
-				// do nothing
+                obj = type.newInstanceMethod.invoke(type.instanceFactory, null);
+			} catch (InvocationTargetException e) {
+				m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 			}
 
 			// set parent
@@ -409,7 +412,7 @@
 					try {
 						method.invoke(obj, new String[] { value });
 					} catch (InvocationTargetException e) {
-						e.getTargetException().printStackTrace(System.err);
+						m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 						throw e;
 					}
 				} else {
@@ -513,7 +516,7 @@
 				try {
 					method.invoke(element.object, new String[] { currentStr });
 				} catch (InvocationTargetException e) {
-					e.getTargetException().printStackTrace(System.err);
+					m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 					throw e;
 				}
 			} else {
@@ -593,7 +596,7 @@
                     method.setAccessible(true);
 					method.invoke(parent.object, new Object[] { element.object });
 				} catch (InvocationTargetException e) {
-					e.getTargetException().printStackTrace(System.err);
+					m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 					throw e;
 				}
 			} else {
@@ -628,7 +631,7 @@
 		try {
 			invokeProcess(element);
 		} catch (Throwable e) {
-			e.printStackTrace();
+			m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e);
 			throw new Exception(e);
 		}
 
@@ -643,7 +646,7 @@
 
 	private void trace(String msg) {
 		if (traceFlag)
-			System.err.println(msg);
+			m_logger.log(Logger.LOG_DEBUG, msg);
 	}
 
 	/**
@@ -746,7 +749,7 @@
 				try {
 					method.invoke(object, new String[] { value });
 				} catch (InvocationTargetException e) {
-					e.getTargetException().printStackTrace(System.err);
+					m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e.getTargetException());
 					throw e;
 				}
 			}
@@ -757,7 +760,7 @@
 		try {
 			invokeProcess(object);
 		} catch (Throwable e) {
-			e.printStackTrace();
+			m_logger.log(Logger.LOG_ERROR, "Error parsing repository metadata", e);
 			throw new Exception(e);
 		}
 */	}

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlMetadataHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlMetadataHandler.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlMetadataHandler.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/metadataparser/XmlMetadataHandler.java
Thu Jul 31 13:19:21 2008
@@ -24,14 +24,16 @@
 import javax.xml.parsers.*;
 
 import org.xml.sax.*;
+import org.apache.felix.bundlerepository.Logger;
 
 /**
  * handles the metadata in XML format
  */
 public class XmlMetadataHandler extends MetadataHandler {
 
-	public XmlMetadataHandler() {
-	}
+	public XmlMetadataHandler(Logger logger) {
+        super(logger);
+    }
 	
 	/**
 	* Called to parse the InputStream and set bundle list and package hash map

Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryImplTest.java?rev=681469&r1=681468&r2=681469&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryImplTest.java
(original)
+++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryImplTest.java
Thu Jul 31 13:19:21 2008
@@ -38,10 +38,8 @@
 
 public class RepositoryImplTest extends TestCase
 {
-
     public void testReferral1() throws Exception
     {
-
         URL url = getClass().getResource("/referral1_repository.xml");
 
         RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
@@ -71,7 +69,6 @@
 
     public void testReferral2() throws Exception
     {
-
         URL url = getClass().getResource("/referral1_repository.xml");
 
         RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
@@ -97,7 +94,8 @@
 
     private RepositoryAdminImpl createRepositoryAdmin()
     {
-        RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(new MockBundleContext());
+        final MockBundleContext bundleContext = new MockBundleContext();
+        RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
 
         // force initialization && remove all initial repositories
         Repository[] repos = repoAdmin.listRepositories();
@@ -111,7 +109,6 @@
 
     private static class MockBundleContext implements BundleContext
     {
-
         public void addBundleListener(BundleListener arg0)
         {
         }
@@ -241,4 +238,4 @@
             return false;
         }
     }
-}
+}
\ No newline at end of file



Mime
View raw message