servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1095257 - in /servicemix/smx4/specs/trunk/locator: ./ src/main/java/org/apache/servicemix/specs/locator/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/servicemix/ src/test/java/org/apache/se...
Date Wed, 20 Apr 2011 02:59:18 GMT
Author: ningjiang
Date: Wed Apr 20 02:59:17 2011
New Revision: 1095257

URL: http://svn.apache.org/viewvc?rev=1095257&view=rev
Log:
SMX4-811 OSGi Locator supports to return the service class which is defined from the system
property

Added:
    servicemix/smx4/specs/trunk/locator/src/test/
    servicemix/smx4/specs/trunk/locator/src/test/java/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
  (with props)
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
  (with props)
    servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
  (with props)
Modified:
    servicemix/smx4/specs/trunk/locator/pom.xml
    servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java

Modified: servicemix/smx4/specs/trunk/locator/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/pom.xml?rev=1095257&r1=1095256&r2=1095257&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/locator/pom.xml (original)
+++ servicemix/smx4/specs/trunk/locator/pom.xml Wed Apr 20 02:59:17 2011
@@ -40,6 +40,12 @@
             <version>1.2.0</version>
             <scope>provided</scope>
         </dependency>
+         <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>

Modified: servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java?rev=1095257&r1=1095256&r2=1095257&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
(original)
+++ servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
Wed Apr 20 02:59:17 2011
@@ -70,11 +70,28 @@ public class OsgiLocator {
             if (factories != null) {
                 List<Callable<Class>> l = factories.get(factoryId);
                 if (l != null && !l.isEmpty()) {
-                    Callable<Class> c = l.get(l.size() - 1);
+                    // look up the System property first
+                    String factoryClassName = System.getProperty(factoryId);
                     try {
-                        return c.call();
-                    } catch (Exception e) {
-                    }
+                        if (factoryClassName != null) {
+                            for (Callable<Class> i : l) {
+                                Class c = null;
+                                try {
+                                    c = i.call();
+                                } catch (Exception ex) {
+                                    // do nothing here
+                                }
+                                if (c != null && c.getName().equals(factoryClassName))
{
+                                    return c;
+                                }
+                            }
+                        } else {
+                            Callable<Class> callable = l.get(l.size() - 1);
+                            return callable.call();
+                        }
+                    } catch (Exception ex) {
+                        // do nothing here
+                    }  
                 }
             }
             return null;

Added: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java?rev=1095257&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
(added)
+++ servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
Wed Apr 20 02:59:17 2011
@@ -0,0 +1,27 @@
+/**
+ * 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.servicemix.specs.locator;
+
+import java.util.concurrent.Callable;
+
+public class MockCallable implements Callable<Class> {
+   
+    public Class call() throws Exception {
+        return this.getClass();
+    }
+
+}

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java?rev=1095257&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
(added)
+++ servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
Wed Apr 20 02:59:17 2011
@@ -0,0 +1,27 @@
+/**
+ * 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.servicemix.specs.locator;
+
+import java.util.concurrent.Callable;
+
+public class MockCallable2 implements Callable<Class> {
+   
+    public Class call() throws Exception {
+        return this.getClass();
+    }
+
+}

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/MockCallable2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java?rev=1095257&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
(added)
+++ servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
Wed Apr 20 02:59:17 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.servicemix.specs.locator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class OsgiLocatorTest extends Assert {
+    
+    @BeforeClass
+    public static void setup() {
+        OsgiLocator.register("Factory", new MockCallable());
+        OsgiLocator.register("Factory", new MockCallable2());
+    }
+    
+    @Test
+    public void testLocatorWithSystemProperty() {
+        System.setProperty("Factory", "org.apache.servicemix.specs.locator.MockCallable");
+        Class clazz = OsgiLocator.locate("Factory");
+        assertNotNull("Except to find the class", clazz);
+        assertEquals("Get a wrong class.", MockCallable.class.getName(), clazz.getName());
+        
+        System.setProperty("Factory", "org.apache.servicemix.specs.locator");
+        clazz = OsgiLocator.locate("Factory");
+        assertNull("Except to find the class", clazz);
+        System.clearProperty("Factory");
+    }
+    
+    @Test
+    public void testLocatorWithoutSystemProperty() {
+        Class clazz = OsgiLocator.locate("Factory");
+        assertNotNull("Except to find the class", clazz);
+        assertEquals("Get a wrong class.", MockCallable2.class.getName(), clazz.getName());
+    }
+
+}

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/specs/trunk/locator/src/test/java/org/apache/servicemix/specs/locator/OsgiLocatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message