geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r924429 - in /geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi: BundleAnnotationFinder.java BundleResourceFinder.java
Date Wed, 17 Mar 2010 19:27:39 GMT
Author: djencks
Date: Wed Mar 17 19:27:38 2010
New Revision: 924429

URL: http://svn.apache.org/viewvc?rev=924429&view=rev
Log:
XBEAN-145 make an osgi-friendly annotation finder using xbean-finder and BundleResourceFinder

Added:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java?rev=924429&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
Wed Mar 17 19:27:38 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.kernel.osgi;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+
+import org.apache.xbean.finder.AbstractFinder;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BundleAnnotationFinder extends AbstractFinder {
+    private static final Logger log = LoggerFactory.getLogger(BundleAnnotationFinder.class);
+    private final Bundle bundle;
+
+    public BundleAnnotationFinder(PackageAdmin packageAdmin, Bundle bundle) throws Exception
{
+        this.bundle = bundle;
+        BundleResourceFinder bundleResourceFinder = new BundleResourceFinder(packageAdmin,
bundle, "", ".class");
+        bundleResourceFinder.find(new AnnotationFindingCallback());
+    }
+
+    @Override
+    protected URL getResource(String s) {
+        return bundle.getResource(s);
+    }
+
+    @Override
+    protected Class<?> loadClass(String s) throws ClassNotFoundException {
+        return bundle.loadClass(s);
+    }
+
+    private class AnnotationFindingCallback implements BundleResourceFinder.ResourceFinderCallback
{
+
+        @Override
+        public void foundInDirectory(Bundle bundle, String baseDir, URL url) throws Exception
{
+            log.info("foundInDirectory: " + url);
+            InputStream in = url.openStream();
+            try {
+                readClassDef(in);
+            } finally {
+                in.close();
+            }
+        }
+
+        @Override
+        public void foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream
in) throws Exception {
+            log.info("foundInJar: " + entry);
+            readClassDef(in);
+        }
+    }
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleAnnotationFinder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java?rev=924429&r1=924428&r2=924429&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java
Wed Mar 17 19:27:38 2010
@@ -43,10 +43,10 @@ import org.osgi.service.packageadmin.Pac
  */
 public class BundleResourceFinder {
    
-    private Bundle bundle;
-    private PackageAdmin packageAdmin;
-    private String prefix;
-    private String suffix;
+    private final Bundle bundle;
+    private final PackageAdmin packageAdmin;
+    private final String prefix;
+    private final String suffix;
     
     public BundleResourceFinder(PackageAdmin packageAdmin, Bundle bundle, String prefix,
String suffix) {
         this.packageAdmin = packageAdmin;
@@ -57,11 +57,13 @@ public class BundleResourceFinder {
     
     public void find(ResourceFinderCallback callback) throws Exception {
         scanBundleClassPath(callback, bundle);
-        
-        Bundle[] fragments = packageAdmin.getFragments(bundle);
-        if (fragments != null) {
-            for (Bundle fragment : fragments) {
-                scanBundleClassPath(callback, fragment);
+
+        if (packageAdmin != null) {
+            Bundle[] fragments = packageAdmin.getFragments(bundle);
+            if (fragments != null) {
+                for (Bundle fragment : fragments) {
+                    scanBundleClassPath(callback, fragment);
+                }
             }
         }
     }



Mime
View raw message