/*
 * $Id: ResourceModel.java 5791 2006-05-20 00:32:57 +0000 (Sat, 20 May 2006)
 * joco01 $ $Revision$ $Date: 2006-05-20 00:32:57 +0000 (Sat, 20 May
 * 2006) $
 * 
 * ==============================================================================
 * 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 wicket.model;

import wicket.Application;
import wicket.Component;

/**
 * A model that represents a localized resource string. This is a lightweight
 * version of the {@link StringResourceModel}. It lacks parameter
 * substitutions, but is generaly easier to use.
 * 
 * @author Igor Vaynberg (ivaynberg)
 * 
 */
public class ResourceModel extends AbstractReadOnlyModel<String>
		implements
			IAssignmentAware<String>
{
	private static final long serialVersionUID = 1L;

	private String defaultValue;

	private String resourceKey;

	/**
	 * Constructor
	 * 
	 * @param resourceKey
	 *            key of the resource this model represents
	 */
	public ResourceModel(String resourceKey)
	{
		this(resourceKey, null);
	}

	/**
	 * Constructor
	 * 
	 * @param resourceKey
	 *            key of the resource this model represents
	 * @param defaultValue
	 *            value that will be returned if resource does not exist
	 * 
	 */
	public ResourceModel(String resourceKey, String defaultValue)
	{
		this.resourceKey = resourceKey;
		this.defaultValue = defaultValue;
	}

	/**
	 * @see wicket.model.AbstractReadOnlyModel#getObject()
	 */
	@Override
	public String getObject()
	{
		return Application.get().getResourceSettings().getLocalizer().getString(resourceKey, null,
				defaultValue);
	}


	/**
	 * FIXME i dont think component<string> is correct here, what if this model
	 * is used for formcomponent.setlabel(imodel<string>)?
	 *
	 * @see wicket.model.IAssignmentAware#wrapOnAssignment(wicket.Component)
	 */
	public <String> IWrapModel<String> wrapOnAssignment(final Component<String> component)
	{
		return new IWrapModel<String>()
		{
			private static final long serialVersionUID = 1L;

			public IModel getNestedModel()
			{
				return ResourceModel.this;
			}

			public String getObject()
			{
				return (String)Application.get().getResourceSettings().getLocalizer().getString(
						resourceKey, component, defaultValue);
			}

			public void setObject(String object)
			{
			}

			public void detach()
			{
				ResourceModel.this.detach();
			}
		};
	}

}

@@ -1338,16 +1338,103 @@
 ceKey;%0A%0A
+%09private Component component;%0A%0A%09void setComponent(Component c)%0A%09%7B%0A%09%09component = c;%0A%09%7D%0A%0A
 %09/**%0A%09 *
@@ -2159,19 +2159,25 @@
 Key,
- null,%0A%09%09%09%09
+%0A%09%09%09%09%09component, 
 defa
@@ -2201,145 +2201,8 @@
 /**%0A
-%09 * FIXME i dont think component%3Cstring%3E is correct here, what if this model%0A%09 * is used for formcomponent.setlabel(imodel%3Cstring%3E)?%0A%09 *%0A
 %09 * 
@@ -2287,17 +2287,8 @@
 blic
- %3CString%3E
  IWr
@@ -2335,24 +2335,88 @@
 omponent
-%3CString%3E
+ component)%0A%09%7B%0A%09%09return new AssignmentWrapper(resourceKey, defaultValue,
  compone
@@ -2422,51 +2422,121 @@
 ent)
+;
 %0A%09
-%7B%0A%09%09return new IWrapModel%3CString%3E()%0A%09%09%7B%0A%09
+%7D%0A%09%0A%09private class AssignmentWrapper extends ResourceModel implements IWrapModel%3CString%3E %7B%0A%0A%09%09/**%0A%09%09 * %0A%09%09 */%0A
 %09%09pr
@@ -2589,207 +2589,108 @@
 %0A%0A%09%09
-%09
 public 
-IModel getNestedModel()%0A%09%09%09%7B%0A%09%09%09%09return ResourceModel.this;%0A%09%09%09%7D%0A%0A%09%09%09public String getObject()%0A%09%09%09%7B%0A%09%09%09%09return (String)Application.get().getResourceSettings().getLocalizer().getString(%0A%09%09%09%09%09%09
+AssignmentWrapper(String resourceKey, String defaultValue, Component component)%0A%09%09%7B%0A%09%09%09super(
 reso
@@ -2701,19 +2701,8 @@
 Key,
- component,
  def
@@ -2720,95 +2720,97 @@
 %0A%09%09%09
-%7D%0A%0A%09%09%09public void setObject(String object)%0A%09%09%09%7B%0A%09%09%09%7D%0A%0A%09%09%09public void detach
+setComponent(component);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public IModel getNestedModel
 ()%0A%09%09
-%09
 %7B%0A%09%09%09
-%09
+return 
 Reso
@@ -2827,28 +2827,13 @@
 this
-.detach();%0A%09%09%09%7D%0A%09%09%7D;
+;%0A%09%09%7D
 %0A%09%7D%0A

implement cleaner wrapping that keeps type