tapestry-dev mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=917697&view=rev
Log:
tap5-1035: Use UnknownValueException inside PersistentFieldManager and NullFieldStrategySource

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImpl.java?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImpl.java
Mon Mar  1 20:29:06 2010
@@ -1,4 +1,4 @@
-// Copyright  2008 The Apache Software Foundation
+// Copyright 2008, 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.
@@ -15,6 +15,8 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.NullFieldStrategy;
+import org.apache.tapestry5.ioc.internal.util.AvailableValues;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
 import org.apache.tapestry5.services.NullFieldStrategySource;
 
 import java.util.Map;
@@ -33,8 +35,9 @@
         NullFieldStrategy result = configuration.get(name);
 
         if (result != null) return result;
+        
+        throw new UnknownValueException(String.format("Unrecognized name '%s' locating a
null field strategy.", name),
+                new AvailableValues("null field strategies", configuration));
 
-        throw new IllegalArgumentException(
-                ServicesMessages.unknownNullFieldStrategyName(name, configuration.keySet()));
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImpl.java?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImpl.java
Mon Mar  1 20:29:06 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,
@@ -16,8 +16,10 @@
 
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.internal.util.AvailableValues;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
 import org.apache.tapestry5.model.ComponentModel;
 import org.apache.tapestry5.services.MetaDataLocator;
 import org.apache.tapestry5.services.PersistentFieldBundle;
@@ -33,8 +35,7 @@
 
     private final Map<String, PersistentFieldStrategy> strategies;
 
-    public PersistentFieldManagerImpl(MetaDataLocator locator,
-                                      Map<String, PersistentFieldStrategy> strategies)
+    public PersistentFieldManagerImpl(MetaDataLocator locator, Map<String, PersistentFieldStrategy>
strategies)
     {
         metaDataLocator = locator;
 
@@ -46,9 +47,8 @@
         PersistentFieldStrategy result = strategies.get(strategyName);
 
         if (result == null)
-            throw new RuntimeException(ServicesMessages.unknownPersistentFieldStrategy(
-                    strategyName,
-                    strategies.keySet()));
+            throw new UnknownValueException(String.format("'%s' is not a defined persistent
strategy.", strategyName),
+                    new AvailableValues("persistent field strategies", strategies));
 
         return result;
     }
@@ -73,8 +73,7 @@
         }
     }
 
-    public void postChange(String pageName, ComponentResources resources, String fieldName,
-                           Object newValue)
+    public void postChange(String pageName, ComponentResources resources, String fieldName,
Object newValue)
     {
         String strategyName = findStrategy(resources, fieldName);
         PersistentFieldStrategy strategy = getStrategy(strategyName);
@@ -88,7 +87,8 @@
 
         String strategy = model.getFieldPersistenceStrategy(fieldName);
 
-        if (InternalUtils.isNonBlank(strategy)) return strategy;
+        if (InternalUtils.isNonBlank(strategy))
+            return strategy;
 
         return metaDataLocator.findMeta(SymbolConstants.PERSISTENCE_STRATEGY, resources,
String.class);
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
Mon Mar  1 20:29:06 2010
@@ -112,12 +112,6 @@
         return MESSAGES.format("component-event-is-aborted", methodDescription);
     }
 
-    static String unknownPersistentFieldStrategy(String stategyName, Collection<String>
strategyNames)
-    {
-        return MESSAGES.format("unknown-persistent-field-strategy", stategyName, InternalUtils
-                .joinSorted(strategyNames));
-    }
-
     static String parameterNameMustBeUnique(String parameterName, String parameterValue)
     {
         return MESSAGES.format("parameter-name-must-be-unique", parameterName, parameterValue);
@@ -305,11 +299,6 @@
         return MESSAGES.format("page-pool-exausted", pageName, locale.toString(), hardLimit);
     }
 
-    static String unknownNullFieldStrategyName(String name, Collection<String> names)
-    {
-        return MESSAGES.format("unknown-null-field-strategy-name", name, InternalUtils.joinSorted(names));
-    }
-
     public static String noTranslatorForType(Class valueType, Collection<String> typeNames)
     {
         return MESSAGES.format("no-translator-for-type", ClassFabUtils.toJavaClassName(valueType),
InternalUtils

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
Mon Mar  1 20:29:06 2010
@@ -31,7 +31,6 @@
 context-index-out-of-range=Method %s has more parameters than there are context values for
this component event.
 exception-in-method-parameter=Exception in method %s, parameter #%d: %s
 component-event-is-aborted=Can not store result from invoking method %s, because an event
result value has already been obtained from some other event handler method.
-unknown-persistent-field-strategy='%s' is not a defined persistent strategy.  Defined strategies:
%s.
 could-not-canonicalize-page-name=Unable to resolve '%s' to a known page name. Available page
names: %s.
 parameter-name-must-be-unique=Parameter names are required to be unique.  Parameter '%s'
already has the value '%s'.
 page-is-dirty=Page %s is dirty, and will be discarded (rather than returned to the page pool).
@@ -74,7 +73,6 @@
 page-pool-exausted=The page pool for page '%s' (in locale %s) has been exausted: there are
%d instances currently being used and no more can be created. \
   Try increasing the hard limit (symbol tapestry.page-pool.hard-limit) to allow additional
instances to be created, \
   or increasing the soft wait (symbol tapestry.page-pool.soft-wait) to trade away some throughput
for more efficient use of page instances.
-unknown-null-field-strategy-name=Unrecognized name '%s' locating a null field strategy. 
Available strategies: %s.
 no-translator-for-type=No translator is defined for type %s.  Registered types: %s.
 parameter-binding-must-not-be-empty=Parameter '%s' must have a non-empty binding.
 no-such-method=Class %s does not contain a method named '%s()'.

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImplTest.java?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/NullFieldStrategySourceImplTest.java
Mon Mar  1 20:29:06 2010
@@ -1,10 +1,10 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 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,
@@ -17,6 +17,7 @@
 import org.apache.tapestry5.NullFieldStrategy;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
 import org.apache.tapestry5.services.NullFieldStrategySource;
 import org.testng.annotations.Test;
 
@@ -58,10 +59,10 @@
             source.get("wilma");
             unreachable();
         }
-        catch (IllegalArgumentException ex)
+        catch (UnknownValueException ex)
         {
-            assertEquals(ex.getMessage(),
-                         "Unrecognized name 'wilma' locating a null field strategy.  Available
strategies: barney, fred.");
+            assertEquals(ex.getMessage(), "Unrecognized name 'wilma' locating a null field
strategy.");
+            assertListsEquals(ex.getAvailableValues().getValues(), "barney", "fred");
         }
 
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImplTest.java?rev=917697&r1=917696&r2=917697&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PersistentFieldManagerImplTest.java
Mon Mar  1 20:29:06 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 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,
@@ -18,6 +18,8 @@
 import org.apache.tapestry5.PersistenceConstants;
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
+import org.apache.tapestry5.ioc.internal.util.UnknownValueException;
+
 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
 import org.apache.tapestry5.model.ComponentModel;
@@ -59,11 +61,10 @@
             manager.postChange("foo.Bar", resources, fieldName, null);
             unreachable();
         }
-        catch (RuntimeException ex)
+        catch (UnknownValueException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "\'braveheart\' is not a defined persistent strategy.  Defined strategies:
bar, foo.");
+            assertEquals(ex.getMessage(), "'braveheart' is not a defined persistent strategy.");
+            assertListsEquals(ex.getAvailableValues().getValues(), "bar", "foo");
         }
 
         verify();
@@ -219,10 +220,7 @@
 
         train_getFieldPersistenceStrategy(model, fieldName, "");
 
-        train_findMeta(
-                locator,
-                SymbolConstants.PERSISTENCE_STRATEGY,
-                resources, String.class,
+        train_findMeta(locator, SymbolConstants.PERSISTENCE_STRATEGY, resources, String.class,
                 PersistenceConstants.SESSION);
 
         train_getNestedId(resources, nestedId);



Mime
View raw message