geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r820466 - in /geronimo/sandbox/jbohn/daytrader-bp/modules: core/src/main/java/org/apache/geronimo/samples/daytrader/core/ core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/ core/src/main/resources/OSGI-INF/blueprint/ util...
Date Wed, 30 Sep 2009 21:51:00 GMT
Author: jbohn
Date: Wed Sep 30 21:50:59 2009
New Revision: 820466

URL: http://svn.apache.org/viewvc?rev=820466&view=rev
Log:
the start of a manager to manage multiple TradeServices implementations

Added:
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
  (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
  (with props)
Modified:
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeAppServlet.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/util/ServletUtilities.java

Added: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java?rev=820466&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
(added)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
Wed Sep 30 21:50:59 2009
@@ -0,0 +1,48 @@
+/**
+ *  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.samples.daytrader.core;
+
+import java.util.Set;
+
+import org.apache.geronimo.samples.daytrader.core.TradeServices;
+
+/**
+  * TradeServicesManager interface provides an interface to be
+  * used for managing the implementations of TradeServices that
+  * are available.
+  * 
+  */ 
+public interface TradeServicesManager {
+
+    /**
+      * Set TradeServices reference
+      */
+    public void setTradeServices(TradeServices tradeServices);
+
+    /**
+      * Get the currently selected TradeServices
+      */
+
+    public TradeServices getTradeServices();
+
+    /**
+      * Get the list of TradeServices as a set.
+      */
+    public Set getTradeServicesSet();
+
+}   
+

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java?rev=820466&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
(added)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
Wed Sep 30 21:50:59 2009
@@ -0,0 +1,128 @@
+/**
+ *  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.samples.daytrader.core;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.samples.daytrader.core.TradeServices;
+
+
+/**
+ * TradeJDBCDirect uses direct JDBC access to a
+ * <code>javax.sql.DataSource</code> to implement the business methods of the
+ * Trade online broker application. These business methods represent the
+ * features and operations that can be performed by customers of the brokerage
+ * such as login, logout, get a stock quote, buy or sell a stock, etc. and are
+ * specified in the {@link org.apache.geronimo.samples.daytrader.TradeServices}
+ * interface
+ * 
+ * Note: In order for this class to be thread-safe, a new TradeJDBC must be
+ * created for each call to a method from the TradeInterface interface.
+ * Otherwise, pooled connections may not be released.
+ * 
+ * @see org.apache.geronimo.samples.daytrader.TradeServices
+ * 
+ */
+
+public class TradeServicesManagerImpl implements TradeServicesManager {
+
+    private Set tradeServicesSet = new HashSet();
+    private TradeServices tradeServices = null;
+    private String test;
+
+    /**
+      * TradeServicesManagerImpl null constructor
+      */
+    public TradeServicesManagerImpl() 
+    {
+        System.out.println("@JAB TradeServicesManagerImpl() ");
+    }
+
+    /**
+      * Set Test
+      */
+    public void setTest(String test)
+    {
+        System.out.println("@JAB TradeServicesManager.setTest " + test);
+        this.test = test;
+    }
+
+    /**
+      * init
+      */
+    public void init()
+    {
+        System.out.println("@JAB TradeServicesManager.init - Initialized ");
+    }
+
+    /**
+      * Set TradeServices reference
+      */
+    public void setTradeServices(TradeServices tradeServices)
+    {
+        System.out.println("@JAB TradeServicesManager.setTradeServices " + tradeServices);
+        tradeServicesSet.add(tradeServices);
+    }
+
+
+    public TradeServices getTradeServices()
+    {
+        System.out.println("@JAB TradeServicesManager.getTradeServices");
+
+        // @JAB for now just return the first (only) item in the set if present.
+        // Eventually, we need to keep track of the selected TradeServices and return that
+        if (tradeServices == null) {
+            Iterator it = tradeServicesSet.iterator();
+            if (it.hasNext()) {
+              tradeServices = (TradeServices) it.next();
+            }
+        }
+        return tradeServices;
+    }
+
+    /**
+      * Get the list of TradeServices as a set.
+      */
+    public Set getTradeServicesSet()
+    {
+        System.out.println("@JAB TradeServicesManager.getTradeServicesSet " + tradeServicesSet.size());
+        return tradeServicesSet;
+    }
+
+
+    /**
+      * Bind a new TradeServices implementation
+      */
+    public void bindService(TradeServices tradeServices, Map props)
+    {
+        System.out.println("@JAB TradeServicesManager.bindService " + tradeServices + " Properties
" + props);
+        tradeServicesSet.add(tradeServices);
+    }
+
+    /**
+      * Unbind a TradeServices implementation
+      */
+    public void unbindService(TradeServices tradeServices, Map props)
+    {
+        System.out.println("@JAB TradeServicesManager.unbindService " + tradeServices + "
Properties " + props);
+        tradeServicesSet.remove(tradeServices);
+    }
+
+}

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
Wed Sep 30 21:50:59 2009
@@ -70,6 +70,7 @@
      * Zero arg constructor for TradeJDBCDirect
      */
     public TradeJDBCDirect() {
+        System.out.println("@JAB TradeJDBCDirect() ");
         if (initialized == false)
             init();
     }

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
Wed Sep 30 21:50:59 2009
@@ -1,6 +1,6 @@
 <blueprint>
 
-  <bean id="tradeServiceComponent" class="org.apache.geronimo.samples.daytrader.core.direct.TradeJDBCDirect"
activation="lazy"/>
+  <bean id="tradeServiceComponent" class="org.apache.geronimo.samples.daytrader.core.direct.TradeJDBCDirect"
activation="lazy" init-method="init"/>
   
   <service id="tradeDBService" ref="tradeServiceComponent" interface="org.apache.geronimo.samples.daytrader.core.TradeDBServices">
       <service-properties>

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml Wed Sep 30 21:50:59 2009
@@ -73,7 +73,9 @@
                         <Export-Package>org.apache.geronimo.samples.daytrader.util;version=1.0.0</Export-Package>
                         <Import-Package>
                             org.apache.geronimo.samples.daytrader.util;version=1.0,
+<!--
                             org.apache.commons.logging;resolution:=optional,
+-->
                             *;resolution:=optional
                         </Import-Package>
                     </instructions>

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeAppServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeAppServlet.java?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeAppServlet.java
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeAppServlet.java
Wed Sep 30 21:50:59 2009
@@ -19,7 +19,11 @@
 import javax.servlet.*;
 import javax.servlet.http.*;
 
+import org.apache.geronimo.samples.daytrader.core.TradeServices;
+import org.apache.geronimo.samples.daytrader.core.TradeServicesManager;
 import org.apache.geronimo.samples.daytrader.util.*;
+//@JAB need to drop this after I move and rename ServletUtilities
+import org.apache.geronimo.samples.daytrader.web.util.*;
 
 import java.io.IOException;
 
@@ -34,6 +38,8 @@
 
 public class TradeAppServlet extends HttpServlet {
 
+    private static TradeServices tradeServices = null;
+
     /**
      * Servlet initialization method.
      */
@@ -102,7 +108,14 @@
         String dispPath = null; // Dispatch Path to TradeAppServlet
 
         resp.setContentType("text/html");
-        TradeServletAction tsAction = new TradeServletAction();
+
+        if (tradeServices == null) {
+            System.out.println("@JAB TradeAppServlet.performTask() - about to do a lookup
of TradeServicesManager");
+            TradeServicesManager tradeServicesManager = ServletUtilities.getTradeServicesManager();
+            tradeServices = tradeServicesManager.getTradeServices();
+        }
+
+        TradeServletAction tsAction = new TradeServletAction(tradeServices);
 
         // Dyna - need status string - prepended to output
         action = req.getParameter("action");

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
Wed Sep 30 21:50:59 2009
@@ -21,6 +21,7 @@
 
 import org.apache.geronimo.samples.daytrader.core.RunStatsDataBean;
 import org.apache.geronimo.samples.daytrader.core.TradeServices;
+import org.apache.geronimo.samples.daytrader.core.TradeServicesManager;
 import org.apache.geronimo.samples.daytrader.util.*;
 import org.apache.geronimo.samples.daytrader.web.util.*;
 
@@ -34,6 +35,8 @@
  */
 public class TradeConfigServlet extends HttpServlet {
 	
+    private static TradeServices tradeServices = null;
+
    /**
 	* Servlet initialization method.
 	*/
@@ -70,7 +73,13 @@
 	{
 		RunStatsDataBean runStatsData = new RunStatsDataBean();
 		TradeConfig currentConfig = new TradeConfig();		
-                TradeServices tradeServices = ServletUtilities.getTradeServices();
+
+                if (tradeServices == null) {
+                    System.out.println("@JAB TradeConfigServlet.performTask() - about to
do a lookup of TradeServicesManager");
+                    TradeServicesManager tradeServicesManager = ServletUtilities.getTradeServicesManager();
+                    tradeServices = tradeServicesManager.getTradeServices();
+                }
+
 		try
 		{
 			runStatsData = tradeServices.resetTrade(false);

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
Wed Sep 30 21:50:59 2009
@@ -46,6 +46,11 @@
  */
 public class TradeServletAction {
 
+    private TradeServices tradeServices = null;
+
+    public TradeServletAction(TradeServices tradeServices) {
+        this.tradeServices = tradeServices;
+    }
 
     /**
      * Display User Profile information such as address, email, etc. for the
@@ -72,7 +77,7 @@
     void doAccount(ServletContext ctx, HttpServletRequest req,
             HttpServletResponse resp, String userID, String results)
             throws javax.servlet.ServletException, java.io.IOException {
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
         try {
 
             AccountDataBean accountData = tradeServices.getAccountData(userID);
@@ -144,7 +149,7 @@
             String creditcard, String email)
             throws javax.servlet.ServletException, java.io.IOException {
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
 
         // First verify input data
         boolean doUpdate = true;
@@ -209,7 +214,7 @@
             String quantity) throws ServletException, IOException {
 
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
 
         try {
             OrderDataBean orderData = tradeServices.buy(userID, symbol, new Double(
@@ -264,7 +269,7 @@
         
         BigDecimal balance;
         String result = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
         
         try {
             AccountDataBean accountData = tradeServices.getAccountData(userID);
@@ -327,7 +332,7 @@
             throws javax.servlet.ServletException, java.io.IOException {
 
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
         try {
             // Got a valid userID and passwd, attempt login
 
@@ -402,7 +407,7 @@
             HttpServletResponse resp, String userID) throws ServletException,
             IOException {
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
 
         try {
             tradeServices.logout(userID);
@@ -473,7 +478,7 @@
             HttpServletResponse resp, String userID, String results)
             throws ServletException, IOException {
 
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
         try {
             // Get the holdiings for this user
 
@@ -594,7 +599,7 @@
             String openBalanceString, String email, String address)
             throws ServletException, IOException {
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
 
         try {
             // Validate user passwords match and are atleast 1 char in length
@@ -659,7 +664,7 @@
             HttpServletResponse resp, String userID, Integer holdingID)
             throws ServletException, IOException {
         String results = "";
-        TradeServices tradeServices = ServletUtilities.getTradeServices();
+//        TradeServices tradeServices = ServletUtilities.getTradeServices();
         try {
             OrderDataBean orderData = tradeServices.sell(userID, holdingID,
                     TradeConfig.orderProcessingMode);

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/util/ServletUtilities.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/util/ServletUtilities.java?rev=820466&r1=820465&r2=820466&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/util/ServletUtilities.java
(original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/util/ServletUtilities.java
Wed Sep 30 21:50:59 2009
@@ -22,62 +22,108 @@
 
 import org.apache.geronimo.samples.daytrader.core.TradeServices;
 import org.apache.geronimo.samples.daytrader.core.TradeDBServices;
-
-import java.io.IOException;
+import org.apache.geronimo.samples.daytrader.core.TradeServicesManager;
+import org.apache.geronimo.samples.daytrader.util.Log;
 
 
 /**
  * ServletUtilities provides servlet specific client side
  * utility functions.
- * 
+ * @JAB  Need to move this to util bundle as ServiceUtilities
  */
 public class ServletUtilities {
 
-    private static String filter = "/(mode=jdbc)";
+    private static String prefix = "osgi:services/";
+
     /**
      * Lookup and return the TradeServices osgi service
      * 
      * @return TradeServices
-     * @exception javax.io.IOException
-     *                If an exception occurs during the service
-     *                lookup
      * 
      */
-    public static final TradeServices getTradeServices()
-        throws IOException
-    {
-        try {
-            InitialContext ic = new InitialContext();
-            return (TradeServices) ic.lookup("osgi:services/" + TradeServices.class.getName()
+ filter);
-        } catch (NamingException e) {
-            e.printStackTrace();
-            IOException ioe = new IOException("Unable to retrieve TradeServices service");
-            ioe.initCause(e);
-            throw ioe;
-        }
+    public static final TradeServices getTradeServices() {
+        return getTradeServices(null);
+    }
+
+    /**
+     * Lookup and return the TradeServices osgi service
+     * 
+     * @return TradeServices
+     * 
+     */
+    public static final TradeServices getTradeServices(String filter) {
+        return (TradeServices) getOSGIService(TradeServices.class.getName(), filter);
     }
 
     /**
      * Lookup and return the TradeDBServices osgi service
      * 
      * @return TradeDBServices
+     * 
+     */
+    public static final TradeDBServices getTradeDBServices() {
+        return getTradeDBServices(null);
+    }
+
+    /**
+     * Lookup and return the TradeDBServices osgi service
+     * 
+     * @return TradeDBServices
+     * 
+     */
+    public static final TradeDBServices getTradeDBServices(String filter) {
+        return (TradeDBServices) getOSGIService(TradeDBServices.class.getName(), filter);
+    }
+
+    /**
+     * Lookup and return the TradeServicesManager osgi service
+     * 
+     * @return TradeServicesManager
+     * 
+     */
+    public static final TradeServicesManager getTradeServicesManager() {
+        return (TradeServicesManager) getOSGIService(TradeServicesManager.class.getName(),
null);
+    }
+
+    /**
+     * Lookup and return an osgi service
+     * 
+     * @return Object
      * @exception javax.io.IOException
      *                If an exception occurs during the service
      *                lookup
      * 
      */
-    public static final TradeDBServices getTradeDBServices()
-        throws IOException
+    public static final Object getOSGIService(String serviceName) {
+        return getOSGIService(serviceName, null);
+    }
+
+    /**
+     * Lookup and return an osgi service
+     * 
+     * @return Object
+     * 
+     */
+    private static final Object getOSGIService(String serviceName, String filter)
     {
+        String name = prefix + serviceName;
+        if (filter != null) {
+            name = name + filter;
+        }
+
         try {
             InitialContext ic = new InitialContext();
-            return (TradeDBServices) ic.lookup("osgi:services/" + TradeDBServices.class.getName()
+ filter);
+            return ic.lookup(name);
         } catch (NamingException e) {
+            System.out.println("@JAB ServletUtilities.getOSGIService() exception on lookup
" + e);
+            Log.error(e,
+                      "ServletUtilities.getOSGIService(...)",
+                      "NamingException on OSGI service lookup");
             e.printStackTrace();
-            IOException ioe = new IOException("Unable to retrieve TradeDBServices service");
-            ioe.initCause(e);
-            throw ioe;
+            return null;
         }
     }
 
+
+
 }
\ No newline at end of file



Mime
View raw message