Author: rfeng
Date: Wed Mar 26 10:23:44 2008
New Revision: 641417

URL: http://svn.apache.org/viewvc?rev=641417&view=rev
Log:
Apply the patch from Wang Feng to TUSCANY-2141. Thanks Wang Feng for the 
contribution!

Added:
    incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/
    incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/
    
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
   (with props)
    
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo1Composite.composite
    
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo2Composite.composite
    incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/
    incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/
    
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java

Added: 
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java?rev=641417&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
 Wed Mar 26 10:23:44 2008
@@ -0,0 +1,27 @@
+/*
+ * 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 circular.include;
+
+public class DemoClass {
+
+    public String demo() {
+        return "hello";
+    }
+}

Propchange: 
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/recursive/src/main/java/circular/include/DemoClass.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo1Composite.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo1Composite.composite?rev=641417&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo1Composite.composite
 (added)
+++ 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo1Composite.composite
 Wed Mar 26 10:23:44 2008
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
xmlns:sca="http://www.osoa.org/xmlns/sca/1.0";
+    targetNamespace="http://sample"; xmlns:sample="http://sample"; 
name="Demo1Composite"
+    xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0";>
+    <include name="sample:Demo2Composite" />
+    <component name="Demo1Component">
+        <implementation.java class="circular.include.DemoClass" />
+    </component>
+</composite>

Added: 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo2Composite.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo2Composite.composite?rev=641417&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo2Composite.composite
 (added)
+++ 
incubator/tuscany/java/sca/itest/recursive/src/main/resources/Demo2Composite.composite
 Wed Mar 26 10:23:44 2008
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
xmlns:sca="http://www.osoa.org/xmlns/sca/1.0";
+    targetNamespace="http://sample"; xmlns:sample="http://sample"; 
name="Demo2Composite"
+    xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0";>
+    <include name="sample:Demo1Composite" />
+    <component name="Demo2Component">
+        <implementation.java class="circular.include.DemoClass" />
+    </component>
+</composite>
+

Added: 
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java?rev=641417&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
 Wed Mar 26 10:23:44 2008
@@ -0,0 +1,39 @@
+/*
+ * 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 circular.include;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.Test;
+
+public class CircularIncludeTestCase {
+
+    @Test
+    public void testCyclicInclude() {
+        SCADomain scaDomain = 
SCADomain.newInstance("Demo1Composite.composite");
+
+        DemoClass demoService = scaDomain.getService(DemoClass.class, 
"Demo1Component");
+        String demo = demoService.demo();
+        Assert.assertEquals("hello", demo);
+        scaDomain.close();
+    }
+
+}

Propchange: 
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java?rev=641417&r1=641416&r2=641417&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java
 Wed Mar 26 10:23:44 2008
@@ -20,7 +20,10 @@
 package org.apache.tuscany.sca.assembly.builder.impl;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
 
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor;
@@ -28,6 +31,8 @@
 
 public class CompositeIncludeBuilderImpl {
     
+    public static Logger logger = 
Logger.getLogger(CompositeIncludeBuilderImpl.class.getName());
+       
     public CompositeIncludeBuilderImpl(CompositeBuilderMonitor monitor) {
     }
 
@@ -37,10 +42,16 @@
      * @param composite
      * @param includes
      */
-    private void collectIncludes(Composite composite, List<Composite> 
includes) {
+    private void collectIncludes(Composite composite, List<Composite> 
includes, Set<Composite> visited) {
         for (Composite include : composite.getIncludes()) {
+            if (visited.contains(include)) {
+                logger.warning("Composite " + include.getName() + " has 
already been included.");
+                continue;
+            }
+                       
             includes.add(include);
-            collectIncludes(include, includes);
+            visited.add(include);
+            collectIncludes(include, includes, visited);
         }
     }
 
@@ -53,8 +64,9 @@
     
         // First collect all includes
         List<Composite> includes = new ArrayList<Composite>();
-        collectIncludes(composite, includes);
-    
+        Set<Composite> visited = new HashSet<Composite>();
+        visited.add(composite);
+        collectIncludes(composite, includes, visited);
         // Then clone them
         for (Composite include : includes) {
             Composite clone;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to