directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcon...@apache.org
Subject svn commit: r473771 - in /directory/sandbox/jconlon/osgi-services: ./ logging-service/ logging-service/src/ logging-service/src/main/ logging-service/src/main/java/ logging-service/src/main/java/org/ logging-service/src/main/java/org/apache/ logging-se...
Date Sat, 11 Nov 2006 18:51:22 GMT
Author: jconlon
Date: Sat Nov 11 10:51:21 2006
New Revision: 473771

URL: http://svn.apache.org/viewvc?view=rev&rev=473771
Log:
adding osgi-services subprojects for OSGi service implementations

Added:
    directory/sandbox/jconlon/osgi-services/
    directory/sandbox/jconlon/osgi-services/logging-service/   (with props)
    directory/sandbox/jconlon/osgi-services/logging-service/pom.xml
    directory/sandbox/jconlon/osgi-services/logging-service/src/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
    directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
    directory/sandbox/jconlon/osgi-services/pom.xml

Propchange: directory/sandbox/jconlon/osgi-services/logging-service/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Nov 11 10:51:21 2006
@@ -0,0 +1,5 @@
+target
+.settings
+.wtpmodules
+.classpath
+.project

Added: directory/sandbox/jconlon/osgi-services/logging-service/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/logging-service/pom.xml?view=auto&rev=473771
==============================================================================
--- directory/sandbox/jconlon/osgi-services/logging-service/pom.xml (added)
+++ directory/sandbox/jconlon/osgi-services/logging-service/pom.xml Sat Nov 11 10:51:21 2006
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.directory.osgi.services</groupId>
+		<artifactId>build</artifactId>
+		<version>1.0.6-SNAPSHOT</version>
+	</parent>
+	
+	<description>
+	An OSGi Bundle offering an implementation of the OSGi LogService, library support for Apache
slf4j, and slf4j support for Apache commons-logging. All services are based on the slf4j simple
implementation. To change the logging configuration, edit the configuration properties in:
conf/log4j.properties file, then stop and restart the bundle.
+	</description>
+	<artifactId>logging-service</artifactId>
+	<packaging>bundle</packaging>
+	<name>${pom.artifactId} bundle</name>
+	<build>
+		<plugins>
+		    <plugin>
+		        <groupId>org.apache.felix</groupId>
+		        <artifactId>maven-bundle-plugin</artifactId>
+		        <extensions>true</extensions>
+		        <configuration>
+		          <instructions>
+		            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+		            <Import-Package>
+		            javax.*,
+		            org.osgi.*,
+		            com.sun.jdmk.comm, 
+		            org.w3c.dom, 
+		            org.xml.sax
+		            </Import-Package>
+		            <Export-Package>
+		            org.apache.commons.logging.*,
+		            org.slf4j.*,
+		            org.apache.log4j.*</Export-Package>
+		            <Private-Package>org.apache.directory.osgi.services.logging.*</Private-Package>
+          			<Bundle-Activator>org.apache.directory.osgi.services.logging.Activator</Bundle-Activator>
+		          </instructions>
+		        </configuration>
+		    </plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>0.8.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<version>0.8.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>jcl104-over-slf4j</artifactId>
+			<version>1.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>nlog4j</artifactId>
+			<version>1.2.25</version>
+			<exclusions>
+				<exclusion>
+					<groupId>xerces</groupId>
+					<artifactId>xerces</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>com.sun.jdmk</groupId>
+					<artifactId>jmxtools</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.jms</groupId>
+					<artifactId>jms</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.mail</groupId>
+					<artifactId>mail</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.activation</groupId>
+					<artifactId>activation</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>com.sun.jmx</groupId>
+					<artifactId>jmxri</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>checkstyle</groupId>
+					<artifactId>checkstyle</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+	</dependencies>
+</project>

Added: directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java?view=auto&rev=473771
==============================================================================
--- directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
(added)
+++ directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
Sat Nov 11 10:51:21 2006
@@ -0,0 +1,109 @@
+package org.apache.directory.osgi.services.logging;
+
+
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * BundleActivator for logging services.
+ *
+ */
+public class Activator implements BundleActivator
+{
+
+    private static final String VENDOR = "org.apache";
+
+    private static final String LOG_PROPERTIES_LOCATION = "log4j.configuration";
+
+    private Logger log = null;
+
+
+    public Activator()
+    {
+        super();
+    }
+
+
+    /**
+     * On bundle start reload the log4J configuration and register the logService.
+     */
+    public void start( BundleContext bundleContext ) throws Exception
+    {
+        try
+        {
+            resetLog4j( bundleContext );
+            log = LoggerFactory.getLogger( Activator.class );
+            log.debug( "Reset log configuration." );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        registerLogService( bundleContext );
+    }
+
+
+    private void registerLogService( BundleContext bundleContext )
+    {
+        Dictionary<String, String> parameters = new Hashtable<String, String>();
+        parameters.put( Constants.SERVICE_VENDOR, VENDOR );
+        bundleContext.registerService( LogService.class.getName(), new LogServiceImpl(),
parameters );
+    }
+
+
+    public void stop( BundleContext arg0 ) throws Exception
+    {
+    }
+
+
+    /**
+     * @return url of the log4j.properties configuration file
+     * 
+     * @throws MalformedURLException
+     * 
+     */
+    private URL getLoggingProperty( BundleContext bundleContext ) throws MalformedURLException
+    {
+        final String logPropertiesLocation = bundleContext.getProperty( LOG_PROPERTIES_LOCATION
);
+        return new URL( logPropertiesLocation );
+    }
+
+
+    /**
+     * Reset the log4j configuration.
+     * @param bundleContext
+     * @throws MalformedURLException
+     * @throws FileNotFoundException
+     */
+    private void resetLog4j( BundleContext bundleContext ) throws MalformedURLException,
FileNotFoundException
+    {
+        LogManager.resetConfiguration();
+        URL log4jprops = getLoggingProperty( bundleContext );
+
+        if ( log4jprops != null )
+        {
+            PropertyConfigurator.configure( log4jprops );
+
+        }
+        else
+        {
+            throw new FileNotFoundException( bundleContext.getProperty( LOG_PROPERTIES_LOCATION
)
+                + " could not be found. " + "Please specify add the file and restart the
"
+                + bundleContext.getBundle().getLocation() + " bundle." );
+        }
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java?view=auto&rev=473771
==============================================================================
--- directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
(added)
+++ directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
Sat Nov 11 10:51:21 2006
@@ -0,0 +1,188 @@
+package org.apache.directory.osgi.services.logging;
+
+
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.osgi.service.log.LogService;
+
+
+public class LogServiceImpl implements LogService
+{
+    /** the log for this class */
+    private static final Logger delegate = LoggerFactory.getLogger( LogServiceImpl.class
);
+
+
+    /**
+     * Logs a message.
+     * 
+     * <p>
+     * The <code>ServiceReference</code> field and the <code>Throwable</code>
+     * field of the <code>LogEntry</code> object will be set to
+     * <code>null</code>.
+     * 
+     * @param level
+     *            The severity of the message. This should be one of the defined
+     *            log levels but may be any integer that is interpreted in a
+     *            user defined way.
+     * @param message
+     *            Human readable string describing the condition or
+     *            <code>null</code>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+    public void log( int level, String message )
+    {
+        switch ( level )
+        {
+            case LOG_DEBUG:
+                delegate.debug( message );
+                break;
+            case LOG_ERROR:
+                delegate.error( message );
+                break;
+            case LOG_INFO:
+                delegate.info( message );
+                break;
+            case LOG_WARNING:
+                delegate.warn( message );
+                break;
+            default:
+                break;
+        }
+    }
+
+
+    /**
+     * Logs a message with an exception.
+     * 
+     * <p>
+     * The <code>ServiceReference</code> field of the <code>LogEntry</code>
+     * object will be set to <code>null</code>.
+     * 
+     * @param level
+     *            The severity of the message. This should be one of the defined
+     *            log levels but may be any integer that is interpreted in a
+     *            user defined way.
+     * @param message
+     *            The human readable string describing the condition or
+     *            <code>null</code>.
+     * @param exception
+     *            The exception that reflects the condition or <code>null</code>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+    public void log( int level, String message, Throwable exception )
+    {
+        switch ( level )
+        {
+            case LOG_DEBUG:
+                delegate.debug( message, exception );
+                break;
+            case LOG_ERROR:
+                delegate.error( message, exception );
+                break;
+            case LOG_INFO:
+                delegate.info( message, exception );
+                break;
+            case LOG_WARNING:
+                delegate.warn( message, exception );
+                break;
+            default:
+                break;
+        }
+    }
+
+
+    /**
+     * Logs a message associated with a specific <code>ServiceReference</code>
+     * object.
+     * 
+     * <p>
+     * The <code>Throwable</code> field of the <code>LogEntry</code>
will be
+     * set to <code>null</code>.
+     * 
+     * @param sr
+     *            The <code>ServiceReference</code> object of the service that
+     *            this message is associated with or <code>null</code>.
+     * @param level
+     *            The severity of the message. This should be one of the defined
+     *            log levels but may be any integer that is interpreted in a
+     *            user defined way.
+     * @param message
+     *            Human readable string describing the condition or
+     *            <code>null</code>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+    public void log( ServiceReference sr, int level, String message )
+    {
+        switch ( level )
+        {
+            case LOG_DEBUG:
+                delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message );
+                break;
+            case LOG_ERROR:
+                delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message );
+                break;
+            case LOG_INFO:
+                delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message );
+                break;
+            case LOG_WARNING:
+                delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message );
+                break;
+            default:
+                break;
+        }
+    }
+
+
+    /**
+     * Logs a message with an exception associated and a
+     * <code>ServiceReference</code> object.
+     * 
+     * @param sr
+     *            The <code>ServiceReference</code> object of the service that
+     *            this message is associated with.
+     * @param level
+     *            The severity of the message. This should be one of the defined
+     *            log levels but may be any integer that is interpreted in a
+     *            user defined way.
+     * @param message
+     *            Human readable string describing the condition or
+     *            <code>null</code>.
+     * @param exception
+     *            The exception that reflects the condition or <code>null</code>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+    public void log( ServiceReference sr, int level, String message, Throwable exception
)
+    {
+        switch ( level )
+        {
+            case LOG_DEBUG:
+                delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message, exception
);
+                break;
+            case LOG_ERROR:
+                delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message, exception
);
+                break;
+            case LOG_INFO:
+                delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message, exception
);
+                break;
+            case LOG_WARNING:
+                delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message, exception
);
+                break;
+            default:
+                break;
+        }
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-services/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/pom.xml?view=auto&rev=473771
==============================================================================
--- directory/sandbox/jconlon/osgi-services/pom.xml (added)
+++ directory/sandbox/jconlon/osgi-services/pom.xml Sat Nov 11 10:51:21 2006
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  
+  <parent>
+    <groupId>org.apache.directory</groupId>
+    <artifactId>build</artifactId>
+    <version>1.0.6-SNAPSHOT</version>
+  </parent>
+  
+  <description>
+    These subprojects implement standard OSGi services. 
+  </description>
+  <groupId>org.apache.directory.osgi.services</groupId>
+  <artifactId>build</artifactId>
+  <name>Apache Directory OSGi Services Build</name>
+  <packaging>pom</packaging>
+  
+  <modules>
+    <module>logging-service</module>
+  </modules>
+  
+</project>



Mime
View raw message