openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r673484 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
Date Wed, 02 Jul 2008 20:26:49 GMT
Author: ppoddar
Date: Wed Jul  2 13:26:48 2008
New Revision: 673484

URL: http://svn.apache.org/viewvc?rev=673484&view=rev
Log:
OPENJPA-647: Change cardinality of listeners for Value update so that ClassMetaData (and others)
can sync with dynamic configuration changes

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=673484&r1=673483&r2=673484&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Wed Jul  2 13:26:48 2008
@@ -2363,7 +2363,7 @@
     		Value value = getRepository().getConfiguration()
     			.getValue(key);
     		if (value != null)
-    			value.setListener(this);
+    			value.addListener(this);
     	}
     }
     

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=673484&r1=673483&r2=673484&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
Wed Jul  2 13:26:48 2008
@@ -912,13 +912,13 @@
     public boolean removeValue(Value val) {
         if (!_vals.remove(val))
             return false;
-        val.setListener(null);
+        val.removeListener(this);
         return true;
     }
 
     public Value addValue(Value val) {
         _vals.add(val);
-        val.setListener(this);
+        val.addListener(this);
         return val;
     }
 

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java?rev=673484&r1=673483&r2=673484&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java Wed Jul
 2 13:26:48 2008
@@ -18,7 +18,10 @@
  */
 package org.apache.openjpa.lib.conf;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
@@ -41,7 +44,7 @@
     private String def = null;
     private String[] aliases = null;
     private String getter = null;
-    private ValueListener listen = null;
+    private List<ValueListener> listeners = null;
     private boolean aliasListComprehensive = false;
     private Class scope = null;
     private boolean isDynamic = false;
@@ -368,25 +371,37 @@
     protected abstract void setInternalObject(Object obj);
 
     /**
-     * Listener for value changes.
+     * Gets unmodifable list of listeners for value changes.
      */
-    public ValueListener getListener() {
-        return this.listen;
+    public List<ValueListener> getListeners() {
+        return Collections.unmodifiableList(this.listeners);
     }
 
     /**
      * Listener for value changes.
      */
-    public void setListener(ValueListener listen) {
-        this.listen = listen;
+    public void addListener(ValueListener listener) {
+    	if (listener == null)
+    		return;
+    	if (listeners == null)
+    		listeners = new ArrayList<ValueListener>();
+        listeners.add(listener);
+    }
+    
+    public void removeListener(ValueListener listener) {
+    	if (listener == null)
+    		return;
+        listeners.remove(listener);
     }
 
     /**
      * Subclasses should call this method when their internal value changes.
      */
     public void valueChanged() {
-        if (listen != null) {
-        	listen.valueChanged(this);
+        if (listeners == null) 
+        	return;
+        for (ValueListener listener : listeners) {
+        	listener.valueChanged(this);
         }
     }
     
@@ -401,13 +416,23 @@
      * <LI>Configuration is read-only
      */
     protected void assertChangeable() {
-    	if (!isDynamic() && listen instanceof Configuration && 
-        	((Configuration)listen).isReadOnly()) {
+    	if (!isDynamic() && containsReadOnlyConfigurationAsListener()) {
         	throw new RuntimeException(s_loc.get("veto-change",
         		this.getProperty()).toString());
        	}
     }
     
+    boolean containsReadOnlyConfigurationAsListener() {
+    	if (listeners == null)
+    		return false;
+    	for (ValueListener listener : listeners) {
+    		if (listener instanceof Configuration
+    		&& ((Configuration)listener).isReadOnly())
+    			return true;
+    	}
+    	return false;
+    }
+    
     /**
      * Sets if this receiver can be mutated even when the configuration it 
      * belongs to has been {@link Configuration#isReadOnly() frozen}.



Mime
View raw message