tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ken...@apache.org
Subject svn commit: r427726 [2/2] - in /incubator/tuscany/java: samples/sca/ samples/sca/bigbank/ samples/sca/bigbank/src/ samples/sca/bigbank/src/main/ samples/sca/bigbank/src/main/java/ samples/sca/bigbank/src/main/java/bigbank/ samples/sca/bigbank/src/main/...
Date Tue, 01 Aug 2006 20:53:13 GMT
Added: incubator/tuscany/java/samples/sca/bigbank/src/main/resources/META-INF/sca/default.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/bigbank/src/main/resources/META-INF/sca/default.scdl?rev=427726&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sca/bigbank/src/main/resources/META-INF/sca/default.scdl
(added)
+++ incubator/tuscany/java/samples/sca/bigbank/src/main/resources/META-INF/sca/default.scdl
Tue Aug  1 13:53:11 2006
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *  Copyright (c) 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           name="BigBankComposite">
+
+    <service name="AccountService">
+        <interface.java interface="bigbank.account.AccountService"/>
+        <reference>AccountServiceComponent</reference>
+    </service>
+
+    <!--
+    <reference name="StockQuoteService">
+        <interface.java interface="bigbank.stock.StockQuoteService"/>
+    </reference>
+    -->
+
+
+    <component name="AccountServiceComponent">
+        <implementation.java class="bigbank.account.AccountServiceImpl"/>
+        <references>
+            <reference name="accountDataService" target="AccountDataServiceComponent"
/>
+            <!-- <reference name="stockQuoteService" target="StockQuoteService" />
-->
+        </references>
+    </component>
+
+    <component name="AccountDataServiceComponent">
+        <implementation.java class="bigbank.accountdata.AccountDataServiceImpl"/>
+    </component>
+
+</composite>

Added: incubator/tuscany/java/samples/sca/bigbank/src/test/java/bigbank/BigBankTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/bigbank/src/test/java/bigbank/BigBankTestCase.java?rev=427726&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sca/bigbank/src/test/java/bigbank/BigBankTestCase.java
(added)
+++ incubator/tuscany/java/samples/sca/bigbank/src/test/java/bigbank/BigBankTestCase.java
Tue Aug  1 13:53:11 2006
@@ -0,0 +1,39 @@
+/**
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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 bigbank;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+
+import org.apache.tuscany.test.SCATestCase;
+import bigbank.account.AccountService;
+
+public class BigBankTestCase extends SCATestCase {
+
+    AccountService accountService;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        CompositeContext context = CurrentCompositeContext.getContext();
+        accountService = context.locateService(AccountService.class, "AccountServiceComponent");
+    }
+
+    public void test() throws Exception {
+        System.out.println("Account summary: " + accountService.getAccountReport("Foo") );
+    }
+}

Propchange: incubator/tuscany/java/samples/sca/bigbank/src/test/java/bigbank/BigBankTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/tuscany/java/samples/sca/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/pom.xml?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/samples/sca/pom.xml (original)
+++ incubator/tuscany/java/samples/sca/pom.xml Tue Aug  1 13:53:11 2006
@@ -33,5 +33,6 @@
         <module>local.wire.cdi</module>
         <module>calculator</module>
         <module>supplychain</module>
+        <module>bigbank</module>
     </modules>
 </project>

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
Tue Aug  1 13:53:11 2006
@@ -30,7 +30,6 @@
 import org.apache.tuscany.spi.extension.LoaderExtension;
 import org.apache.tuscany.spi.loader.LoaderRegistry;
 import org.apache.tuscany.spi.loader.StAXPropertyFactory;
-import org.apache.tuscany.spi.model.Scope;
 import org.apache.tuscany.spi.monitor.MonitorFactory;
 
 import org.apache.tuscany.core.builder.BuilderRegistryImpl;
@@ -144,7 +143,7 @@
      */
     public ScopeRegistry createScopeRegistry(WorkContext workContext) {
         ScopeRegistry scopeRegistry = new ScopeRegistryImpl(workContext);
-        scopeRegistry.registerFactory(Scope.MODULE, new ModuleScopeObjectFactory());
+        new ModuleScopeObjectFactory(scopeRegistry); // self-registers
         return scopeRegistry;
     }
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactory.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactory.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactory.java
Tue Aug  1 13:53:11 2006
@@ -2,6 +2,10 @@
 
 import org.apache.tuscany.spi.ObjectCreationException;
 import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.osoa.sca.annotations.Init;
 
 /**
  * Creates a new module scope context
@@ -9,6 +13,14 @@
  * @version $$Rev: 412208 $$ $$Date: 2006-06-06 13:47:19 -0700 (Tue, 06 Jun 2006) $$
  */
 public class ModuleScopeObjectFactory implements ObjectFactory<ModuleScopeContainer>
{
+
+    public ModuleScopeObjectFactory(@Autowire ScopeRegistry registry) {
+        registry.registerFactory(Scope.MODULE, this);
+    }
+
+    @Init(eager = true)
+    public void init() {
+    }
 
     public ModuleScopeContainer getInstance() throws ObjectCreationException {
         return new ModuleScopeContainer();

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactory.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactory.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactory.java
Tue Aug  1 13:53:11 2006
@@ -2,6 +2,10 @@
 
 import org.apache.tuscany.spi.ObjectCreationException;
 import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.osoa.sca.annotations.Init;
 
 /**
  * Creates a new stateless scope context
@@ -9,6 +13,14 @@
  * @version $$Rev: 412208 $$ $$Date: 2006-06-06 13:47:19 -0700 (Tue, 06 Jun 2006) $$
  */
 public class StatelessScopeObjectFactory implements ObjectFactory<StatelessScopeContainer>
{
+
+    public StatelessScopeObjectFactory(@Autowire ScopeRegistry registry) {
+        registry.registerFactory(Scope.STATELESS, this);
+    }
+
+    @Init(eager = true)
+    public void init() {
+    }
 
     public StatelessScopeContainer getInstance() throws ObjectCreationException {
         return new StatelessScopeContainer();

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java
Tue Aug  1 13:53:11 2006
@@ -18,7 +18,6 @@
 
 import java.io.File;
 import java.net.URL;
-import java.net.URI;
 
 import javax.xml.stream.XMLInputFactory;
 
@@ -29,9 +28,9 @@
 import org.apache.tuscany.spi.bootstrap.ComponentNames;
 import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
 import org.apache.tuscany.spi.services.info.RuntimeInfo;
+import org.apache.tuscany.spi.monitor.MonitorFactory;
 import org.apache.tuscany.core.bootstrap.Bootstrapper;
 import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
-import org.apache.tuscany.core.monitor.NullMonitorFactory;
 import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
 import org.apache.tuscany.core.implementation.system.component.SystemCompositeComponent;
 
@@ -41,14 +40,10 @@
  * @version $Rev: 417136 $ $Date: 2006-06-26 03:54:48 -0400 (Mon, 26 Jun 2006) $
  */
 public class Launcher {
-    private ClassLoader applicationLoader;
-    private RuntimeComponent runtime;
-    private Deployer deployer;
-
     /**
      * A conventional META-INF based location for the system SCDL.
      *
-     * @see #bootRuntime(URL)
+     * @see #bootRuntime(URL, MonitorFactory)
      */
     public static final String METAINF_SYSTEM_SCDL_PATH = "META-INF/tuscany/system.scdl";
 
@@ -59,6 +54,10 @@
      */
     public static final String METAINF_APPLICATION_SCDL_PATH = "META-INF/sca/default.scdl";
 
+    private ClassLoader applicationLoader;
+    private RuntimeComponent runtime;
+    private Deployer deployer;
+
     /**
      * Returns the classloader for application classes.
      *
@@ -85,14 +84,14 @@
      * @return a CompositeComponent for the newly booted runtime system
      * @throws LoaderException
      */
-    public CompositeComponent<?> bootRuntime(URL systemScdl) throws LoaderException
{
+    public CompositeComponent<?> bootRuntime(URL systemScdl, MonitorFactory monitor)
throws LoaderException {
         if (systemScdl == null) {
             throw new LoaderException("Null system SCDL URL");
         }
 
         ClassLoader systemClassLoader = getClass().getClassLoader();
         XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory",
systemClassLoader);
-        Bootstrapper bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), xmlFactory);
+        Bootstrapper bootstrapper = new DefaultBootstrapper(monitor, xmlFactory);
         Deployer bootDeployer = bootstrapper.createDeployer();
 
         // create and start the core runtime
@@ -126,8 +125,9 @@
      * Shuts down the active runtime being managed by this instance.
      */
     public void shutdownRuntime() {
-        if (runtime != null)
+        if (runtime != null) {
             runtime.stop();
+        }
 
         runtime = null;
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
Tue Aug  1 13:53:11 2006
@@ -27,6 +27,7 @@
 
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.core.util.ClassLoaderHelper;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
 
 
 /**
@@ -133,7 +134,7 @@
             parseArguments(args);
             // need to use the classloader as the path does not start with a '/'
             URL scdl = getClass().getClassLoader().getResource(METAINF_SYSTEM_SCDL_PATH);
-            bootRuntime(scdl);
+            bootRuntime(scdl, new NullMonitorFactory());
             URL appScdl = getApplicationLoader().getResource(METAINF_APPLICATION_SCDL_PATH);
             CompositeComponent application = bootApplication(appScdl);
             application.start();
@@ -152,8 +153,7 @@
         } catch (InvocationTargetException e) {
             e.getCause().printStackTrace(System.err);
             System.exit(2);
-        }
-        finally {
+        } finally {
             shutdownRuntime();
         }
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletLauncherListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletLauncherListener.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletLauncherListener.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletLauncherListener.java
Tue Aug  1 13:53:11 2006
@@ -2,12 +2,17 @@
 
 import org.apache.tuscany.spi.loader.LoaderException;
 import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.monitor.MonitorFactory;
+import org.apache.tuscany.core.monitor.MonitorFactoryUtil;
 
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContext;
 import java.net.URL;
 import java.net.MalformedURLException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.logging.Level;
 
 /**
  * Launcher for runtime environment that loads info from servlet context params.
@@ -32,6 +37,12 @@
      * Servlet context-param name for user-specified application SCDL path.
      */
     public static final String APPLICATION_SCDL_PATH_PARAM = "applicationScdlPath";
+    /**
+     * Servlet context-param name for system monitoring level.
+     * Supported values are the names of statics defined in java.util.logging.Level.
+     * If absent, no monitoring will take place.
+     */
+    public static final String SYSTEM_MONITORING_PARAM = "tuscanyMonitoringLevel";
 
     /**
      * Default application SCDL path used if no "applicationScdlPath" param is specified
@@ -65,6 +76,10 @@
             applicationScdlPath = DEFAULT_APPLICATION_SCDL_PATH;
         }
 
+        // Read optional system monitor factory classname
+        String systemLogging = servletContext.getInitParameter(SYSTEM_MONITORING_PARAM);
+        MonitorFactory mf = getMonitorFactory(systemLogging);
+
         Launcher launcher = new Launcher();
 
         // Current thread context classloader should be the webapp classloader
@@ -75,7 +90,7 @@
 
         try {
             URL systemScdl = getClass().getResource(systemScdlPath);
-            launcher.bootRuntime(systemScdl);
+            launcher.bootRuntime(systemScdl, mf);
             servletContext.setAttribute(LAUNCHER_ATTRIBUTE, launcher);
 
             URL appScdl;
@@ -83,24 +98,22 @@
                 // Paths begining w/ "/" are treated as webapp resources
                 try {
                     appScdl = servletContext.getResource(applicationScdlPath);
-                }
-                catch (MalformedURLException mue) {
+                } catch (MalformedURLException mue) {
                     throw new LoaderException("Unable to find application SCDL: " + applicationScdlPath);
                 }
-            }
-            else {
+            } else {
                 // Other paths are searched using the application classloader
                 appScdl = launcher.getApplicationLoader().getResource(applicationScdlPath);
-                if (appScdl == null)
+                if (appScdl == null) {
                     throw new LoaderException("Unable to find application SCDL: " + applicationScdlPath);
+                }
             }
 
             component = launcher.bootApplication(appScdl);
             component.start();
             context = new CompositeContextImpl(component);
             context.start();
-        }
-        catch (Throwable t) {
+        } catch (Throwable t) {
             servletContext.setAttribute(LAUNCHER_THROWABLE_ATTRIBUTE, t);
             t.printStackTrace();
         }
@@ -111,7 +124,27 @@
 
         Launcher launcher = (Launcher) servletContext.getAttribute(LAUNCHER_ATTRIBUTE);
 
-        if (launcher != null)
+        if (launcher != null) {
             launcher.shutdownRuntime();
+        }
+    }
+
+    private MonitorFactory getMonitorFactory(String loggingLevel) {
+        String factoryName = "org.apache.tuscany.core.monitor.NullMonitorFactory";
+        Map<String, Object> props = null;
+        if (loggingLevel != null) {
+            factoryName = "org.apache.tuscany.core.monitor.JavaLoggingMonitorFactory";
+            props = new HashMap<String, Object>();
+            Level level = Level.SEVERE;
+            try {
+                level = Level.parse(loggingLevel);
+            } catch (IllegalArgumentException e) {
+                // ignore bad loggingLevel
+            }
+            props.put("bundleName", "SystemMessages");
+            props.put("defaultLevel", level);
+        }
+
+        return MonitorFactoryUtil.createMonitorFactory(factoryName, props);
     }
 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
Tue Aug  1 13:53:11 2006
@@ -159,6 +159,13 @@
         throws XMLStreamException, LoaderException {
         String name = reader.getAttributeValue(null, "name");
         String target = reader.getAttributeValue(null, "target");
+
+        if (name == null || target == null) {
+            InvalidReferenceException le = new InvalidReferenceException();
+            le.setIdentifier(target);
+            throw le;
+        }
+
         ReferenceTarget referenceTarget = new ReferenceTarget();
         referenceTarget.setReferenceName(name);
         try {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
Tue Aug  1 13:53:11 2006
@@ -55,13 +55,13 @@
      * the method name in form returned by <code>Class.getName() + '#' + Method.getName()</code>
and the value the log
      * level to use as defined by {@link java.util.logging.Level}.
      *
-     * @param levels       definition of custom levels for specific monitored methods
+     * @param levels       definition of custom levels for specific monitored methods, may
be null or empty.
      * @param defaultLevel the default log level to use
      * @param bundleName   the name of a resource bundle that will be passed to the logger
      * @see java.util.logging.Logger
      */
     public JavaLoggingMonitorFactory(Properties levels, Level defaultLevel, String bundleName)
{
-        Map<String,Object> configProperties = new HashMap<String,Object>();
+        Map<String, Object> configProperties = new HashMap<String, Object>();
         configProperties.put("levels", levels);
         configProperties.put("defaultLevel", defaultLevel);
         configProperties.put("bundleName", bundleName);
@@ -74,24 +74,29 @@
     public JavaLoggingMonitorFactory() {
     }
 
-    public void initialize(Map<String,Object> configProperties) {
+    public void initialize(Map<String, Object> configProperties) {
+        if (configProperties == null) {
+            return;
+        }
+
         try {
             this.defaultLevel = (Level) configProperties.get("defaultLevel");
             this.bundleName = (String) configProperties.get("bundleName");
             Properties levels = (Properties) configProperties.get("levels");
 
-            this.levels = new HashMap<String, Level>(levels.size());
-            for (Map.Entry<Object, Object> entry : levels.entrySet()) {
-                String method = (String) entry.getKey();
-                String level = (String) entry.getValue();
-                try {
-                    this.levels.put(method, Level.parse(level));
-                } catch (IllegalArgumentException e) {
-                    throw new InvalidLevelException(method, level);
+            this.levels = new HashMap<String, Level>();
+            if (levels != null) {
+                for (Map.Entry<Object, Object> entry : levels.entrySet()) {
+                    String method = (String) entry.getKey();
+                    String level = (String) entry.getValue();
+                    try {
+                        this.levels.put(method, Level.parse(level));
+                    } catch (IllegalArgumentException e) {
+                        throw new InvalidLevelException(method, level);
+                    }
                 }
             }
-        }
-        catch (ClassCastException cce) {
+        } catch (ClassCastException cce) {
             throw new IllegalArgumentException(cce.getLocalizedMessage());
         }
     }

Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java?rev=427726&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java
(added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java
Tue Aug  1 13:53:11 2006
@@ -0,0 +1,59 @@
+package org.apache.tuscany.core.monitor;
+
+import org.apache.tuscany.spi.monitor.MonitorFactory;
+
+import java.util.Map;
+
+/**
+ * Helper for creating MonitorFactory instances.
+ * 
+ * @version $$Rev: $$ $$Date: $$
+ */
+
+public final class MonitorFactoryUtil {
+    /**
+     * Hide the constructor
+     */
+    private MonitorFactoryUtil() {
+    }
+
+    /**
+     * Creates a MonitorFactory instance of the specified type.
+     * @param name fully qualified classname of the desired MonitorFactory type
+     * @param props collection of initialization properties
+     * @return a configured MonitorFactory instance, or null if the factory could not be
instantiated.
+     */
+    public static MonitorFactory createMonitorFactory(String name, Map<String, Object>
props) {
+        Class<? extends MonitorFactory> clazz;
+        try {
+            clazz = (Class<? extends MonitorFactory>) Class.forName(name);
+        } catch (ClassNotFoundException cnfe) {
+            return null;
+        } catch (ClassCastException cce) {
+            return null;
+        }
+
+        return createMonitorFactory(clazz, props);
+    }
+
+    /**
+     * Creates a MonitorFactory instance of the specified type.
+     * @param mfc class of the desired MonitorFactory type
+     * @param props collection of initialization properties
+     * @return a configured MonitorFactory instance, or null if the factory could not be
instantiated.
+     */
+    public static MonitorFactory createMonitorFactory(Class<? extends MonitorFactory>
mfc, Map<String, Object> props) {
+        MonitorFactory mf;
+        try {
+            mf = mfc.newInstance();
+            mf.initialize(props);
+        } catch (InstantiationException e) {
+            throw new AssertionError(e);
+        } catch (IllegalAccessException e) {
+            throw new AssertionError(e);
+        }
+        // allow IllegalArgumentException to propogate out
+
+        return mf;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
Tue Aug  1 13:53:11 2006
@@ -44,7 +44,7 @@
     public void init() {
     }
 
-    public void initialize(Map<String,Object> configProperties) {
+    public void initialize(Map<String, Object> configProperties) {
     }
 
     public <T> T getMonitor(Class<T> monitorInterface) {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/util/ClassLoaderHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/util/ClassLoaderHelper.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/util/ClassLoaderHelper.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/util/ClassLoaderHelper.java
Tue Aug  1 13:53:11 2006
@@ -11,7 +11,13 @@
  * @version $$Rev: $$ $$Date: $$
  */
 
-public class ClassLoaderHelper {
+public final class ClassLoaderHelper {
+    /**
+     * Hide constructor
+     */
+    private ClassLoaderHelper() {
+    }
+    
     /**
      * Create a classloader for the supplied classpath.
      *

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
(original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
Tue Aug  1 13:53:11 2006
@@ -1,13 +1,18 @@
 package org.apache.tuscany.core.component.scope;
 
-import junit.framework.TestCase;
+import org.jmock.MockObjectTestCase;
+import org.jmock.Mock;
+import org.apache.tuscany.spi.component.ScopeRegistry;
 
 /**
  * @version $Rev$ $Date$
  */
-public class ModuleScopeObjectFactoryTestCase extends TestCase {
+public class ModuleScopeObjectFactoryTestCase extends MockObjectTestCase {
 
     public void testCreation() {
-        assertNotNull(new ModuleScopeObjectFactory().getInstance());
+        Mock registry = mock(ScopeRegistry.class);
+        registry.expects(once()).method("registerFactory").withAnyArguments();
+
+        assertNotNull(new ModuleScopeObjectFactory((ScopeRegistry)registry.proxy()).getInstance());
     }
 }

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
(original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
Tue Aug  1 13:53:11 2006
@@ -1,13 +1,18 @@
 package org.apache.tuscany.core.component.scope;
 
-import junit.framework.TestCase;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.apache.tuscany.spi.component.ScopeRegistry;
 
 /**
  * @version $Rev$ $Date$
  */
-public class StatelessScopeObjectFactoryTestCase extends TestCase {
+public class StatelessScopeObjectFactoryTestCase extends MockObjectTestCase {
 
     public void testCreation() {
-        assertNotNull(new StatelessScopeObjectFactory().getInstance());
+        Mock registry = mock(ScopeRegistry.class);
+        registry.expects(once()).method("registerFactory").withAnyArguments();
+
+        assertNotNull(new StatelessScopeObjectFactory((ScopeRegistry)registry.proxy()).getInstance());
     }
 }

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/builder/JavaBuilderPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/builder/JavaBuilderPropertyTestCase.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/builder/JavaBuilderPropertyTestCase.java
(original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/builder/JavaBuilderPropertyTestCase.java
Tue Aug  1 13:53:11 2006
@@ -61,7 +61,7 @@
         Mock mock = mock(AutowireComponent.class);
         parent = (CompositeComponent<?>) mock.proxy();
         registry = new ScopeRegistryImpl(new WorkContextImpl());
-        registry.registerFactory(Scope.STATELESS, new StatelessScopeObjectFactory());
+        new StatelessScopeObjectFactory(registry);
     }
 
     private static class Foo {

Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
(original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
Tue Aug  1 13:53:11 2006
@@ -33,10 +33,10 @@
     /**
      * Initializes MonitorFactory instances with implementation-specific configuration properties.
      *
-     * @param configProperties a map of named configuration properties
+     * @param configProperties a map of named configuration properties.  May be null.
      * @throws IllegalArgumentException if the instance can't be configured using the supplied
properties
      */
-    void initialize(Map<String,Object> configProperties);
+    void initialize(Map<String, Object> configProperties);
     /**
      * Return a monitor for a component's monitor interface.
      *

Modified: incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java?rev=427726&r1=427725&r2=427726&view=diff
==============================================================================
--- incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
(original)
+++ incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
Tue Aug  1 13:53:11 2006
@@ -27,6 +27,7 @@
 import org.apache.tuscany.core.launcher.CompositeContextImpl;
 import org.apache.tuscany.core.launcher.Launcher;
 import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.Deployer;
 import org.apache.tuscany.spi.loader.LoaderException;
@@ -38,7 +39,6 @@
  * @version $Rev$ $Date$
  */
 public class SCATestCase extends TestCase {
-    private Launcher launcher;
     private CompositeComponent<?> component;
     private CompositeContextImpl context;
     private Map<String, URL> extensions = new HashMap<String, URL>();
@@ -47,9 +47,10 @@
     protected void setUp() throws Exception {
         super.setUp();
         ClassLoader cl = getClass().getClassLoader();
-        launcher = new Launcher();
+        Launcher launcher = new Launcher();
         launcher.setApplicationLoader(cl);
-        CompositeComponent<?> composite = launcher.bootRuntime(cl.getResource(Launcher.METAINF_SYSTEM_SCDL_PATH));
+        CompositeComponent<?> composite = launcher.bootRuntime(cl.getResource(Launcher.METAINF_SYSTEM_SCDL_PATH),
+                new NullMonitorFactory());
 
         for (String extensionName : extensions.keySet()) {
             deployExtension(composite, extensionName, extensions.get(extensionName));



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message