You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2009/04/17 22:02:07 UTC

svn commit: r766129 - in /geronimo/sandbox/blueprint/sample: ./ src/main/java/org/apache/geronimo/osgi/example/ src/main/resources/OSGI-INF/blueprint/

Author: gawor
Date: Fri Apr 17 20:02:06 2009
New Revision: 766129

URL: http://svn.apache.org/viewvc?rev=766129&view=rev
Log:
update sample to use type-converters

Added:
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java   (with props)
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java   (with props)
Modified:
    geronimo/sandbox/blueprint/sample/pom.xml
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Bar.java
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java
    geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: geronimo/sandbox/blueprint/sample/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/pom.xml?rev=766129&r1=766128&r2=766129&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/pom.xml (original)
+++ geronimo/sandbox/blueprint/sample/pom.xml Fri Apr 17 20:02:06 2009
@@ -53,5 +53,10 @@
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>
+       <dependency>
+           <groupId>org.apache.felix</groupId>
+           <artifactId>blueprint-api</artifactId>
+           <version>${version}</version>
+       </dependency>
     </dependencies>
 </project>

Modified: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Bar.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Bar.java?rev=766129&r1=766128&r2=766129&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Bar.java (original)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Bar.java Fri Apr 17 20:02:06 2009
@@ -16,13 +16,18 @@
  */
 package org.apache.geronimo.osgi.example;
 
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+
 public class Bar {
     
+    private BundleContext context;
     private String value;
+    private List list;
     
     public String toString() {
-        return hashCode() + ": " + value;
+        return hashCode() + ": " + value + " " + context + " " + list;
     }
 
 }
-

Added: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java?rev=766129&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java (added)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java Fri Apr 17 20:02:06 2009
@@ -0,0 +1,33 @@
+/**
+ *  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.osgi.example;
+
+import java.util.Currency;
+
+import org.osgi.service.blueprint.convert.Converter;
+
+public class CurrencyTypeConverter implements Converter {
+
+    public Object convert(Object source) throws Exception {
+        return Currency.getInstance(source.toString());
+    }
+
+    public Class getTargetClass() {
+        return Currency.class;
+    }
+    
+}

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/CurrencyTypeConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java?rev=766129&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java (added)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java Fri Apr 17 20:02:06 2009
@@ -0,0 +1,41 @@
+/**
+ *  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.osgi.example;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.osgi.service.blueprint.convert.Converter;
+
+public class DateTypeConverter implements Converter {
+
+    DateFormat dateFormat;
+    
+    public void setFormat(String format) {
+        dateFormat = new SimpleDateFormat(format);
+    }
+    
+    public Object convert(Object source) throws Exception {
+        return dateFormat.parse(source.toString());
+    }
+
+    public Class getTargetClass() {
+        return Date.class;
+    }
+    
+}

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/DateTypeConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java?rev=766129&r1=766128&r2=766129&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java (original)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java Fri Apr 17 20:02:06 2009
@@ -16,14 +16,19 @@
  */
 package org.apache.geronimo.osgi.example;
 
+import java.util.Currency;
+import java.util.Date;
+
 public class Foo {
     
     private int a;
     private int b;
     private Bar bar;
+    private Currency currency;
+    private Date date;
 
     public String toString() {
-        return a + " " + b + " " + bar;
+        return a + " " + b + " " + bar + " " + currency + " " + date;
     }
 
 }

Modified: geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=766129&r1=766128&r2=766129&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml (original)
+++ geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml Fri Apr 17 20:02:06 2009
@@ -2,15 +2,37 @@
 
 <components xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
 
+    <type-converters>
+            <component id="converter1" class="org.apache.geronimo.osgi.example.DateTypeConverter">
+                <property name="format" value="yyyy.MM.dd"/>
+            </component>
+            <ref component="converter2"/>
+    </type-converters>
+
     <component id="foo" class="org.apache.geronimo.osgi.example.Foo">
         <property name="a" value="5" />
         <property name="b" value="10" />
         <property name="bar" ref="bar" />
+        <property name="currency">
+              <value type="java.util.Currency">PLN</value>
+        </property>
+        <property name="date">
+              <value type="java.util.Date">2009.04.17</value>
+        </property>
     </component>
 
     <component id="bar" class="org.apache.geronimo.osgi.example.Bar">
         <property name="value"><value>Hello FooBar</value></property>
+        <property name="context" ref="bundleContext"/>
+        <property name="list">
+            <list>
+                <value>a list element followed by a reference</value>
+                <value type = "java.lang.Integer">5</value>
+            </list>        
+        </property>
     </component>
 
+    <component id="converter2" class="org.apache.geronimo.osgi.example.CurrencyTypeConverter"/>
+    
 </components>