You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cs...@apache.org on 2006/04/28 00:48:37 UTC
svn commit: r397664 - in /beehive/trunk/controls:
src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/
test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/
test/src/junit-controls/org/apache/beehive/controls/test/c...
Author: cschoett
Date: Thu Apr 27 15:48:35 2006
New Revision: 397664
URL: http://svn.apache.org/viewcvs?rev=397664&view=rev
Log:
Some additional serialization clean in ControlBeanContextSupport, refactoring for peer support in all three support classes. Added additional junits for testing peer cases.
Added:
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java (with props)
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java (contents, props changed)
- copied, changed from r397621, beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanDelegate.java
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java (with props)
Removed:
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanDelegate.java
Modified:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextChildSupport.java
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextServicesSupport.java
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextSupport.java
beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextChildSupportTest.java
beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextServicesSupportTest.java
beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextSupportTest.java
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextChildSupport.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextChildSupport.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextChildSupport.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextChildSupport.java Thu Apr 27 15:48:35 2006
@@ -44,7 +44,7 @@
private transient BeanContext _beanContext;
private transient boolean _vetodOnce;
- private BeanContextChild _bccDelegate;
+ private BeanContextChild _peer;
private PropertyChangeSupport _propertyChangeSupport;
private VetoableChangeSupport _vetoableChangeSupport;
@@ -53,10 +53,10 @@
*/
public ControlBeanContextChildSupport() {
_beanContext = null;
- _bccDelegate = this;
+ _peer = this;
_vetodOnce = false;
- _propertyChangeSupport = new PropertyChangeSupport(_bccDelegate);
- _vetoableChangeSupport = new VetoableChangeSupport(_bccDelegate);
+ _propertyChangeSupport = new PropertyChangeSupport(_peer);
+ _vetoableChangeSupport = new VetoableChangeSupport(_peer);
}
/**
@@ -68,9 +68,9 @@
public ControlBeanContextChildSupport(BeanContextChild bcc) {
_beanContext = null;
_vetodOnce = false;
- _bccDelegate = (bcc != null) ? bcc : this;
- _propertyChangeSupport = new PropertyChangeSupport(_bccDelegate);
- _vetoableChangeSupport = new VetoableChangeSupport(_bccDelegate);
+ _peer = (bcc != null) ? bcc : this;
+ _propertyChangeSupport = new PropertyChangeSupport(_peer);
+ _vetoableChangeSupport = new VetoableChangeSupport(_peer);
}
/**
@@ -201,8 +201,8 @@
/**
* Get the delegate for this child.
*/
- protected BeanContextChild getBCCDelegate() {
- return _bccDelegate;
+ protected BeanContextChild getPeer() {
+ return _peer;
}
/**
@@ -229,7 +229,7 @@
* @param out
*/
private void writeObject(ObjectOutputStream out) throws IOException {
- if (!_bccDelegate.equals(this) && !(_bccDelegate instanceof Serializable)) {
+ if (!_peer.equals(this) && !(_peer instanceof Serializable)) {
throw new IOException("Bean context child delegate does not support serialization!!!");
}
out.defaultWriteObject();
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextServicesSupport.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextServicesSupport.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextServicesSupport.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextServicesSupport.java Thu Apr 27 15:48:35 2006
@@ -57,10 +57,10 @@
/**
* Constructor which allows delegate to be passed in.
*
- * @param bcc BeanContextChild delegate.
+ * @param peer BeanContextServices peer.
*/
- public ControlBeanContextServicesSupport(BeanContextChild bcc) {
- super(bcc);
+ public ControlBeanContextServicesSupport(BeanContextServices peer) {
+ super(peer);
}
/**
@@ -86,7 +86,7 @@
// todo: for multithreaded usage this block needs to be synchronized
if (!_serviceProviders.containsKey(serviceClass)) {
_serviceProviders.put(serviceClass, new ServiceProvider(serviceProvider));
- BeanContextServiceAvailableEvent bcsae = new BeanContextServiceAvailableEvent(this, serviceClass);
+ BeanContextServiceAvailableEvent bcsae = new BeanContextServiceAvailableEvent((BeanContextServices)getPeer(), serviceClass);
fireServiceAvailableEvent(bcsae);
return true;
}
@@ -130,7 +130,7 @@
}
BeanContextServiceRevokedEvent bcsre =
- new BeanContextServiceRevokedEvent(this, serviceClass, revokeCurrentServicesNow);
+ new BeanContextServiceRevokedEvent((BeanContextServices)getPeer(), serviceClass, revokeCurrentServicesNow);
fireServiceRevokedEvent(bcsre);
// fire revoked event to requestor listeners, if the service is delegated the owner of the
@@ -211,10 +211,10 @@
return null;
}
else if (sp.isDelegated()) {
- service = ((BeanContextServices) bc).getService(this, requestor, serviceClass, serviceSelector, bcsrl);
+ service = ((BeanContextServices) bc).getService(getPeer(), requestor, serviceClass, serviceSelector, bcsrl);
}
else {
- service = sp.getBCServiceProvider().getService(this, requestor, serviceClass, serviceSelector);
+ service = sp.getBCServiceProvider().getService((BeanContextServices)getPeer(), requestor, serviceClass, serviceSelector);
}
if (service != null) {
@@ -225,7 +225,7 @@
// unknown service provider, delegate the request to the nested BeanContextServices (if available)
if (bc instanceof BeanContextServices) {
- service = ((BeanContextServices) bc).getService(this, requestor, serviceClass, serviceSelector, bcsrl);
+ service = ((BeanContextServices) bc).getService(getPeer(), requestor, serviceClass, serviceSelector, bcsrl);
if (service != null) {
sp = new ServiceProvider();
sp.addChildReference(requestor, bcsrl);
@@ -268,7 +268,7 @@
}
}
else {
- sp.getBCServiceProvider().releaseService(this, requestor, service);
+ sp.getBCServiceProvider().releaseService((BeanContextServices)getPeer(), requestor, service);
}
// end synchronized
}
@@ -306,7 +306,7 @@
if (_serviceProviders.containsKey(serviceClass)) {
ServiceProvider sp = _serviceProviders.get(serviceClass);
if (!sp.isDelegated() && !sp.isRevoked()) {
- return sp.getBCServiceProvider().getCurrentServiceSelectors(this, serviceClass);
+ return sp.getBCServiceProvider().getCurrentServiceSelectors((BeanContextServices)getPeer(), serviceClass);
}
}
return null;
@@ -351,7 +351,7 @@
for (Class serviceClass : _serviceProviders.keySet()) {
ServiceProvider sp = _serviceProviders.get(serviceClass);
if (sp.isDelegated()) {
- sp.revoke(new BeanContextServiceRevokedEvent(this, serviceClass, true));
+ sp.revoke(new BeanContextServiceRevokedEvent((BeanContextServices)getPeer(), serviceClass, true));
}
}
}
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextSupport.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextSupport.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextSupport.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/webcontext/ControlBeanContextSupport.java Thu Apr 27 15:48:35 2006
@@ -69,10 +69,10 @@
/**
* Constructor.
*
- * @param bcc
+ * @param peer
*/
- public ControlBeanContextSupport(java.beans.beancontext.BeanContextChild bcc) {
- super(bcc);
+ public ControlBeanContextSupport(BeanContext peer) {
+ super(peer);
initialize();
}
@@ -91,7 +91,7 @@
* by the beanName parameter is not found
*/
public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException {
- BeanContextChild bcc = getBCCDelegate();
+ BeanContextChild bcc = getPeer();
return Beans.instantiate(bcc.getClass().getClassLoader(), beanName, (BeanContext) bcc);
}
@@ -210,6 +210,7 @@
* Returns an iterator over the elements in this collection. The
* iterator's collection is non-modifiable and element does not
* correspond to the order that children are added.
+ *
* @return an <tt>Iterator</tt> over the children of this BeanContext
*/
public Iterator iterator() {
@@ -255,63 +256,7 @@
* it from being added to this collection.
*/
public boolean add(Object o) {
-
- if (contains(o)) return false;
-
- // todo: for multithreaded usage this block needs to be synchronized
- // spec: if the object being added implements BeanContextChild or BeanContextProxy
- // need to set the bean context of the object to this bean context.
- BeanContextChild bcc = null;
- BeanContextProxy bcp = null;
-
- if (o instanceof BeanContextProxy) {
- if (o instanceof BeanContext) {
- throw new IllegalArgumentException("May not implement both BeanContextProxy and BeanContext!!");
- }
- bcp = (BeanContextProxy) o;
- bcc = bcp.getBeanContextProxy();
- }
- else if (o instanceof BeanContextChild) {
- bcc = (BeanContextChild) o;
- }
-
- if (bcc != null) {
- try {
- bcc.setBeanContext(this);
- }
- catch (PropertyVetoException e) {
- throw new IllegalStateException(e);
- }
-
- bcc.addPropertyChangeListener("beanContext", this);
- bcc.addVetoableChangeListener("beanContext", this);
- }
-
- if (o instanceof Visibility) {
- if (_mayUseGui) {
- ((Visibility) o).okToUseGui();
- }
- else {
- ((Visibility) o).dontUseGui();
- }
- }
-
- if (o instanceof BeanContextMembershipListener) {
- addBeanContextMembershipListener((BeanContextMembershipListener) o);
- }
-
- if (bcp == null) {
- _children.put(o, new BCChild(o));
- }
- else {
- _children.put(bcp, new BCChild(bcp, bcc, true));
- _children.put(bcc, new BCChild(bcp, bcc, false));
- }
-
- BeanContextMembershipEvent bcme = new BeanContextMembershipEvent(this, new Object[]{o});
- fireMembershipEvent(bcme, true);
-// }
- return true;
+ return interalAdd(o, true);
}
/**
@@ -454,7 +399,7 @@
* order to get its work done.
*/
public boolean needsGui() {
- BeanContextChild bcc = getBCCDelegate();
+ BeanContextChild bcc = getPeer();
if (bcc != this && bcc instanceof Visibility) {
return ((Visibility) bcc).needsGui();
}
@@ -519,7 +464,7 @@
public void propertyChange(PropertyChangeEvent evt) {
// monitor "beanContext" property
if ("beanContext".equals(evt.getPropertyName()) && contains(evt.getSource())) {
- BeanContext bc = (BeanContext) getBCCDelegate();
+ BeanContext bc = (BeanContext) getPeer();
if (bc.equals(evt.getOldValue()) && !bc.equals(evt.getNewValue())) {
internalRemove(evt.getSource(), false);
}
@@ -575,6 +520,78 @@
}
/**
+ * The interalAdd method is used in two different cases. If an add is done
+ * through the public add() api, this method is invoked with the publicApi
+ * parameter set to true. During deserialization of children this method
+ * is invoked with publicApi set to false. During deserialization it is
+ * not necessary to set Visibility features or re-register as a listener.
+ *
+ * @param o
+ * @param publicApi
+ * @return true if added.
+ */
+ private boolean interalAdd(Object o, boolean publicApi) {
+
+ if (contains(o)) return false;
+
+ // todo: for multithreaded usage this block needs to be synchronized
+ // spec: if the object being added implements BeanContextChild or BeanContextProxy
+ // need to set the bean context of the object to this bean context.
+ BeanContextChild bcc = null;
+ BeanContextProxy bcp = null;
+
+ if (o instanceof BeanContextProxy) {
+ if (o instanceof BeanContext) {
+ throw new IllegalArgumentException("May not implement both BeanContextProxy and BeanContext!!");
+ }
+ bcp = (BeanContextProxy) o;
+ bcc = bcp.getBeanContextProxy();
+ }
+ else if (o instanceof BeanContextChild) {
+ bcc = (BeanContextChild) o;
+ }
+
+ if (bcc != null) {
+ try {
+ bcc.setBeanContext((BeanContext) getPeer());
+ }
+ catch (PropertyVetoException e) {
+ throw new IllegalStateException(e);
+ }
+
+ bcc.addPropertyChangeListener("beanContext", this);
+ bcc.addVetoableChangeListener("beanContext", this);
+ }
+
+ if (publicApi) {
+ if (o instanceof Visibility) {
+ if (_mayUseGui) {
+ ((Visibility) o).okToUseGui();
+ }
+ else {
+ ((Visibility) o).dontUseGui();
+ }
+ }
+ if (o instanceof BeanContextMembershipListener) {
+ addBeanContextMembershipListener((BeanContextMembershipListener) o);
+ }
+ }
+
+ if (bcp == null) {
+ _children.put(o, new BCChild(o));
+ }
+ else {
+ _children.put(bcp, new BCChild(bcp, bcc, true));
+ _children.put(bcc, new BCChild(bcp, bcc, false));
+ }
+
+ BeanContextMembershipEvent bcme = new BeanContextMembershipEvent((BeanContext)getPeer(), new Object[]{o});
+ fireMembershipEvent(bcme, true);
+// }
+ return true;
+ }
+
+ /**
* There are two ways a object can be removed from a BeanContext, by either explicitly invoking the
* remove() api or if the child implements BeanContextChild by calling its setBeanContext() api.
*
@@ -588,10 +605,8 @@
// todo: for multithreaded usage this block needs to be synchronized
BeanContextChild bcc = null;
- BeanContextProxy bcp = null;
if (o instanceof BeanContextProxy) {
- bcp = (BeanContextProxy) o;
- bcc = bcp.getBeanContextProxy();
+ bcc = ((BeanContextProxy) o).getBeanContextProxy();
}
else if (o instanceof BeanContextChild) {
bcc = (BeanContextChild) o;
@@ -637,7 +652,7 @@
}
_children.remove(o);
- BeanContextMembershipEvent bcme = new BeanContextMembershipEvent(this, new Object[]{o});
+ BeanContextMembershipEvent bcme = new BeanContextMembershipEvent((BeanContext)getPeer(), new Object[]{o});
fireMembershipEvent(bcme, false);
// end synchronized block
return true;
@@ -656,8 +671,8 @@
int serializable = 0;
out.defaultWriteObject();
- // spec: only write children if not using a delegate
- if (this.equals(getBCCDelegate())) {
+ // spec: only write children if not using a peer
+ if (this.equals(getPeer())) {
Set<Map.Entry<Object, BCChild>> bcChildren = _children.entrySet();
for (Map.Entry<Object, BCChild> entry : bcChildren) {
@@ -708,9 +723,12 @@
in.defaultReadObject();
initialize();
- int childCount = in.readInt();
- for (int i = 0; i < childCount; i++) {
- add(in.readObject());
+ // only deserialize child if not using a peer
+ if (this.equals(getPeer())) {
+ int childCount = in.readInt();
+ for (int i = 0; i < childCount; i++) {
+ interalAdd(in.readObject(), false);
+ }
}
int listenerCount = in.readInt();
Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java?rev=397664&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java Thu Apr 27 15:48:35 2006
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.test.controls.beancontext;
+
+import java.beans.beancontext.BeanContextChild;
+import java.beans.beancontext.BeanContext;
+import java.beans.beancontext.BeanContextMembershipListener;
+import java.beans.PropertyVetoException;
+import java.beans.PropertyChangeListener;
+import java.beans.VetoableChangeListener;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Collection;
+
+/**
+ */
+public class BeanContextPeer implements BeanContext, Serializable {
+
+ private String _message;
+
+ public String getMessage() { return _message; }
+ public void setMessage(String message) { _message = message; }
+
+ public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public InputStream getResourceAsStream(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public URL getResource(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setBeanContext(BeanContext bc) throws PropertyVetoException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public BeanContext getBeanContext() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int size() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isEmpty() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean contains(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Iterator iterator() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object[] toArray() {
+ return new Object[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean add(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean remove(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean addAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void clear() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean retainAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean removeAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean containsAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object[] toArray(Object[] a) {
+ return new Object[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDesignTime(boolean designTime) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isDesignTime() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean needsGui() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void dontUseGui() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void okToUseGui() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean avoidingGui() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontext/BeanContextPeer.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java (from r397621, beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanDelegate.java)
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java?p2=beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java&p1=beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanDelegate.java&r1=397621&r2=397664&rev=397664&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanDelegate.java (original)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java Thu Apr 27 15:48:35 2006
@@ -23,6 +23,7 @@
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
+import java.io.Serializable;
/**
* Created by IntelliJ IDEA.
@@ -31,92 +32,33 @@
* Time: 9:20:54 AM
* To change this template use File | Settings | File Templates.
*/
-public class BeanDelegate implements BeanContextChild {
+public class BeanChildPeer implements BeanContextChild, Serializable {
private String _message;
public String getMessage() { return _message; }
public void setMessage(String message) { _message = message; }
- /**
- * <p/>
- * Objects that implement this interface,
- * shall fire a java.beans.PropertyChangeEvent, with parameters:
- * <p/>
- * propertyName "beanContext", oldValue (the previous nesting
- * <code>BeanContext</code> instance, or <code>null</code>),
- * newValue (the current nesting
- * <code>BeanContext</code> instance, or <code>null</code>).
- * <p/>
- * A change in the value of the nesting BeanContext property of this
- * BeanContextChild may be vetoed by throwing the appropriate exception.
- * </p>
- *
- * @param bc The <code>BeanContext</code> with which
- * to associate this <code>BeanContextChild</code>.
- * @throws PropertyVetoException if the addition of the specified <code>BeanContext</code> is refused.
- */
public void setBeanContext(BeanContext bc) throws PropertyVetoException {
//To change body of implemented methods use File | Settings | File Templates.
}
- /**
- * Gets the <code>BeanContext</code> associated
- * with this <code>BeanContextChild</code>.
- *
- * @return the <code>BeanContext</code> associated
- * with this <code>BeanContextChild</code>.
- */
public BeanContext getBeanContext() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
- /**
- * Adds a <code>PropertyChangeListener</code>
- * to this <code>BeanContextChild</code>
- * in order to receive a <code>PropertyChangeEvent</code>
- * whenever the specified property has changed.
- *
- * @param name the name of the property to listen on
- * @param pcl the <code>PropertyChangeListener</code> to add
- */
public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
//To change body of implemented methods use File | Settings | File Templates.
}
- /**
- * Removes a <code>PropertyChangeListener</code> from this
- * <code>BeanContextChild</code> so that it no longer
- * receives <code>PropertyChangeEvents</code> when the
- * specified property is changed.
- *
- * @param name the name of the property that was listened on
- * @param pcl the <code>PropertyChangeListener</code> to remove
- */
public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
//To change body of implemented methods use File | Settings | File Templates.
}
- /**
- * Adds a <code>VetoableChangeListener</code> to
- * this <code>BeanContextChild</code>
- * to receive events whenever the specified property changes.
- *
- * @param name the name of the property to listen on
- * @param vcl the <code>VetoableChangeListener</code> to add
- */
public void addVetoableChangeListener(String name, VetoableChangeListener vcl) {
//To change body of implemented methods use File | Settings | File Templates.
}
- /**
- * Removes a <code>VetoableChangeListener</code> from this
- * <code>BeanContextChild</code> so that it no longer receives
- * events when the specified property changes.
- *
- * @param name the name of the property that was listened on.
- * @param vcl the <code>VetoableChangeListener</code> to remove.
- */
public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) {
//To change body of implemented methods use File | Settings | File Templates.
}
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextchild/BeanChildPeer.java
------------------------------------------------------------------------------
svn:executable = *
Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java?rev=397664&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java Thu Apr 27 15:48:35 2006
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.test.controls.beancontextservices;
+
+import java.beans.beancontext.BeanContextChild;
+import java.beans.beancontext.BeanContext;
+import java.beans.beancontext.BeanContextServices;
+import java.beans.beancontext.BeanContextServiceProvider;
+import java.beans.beancontext.BeanContextServiceRevokedListener;
+import java.beans.beancontext.BeanContextServicesListener;
+import java.beans.beancontext.BeanContextMembershipListener;
+import java.beans.beancontext.BeanContextServiceAvailableEvent;
+import java.beans.beancontext.BeanContextServiceRevokedEvent;
+import java.beans.PropertyVetoException;
+import java.beans.PropertyChangeListener;
+import java.beans.VetoableChangeListener;
+import java.util.TooManyListenersException;
+import java.util.Iterator;
+import java.util.Collection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: cschoett
+ * Date: Apr 13, 2006
+ * Time: 9:20:54 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ServicesBeanPeer implements BeanContextServices {
+
+ private String _message;
+
+ public String getMessage() { return _message; }
+ public void setMessage(String message) { _message = message; }
+
+ public boolean addService(Class serviceClass, BeanContextServiceProvider serviceProvider) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean hasService(Class serviceClass) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void releaseService(BeanContextChild child, Object requestor, Object service) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Iterator getCurrentServiceClasses() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Iterator getCurrentServiceSelectors(Class serviceClass) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addBeanContextServicesListener(BeanContextServicesListener bcsl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeBeanContextServicesListener(BeanContextServicesListener bcsl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public InputStream getResourceAsStream(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public URL getResource(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setBeanContext(BeanContext bc) throws PropertyVetoException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public BeanContext getBeanContext() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int size() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isEmpty() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean contains(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Iterator iterator() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object[] toArray() {
+ return new Object[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean add(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean remove(Object o) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean addAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void clear() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean retainAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean removeAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean containsAll(Collection c) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object[] toArray(Object[] a) {
+ return new Object[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDesignTime(boolean designTime) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isDesignTime() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean needsGui() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void dontUseGui() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void okToUseGui() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean avoidingGui() {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/beancontextservices/ServicesBeanPeer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextChildSupportTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextChildSupportTest.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextChildSupportTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextChildSupportTest.java Thu Apr 27 15:48:35 2006
@@ -18,7 +18,7 @@
package org.apache.beehive.controls.test.junit;
-import org.apache.beehive.controls.test.controls.beancontextchild.BeanDelegate;
+import org.apache.beehive.controls.test.controls.beancontextchild.BeanChildPeer;
import org.apache.beehive.controls.test.controls.beancontextchild.DummyBeanContext;
import org.apache.beehive.controls.test.controls.beancontextchild.ChangeListener;
import org.apache.beehive.controls.test.controls.beancontextchild.AlwaysVetoListener;
@@ -26,11 +26,11 @@
import junit.framework.TestCase;
import java.beans.beancontext.BeanContext;
-import java.beans.beancontext.BeanContextChildSupport;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeEvent;
/**
+ * Junit tests for the ControlBeanContextChildSupport class.
*/
public class ControlBeanContextChildSupportTest extends TestCase {
@@ -43,11 +43,11 @@
}
/**
- * Create a new ControlBeanContextChildSupport instance with a bean delegate.
+ * Create a new ControlBeanContextChildSupport instance with a bean context child peer.
*/
- public void testCreateWithDelegate() {
- ControlBeanContextChildSupport _cbcChildSupport = new ControlBeanContextChildSupport(new BeanDelegate());
- assertNotNull(_cbcChildSupport);
+ public void testCreateWithPeer() {
+ ControlBeanContextChildSupport cbcChildSupport = new ControlBeanContextChildSupport(new BeanChildPeer());
+ assertNotNull(cbcChildSupport);
}
/**
@@ -55,18 +55,46 @@
* the bean context with no listeners registered.
*/
public void testSetBeanContext_NoListeners() {
- ControlBeanContextChildSupport _cbcChildSupport = getContext();
- assertNotNull(_cbcChildSupport);
+ ControlBeanContextChildSupport cbcChildSupport = getContext();
+ assertNotNull(cbcChildSupport);
+
+ BeanContext bc = new DummyBeanContext();
+
+ try {
+ cbcChildSupport.setBeanContext(bc);
+ } catch (PropertyVetoException pve) {
+ fail("Unexpected PropertyVetoException:" + pve.toString());
+ }
+
+ assertEquals(bc, cbcChildSupport.getBeanContext());
+ }
+
+ /**
+ * Test setting a bean context on a child which has a peer defined.
+ * The main difference here is that the peer should be set as the
+ * event source for any PropertyChangeEvents/VetoableChangeEvents thrown.
+ */
+ public void testSetBeanContext_PropertyChangeListener_Peer() {
+ BeanChildPeer bcp = new BeanChildPeer();
+ ControlBeanContextChildSupport cbcChildSupport = new ControlBeanContextChildSupport(bcp);
+ ChangeListener cl1 = new ChangeListener();
+ cbcChildSupport.addPropertyChangeListener("beanContext", cl1);
BeanContext bc = new DummyBeanContext();
+ // change beancontext value from null to bc
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
fail("Unexpected PropertyVetoException:" + pve.toString());
}
- assertEquals(bc, _cbcChildSupport.getBeanContext());
+ PropertyChangeEvent[] evts1 = cl1.getEvents();
+ assertEquals(1, evts1.length);
+ assertNull(evts1[0].getOldValue());
+ assertEquals(bc, evts1[0].getNewValue());
+ assertEquals("beanContext", evts1[0].getPropertyName());
+ assertEquals(bcp, evts1[0].getSource());
}
/**
@@ -76,19 +104,19 @@
* generated (noop).
*/
public void testSetBeanContext_PropertyChangeListeners() {
- ControlBeanContextChildSupport _cbcChildSupport = getContext();
- assertNotNull(_cbcChildSupport);
+ ControlBeanContextChildSupport cbcChildSupport = getContext();
+ assertNotNull(cbcChildSupport);
ChangeListener cl1 = new ChangeListener();
ChangeListener cl2 = new ChangeListener();
- _cbcChildSupport.addPropertyChangeListener("beanContext", cl1);
- _cbcChildSupport.addPropertyChangeListener("beanContext", cl2);
+ cbcChildSupport.addPropertyChangeListener("beanContext", cl1);
+ cbcChildSupport.addPropertyChangeListener("beanContext", cl2);
BeanContext bc = new DummyBeanContext();
// change beancontext value from null to bc
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
fail("Unexpected PropertyVetoException:" + pve.toString());
}
@@ -98,12 +126,14 @@
assertNull(evts1[0].getOldValue());
assertEquals(bc, evts1[0].getNewValue());
assertEquals("beanContext", evts1[0].getPropertyName());
+ assertEquals(cbcChildSupport, evts1[0].getSource());
PropertyChangeEvent[] evts2 = cl2.getEvents();
assertEquals(1, evts2.length);
- assertNull(evts1[0].getOldValue());
- assertEquals(bc, evts1[0].getNewValue());
- assertEquals("beanContext", evts1[0].getPropertyName());
+ assertNull(evts2[0].getOldValue());
+ assertEquals(bc, evts2[0].getNewValue());
+ assertEquals("beanContext", evts2[0].getPropertyName());
+ assertEquals(cbcChildSupport, evts2[0].getSource());
// this should be a noop event-wise, setBeanContext just returns
@@ -111,7 +141,7 @@
cl1.reset();
cl2.reset();
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
fail("Unexpected PropertyVetoException:" + pve.toString());
}
@@ -121,26 +151,26 @@
evts2 = cl2.getEvents();
assertEquals(0, evts2.length);
- _cbcChildSupport.removePropertyChangeListener("beanContext", cl1);
- _cbcChildSupport.removePropertyChangeListener("beanContext", cl2);
+ cbcChildSupport.removePropertyChangeListener("beanContext", cl1);
+ cbcChildSupport.removePropertyChangeListener("beanContext", cl2);
}
/**
* Test a veto of setting the bean context.
*/
public void testSetBeanContext_VetoListeners() {
- ControlBeanContextChildSupport _cbcChildSupport = getContext();
- assertNotNull(_cbcChildSupport);
+ ControlBeanContextChildSupport cbcChildSupport = getContext();
+ assertNotNull(cbcChildSupport);
ChangeListener cl = new ChangeListener();
AlwaysVetoListener avl = new AlwaysVetoListener();
- _cbcChildSupport.addPropertyChangeListener("beanContext", cl);
- _cbcChildSupport.addVetoableChangeListener("beanContext", avl);
+ cbcChildSupport.addPropertyChangeListener("beanContext", cl);
+ cbcChildSupport.addVetoableChangeListener("beanContext", avl);
BeanContext bc = new DummyBeanContext();
// change beancontext value from null to bc
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
assertEquals("beanContext", pve.getPropertyChangeEvent().getPropertyName());
assertEquals(bc, pve.getPropertyChangeEvent().getNewValue());
@@ -160,17 +190,17 @@
* this is enforced by the setBeanContext() method of the CBCCS.
*/
public void testSetBeanContext_VetoOverride() {
- ControlBeanContextChildSupport _cbcChildSupport = getContext();
+ ControlBeanContextChildSupport cbcChildSupport = getContext();
boolean caughtVeto = false;
- assertNotNull(_cbcChildSupport);
+ assertNotNull(cbcChildSupport);
AlwaysVetoListener avl = new AlwaysVetoListener();
- _cbcChildSupport.addVetoableChangeListener("beanContext", avl);
+ cbcChildSupport.addVetoableChangeListener("beanContext", avl);
BeanContext bc = new DummyBeanContext();
// change beancontext value from null to bc
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
assertEquals("beanContext", pve.getPropertyChangeEvent().getPropertyName());
assertEquals(bc, pve.getPropertyChangeEvent().getNewValue());
@@ -182,14 +212,17 @@
// try again this should force override of veto
try {
- _cbcChildSupport.setBeanContext(bc);
+ cbcChildSupport.setBeanContext(bc);
} catch (PropertyVetoException pve) {
fail("Unexpected PropertyVetoException:" + pve.toString());
}
- assertEquals(bc, _cbcChildSupport.getBeanContext());
+ assertEquals(bc, cbcChildSupport.getBeanContext());
}
-
+
+ /**
+ * Abstracts the type of BeanContextSupport object being created.
+ */
protected ControlBeanContextChildSupport getContext() {
return new ControlBeanContextChildSupport();
}
Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextServicesSupportTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextServicesSupportTest.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextServicesSupportTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextServicesSupportTest.java Thu Apr 27 15:48:35 2006
@@ -33,7 +33,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.beehive.controls.runtime.bean.webcontext.ControlBeanContextServicesSupport;
-import org.apache.beehive.controls.test.controls.beancontextchild.BeanDelegate;
import org.apache.beehive.controls.test.controls.beancontextservices.BCChild;
import org.apache.beehive.controls.test.controls.beancontextservices.BCChildNoServiceRelease;
import org.apache.beehive.controls.test.controls.beancontextservices.ServiceListener;
@@ -42,6 +41,7 @@
import org.apache.beehive.controls.test.controls.beancontextservices.TestNonSerializableBCServiceProviderImpl;
import org.apache.beehive.controls.test.controls.beancontextservices.TestNonSerializableService;
import org.apache.beehive.controls.test.controls.beancontextservices.NonSerializableServiceListener;
+import org.apache.beehive.controls.test.controls.beancontextservices.ServicesBeanPeer;
/**
*/
@@ -59,7 +59,8 @@
* Create a new ControlBeanContextServicesSupport instance with a bean delegate.
*/
public void testCreateCBCSSWithDelegate() {
- ControlBeanContextServicesSupport _cbcsSupport = new ControlBeanContextServicesSupport(new BeanDelegate());
+ ControlBeanContextServicesSupport _cbcsSupport =
+ new ControlBeanContextServicesSupport(new ServicesBeanPeer());
assertNotNull(_cbcsSupport);
}
@@ -104,6 +105,25 @@
}
/**
+ * Add a service to a beancontextservices which has a peer, verify the event source is the peer.
+ */
+ public void testAddServiceWithListener_Peer() {
+ ServicesBeanPeer sbp = new ServicesBeanPeer();
+ ControlBeanContextServicesSupport cbcss = new ControlBeanContextServicesSupport(sbp);
+ ServiceListener sl = new ServiceListener();
+ cbcss.addBeanContextServicesListener(sl);
+
+ TestBCServiceProviderImpl sp = new TestBCServiceProviderImpl();
+ assertTrue(cbcss.addService(TestService.class, sp));
+
+ EventObject[] evts = sl.getEvents();
+ assertEquals(1, evts.length);
+ assertTrue(evts[0] instanceof BeanContextServiceAvailableEvent);
+ assertTrue(((BeanContextServiceAvailableEvent) evts[0]).getServiceClass().equals(TestService.class));
+ assertEquals(sbp, evts[0].getSource());
+ }
+
+ /**
* Verify that a services listener can be removed.
*/
public void testRemoveServiceListenerTest() {
@@ -144,6 +164,30 @@
}
/**
+ * Test the revocation of a service when the when the cbcss has a peer.
+ */
+ public void testRevokeService_NoReferences_Peer() {
+ ServicesBeanPeer sbp = new ServicesBeanPeer();
+ ControlBeanContextServicesSupport cbcss = new ControlBeanContextServicesSupport(sbp);
+
+ TestBCServiceProviderImpl service1 = new TestBCServiceProviderImpl();
+ assertTrue(cbcss.addService(TestService.class, service1));
+
+ ServiceListener sl = new ServiceListener();
+ cbcss.addBeanContextServicesListener(sl);
+ cbcss.revokeService(TestService.class, service1, false);
+
+ // verify that the service was removed and that the Revoked event was fired and looks correct.
+ assertFalse(cbcss.hasService(TestService.class));
+
+ EventObject[] evts = sl.getEvents();
+ assertEquals(1, evts.length);
+ assertTrue(evts[0] instanceof BeanContextServiceRevokedEvent);
+ assertTrue(((BeanContextServiceRevokedEvent) evts[0]).getSourceAsBeanContextServices().equals(sbp));
+ assertFalse(((BeanContextServiceRevokedEvent) evts[0]).isCurrentServiceInvalidNow());
+ }
+
+ /**
* Test the immediate revocation of a service which has no references to it.
*/
public void testRevokeServiceNOW_NoReferences() {
@@ -476,7 +520,7 @@
assertEquals(0, service1.getRefCount());
assertTrue(cbcss.hasService(TestService.class));
}
-
+
/**
* Test reparenting a cbcss which is a service provider to a child that
* has a reference to the service. The expected behavior here is that
Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextSupportTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextSupportTest.java?rev=397664&r1=397663&r2=397664&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextSupportTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/ControlBeanContextSupportTest.java Thu Apr 27 15:48:35 2006
@@ -39,8 +39,8 @@
import org.apache.beehive.controls.test.controls.beancontext.BeanContextProxyImpl;
import org.apache.beehive.controls.test.controls.beancontext.MembershipListener;
import org.apache.beehive.controls.test.controls.beancontext.VisibilityImpl;
+import org.apache.beehive.controls.test.controls.beancontext.BeanContextPeer;
import org.apache.beehive.controls.test.controls.beancontextchild.AlwaysVetoListener;
-import org.apache.beehive.controls.test.controls.beancontextchild.BeanDelegate;
import org.apache.beehive.controls.test.controls.beancontextchild.ChangeListener;
/**
@@ -60,7 +60,7 @@
* Create a new ControlBeanContextChildSupport instance with a bean delegate.
*/
public void testCreateWithDelegate() {
- ControlBeanContextSupport _cbcSupport = new ControlBeanContextSupport(new BeanDelegate());
+ ControlBeanContextSupport _cbcSupport = new ControlBeanContextSupport(new BeanContextPeer());
assertNotNull(_cbcSupport);
}
@@ -273,6 +273,36 @@
}
/**
+ * Add a single child to a BeanContext which has a peer.
+ */
+ public void testAddSingleChild_Peer() {
+ BeanContextPeer bcp = new BeanContextPeer();
+ ControlBeanContextSupport cbcs = new ControlBeanContextSupport(bcp);
+
+ MembershipListener ml = new MembershipListener();
+ cbcs.addBeanContextMembershipListener(ml);
+
+ ControlBeanContextChildSupport child = new ControlBeanContextChildSupport();
+ assertTrue(cbcs.add(child));
+
+ // verify that....
+
+ // a BeanContextMembershipEvent is fired and the source is the peer ...
+ BeanContextMembershipEvent[] bcme = ml.getEvents();
+ assertEquals(1, bcme.length);
+ assertTrue(bcme[0].contains(child));
+ assertEquals(bcp, bcme[0].getSource());
+
+ // the nested context of the child is the peer
+ assertEquals(bcp, child.getBeanContext());
+
+ // that the child was added to the collection
+ Object[] children = cbcs.toArray();
+ assertEquals(1, children.length);
+ assertEquals(child, children[0]);
+ }
+
+ /**
* Add a child which implements the BeanContextProxy interface.
*/
public void testAddProxyChild() {
@@ -474,7 +504,54 @@
assertNull(pce[0].getNewValue());
assertEquals(cbcs, pce[0].getOldValue());
- // that the child was added to the collection
+ // that the child was removed from the collection
+ Object[] children = cbcs.toArray();
+ assertEquals(0, children.length);
+ }
+
+ /**
+ * Test an implicit remove of a child from a BeanContext which has a peer.
+ */
+ public void testImplicitRemoveSingleChild_Peer() {
+ BeanContextPeer bcp = new BeanContextPeer();
+ ControlBeanContextSupport cbcs = new ControlBeanContextSupport(bcp);
+ ControlBeanContextChildSupport child = new ControlBeanContextChildSupport();
+
+ // add the child
+ assertTrue(cbcs.add(child));
+
+ // setup listeners
+ ChangeListener cl = new ChangeListener();
+ child.addPropertyChangeListener("beanContext", cl);
+
+ MembershipListener ml = new MembershipListener();
+ cbcs.addBeanContextMembershipListener(ml);
+
+ // set the child's bean context (implicitly remove from cbcs)
+ try {
+ child.setBeanContext(null);
+ }
+ catch (PropertyVetoException pve) {
+ fail("Unexpected PropertyVetoException!!!");
+ }
+
+ // verify that....
+
+ // a BeanContextMembershipEvent is fired...
+ BeanContextMembershipEvent[] bcme = ml.getEvents();
+ assertEquals(1, bcme.length);
+ assertTrue(bcme[0].contains(child));
+ assertEquals(bcp, bcme[0].getSource());
+
+ // the child recieved a PropertyChangeEvent that is parent was changed
+ PropertyChangeEvent[] pce = cl.getEvents();
+ assertEquals(1, pce.length);
+ assertEquals("beanContext", pce[0].getPropertyName());
+ assertNull(pce[0].getNewValue());
+ assertEquals(bcp, pce[0].getOldValue());
+ assertEquals(child, pce[0].getSource());
+
+ // that the child was removed from the collection
Object[] children = cbcs.toArray();
assertEquals(0, children.length);
}
@@ -713,6 +790,25 @@
assertFalse(cbcs.isEmpty());
assertEquals(2, cbcs.size());
+ }
+
+ /**
+ * Serailize BC which has Peer and two child, children should NOT be serialized.
+ */
+ public void testSerializationWithChildren_Peer() throws IOException, ClassNotFoundException {
+ BeanContextPeer bcp = new BeanContextPeer();
+ ControlBeanContextSupport cbcs = new ControlBeanContextSupport(bcp);
+ ControlBeanContextChildSupport child1 = new ControlBeanContextChildSupport();
+ ControlBeanContextChildSupport child2 = new ControlBeanContextChildSupport();
+
+ assertTrue(cbcs.add(child1));
+ assertTrue(cbcs.add(child2));
+
+ File serFile = serializeCBCS(cbcs, "cbcs_2p");
+ cbcs = deserializeCBCS(serFile);
+
+ // when peer is present children should not be serialized.
+ assertTrue(cbcs.isEmpty());
}
/**