Author: knopp
Date: Mon Mar 31 07:20:58 2008
New Revision: 643000

URL: http://svn.apache.org/viewvc?rev=643000&view=rev
Log:
WICKET-1467

Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java?rev=643000&r1=642999&r2=643000&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
 Mon Mar 31 07:20:58 2008
@@ -175,7 +175,7 @@
  * 
  * @author Chris Turner
  */
-public class StringResourceModel extends LoadableDetachableModel
+public class StringResourceModel extends LoadableDetachableModel implements 
IComponentAssignedModel
 {
        private static final long serialVersionUID = 1L;
 
@@ -195,7 +195,7 @@
        private final Object[] parameters;
 
        /** The relative component used for lookups. */
-       private final Component component;
+       private Component component;
 
        /** The key of message to get. */
        private final String resourceKey;
@@ -203,6 +203,48 @@
        /** The default value of the message. */
        private final String defaultValue;
 
+       public IWrapModel wrapOnAssignment(Component component)
+       {
+               return new AssignmentWrapper(component);
+       }
+
+       private class AssignmentWrapper implements IWrapModel
+       {
+               private static final long serialVersionUID = 1L;
+
+               private final Component component;
+
+               public AssignmentWrapper(Component component)
+               {
+                       this.component = component;
+               }
+
+               public void detach()
+               {
+                       StringResourceModel.this.detach();
+               }
+
+               public Object getObject()
+               {
+                       // TODO: Remove this as soon as we can break binary 
compatibility
+                       Component old = StringResourceModel.this.component;
+                       StringResourceModel.this.component = this.component;
+                       Object res = StringResourceModel.this.getObject();
+                       StringResourceModel.this.component = old;
+                       return res;
+               }
+
+               public void setObject(Object object)
+               {
+                       StringResourceModel.this.setObject(object);
+               }
+
+               public IModel getWrappedModel()
+               {
+                       return StringResourceModel.this;
+               }
+       };
+
        /**
         * Construct.
         * 
@@ -305,6 +347,83 @@
                this.parameters = parameters;
                this.defaultValue = defaultValue;
        }
+
+       /**
+        * Construct.
+        * 
+        * @param resourceKey
+        *            The resource key for this string resource
+        * @param model
+        *            The model to use for property substitutions
+        * @see #StringResourceModel(String, Component, IModel, Object[])
+        */
+       public StringResourceModel(final String resourceKey, final IModel model)
+       {
+               this(resourceKey, null, model, null, null);
+       }
+
+       /**
+        * Construct.
+        * 
+        * @param resourceKey
+        *            The resource key for this string resource
+        * @param model
+        *            The model to use for property substitutions
+        * @param defaultValue
+        *            The default value if the resource key is not found.
+        * 
+        * @see #StringResourceModel(String, Component, IModel, Object[])
+        */
+       public StringResourceModel(final String resourceKey, final IModel model,
+               final String defaultValue)
+       {
+               this(resourceKey, null, model, null, defaultValue);
+       }
+
+       /**
+        * Creates a new string resource model using the supplied parameters.
+        * <p>
+        * The model parameter is also optional and only needs to be supplied 
if value substitutions are
+        * to take place on either the resource key or the actual resource 
strings.
+        * <p>
+        * The parameters parameter is also optional and is used for 
substitutions.
+        * 
+        * @param resourceKey
+        *            The resource key for this string resource
+        * @param model
+        *            The model to use for property substitutions
+        * @param parameters
+        *            The parameters to substitute using a Java MessageFormat 
object
+        */
+       public StringResourceModel(final String resourceKey, final IModel model,
+               final Object[] parameters)
+       {
+               this(resourceKey, null, model, parameters, null);
+       }
+
+       /**
+        * Creates a new string resource model using the supplied parameters.
+        * <p>
+        * The model parameter is also optional and only needs to be supplied 
if value substitutions are
+        * to take place on either the resource key or the actual resource 
strings.
+        * <p>
+        * The parameters parameter is also optional and is used for 
substitutions.
+        * 
+        * @param resourceKey
+        *            The resource key for this string resource
+        * @param model
+        *            The model to use for property substitutions
+        * @param parameters
+        *            The parameters to substitute using a Java MessageFormat 
object
+        * @param defaultValue
+        *            The default value if the resource key is not found.
+        */
+       public StringResourceModel(final String resourceKey, final IModel model,
+               final Object[] parameters, final String defaultValue)
+       {
+               this(resourceKey, null, model, parameters, defaultValue);
+       }
+
 
        /**
         * Gets the localizer that is being used by this string resource model.

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java?rev=643000&r1=642999&r2=643000&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
 Mon Mar 31 07:20:58 2008
@@ -196,7 +196,7 @@
         */
        public void testUninitialisedLocalizer()
        {
-               StringResourceModel model = new 
StringResourceModel("simple.text", null, null);
+               StringResourceModel model = new 
StringResourceModel("simple.text", null);
                try
                {
                        model.getString();


Reply via email to