geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r920321 - in /geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org: ./ apache/ apache/geronimo/ apache/geronimo/specs/ apache/geronimo/specs/activation/
Date Mon, 08 Mar 2010 13:40:58 GMT
Author: rickmcguire
Date: Mon Mar  8 13:40:57 2010
New Revision: 920321

URL: http://svn.apache.org/viewvc?rev=920321&view=rev
Log:
Missed checkins of new files

Added:
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
  (with props)
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
  (with props)

Added: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java?rev=920321&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
(added)
+++ geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
Mon Mar  8 13:40:57 2010
@@ -0,0 +1,104 @@
+/**
+ * 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.geronimo.specs.activation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * The activator that starts and manages the tracking of
+ * JAF activation command maps
+ */
+public class Activator extends org.apache.geronimo.osgi.locator.Activator {
+    // tracker to watch for bundle updates
+    protected BundleTracker bt;
+    // service tracker for a logging service
+    protected ServiceTracker lst;
+    // an array of all active logging services.
+    List<LogService> logServices = new ArrayList<LogService>();
+
+
+    @Override
+    public synchronized void start(final BundleContext context) throws Exception {
+        super.start(context);
+        lst = new LogServiceTracker(context, LogService.class.getName(), null);
+        lst.open();
+	    bt = new BundleTracker(context, Bundle.ACTIVE, new CommandMapBundleTrackerCustomizer(this,
context.getBundle()));
+	    bt.open();
+	}
+
+    @Override
+	public synchronized void stop(BundleContext context) throws Exception {
+	    bt.close();
+	    lst.close();
+        super.stop(context);
+	}
+
+	void log(int level, String message) {
+	    synchronized (logServices) {
+	        for (LogService log : logServices) {
+	            log.log(level, message);
+	        }
+        }
+	}
+
+	void log(int level, String message, Throwable th) {
+        synchronized (logServices) {
+            for (LogService log : logServices) {
+                log.log(level, message, th);
+            }
+        }
+    }
+
+	private final class LogServiceTracker extends ServiceTracker {
+        private LogServiceTracker(BundleContext context, String clazz,
+                ServiceTrackerCustomizer customizer) {
+            super(context, clazz, customizer);
+        }
+
+        @Override
+        public Object addingService(ServiceReference reference) {
+            Object svc = super.addingService(reference);
+            if (svc instanceof LogService) {
+                synchronized (logServices) {
+                    logServices.add((LogService) svc);
+                }
+            }
+            return svc;
+        }
+
+        @Override
+        public void removedService(ServiceReference reference, Object service) {
+            synchronized (logServices) {
+                logServices.remove(service);
+            }
+            super.removedService(reference, service);
+        }
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/Activator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java?rev=920321&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
(added)
+++ geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
Mon Mar  8 13:40:57 2010
@@ -0,0 +1,148 @@
+/**
+ * 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.geronimo.specs.activation;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.activation.MailcapCommandMap;
+import javax.activation.CommandMap;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+
+public class CommandMapBundleTrackerCustomizer implements BundleTrackerCustomizer {
+    // our base Activator (used as a service source)
+    private Activator activator;
+    // the bundle hosting the activation code
+    private Bundle activationBundle;
+    // the accumulated list of provider bundles that have command definitions
+    private ConcurrentMap<Long, URL> mailCaps = new ConcurrentHashMap<Long, URL>();
+
+    public CommandMapBundleTrackerCustomizer(Activator a, Bundle b) {
+        activator = a;
+        activationBundle = b;
+    }
+
+    /**
+     * Handle the activation of a new bundle.
+     *
+     * @param bundle The source bundle.
+     * @param event  The bundle event information.
+     *
+     * @return A return object.
+     */
+    @Override
+    public Object addingBundle(Bundle bundle, BundleEvent event) {
+        log(LogService.LOG_DEBUG, "Bundle Considered for mailcap providers: " + bundle.getSymbolicName());
+        if (bundle.equals(activationBundle)) {
+            return null;
+        }
+
+        return registerBundle(bundle);
+    }
+
+    /**
+     * Perform the check for an existing mailcap file when
+     * a bundle is registered.
+     *
+     * @param bundle The potential provider bundle.
+     *
+     * @return A URL object if this bundle contains a mailcap file.
+     */
+    private Object registerBundle(Bundle bundle) {
+        URL url = bundle.getResource("/META-INF/mailcap");
+        if (url != null) {
+            log(LogService.LOG_DEBUG, "found mailcap at " + url);
+            mailCaps.put(bundle.getBundleId(), url);
+            rebuildCommandMap();
+        }
+        // the url marks our interest in additional activity for this
+        // bundle.
+        return url;
+    }
+
+
+    /**
+     * Remove a bundle from our potential mailcap pool.
+     *
+     * @param bundle The potential source bundle.
+     */
+    protected void unregisterBundle(Bundle bundle) {
+        URL mailcap = mailCaps.remove(bundle.getBundleId());
+        if (mailcap != null ){
+            log(LogService.LOG_DEBUG, "removing mailcap at " + mailcap);
+            rebuildCommandMap();
+        }
+    }
+
+
+    @Override
+    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+        log(LogService.LOG_DEBUG, "Bundle Considered for mailcap providers: " + bundle.getSymbolicName());
+        // this will update for the new bundle
+        registerBundle(bundle);
+    }
+
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+        unregisterBundle(bundle);
+    }
+
+    private void log(int level, String message) {
+        activator.log(level, message);
+    }
+
+    private void log(int level, String message, Throwable th) {
+        activator.log(level, message, th);
+    }
+
+    /**
+     * Rebuild a new default command map after a change in
+     * the status of bundles providing command maps.
+     */
+    private void rebuildCommandMap() {
+        MailcapCommandMap commandMap = new MailcapCommandMap();
+        for (URL url : mailCaps.values()) {
+            try {
+                InputStream is = url.openStream();
+                try {
+                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
+                    String line;
+                    while ((line = br.readLine()) != null) {
+                        commandMap.addMailcap(line);
+                    }
+                } finally {
+                    is.close();
+                }
+            } catch (Exception e) {
+                // Ignore
+            }
+        }
+        // this is our new default command map
+        CommandMap.setDefaultCommandMap(commandMap);
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/org/apache/geronimo/specs/activation/CommandMapBundleTrackerCustomizer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message