All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nablarch.test.support.message.MockStringResourceHolder Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package nablarch.test.support.message;

import java.util.HashMap;
import java.util.Map;

import nablarch.core.message.BasicStringResource;
import nablarch.core.message.MessageNotFoundException;
import nablarch.core.message.StringResource;
import nablarch.core.message.StringResourceHolder;


public class MockStringResourceHolder extends StringResourceHolder {

    private Map messages = new HashMap();

    public void setMessages(String[][] messages) {
        for (String[] params : messages) {
            String msgId = params[0];
            Map formats = new HashMap();
            for (int i = 0; i * 2 + 2 <= params.length; i++) {
                formats.put(params[i * 2 + 1], params[i * 2 + 2]);
            }

            this.messages.put(msgId, new BasicStringResource(msgId, formats));
        }

    }

    @Override
    public StringResource get(String messageId) {
        StringResource message = messages.get(messageId);

        if (message == null) {
            throw new MessageNotFoundException("message was not found. message id = " + messageId);
        }

        return message;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy