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/03/08 17:36:59 UTC
svn commit: r384259 - in /beehive/trunk/controls:
src/runtime/org/apache/beehive/controls/runtime/generator/
test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/
test/src/junit-tests/org/apache/beehive/controls/test/junit/
Author: cschoett
Date: Wed Mar 8 08:36:57 2006
New Revision: 384259
URL: http://svn.apache.org/viewcvs?rev=384259&view=rev
Log:
Fix for BEEHIVE-1077, if a control interface has a PropertySet which is optional, don't add the property getter to the PropertyDescriptor created by the generated control bean info class.
Also added new unit test for this case.
Added:
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java (with props)
beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java (with props)
Modified:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/PropertyTest.java
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm?rev=384259&r1=384258&r2=384259&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm Wed Mar 8 08:36:57 2006
@@ -204,9 +204,15 @@
#end
#if ($propertySet.hasSetters())
#set ( $setterName = "set${property.accessorName}" )
+ #if ($propertySet.isOptional())
+ pd = new PropertyDescriptor(#localizeString("$property.name"), ${bean.className}.class, null, "$setterName");
+ #else
pd = new PropertyDescriptor(#localizeString("$property.name"), ${bean.className}.class, "$getterName", "$setterName");
+ #end
#else
+ #if (! $propertySet.isOptional())
pd = new PropertyDescriptor(#localizeString("$property.name"), ${bean.className}.class, "$getterName", null );
+ #end
#end
#if ($property.propertyInfo)
pd.setBound($property.propertyInfo.bound());
Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java?rev=384259&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java Wed Mar 8 08:36:57 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.propertiesoptional;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
+import org.apache.beehive.controls.api.packaging.PropertyInfo;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Control interface for testing optional property sets.
+ */
+@ControlInterface
+public interface OptionalPropertySet {
+
+ public String echo(String echo);
+
+ @PropertySet(optional = true)
+ @Target({ElementType.FIELD, ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Optional {
+ public String value() default "optional";
+ }
+
+ @PropertySet(prefix="pre", optional = true, hasSetters = false)
+ @Target({ElementType.FIELD, ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface OptionalNoSetters {
+ public String value() default "optionalNoSetters";
+ }
+}
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java?rev=384259&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java Wed Mar 8 08:36:57 2006
@@ -0,0 +1,40 @@
+/*
+ * 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.propertiesoptional;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+import java.io.Serializable;
+
+/**
+ * Control impl for optional PropertySet unit test.
+ */
+@ControlImplementation()
+public class OptionalPropertySetImpl
+ implements OptionalPropertySet, Serializable {
+
+ @Context
+ private ControlBeanContext _beanContext;
+
+ public String echo(String echo) {
+ return null;
+ }
+}
Propchange: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/propertiesoptional/OptionalPropertySetImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/PropertyTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/PropertyTest.java?rev=384259&r1=384258&r2=384259&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/PropertyTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/PropertyTest.java Wed Mar 8 08:36:57 2006
@@ -19,12 +19,17 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.test.junit.ControlTestCase;
import org.apache.beehive.controls.test.controls.propertiessimple.Property;
import org.apache.beehive.controls.test.controls.propertiessimple.PropertyBean;
+import org.apache.beehive.controls.test.controls.propertiesoptional.OptionalPropertySet;
+import org.apache.beehive.controls.test.controls.propertiesoptional.OptionalPropertySetBean;
/**
*
@@ -36,6 +41,9 @@
@Property.Text(value = "Test value override")
private PropertyBean _propertyControl;
+ @Control
+ private OptionalPropertySetBean _optionalControl;
+
private boolean _eventHandlerCalled = false;
public void testDeclarativePropertyInstantiation() {
@@ -47,7 +55,7 @@
PropertyBean propertyBean = (PropertyBean)property;
- propertyBean.addPropertyChangeListener("value",
+ propertyBean.addPropertyChangeListener("value",
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
_eventHandlerCalled = true;
@@ -58,5 +66,26 @@
propertyBean.setValue("does this work?");
assertEquals("does this work?", propertyBean.getValue());
assertTrue(_eventHandlerCalled); //, "Appears that the event handler wasn't called!");
+ }
+
+ /**
+ * Verify that members of a PropertySet marked optional do not have property descriptors for
+ * their getter methods.
+ *
+ * @throws Exception
+ */
+ public void testOptionalPropertySet() throws Exception {
+ OptionalPropertySet property = (OptionalPropertySet)instantiateControl(OptionalPropertySetBean.class.getName());
+ OptionalPropertySetBean propertyBean = (OptionalPropertySetBean)property;
+ BeanInfo bi = Introspector.getBeanInfo(propertyBean.getClass());
+ PropertyDescriptor[] pds = bi.getPropertyDescriptors();
+
+ // There should not be a PropertyDescriptor for a property set which has optional=true and hasSetters=false
+ // (no getter or setter for property), so there should only be 2 PropertyDescriptors for this control
+ assertEquals(2, pds.length);
+
+ assertEquals("value", pds[1].getName());
+ assertNull(pds[1].getReadMethod());
+ assertNotNull(pds[1].getWriteMethod());
}
}