geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r566236 - in /geronimo/server/trunk/modules/geronimo-j2ee/src: main/java/org/apache/geronimo/j2ee/annotation/Holder.java test/java/org/apache/geronimo/j2ee/annotation/ test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
Date Wed, 15 Aug 2007 15:58:51 GMT
Author: gawor
Date: Wed Aug 15 08:58:50 2007
New Revision: 566236

URL: http://svn.apache.org/viewvc?view=rev&rev=566236
Log:
add a copy constructor to the Holder object

Added:
    geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/
    geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java?view=diff&rev=566236&r1=566235&r2=566236
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
Wed Aug 15 08:58:50 2007
@@ -50,8 +50,24 @@
     public Holder() {
     }
 
-
-    public void addInjection(String className, Injection injection) {
+    public Holder(Holder source) {
+        if (source.getInjectionMap() != null) {
+            this.injectionMap = new HashMap<String, List<Injection>>();
+            addInjectionMap(source.getInjectionMap());
+        }
+        
+        if (source.getPostConstruct() != null) {
+            this.postConstruct = new HashMap<String, LifecycleMethod>();
+            addPostConstructs(source.getPostConstruct());
+        }
+        
+        if (source.getPreDestroy() != null) {
+            this.preDestroy = new HashMap<String, LifecycleMethod>();
+            addPreDestroys(source.getPreDestroy());
+        }
+    }
+    
+    private List<Injection> getInjectionList(String className) {
         if (injectionMap == null) {
             injectionMap = new HashMap<String, List<Injection>>();
         }
@@ -60,7 +76,19 @@
             injections = new ArrayList<Injection>();
             injectionMap.put(className, injections);
         }
-        injections.add(injection);
+        return injections;
+    }
+    
+    public void addInjection(String className, Injection newInjection) {
+        List<Injection> injections = getInjectionList(className);
+        injections.add(newInjection);
+    }
+    
+    public void addInjections(String className, List<Injection> newInjections) {
+        List<Injection> injections = getInjectionList(className);        
+        for (Injection injection : newInjections) {
+            injections.add(injection);
+        }
     }
 
     public void addPostConstructs(Map<String, LifecycleMethod> newPostConstructs) {
@@ -82,6 +110,17 @@
         return old;
     }
 
+    public void addInjectionMap(Map<String, List<Injection>> injectionMap) {
+        if (injectionMap == null) {
+            return;
+        }
+        for (Map.Entry<String, List<Injection>> entry : injectionMap.entrySet())
{
+            String className = entry.getKey();
+            List<Injection> injections = entry.getValue();
+            addInjections(className, injections);            
+        }
+    }
+    
     public List<Injection> getInjections(String className) {
         if (injectionMap == null) {
             return null;
@@ -89,6 +128,10 @@
         return injectionMap.get(className);
     }
 
+    public Map<String, List<Injection>> getInjectionMap() {
+        return injectionMap;
+    }
+    
     public Map<String, LifecycleMethod> getPostConstruct() {
         return postConstruct;
     }

Added: geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java?view=auto&rev=566236
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
(added)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
Wed Aug 15 08:58:50 2007
@@ -0,0 +1,94 @@
+/**
+ *  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.j2ee.annotation;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class HolderTest extends TestCase {
+
+    public void testCopy() throws Exception {
+        Holder source = new Holder();
+        source.addInjection("a1", new Injection("a1", "1", "2"));
+        source.addInjection("a1", new Injection("a1", "3", "4"));
+        
+        source.addInjection("b1", new Injection("b1", "5", "6"));
+
+        HashMap<String, LifecycleMethod> postConstruct = new HashMap<String, LifecycleMethod>();
+        postConstruct.put("class1", new LifecycleMethod("class1", "method1"));
+        postConstruct.put("class2", new LifecycleMethod("class2", "method2"));
+        
+        source.addPostConstructs(postConstruct);
+        
+        HashMap<String, LifecycleMethod> preDestroy = new HashMap<String, LifecycleMethod>();
+        preDestroy.put("class3", new LifecycleMethod("class3", "method1"));
+        preDestroy.put("class4", new LifecycleMethod("class4", "method2"));
+        
+        source.addPreDestroys(preDestroy);
+        
+        Holder copy = new Holder(source);
+        
+        compareInjection(source.getInjectionMap(), copy.getInjectionMap());  
+        compareLifecycleMethod(source.getPostConstruct(), copy.getPostConstruct());
+        compareLifecycleMethod(source.getPreDestroy(), copy.getPreDestroy());
+    }
+    
+    private void compareInjection(Map<String, List<Injection>> expected, Map<String,
List<Injection>> actual) {
+        assertNotNull(expected);
+        assertNotNull(actual);
+        assertTrue(expected != actual);
+        assertEquals(expected.size(), actual.size());
+        
+        for (Map.Entry<String, List<Injection>> entry : expected.entrySet())
{
+            String className = entry.getKey();
+            List<Injection> expectedInjections = entry.getValue();
+            
+            List<Injection> actualInjections = actual.get(className);
+            compare(expectedInjections, actualInjections);
+        }                            
+    }
+    
+    private void compare(List<Injection> expected, List<Injection> actual) {
+        assertNotNull(expected);
+        assertNotNull(actual);
+        assertTrue(expected != actual);
+        assertEquals(expected.size(), actual.size());
+        
+        for (int i = 0; i < expected.size(); i++) {
+            assertEquals(expected.get(i), actual.get(i));
+        }
+    }
+    
+    private void compareLifecycleMethod(Map<String, LifecycleMethod> expected, Map<String,
LifecycleMethod> actual) {
+        assertNotNull(expected);
+        assertNotNull(actual);
+        assertTrue(expected != actual);
+        assertEquals(expected.size(), actual.size());
+        
+        for (Map.Entry<String, LifecycleMethod> entry : expected.entrySet()) {
+            String className = entry.getKey();
+            LifecycleMethod expectedMethod = entry.getValue();
+            
+            LifecycleMethod actualMethod = actual.get(className);
+            assertEquals(expectedMethod, actualMethod);
+        }
+    }
+    
+}

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/test/java/org/apache/geronimo/j2ee/annotation/HolderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message