Coverage Report - org.seasar.cubby.validator.MessageInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageInfo
67%
8/12
0%
0/2
0
MessageInfo$1
N/A
N/A
0
MessageInfo$MessageBuilder
93%
14/15
50%
1/2
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.validator;
 17  
 
 18  
 import org.seasar.cubby.util.Messages;
 19  
 
 20  30
 public class MessageInfo {
 21  
 
 22  
         private String key;
 23  
 
 24  
         private Object[] arguments;
 25  
 
 26  
         public String getKey() {
 27  0
                 return key;
 28  
         }
 29  
 
 30  
         public void setKey(String key) {
 31  30
                 this.key = key;
 32  30
         }
 33  
 
 34  
         public Object[] getArguments() {
 35  0
                 if (arguments == null) {
 36  0
                         return null;
 37  
                 }
 38  0
                 return arguments.clone();
 39  
         }
 40  
 
 41  
         public void setArguments(Object... arguments) {
 42  30
                 this.arguments = arguments;
 43  30
         }
 44  
 
 45  
         public MessageBuilder builder() {
 46  5
                 MessageBuilder builder = new MessageBuilder(key, arguments);
 47  5
                 return builder;
 48  
         }
 49  
 
 50  5
         public class MessageBuilder {
 51  
 
 52  
                 private final String messageKey;
 53  
 
 54  
                 private String fieldNameKey;
 55  
 
 56  
                 public final Object[] arguments;
 57  
 
 58  5
                 private MessageBuilder(final String messageKey, final Object[] arguments) {
 59  5
                         this.messageKey = messageKey;
 60  5
                         this.arguments = arguments;
 61  5
                 }
 62  
 
 63  
                 public MessageBuilder fieldNameKey(final String fieldNameKey) {
 64  5
                         this.fieldNameKey = fieldNameKey;
 65  5
                         return this;
 66  
                 }
 67  
 
 68  
                 public String toString() {
 69  
                         final Object[] args;
 70  5
                         if (fieldNameKey != null) {
 71  5
                                 args = new Object[this.arguments.length + 1];
 72  5
                                 final String paramNameText = Messages.getText(fieldNameKey);
 73  5
                                 args[0] = paramNameText;
 74  5
                                 System.arraycopy(this.arguments, 0, args, 1, this.arguments.length);
 75  5
                         } else {
 76  0
                                 args = this.arguments;
 77  
                         }
 78  5
                         return Messages.getText(messageKey, args);
 79  
                 }
 80  
         }
 81  
 }