You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/05/18 19:48:31 UTC
svn commit: r539534 - in
/incubator/tuscany/java/sca/modules/host-embedded/src:
main/java/org/apache/tuscany/sca/host/embedded/impl/ test/java/
test/java/org/apache/tuscany/sca/host/embedded/impl/
Author: jsdelfino
Date: Fri May 18 10:48:30 2007
New Revision: 539534
URL: http://svn.apache.org/viewvc?view=rev&rev=539534
Log:
Cleaned up EmbeddedSCADomain, and added a test case for it.
Added:
incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java (with props)
incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java (with props)
incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt (with props)
Modified:
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?view=diff&rev=539534&r1=539533&r2=539534
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java Fri May 18 10:48:30 2007
@@ -107,38 +107,41 @@
/**
* Constructs a new domain facade.
- *
+ *
+ * @param runtimeClassLoader
* @param domainURI
- * @param contributionLocation
- * @param composites
*/
public EmbeddedSCADomain(ClassLoader runtimeClassLoader,
String domainURI) {
this.uri = domainURI;
-
- // Create an in-memory domain level composite
- AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
- domainComposite = assemblyFactory.createComposite();
- domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
- domainComposite.setURI(domainURI);
- domainCompositeHelper = new DomainCompositeHelper();
-
- // Create the runtime
+ // Create a runtime
runtime = new ReallySmallRuntime(runtimeClassLoader);
-
- // Index the top level components
- for (Component component : domainComposite.getComponents()) {
- components.put(component.getName(), component);
- }
}
public void start() throws ActivationException {
+
+ // Start the runtime
runtime.start();
+
+ // Create an in-memory domain level composite
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ domainComposite = assemblyFactory.createComposite();
+ domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
+ domainComposite.setURI(uri);
+
+ // Create a domain composite helper
+ domainCompositeHelper = new DomainCompositeHelper();
}
public void stop() throws ActivationException {
+
+ // Stop the runtime
runtime.stop();
+
+ // Cleanup
+ domainComposite = null;
+ domainCompositeHelper = null;
}
public ContributionService getContributionService() {
Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?view=diff&rev=539534&r1=539533&r2=539534
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java Fri May 18 10:48:30 2007
@@ -118,7 +118,15 @@
// Stop and destroy the work manager
workManager.destroy();
-
+
+ // Cleanup
+ modules = null;
+ registry = null;
+ assemblyFactory = null;
+ contributionService = null;
+ compositeActivator = null;
+ workManager = null;
+ scopeRegistry = null;
}
public ContributionService getContributionService() {
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java?view=auto&rev=539534
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java Fri May 18 10:48:30 2007
@@ -0,0 +1,112 @@
+/*
+ * 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.tuscany.sca.host.embedded.impl;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+
+import crud.CRUD;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedSCADomainTestCase extends TestCase {
+ private EmbeddedSCADomain domain;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+
+ // Create a test embedded SCA domain
+ domain = new EmbeddedSCADomain(getClass().getClassLoader(), "http://localhost");
+ }
+
+ public void testDomain() throws Exception {
+
+ // Start the domain
+ domain.start();
+
+ // Determine my class loader and my test SCA contribution location
+ ClassLoader myClassLoader = getClass().getClassLoader();
+ String url = myClassLoader.getResource("test.txt").toString();
+ url = url.substring(0, url.length()-8);
+
+ // Contribute the SCA contribution
+ TestModelResolver myResolver = new TestModelResolver(myClassLoader);
+ ContributionService contributionService = domain.getContributionService();
+ Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
+ assertNotNull(contribution);
+
+ // Decide which SCA composite I want to deploy
+ Composite myComposite = myResolver.getComposite(new QName("http://sample/crud", "crud"));
+
+ // Add the deployable composite to the domain
+ EmbeddedSCADomain.DomainCompositeHelper domainHelper = domain.getDomainCompositeHelper();
+ domainHelper.addComposite(myComposite);
+
+ // Start the components in my composite
+ domainHelper.startComposite(myComposite);
+
+ // At this point the domain contains my contribution, my composite and
+ // it's started, my application code can start using it
+
+ // Get the CRUDServiceComponent service
+ CRUD service = domain.getService(CRUD.class, "CRUDServiceComponent");
+
+ // Invoke the service
+ String id = service.create("ABC");
+ Object result = service.retrieve(id);
+ assertEquals("ABC", result);
+ service.update(id, "EFG");
+ result = service.retrieve(id);
+ assertEquals("EFG", result);
+ service.delete(id);
+ result = service.retrieve(id);
+ assertNull(result);
+
+ // Stop my composite
+ domainHelper.stopComposite(myComposite);
+
+ // Remove my composite
+ domainHelper.removeComposite(myComposite);
+
+ // Remove my contribution
+ contributionService.remove("http://test/contribution");
+
+ // Stop the domain
+ domain.stop();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java?view=auto&rev=539534
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java Fri May 18 10:48:30 2007
@@ -0,0 +1,104 @@
+/*
+ * 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.tuscany.sca.host.embedded.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A test model resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+ private WeakReference<ClassLoader> classLoader;
+
+ private Map<QName, Composite> composites = new HashMap<QName, Composite>();
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrappering the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ if (resolved instanceof Composite) {
+ Composite composite = (Composite)resolved;
+ composites.put(composite.getName(), composite);
+ }
+ }
+
+ public Object removeModel(Object resolved) {
+ if (resolved instanceof Composite) {
+ Composite composite = (Composite)resolved;
+ composites.remove(composite.getName());
+ }
+ return map.remove(resolved);
+ }
+
+ public Composite getComposite(QName qname) {
+ return composites.get(qname);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt?view=auto&rev=539534
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt Fri May 18 10:48:30 2007
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org
Merging with the 0.90 branch, was: svn commit: r539534
Posted by Jean-Sebastien Delfino <js...@apache.org>.
I'd like to merge these changes into the 0.90 branch, I try to do this
later in the afternoon or this evening.
jsdelfino@apache.org wrote:
> Author: jsdelfino
> Date: Fri May 18 10:48:30 2007
> New Revision: 539534
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=539534
> Log:
> Cleaned up EmbeddedSCADomain, and added a test case for it.
>
> Added:
> incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java (with props)
> incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java (with props)
> incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt (with props)
> Modified:
> incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
> incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
>
> Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?view=diff&rev=539534&r1=539533&r2=539534
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java (original)
> +++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java Fri May 18 10:48:30 2007
> @@ -107,38 +107,41 @@
>
> /**
> * Constructs a new domain facade.
> - *
> + *
> + * @param runtimeClassLoader
> * @param domainURI
> - * @param contributionLocation
> - * @param composites
> */
> public EmbeddedSCADomain(ClassLoader runtimeClassLoader,
> String domainURI) {
> this.uri = domainURI;
> -
> - // Create an in-memory domain level composite
> - AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
> - domainComposite = assemblyFactory.createComposite();
> - domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
> - domainComposite.setURI(domainURI);
>
> - domainCompositeHelper = new DomainCompositeHelper();
> -
> - // Create the runtime
> + // Create a runtime
> runtime = new ReallySmallRuntime(runtimeClassLoader);
> -
> - // Index the top level components
> - for (Component component : domainComposite.getComponents()) {
> - components.put(component.getName(), component);
> - }
> }
>
> public void start() throws ActivationException {
> +
> + // Start the runtime
> runtime.start();
> +
> + // Create an in-memory domain level composite
> + AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
> + domainComposite = assemblyFactory.createComposite();
> + domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
> + domainComposite.setURI(uri);
> +
> + // Create a domain composite helper
> + domainCompositeHelper = new DomainCompositeHelper();
> }
>
> public void stop() throws ActivationException {
> +
> + // Stop the runtime
> runtime.stop();
> +
> + // Cleanup
> + domainComposite = null;
> + domainCompositeHelper = null;
> }
>
> public ContributionService getContributionService() {
>
> Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?view=diff&rev=539534&r1=539533&r2=539534
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java (original)
> +++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java Fri May 18 10:48:30 2007
> @@ -118,7 +118,15 @@
>
> // Stop and destroy the work manager
> workManager.destroy();
> -
> +
> + // Cleanup
> + modules = null;
> + registry = null;
> + assemblyFactory = null;
> + contributionService = null;
> + compositeActivator = null;
> + workManager = null;
> + scopeRegistry = null;
> }
>
> public ContributionService getContributionService() {
>
> Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java?view=auto&rev=539534
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java (added)
> +++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java Fri May 18 10:48:30 2007
> @@ -0,0 +1,112 @@
> +/*
> + * 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.tuscany.sca.host.embedded.impl;
> +
> +import java.net.URL;
> +
> +import javax.xml.namespace.QName;
> +
> +import junit.framework.TestCase;
> +
> +import org.apache.tuscany.sca.assembly.Composite;
> +import org.apache.tuscany.sca.contribution.Contribution;
> +import org.apache.tuscany.sca.contribution.service.ContributionService;
> +
> +import crud.CRUD;
> +
> +/**
> + * @version $Rev$ $Date$
> + */
> +public class EmbeddedSCADomainTestCase extends TestCase {
> + private EmbeddedSCADomain domain;
> +
> + /**
> + * @throws java.lang.Exception
> + */
> + protected void setUp() throws Exception {
> +
> + // Create a test embedded SCA domain
> + domain = new EmbeddedSCADomain(getClass().getClassLoader(), "http://localhost");
> + }
> +
> + public void testDomain() throws Exception {
> +
> + // Start the domain
> + domain.start();
> +
> + // Determine my class loader and my test SCA contribution location
> + ClassLoader myClassLoader = getClass().getClassLoader();
> + String url = myClassLoader.getResource("test.txt").toString();
> + url = url.substring(0, url.length()-8);
> +
> + // Contribute the SCA contribution
> + TestModelResolver myResolver = new TestModelResolver(myClassLoader);
> + ContributionService contributionService = domain.getContributionService();
> + Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
> + assertNotNull(contribution);
> +
> + // Decide which SCA composite I want to deploy
> + Composite myComposite = myResolver.getComposite(new QName("http://sample/crud", "crud"));
> +
> + // Add the deployable composite to the domain
> + EmbeddedSCADomain.DomainCompositeHelper domainHelper = domain.getDomainCompositeHelper();
> + domainHelper.addComposite(myComposite);
> +
> + // Start the components in my composite
> + domainHelper.startComposite(myComposite);
> +
> + // At this point the domain contains my contribution, my composite and
> + // it's started, my application code can start using it
> +
> + // Get the CRUDServiceComponent service
> + CRUD service = domain.getService(CRUD.class, "CRUDServiceComponent");
> +
> + // Invoke the service
> + String id = service.create("ABC");
> + Object result = service.retrieve(id);
> + assertEquals("ABC", result);
> + service.update(id, "EFG");
> + result = service.retrieve(id);
> + assertEquals("EFG", result);
> + service.delete(id);
> + result = service.retrieve(id);
> + assertNull(result);
> +
> + // Stop my composite
> + domainHelper.stopComposite(myComposite);
> +
> + // Remove my composite
> + domainHelper.removeComposite(myComposite);
> +
> + // Remove my contribution
> + contributionService.remove("http://test/contribution");
> +
> + // Stop the domain
> + domain.stop();
> + }
> +
> + /**
> + * @throws java.lang.Exception
> + */
> + protected void tearDown() throws Exception {
> + domain.close();
> + }
> +
> +}
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
> ------------------------------------------------------------------------------
> svn:keywords = Rev Date
>
> Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java?view=auto&rev=539534
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java (added)
> +++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java Fri May 18 10:48:30 2007
> @@ -0,0 +1,104 @@
> +/*
> + * 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.tuscany.sca.host.embedded.impl;
> +
> +import java.lang.ref.WeakReference;
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +import javax.xml.namespace.QName;
> +
> +import org.apache.tuscany.sca.assembly.Composite;
> +import org.apache.tuscany.sca.contribution.resolver.ClassReference;
> +import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
> +
> +
> +/**
> + * A test model resolver, based on a map.
> + *
> + * @version $Rev$ $Date$
> + */
> +public class TestModelResolver implements ModelResolver {
> + private static final long serialVersionUID = -7826976465762296634L;
> +
> + private Map<Object, Object> map = new HashMap<Object, Object>();
> + private WeakReference<ClassLoader> classLoader;
> +
> + private Map<QName, Composite> composites = new HashMap<QName, Composite>();
> +
> + public TestModelResolver(ClassLoader classLoader) {
> + this.classLoader = new WeakReference<ClassLoader>(classLoader);
> + }
> +
> + public <T> T resolveModel(Class<T> modelClass, T unresolved) {
> + Object resolved = map.get(unresolved);
> + if (resolved != null) {
> +
> + // Return the resolved object
> + return modelClass.cast(resolved);
> +
> + } else if (unresolved instanceof ClassReference) {
> +
> + // Load a class on demand
> + ClassReference classReference = (ClassReference)unresolved;
> + Class clazz;
> + try {
> + clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
> + } catch (ClassNotFoundException e) {
> +
> + // Return the unresolved object
> + return unresolved;
> + }
> +
> + // Store a new ClassReference wrappering the loaded class
> + resolved = new ClassReference(clazz);
> + map.put(resolved, resolved);
> +
> + // Return the resolved ClassReference
> + return modelClass.cast(resolved);
> +
> + } else {
> +
> + // Return the unresolved object
> + return unresolved;
> + }
> + }
> +
> + public void addModel(Object resolved) {
> + map.put(resolved, resolved);
> + if (resolved instanceof Composite) {
> + Composite composite = (Composite)resolved;
> + composites.put(composite.getName(), composite);
> + }
> + }
> +
> + public Object removeModel(Object resolved) {
> + if (resolved instanceof Composite) {
> + Composite composite = (Composite)resolved;
> + composites.remove(composite.getName());
> + }
> + return map.remove(resolved);
> + }
> +
> + public Composite getComposite(QName qname) {
> + return composites.get(qname);
> + }
> +
> +}
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
> ------------------------------------------------------------------------------
> svn:keywords = Rev Date
>
> Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt?view=auto&rev=539534
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt (added)
> +++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt Fri May 18 10:48:30 2007
> @@ -0,0 +1,16 @@
> +# 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.
> \ No newline at end of file
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/test.txt
> ------------------------------------------------------------------------------
> svn:keywords = Rev Date
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-commits-help@ws.apache.org
>
>
>
--
Jean-Sebastien
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org