Revision: 1616 http://svn.sourceforge.net/spring-rich-c/?rev=1616&view=rev Author: mathiasbr Date: 2006-12-29 06:36:43 -0800 (Fri, 29 Dec 2006)
Log Message: ----------- refactored FieldFaceSource to allow using any context instance strategy to build up message codes extracted into MessageCodeStrategy Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/AbstractFormModel.java trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/CachingFieldFaceSource.java trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageSourceFieldFaceSource.java Added Paths: ----------- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultMessageCodeStrategy.java trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageCodeStrategy.java trunk/spring-richclient/support/src/test/java/org/springframework/binding/form/support/DefaultMessageCodeStrategyTests.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/AbstractFormModel.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/AbstractFormModel.java 2006-12-28 22:57:45 UTC (rev 1615) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/AbstractFormModel.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -462,7 +462,7 @@ } public FieldFace getFieldFace(String field) { - return getFieldFaceSource().getFieldFace(this, field); + return getFieldFaceSource().getFieldFace(field, this); } public ValueModel addMethod(String propertyMethodName, String derivedFromProperty) { Modified: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/CachingFieldFaceSource.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/CachingFieldFaceSource.java 2006-12-28 22:57:45 UTC (rev 1615) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/CachingFieldFaceSource.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -18,11 +18,8 @@ import java.util.HashMap; import java.util.Map; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.ObjectFactory; import org.springframework.binding.form.FieldFace; import org.springframework.binding.form.FieldFaceSource; -import org.springframework.binding.form.FormModel; import org.springframework.util.Assert; import org.springframework.util.CachingMapDecorator; @@ -30,8 +27,7 @@ * A convenience superclass for FieldFaceSource's that require caching to improve the performance of FieldFace lookup. * * <p> - * FieldFace retrieval is delegated to subclasses using one of the [EMAIL PROTECTED] #loadFieldFace(FormModel, String)}, - * [EMAIL PROTECTED] #loadFieldFace(String, String)} or [EMAIL PROTECTED] #loadFieldFace(String, String, Map)} methods. + * FieldFace retrieval is delegated to subclasses using the [EMAIL PROTECTED] #loadFieldFace(String, Object)} method. * * @author Oliver Hutchison * @author Mathias Broekelmann @@ -41,10 +37,10 @@ private static final Object DEFAULT_CONTEXT = new Object(); /* - * A cache with FormModel keys and Map from formFieldPath to FieldFace values. The keys are held with week - * references so this class will not prevent GC of FormModels. + * A cache with context keys and Map from field to FieldFace values. The keys are held with week references so this + * class will not prevent GC of context instances. */ - private CachingMapDecorator cachedPropertyFaceDescriptors = new CachingMapDecorator(true) { + private final CachingMapDecorator cachedFieldFaceDescriptors = new CachingMapDecorator(true) { public Object create(Object key) { return new HashMap(); } @@ -53,74 +49,30 @@ protected CachingFieldFaceSource() { } - public FieldFace getFieldFace(final FormModel formModel, final String formFieldPath) { - return getFieldFace(formModel, formFieldPath, new ObjectFactory() { - public Object getObject() throws BeansException { - return loadFieldFace(formModel, formFieldPath); - } - }); + public FieldFace getFieldFace(String field) { + return getFieldFace(field, null); } - public FieldFace getFieldFace(final String field, final String contextId) { - return getFieldFace(contextId, field, new ObjectFactory() { - public Object getObject() throws BeansException { - return loadFieldFace(field, contextId); - } - }); - } - - protected FieldFace getFieldFace(Object key, String field, ObjectFactory factory) { - Map faceDescriptors = (Map) cachedPropertyFaceDescriptors.get(key == null ? DEFAULT_CONTEXT : key); + public FieldFace getFieldFace(final String field, final Object context) { + Map faceDescriptors = (Map) cachedFieldFaceDescriptors.get(context == null ? DEFAULT_CONTEXT : context); FieldFace fieldFaceDescriptor = (FieldFace) faceDescriptors.get(field); if (fieldFaceDescriptor == null) { - fieldFaceDescriptor = (FieldFace) factory.getObject(); + fieldFaceDescriptor = loadFieldFace(field, context); Assert.notNull(fieldFaceDescriptor, "FieldFace must not be null."); faceDescriptors.put(field, fieldFaceDescriptor); } return fieldFaceDescriptor; } - public FieldFace getFieldFace(String field, String contextId, Map context) { - if (context == null || context.isEmpty()) { - return getFieldFace(field, contextId); - } - return loadFieldFace(field, contextId, context); - } - /** - * Loads the FieldFace for the given field path and context id. This value will not be cached. - * - * @param field - * the form field path - * @param contextId - * optional context id for which the FieldFace is being resolved - * @param context - * contains context parameters - * @return the FieldFace for the given context id and the context parameters (never null). - */ - protected abstract FieldFace loadFieldFace(String field, String contextId, Map context); - - /** * Loads the FieldFace for the given field path and context id. This value will be cached so performance need not be * a concern of this method. * * @param field * the form field path - * @param contextId - * optional context id for which the FieldFace is being resolved + * @param context + * optional context for which the FieldFace is being resolved * @return the FieldFace for the given context id (never null). */ - protected abstract FieldFace loadFieldFace(String field, String contextId); - - /** - * Loads the FieldFace for the given form model and form property path. This value will be cached so performance - * need not be a concern of this method. - * - * @param formModel - * the form model for which the FieldFace is being resolved - * @param formPropertyPath - * the form property path - * @return the FieldFace for the given form model and form property path (never null). - */ - protected abstract FieldFace loadFieldFace(FormModel formModel, String formPropertyPath); + protected abstract FieldFace loadFieldFace(String field, Object context); } \ No newline at end of file Added: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultMessageCodeStrategy.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultMessageCodeStrategy.java (rev 0) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultMessageCodeStrategy.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -0,0 +1,85 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * 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.springframework.binding.form.support; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.util.StringUtils; + +/** + * Default implementation for [EMAIL PROTECTED] MessageCodeStrategy}. It creates message codes as follows: + * <p> + * <code>{contextId}.{field}.{suffix}</code><br> + * <code>{field}.{suffix}</code> - without a contextId<br> + * <code>{field}</code> - without a contextId and no suffix<br> + * <p> + * If field contains a name which is separated by <code>'.'</code> like <code>'fieldcontext.field'</code>: + * <p> + * <code>{contextId}.fieldcontext.field.{suffix}</code><br> + * <code>{contextId}.field.{suffix}</code><br> + * <code>fieldcontext.field.{suffix}</code> - without a contextId<br> + * <code>field.{suffix}</code> - without a contextId<br> + * <code>fieldcontext.field</code> - without a contextId and no suffix<br> + * <code>field</code> - without a contextId and no suffix<br> + * <p> + * + * @author Mathias Broekelmann + * + */ +public class DefaultMessageCodeStrategy implements MessageCodeStrategy { + + public String[] getMessageCodes(String contextId, String field, String[] suffixes) { + boolean hasContextId = StringUtils.hasText(contextId); + String[] fieldPathElements = StringUtils.delimitedListToStringArray(field, "."); + Collection keys = new ArrayList((hasContextId ? 2 * fieldPathElements.length : fieldPathElements.length) + * (suffixes == null ? 1 : suffixes.length)); + if (hasContextId) { + String prefix = contextId + '.'; + addKeys(keys, prefix, fieldPathElements, suffixes); + } + addKeys(keys, "", fieldPathElements, suffixes); + return (String[]) keys.toArray(new String[keys.size()]); + } + + private void addKeys(Collection keys, String prefix, String[] fieldPathElements, String[] suffix) { + final int size = fieldPathElements.length; + final int suffixSize = suffix == null ? 0 : suffix.length; + for (int i = 0; i < size; i++) { + StringBuffer path = new StringBuffer(prefix); + for (int j = i; j < size; j++) { + path.append(fieldPathElements[j]); + if (j + 1 < size) { + path.append('.'); + } + } + if (suffixSize == 0) { + keys.add(path.toString()); + } else { + for (int j = 0; j < suffixSize; j++) { + String currentSuffix = suffix[j]; + if (StringUtils.hasText(currentSuffix)) { + keys.add(path.toString() + "." + currentSuffix); + } else { + keys.add(path.toString()); + } + + } + } + } + } + +} Property changes on: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultMessageCodeStrategy.java ___________________________________________________________________ Name: svn:keywords + Revision Author Date Id Name: svn:eol-style + native Added: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageCodeStrategy.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageCodeStrategy.java (rev 0) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageCodeStrategy.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * 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.springframework.binding.form.support; + +/** + * MessageKeyStrategy is used by [EMAIL PROTECTED] MessageSourceFieldFaceSource} to create the codes for resolving messages. + * + * @author Mathias Broekelmann + * + */ +public interface MessageCodeStrategy { + + /** + * Creates message codes. + * + * @param contextId + * optional contextId of the field. + * @param field + * the field. The field name + * @param suffixes + * optional array of suffixes. + * @return an array of message codes + */ + String[] getMessageCodes(String contextId, String field, String[] suffixes); + +} Property changes on: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageCodeStrategy.java ___________________________________________________________________ Name: svn:keywords + Revision Author Date Id Name: svn:eol-style + native Modified: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageSourceFieldFaceSource.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageSourceFieldFaceSource.java 2006-12-28 22:57:45 UTC (rev 1615) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/MessageSourceFieldFaceSource.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -15,27 +15,21 @@ */ package org.springframework.binding.form.support; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - import javax.swing.Icon; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.binding.form.FieldFace; import org.springframework.binding.form.FormModel; -import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.context.support.MessageSourceAccessor; +import org.springframework.core.ReflectiveVisitorHelper; import org.springframework.richclient.application.ApplicationServices; import org.springframework.richclient.application.ApplicationServicesLocator; import org.springframework.richclient.factory.LabelInfo; import org.springframework.richclient.factory.LabelInfoFactory; import org.springframework.richclient.image.IconSource; -import org.springframework.util.StringUtils; /** * An implementation of FieldFaceSource that resolves the FieldFace from the <code>MessageSourceAccessor</code> @@ -43,31 +37,10 @@ * provided. * * <p> - * The various properties of the FieldFace are resolved from the message source using message keys in the following - * order: + * The various properties of the FieldFace are resolved from a message source using message codes. These codes where + * generated by a [EMAIL PROTECTED] MessageCodeStrategy}. If no other [EMAIL PROTECTED] MessageCodeStrategy} is defined an instance of + * [EMAIL PROTECTED] DefaultMessageCodeStrategy} will be used * - * <p> - * <code>{formModelId}.{formPropertyPath}.{faceDescriptorProperty}</code><br> - * <code>{formPropertyPath}.{faceDescriptorProperty}</code><br> - * <p> - * Where <code>{formModelId}</code> is the id of the form model, <code>{formPropertyPath}</code> is the form - * property path being resolved and <code>{faceDescriptorProperty}</code> is one of <code>displayName, caption, - * description</code> - * or <code>label</code>. - * <p> - * if contextId is used - * <p> - * <code>{contextId}.{formPropertyPath}.{faceDescriptorProperty}</code><br> - * <code>{formPropertyPath}.{faceDescriptorProperty}</code><br> - * <p> - * [EMAIL PROTECTED] #getFieldFace(String, String, Map)} can be used to provide context arguments when resolving the - * <code>{faceDescriptorProperty}</code> values. If the map contains for a <code>{faceDescriptorProperty}</code> key - * a value it must be an instance of <code>Object[]</code> or null. The value is used as the argument property while - * resolving the message through [EMAIL PROTECTED] MessageSourceResolvable} - * <p> - * If required the strategy for generating these keys can be overridden be providing an alternative implementation of the - * [EMAIL PROTECTED] #getMessageKeys(String, String, String[])} method. - * * @author Oliver Hutchison * @author Mathias Broekelmann */ @@ -102,18 +75,18 @@ private MessageSourceAccessor messageSourceAccessor; + private MessageCodeStrategy messageKeyStrategy; + private IconSource iconSource; + private final ReflectiveVisitorHelper visitorHelper = new ReflectiveVisitorHelper(); + /** * Constructs a new MessageSourcePropertyFaceDescriptorSource. */ public MessageSourceFieldFaceSource() { } - protected FieldFace loadFieldFace(FormModel formModel, String formFieldPath) { - return loadFieldFace(formFieldPath, formModel.getId()); - } - /** * Set the message source that will be used to resolve the FieldFace's properties. */ @@ -147,29 +120,25 @@ return iconSource; } - protected String getMessage(String contextId, String formPropertyPath, Map context, String[] faceDescriptorProperty) { - String[] keys = getMessageKeys(contextId, formPropertyPath, faceDescriptorProperty); - Object[] arguments = null; - if (faceDescriptorProperty != null) { - arguments = (Object[]) context.get(faceDescriptorProperty); - } - return getMessageSourceAccessor().getMessage(new DefaultMessageSourceResolvable(keys, arguments, keys[0])); + /** + * Returns the value of the required property of the FieldFace. Delegates to the getMessageKeys for the message key + * generation strategy. This method uses </code>[contextId + "." + ] fieldPath [ + "." + faceDescriptorProperty[0]]</code> + * for the default value + */ + protected String getMessage(String contextId, String fieldPath, String[] faceDescriptorProperty) { + String[] keys = getMessageKeys(contextId, fieldPath, faceDescriptorProperty); + return getMessageSourceAccessor().getMessage(new DefaultMessageSourceResolvable(keys, null, keys[0])); } /** * Returns the value of the required property of the FieldFace. Delegates to the getMessageKeys for the message key * generation strategy. */ - protected String getMessage(String contextId, String fieldPath, Map context, String[] faceDescriptorProperties, + protected String getMessage(String contextId, String fieldPath, String[] faceDescriptorProperties, String defaultValue) { String[] keys = getMessageKeys(contextId, fieldPath, faceDescriptorProperties); - Object[] arguments = null; - if (faceDescriptorProperties.length > 0) { - arguments = (Object[]) context.get(faceDescriptorProperties[0]); - } try { - return getMessageSourceAccessor().getMessage( - new DefaultMessageSourceResolvable(keys, arguments, defaultValue)); + return getMessageSourceAccessor().getMessage(new DefaultMessageSourceResolvable(keys, null, defaultValue)); } catch (NoSuchMessageException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage()); @@ -185,60 +154,54 @@ * Subclasses my override this method to provide an alternative to the default message key generation strategy. */ protected String[] getMessageKeys(String contextId, String fieldPath, String[] faceDescriptorProperties) { - boolean hasContextId = StringUtils.hasText(contextId); - String[] fieldPathElements = StringUtils.delimitedListToStringArray(fieldPath, "."); - Collection keys = new ArrayList((hasContextId ? 2 * fieldPathElements.length : fieldPathElements.length) - * faceDescriptorProperties.length); - if (hasContextId) { - String prefix = contextId + '.'; - addKeys(keys, prefix, fieldPathElements, faceDescriptorProperties); - } - addKeys(keys, "", fieldPathElements, faceDescriptorProperties); - return (String[]) keys.toArray(new String[keys.size()]); + return getMessageKeyStrategy().getMessageCodes(contextId, fieldPath, faceDescriptorProperties); } - private void addKeys(Collection keys, String prefix, String[] fieldPathElements, String[] suffix) { - final int size = fieldPathElements.length; - final int suffixSize = suffix.length; - for (int i = 0; i < size; i++) { - StringBuffer path = new StringBuffer(prefix); - for (int j = i; j < size; j++) { - path.append(fieldPathElements[j]); - if (j + 1 < size) { - path.append('.'); - } - } - for (int j = 0; j < suffixSize; j++) { - String currentSuffix = suffix[j]; - if (StringUtils.hasText(currentSuffix)) { - keys.add(path.toString() + "." + currentSuffix); - } else { - keys.add(path.toString()); - } - - } - } - } - - protected FieldFace loadFieldFace(String field, String contextId, Map context) { - String caption = getMessage(contextId, field, context, CAPTION_PROPERTY, null); - String description = getMessage(contextId, field, context, DESCRIPTION_PROPERTY, null); - String encodedLabel = getMessage(contextId, field, context, ENCODED_LABEL_PROPERTY); + protected FieldFace loadFieldFace(String field, String contextId) { + String caption = getMessage(contextId, field, CAPTION_PROPERTY, null); + String description = getMessage(contextId, field, DESCRIPTION_PROPERTY, null); + String encodedLabel = getMessage(contextId, field, ENCODED_LABEL_PROPERTY); if (encodedLabel == null) { // try loading the default value - encodedLabel = getMessage(contextId, field, context, null); + encodedLabel = getMessage(contextId, field, null); } - String iconName = getMessage(contextId, field, context, ICON_PROPERTY, null); + String iconName = getMessage(contextId, field, ICON_PROPERTY, null); Icon icon = null; if (iconName != null) { icon = getIconSource().getIcon(iconName); } LabelInfo labelInfo = LabelInfoFactory.createLabelInfo(encodedLabel); - String displayName = getMessage(contextId, field, context, DISPLAY_NAME_PROPERTY, labelInfo.getText()); + String displayName = getMessage(contextId, field, DISPLAY_NAME_PROPERTY, labelInfo.getText()); return new DefaultFieldFace(displayName, caption, description, labelInfo, icon); } - protected FieldFace loadFieldFace(String field, String contextId) { - return loadFieldFace(field, contextId, Collections.EMPTY_MAP); + protected FieldFace loadFieldFace(String field, Object context) { + String contextId = (String) visitorHelper.invokeVisit(this, context); + return loadFieldFace(field, contextId); } + + public MessageCodeStrategy getMessageKeyStrategy() { + if (messageKeyStrategy == null) { + messageKeyStrategy = new DefaultMessageCodeStrategy(); + } + return messageKeyStrategy; + } + + public void setMessageKeyStrategy(MessageCodeStrategy messageKeyStrategy) { + this.messageKeyStrategy = messageKeyStrategy; + } + + // visit methods for getting a context id from various context instances + + String visit(FormModel formModel) { + return formModel.getId(); + } + + String visit(CharSequence contextId) { + return contextId.toString(); + } + + String visitNull() { + return null; + } } \ No newline at end of file Added: trunk/spring-richclient/support/src/test/java/org/springframework/binding/form/support/DefaultMessageCodeStrategyTests.java =================================================================== --- trunk/spring-richclient/support/src/test/java/org/springframework/binding/form/support/DefaultMessageCodeStrategyTests.java (rev 0) +++ trunk/spring-richclient/support/src/test/java/org/springframework/binding/form/support/DefaultMessageCodeStrategyTests.java 2006-12-29 14:36:43 UTC (rev 1616) @@ -0,0 +1,91 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * 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.springframework.binding.form.support; + +import java.util.Arrays; + +import junit.framework.TestCase; + +import org.springframework.util.ObjectUtils; + +/** + * @author Mathias Broekelmann + * + */ +public class DefaultMessageCodeStrategyTests extends TestCase { + + private DefaultMessageCodeStrategy strategy; + + protected void setUp() throws Exception { + strategy = new DefaultMessageCodeStrategy(); + } + + protected void tearDown() throws Exception { + strategy = null; + } + + public final void testGetMessageCodesEmptyArgs() { + String[] emptyValues = new String[0]; + assertEquals(emptyValues, strategy.getMessageCodes(null, null, null)); + assertEquals(emptyValues, strategy.getMessageCodes(null, "", null)); + assertEquals(emptyValues, strategy.getMessageCodes("", "", null)); + assertEquals(emptyValues, strategy.getMessageCodes("", "", emptyValues)); + assertEquals(emptyValues, strategy.getMessageCodes("", "", new String[] { "" })); + assertEquals(emptyValues, strategy.getMessageCodes("", "", new String[] { "", "" })); + } + + public final void testGetMessageCodesNullContextNullSuffixes() { + assertEquals(new String[] { "simpleField" }, strategy.getMessageCodes(null, "simpleField", null)); + assertEquals(new String[] { "fieldbase.simpleField", "simpleField" }, strategy.getMessageCodes(null, + "fieldbase.simpleField", null)); + } + + public final void testGetMessageCodesWithContext() { + assertEquals(new String[] { "context.fieldbase.simpleField", "context.simpleField", "fieldbase.simpleField", + "simpleField" }, strategy.getMessageCodes("context", "fieldbase.simpleField", null)); + } + + public final void testGetMessageCodesWithSuffix() { + assertEquals(new String[] { "simpleField.suffix" }, strategy.getMessageCodes(null, "simpleField", + new String[] { "suffix" })); + assertEquals(new String[] { "simpleField.suffix1", "simpleField" }, strategy.getMessageCodes(null, + "simpleField", new String[] { "suffix1", "" })); + assertEquals(new String[] { "simpleField.suffix1", "simpleField.suffix2" }, strategy.getMessageCodes(null, + "simpleField", new String[] { "suffix1", "suffix2" })); + } + + public final void testGetMessageCodesWithContextAndSuffix() { + assertEquals(new String[] { "context.fieldbase.simpleField.suffix", "context.simpleField.suffix", + "fieldbase.simpleField.suffix", "simpleField.suffix" }, strategy.getMessageCodes("context", + "fieldbase.simpleField", new String[] { "suffix" })); + } + + protected void assertEquals(Object[] expected, Object[] actual) { + if (!Arrays.equals(expected, actual)) { + fail(buildMessage(expected, actual)); + } + } + + private String buildMessage(Object[] expected, Object[] actual) { + return "expected " + ObjectUtils.nullSafeToString(expected) + ", got " + ObjectUtils.nullSafeToString(actual); + } + + protected void assertEquals(String message, Object[] expected, Object[] actual) { + if (!Arrays.equals(expected, actual)) { + fail(message); + } + } +} Property changes on: trunk/spring-richclient/support/src/test/java/org/springframework/binding/form/support/DefaultMessageCodeStrategyTests.java ___________________________________________________________________ Name: svn:keywords + Revision Author Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs