[jboss-osgi-commits] JBoss-OSGI SVN: r91493 - in projects/jboss-osgi/projects/bundles/jaxb/trunk: src/main/java/org/jboss/osgi/jaxb and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Jul 21 05:58:10 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-07-21 05:58:10 -0400 (Tue, 21 Jul 2009)
New Revision: 91493

Added:
   projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java
Modified:
   projects/jboss-osgi/projects/bundles/jaxb/trunk/pom.xml
   projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java
   projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceActivator.java
Log:
Expand JAXBService o provide JAXBContext

Modified: projects/jboss-osgi/projects/bundles/jaxb/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/pom.xml	2009-07-21 09:28:20 UTC (rev 91492)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/pom.xml	2009-07-21 09:58:10 UTC (rev 91493)
@@ -95,6 +95,7 @@
               <!-- import -->
               org.jboss.osgi.common.log;version=1.0, 
               org.jboss.osgi.spi.capability;version=1.0,
+              org.jboss.osgi.spi.util;version=1.0,
               org.jboss.osgi.xml, 
               org.osgi.framework, 
               org.osgi.service.log,
@@ -111,6 +112,7 @@
               activation;inline=false,
             </Embed-Dependency>
             <_exportcontents>
+              com.sun.xml.bind.v2*;version=${version.xml.bind},
               javax.activation;version=1.1,
               javax.xml.bind*;version=2.1,
               javax.xml.stream*;version=1.0,

Modified: projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java	2009-07-21 09:28:20 UTC (rev 91492)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java	2009-07-21 09:58:10 UTC (rev 91493)
@@ -23,12 +23,44 @@
 
 //$Id$
 
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
 /**
- * A marker service that is registered by jboss-osgi-jaxb
+ * A service to obtain the JAXBContext
  * 
  * @author thomas.diesler at jboss.com
  * @since 29-May-2009
  */
 public interface JAXBService
 {
+   /**
+    * Obtain a new instance of a JAXBContext class. 
+    * 
+    * @see {@link JAXBContext#newInstance(String)}
+    */
+   JAXBContext newInstance(String contextPath) throws JAXBException;
+   
+   /**
+    * Obtain a new instance of a JAXBContext class. 
+    * 
+    * @see {@link JAXBContext#newInstance(String,ClassLoader,Map)}
+    */
+   JAXBContext newInstance(String contextPath, Map<String,?> props) throws JAXBException;
+   
+   /**
+    * Obtain a new instance of a JAXBContext class. 
+    * 
+    * @see {@link JAXBContext#newInstance(Class...)}
+    */
+   JAXBContext newInstance(Class<?> ... classesToBeBound) throws JAXBException;
+   
+   /**
+    * Obtain a new instance of a JAXBContext class. 
+    * 
+    * @see {@link JAXBContext#newInstance(Class[], Map)}
+    */
+   JAXBContext newInstance(Class<?>[] classesToBeBound, Map<String,?> props) throws JAXBException;
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceActivator.java	2009-07-21 09:28:20 UTC (rev 91492)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceActivator.java	2009-07-21 09:58:10 UTC (rev 91493)
@@ -25,8 +25,11 @@
 
 import org.jboss.osgi.common.log.LogServiceTracker;
 import org.jboss.osgi.jaxb.JAXBService;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.log.LogService;
 
 /**
@@ -43,8 +46,18 @@
    {
       log = new LogServiceTracker(context);
       
-      JAXBService service = new JAXBService(){};
-      context.registerService(JAXBService.class.getName(), service, null);
+      ServiceFactory factory = new ServiceFactory()
+      {
+         public Object getService(Bundle bundle, ServiceRegistration registration)
+         {
+            return new JAXBServiceImpl(bundle);
+         }
+
+         public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+         {
+         }
+      };
+      context.registerService(JAXBService.class.getName(), factory, null);
       log.log(LogService.LOG_INFO, "JAXBService registered");
    }
 

Added: projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java	2009-07-21 09:58:10 UTC (rev 91493)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jaxb.internal;
+
+//$Id: JAXBServiceActivator.java 91417 2009-07-20 09:25:44Z thomas.diesler at jboss.com $
+
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.jboss.osgi.jaxb.JAXBService;
+import org.jboss.osgi.spi.util.BundleClassLoader;
+import org.osgi.framework.Bundle;
+
+/**
+ * An implementation of the {@link JAXBService}
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 21-Jul-2009
+ */
+public class JAXBServiceImpl implements JAXBService
+{
+   private Bundle bundle;
+
+   public JAXBServiceImpl(Bundle bundle)
+   {
+      this.bundle = bundle;
+   }
+
+   public JAXBContext newInstance(String contextPath) throws JAXBException
+   {
+      return newInstance(contextPath, null);
+   }
+
+   public JAXBContext newInstance(String contextPath, Map<String, ?> props) throws JAXBException
+   {
+      ClassLoader classLoader = BundleClassLoader.createClassLoader(bundle);
+      return JAXBContext.newInstance(contextPath, classLoader, props);
+   }
+
+   public JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException
+   {
+      return JAXBContext.newInstance(classesToBeBound);
+   }
+
+   public JAXBContext newInstance(Class<?>[] classesToBeBound, Map<String, ?> props) throws JAXBException
+   {
+      return JAXBContext.newInstance(classesToBeBound, props);
+   }
+}
\ No newline at end of file



More information about the jboss-osgi-commits mailing list