tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r917696 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/beaneditor/ main/java/org/apache/tapestry5/internal/pageload/ main/resources/org/apache/tapestry5/internal/beaneditor/ test/java/org/apache/ta...
Date Mon, 01 Mar 2010 20:29:01 GMT
Author: hlship
Date: Mon Mar  1 20:29:01 2010
New Revision: 917696

URL: http://svn.apache.org/viewvc?rev=917696&view=rev
Log:
TAP5-1034: Use UnknownValueException inside BeanModelSourceImpl

Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanEditorMessages.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/beaneditor/BeanEditorStrings.properties
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/pageload/PageloadMessages.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java?rev=917696&r1=917695&r2=917696&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java
Mon Mar  1 20:29:01 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -24,8 +24,10 @@
 import org.apache.tapestry5.internal.services.CoercingPropertyConduitWrapper;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.ObjectLocator;
+import org.apache.tapestry5.ioc.internal.util.AvailableValues;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.Defense;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.services.PropertyConduitSource;
@@ -48,8 +50,8 @@
 
     private final List<String> propertyNames = CollectionFactory.newList();
 
-    public BeanModelImpl(Class<T> beanType, PropertyConduitSource propertyConduitSource,
-            TypeCoercer typeCoercer, Messages messages, ObjectLocator locator)
+    public BeanModelImpl(Class<T> beanType, PropertyConduitSource propertyConduitSource,
TypeCoercer typeCoercer,
+            Messages messages, ObjectLocator locator)
 
     {
         this.beanType = beanType;
@@ -81,12 +83,13 @@
         Defense.notBlank(propertyName, "propertyName");
 
         if (properties.containsKey(propertyName))
-            throw new RuntimeException(BeanEditorMessages.duplicatePropertyName(beanType,
-                    propertyName));
+            throw new RuntimeException(String.format(
+                    "Bean editor model for %s already contains a property model for property
'%s'.",
+                    beanType.getName(), propertyName));
     }
 
-    public PropertyModel add(RelativePosition position, String existingPropertyName,
-            String propertyName, PropertyConduit conduit)
+    public PropertyModel add(RelativePosition position, String existingPropertyName, String
propertyName,
+            PropertyConduit conduit)
     {
         Defense.notNull(position, "position");
 
@@ -111,8 +114,7 @@
         return newModel;
     }
 
-    public PropertyModel add(RelativePosition position, String existingPropertyName,
-            String propertyName)
+    public PropertyModel add(RelativePosition position, String existingPropertyName, String
propertyName)
     {
         PropertyConduit conduit = createConduit(propertyName);
 
@@ -136,8 +138,7 @@
 
     private CoercingPropertyConduitWrapper createConduit(String propertyName)
     {
-        return new CoercingPropertyConduitWrapper(propertyConduitSource.create(beanType,
-                propertyName), typeCoercer);
+        return new CoercingPropertyConduitWrapper(propertyConduitSource.create(beanType,
propertyName), typeCoercer);
     }
 
     public PropertyModel get(String propertyName)
@@ -145,8 +146,9 @@
         PropertyModel propertyModel = properties.get(propertyName);
 
         if (propertyModel == null)
-            throw new RuntimeException(BeanEditorMessages.unknownProperty(beanType, propertyName,
-                    properties.keySet()));
+            throw new UnknownValueException(String.format(
+                    "Bean editor model for %s does not contain a property named '%s'.", beanType.getName(),
+                    propertyName), new AvailableValues("properties", propertyNames));
 
         return propertyModel;
     }
@@ -169,8 +171,9 @@
             ids.add(model.getId());
         }
 
-        throw new RuntimeException(BeanEditorMessages.unknownPropertyId(beanType, propertyId,
ids));
-
+        throw new UnknownValueException(String.format(
+                "Bean editor model for %s does not contain a property with id '%s'.", beanType.getName(),
propertyId),
+                new AvailableValues("property ids", ids));
     }
 
     public List<String> getPropertyNames()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/pageload/PageloadMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/pageload/PageloadMessages.java?rev=917696&r1=917695&r2=917696&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/pageload/PageloadMessages.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/pageload/PageloadMessages.java
Mon Mar  1 20:29:01 2010
@@ -1,4 +1,4 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2010 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.
@@ -25,7 +25,7 @@
 
 /**
  * Localized exception message support for pageload-related classes.
- * @since 5.2.0.0
+ * @since 5.2.0
  */
 final class PageloadMessages
 {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java?rev=917696&r1=917695&r2=917696&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
Mon Mar  1 20:29:01 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 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
+// 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,
@@ -22,6 +22,7 @@
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.internal.transform.pages.ReadOnlyBean;
 import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
 import org.apache.tapestry5.services.BeanModelSource;
 import org.easymock.EasyMock;
 import org.testng.annotations.BeforeClass;
@@ -64,7 +65,7 @@
         assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
 
         assertEquals(model.toString(),
-                     "BeanModel[org.apache.tapestry5.internal.services.SimpleBean properties:firstName,
lastName, age]");
+                "BeanModel[org.apache.tapestry5.internal.services.SimpleBean properties:firstName,
lastName, age]");
 
         PropertyModel age = model.get("age");
 
@@ -295,8 +296,9 @@
         }
         catch (RuntimeException ex)
         {
-            assertEquals(ex.getMessage(),
-                         "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
already contains a property model for property \'age\'.");
+            assertEquals(
+                    ex.getMessage(),
+                    "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
already contains a property model for property \'age\'.");
         }
 
         verify();
@@ -318,10 +320,13 @@
             model.get("frobozz");
             unreachable();
         }
-        catch (RuntimeException ex)
+        catch (UnknownValueException ex)
         {
-            assertEquals(ex.getMessage(),
-                         "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
does not contain a property named \'frobozz\'.  " + "Available properties: age, firstName,
lastName.");
+            assertEquals(
+                    ex.getMessage(),
+                    "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
does not contain a property named \'frobozz\'.");
+
+            assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName");
         }
 
         verify();
@@ -345,11 +350,13 @@
             model.getById("frobozz");
             unreachable();
         }
-        catch (RuntimeException ex)
+        catch (UnknownValueException ex)
         {
-            assertEquals(ex.getMessage(),
-                         "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
does not contain a property with id \'frobozz\'.  "
-                                 + "Available property ids: age, firstName, lastName, shrubfoo.");
+            assertEquals(
+                    ex.getMessage(),
+                    "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean
does not contain a property with id \'frobozz\'.");
+
+            assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName",
"shrubfoo");
         }
 
         verify();
@@ -460,7 +467,8 @@
 
         assertSame(propertyModel.getPropertyType(), String[].class);
 
-        String[] value = { "foo", "bar" };
+        String[] value =
+        { "foo", "bar" };
 
         StringArrayBean bean = new StringArrayBean();
 



Mime
View raw message