You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/02/20 00:20:06 UTC
svn commit: r509376 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/beaneditor/
main/java/org/apache/tapestry/internal/services/
test/java/org/apache/tapestry/internal/services/
Author: hlship
Date: Mon Feb 19 15:20:05 2007
New Revision: 509376
URL: http://svn.apache.org/viewvc?view=rev&rev=509376
Log:
Add a NonVisual annotation, to apply to bean properties that should not be presented to the user (typically, this is used for primary keys).
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/NonVisual.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NonVisualBean.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BeanModelSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/NonVisual.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/NonVisual.java?view=auto&rev=509376
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/NonVisual.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/NonVisual.java Mon Feb 19 15:20:05 2007
@@ -0,0 +1,34 @@
+// Copyright 2007 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.
+
+package org.apache.tapestry.beaneditor;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marker annotation for properties which are non-visual, and so should not appear (by default)
+ * inside a {@link BeanModel}. The annotation may be placed on either the getter or the setter
+ * method.
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface NonVisual {
+
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BeanModelSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BeanModelSourceImpl.java?view=diff&rev=509376&r1=509375&r2=509376
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BeanModelSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BeanModelSourceImpl.java Mon Feb 19 15:20:05 2007
@@ -22,6 +22,7 @@
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.beaneditor.BeanModel;
+import org.apache.tapestry.beaneditor.NonVisual;
import org.apache.tapestry.events.InvalidationListener;
import org.apache.tapestry.internal.TapestryUtils;
import org.apache.tapestry.internal.beaneditor.BeanModelImpl;
@@ -47,9 +48,9 @@
private final StrategyRegistry<String> _registry;
- public BeanModelSourceImpl(final TypeCoercer typeCoercer,
- final PropertyAccess propertyAccess, final PropertyConduitSource propertyConduitSource,
- ClassFactory classFactory, Map<Class, String> configuration)
+ public BeanModelSourceImpl(final TypeCoercer typeCoercer, final PropertyAccess propertyAccess,
+ final PropertyConduitSource propertyConduitSource, ClassFactory classFactory,
+ Map<Class, String> configuration)
{
_typeCoercer = typeCoercer;
_propertyAccess = propertyAccess;
@@ -74,8 +75,8 @@
ClassPropertyAdapter adapter = _propertyAccess.getAdapter(beanClass);
- BeanModel model = new BeanModelImpl(beanClass, _propertyConduitSource,
- _typeCoercer, messages);
+ BeanModel model = new BeanModelImpl(beanClass, _propertyConduitSource, _typeCoercer,
+ messages);
List<String> propertyNames = newList();
@@ -84,6 +85,9 @@
PropertyAdapter pa = adapter.getPropertyAdapter(propertyName);
if (!pa.isRead())
+ continue;
+
+ if (pa.getAnnotation(NonVisual.class) != null)
continue;
if (filterReadOnlyProperties && !pa.isUpdate())
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java?view=diff&rev=509376&r1=509375&r2=509376
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java Mon Feb 19 15:20:05 2007
@@ -415,6 +415,23 @@
assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
verify();
+ }
+ @Test
+ public void nonvisual_properties_are_excluded()
+ {
+ ComponentResources resources = newComponentResources();
+ Messages messages = newMessages();
+
+ train_getMessages(resources, messages);
+ stub_contains(messages, false);
+
+ replay();
+
+ BeanModel model = _source.create(NonVisualBean.class, true, resources);
+
+ assertEquals(model.getPropertyNames(), Arrays.asList("name"));
+
+ verify();
}
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NonVisualBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NonVisualBean.java?view=auto&rev=509376
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NonVisualBean.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NonVisualBean.java Mon Feb 19 15:20:05 2007
@@ -0,0 +1,45 @@
+// Copyright 2007 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.
+
+package org.apache.tapestry.internal.services;
+
+import org.apache.tapestry.beaneditor.NonVisual;
+
+public class NonVisualBean
+{
+ private int _id;
+
+ private String _name;
+
+ @NonVisual
+ public int getId()
+ {
+ return _id;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public void setId(int id)
+ {
+ _id = id;
+ }
+
+ public void setName(String name)
+ {
+ _name = name;
+ }
+}