You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/02/12 17:50:41 UTC
svn commit: r377203 - in /incubator/tuscany/java/sca/core/src:
main/java/org/apache/tuscany/core/context/
main/java/org/apache/tuscany/core/system/config/
main/java/org/apache/tuscany/core/system/context/
test/java/org/apache/tuscany/core/system/context/
Author: jboynes
Date: Sun Feb 12 08:50:39 2006
New Revision: 377203
URL: http://svn.apache.org/viewcvs?rev=377203&view=rev
Log:
support addition of Java Objects as module scoped system components
Added:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java (with props)
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java (with props)
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/SystemAggregateContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/SystemAggregateContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/SystemAggregateContext.java?rev=377203&r1=377202&r2=377203&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/SystemAggregateContext.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/SystemAggregateContext.java Sun Feb 12 08:50:39 2006
@@ -13,12 +13,24 @@
*/
package org.apache.tuscany.core.context;
+import org.apache.tuscany.core.config.ConfigurationException;
+
/**
* Marker type for system aggregate contexts
- *
+ *
* @version $Rev$ $Date$
*/
public interface SystemAggregateContext extends AutowireContext, ScopeAwareContext, ConfigurationContext {
+ /**
+ * Register a simple Java Object as a system component.
+ * This is primarily intended for use by bootstrap code to create the initial
+ * configuration components.
+ *
+ * @param name the name of the resulting component
+ * @param instance the Object that will become the component's implementation
+ * @throws ConfigurationException
+ */
+ void registerJavaObject(String name, Object instance) throws ConfigurationException;
}
Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java?rev=377203&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java Sun Feb 12 08:50:39 2006
@@ -0,0 +1,92 @@
+/**
+ *
+ * Copyright 2005 BEA Systems Inc.
+ * Copyright 2005 International Business Machines Corporation
+ *
+ * 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 org.apache.tuscany.core.system.config;
+
+import java.util.Map;
+
+import org.apache.tuscany.core.builder.ContextCreationException;
+import org.apache.tuscany.core.builder.RuntimeConfiguration;
+import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.injection.ObjectFactory;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.system.context.SystemComponentContext;
+import org.apache.tuscany.model.assembly.ScopeEnum;
+
+/**
+ * A RuntimeConfiguration that contains the configuration needed to convert a simple
+ * Java Object into a component. The object is assumed to be fully initialized and
+ * will always be added with MODULE scope.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemObjectRuntimeConfiguration implements RuntimeConfiguration {
+ private final String name;
+ private final ObjectFactory<?> objectFactory;
+
+ /**
+ * Construct a RuntimeConfiguration for the supplied Java Object.
+ *
+ * @param name the name to be assigned to the resulting component
+ * @param instance the Java Object that provides the implementation
+ */
+ public SystemObjectRuntimeConfiguration(String name, Object instance) {
+ this.name = name;
+ objectFactory = new SingletonObjectFactory(instance);
+ }
+
+ public Context createInstanceContext() throws ContextCreationException {
+ return new SystemComponentContext(name, objectFactory, false, null, null, false);
+ }
+
+ public int getScope() {
+ return ScopeEnum.MODULE;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void prepare() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addTargetProxyFactory(String serviceName, ProxyFactory factory) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProxyFactory getTargetProxyFactory(String serviceName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Map getTargetProxyFactories() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addSourceProxyFactory(String referenceName, ProxyFactory factory) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProxyFactory getSourceProxyFactory(String referenceName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Map getSourceProxyFactories() {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectRuntimeConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java?rev=377203&r1=377202&r2=377203&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java Sun Feb 12 08:50:39 2006
@@ -59,6 +59,7 @@
import org.apache.tuscany.core.system.annotation.Autowire;
import org.apache.tuscany.core.system.annotation.ParentContext;
import org.apache.tuscany.core.system.assembly.SystemBinding;
+import org.apache.tuscany.core.system.config.SystemObjectRuntimeConfiguration;
import org.apache.tuscany.core.runtime.RuntimeContext;
import org.apache.tuscany.model.assembly.Component;
import org.apache.tuscany.model.assembly.EntryPoint;
@@ -373,6 +374,10 @@
registerConfiguration(configuration);
registerAutowire(model);
}
+ }
+
+ public void registerJavaObject(String name, Object instance) throws ConfigurationException {
+ registerConfiguration(new SystemObjectRuntimeConfiguration(name, instance));
}
protected void registerConfiguration(RuntimeConfiguration<InstanceContext> configuration) throws ConfigurationException {
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java?rev=377203&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java Sun Feb 12 08:50:39 2006
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2005 BEA Systems Inc.
+ * Copyright 2005 International Business Machines Corporation
+ *
+ * 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 org.apache.tuscany.core.system.context;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.runtime.RuntimeContext;
+import org.apache.tuscany.core.runtime.RuntimeContextImpl;
+import org.apache.tuscany.core.context.SystemAggregateContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.config.ConfigurationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemObjectRegistrationTestCase extends TestCase {
+ private RuntimeContext runtime;
+ private SystemAggregateContext systemContext;
+
+ public void testRegistration() throws ConfigurationException {
+ MockComponent instance = new MockComponent();
+ systemContext.registerJavaObject("foo", instance);
+ assertSame(instance, systemContext.locateInstance("foo"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ runtime = new RuntimeContextImpl();
+ runtime.start();
+ systemContext = runtime.getSystemContext();
+ systemContext.fireEvent(EventContext.MODULE_START, null);
+ }
+
+ protected void tearDown() throws Exception {
+ runtime.stop();
+ super.tearDown();
+ }
+
+ private static class MockComponent {
+ public String hello(String message) {
+ return message;
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date