1 16 17 package org.springframework.context.support; 18 19 import java.io.Serializable ; 20 21 import org.springframework.context.MessageSourceResolvable; 22 import org.springframework.util.ObjectUtils; 23 import org.springframework.util.StringUtils; 24 25 34 public class DefaultMessageSourceResolvable implements MessageSourceResolvable, Serializable { 35 36 private final String [] codes; 37 38 private final Object [] arguments; 39 40 private final String defaultMessage; 41 42 43 47 public DefaultMessageSourceResolvable(String code) { 48 this(new String [] {code}, null, null); 49 } 50 51 55 public DefaultMessageSourceResolvable(String [] codes) { 56 this(codes, null, null); 57 } 58 59 64 public DefaultMessageSourceResolvable(String [] codes, String defaultMessage) { 65 this(codes, null, defaultMessage); 66 } 67 68 73 public DefaultMessageSourceResolvable(String [] codes, Object [] arguments) { 74 this(codes, arguments, null); 75 } 76 77 83 public DefaultMessageSourceResolvable(String [] codes, Object [] arguments, String defaultMessage) { 84 this.codes = codes; 85 this.arguments = arguments; 86 this.defaultMessage = defaultMessage; 87 } 88 89 93 public DefaultMessageSourceResolvable(MessageSourceResolvable resolvable) { 94 this(resolvable.getCodes(), resolvable.getArguments(), resolvable.getDefaultMessage()); 95 } 96 97 98 public String [] getCodes() { 99 return codes; 100 } 101 102 106 public String getCode() { 107 return (this.codes != null && this.codes.length > 0) ? this.codes[this.codes.length - 1] : null; 108 } 109 110 public Object [] getArguments() { 111 return arguments; 112 } 113 114 public String getDefaultMessage() { 115 return defaultMessage; 116 } 117 118 119 123 protected final String resolvableToString() { 124 StringBuffer buf = new StringBuffer (); 125 buf.append("codes [").append(StringUtils.arrayToDelimitedString(this.codes, ",")); 126 buf.append("]; arguments [" + StringUtils.arrayToDelimitedString(this.arguments, ",")); 127 buf.append("]; default message [").append(this.defaultMessage).append(']'); 128 return buf.toString(); 129 } 130 131 137 public String toString() { 138 return getClass().getName() + ": " + resolvableToString(); 139 } 140 141 142 public boolean equals(Object other) { 143 if (this == other) { 144 return true; 145 } 146 if (!(other instanceof MessageSourceResolvable)) { 147 return false; 148 } 149 MessageSourceResolvable otherResolvable = (MessageSourceResolvable) other; 150 return ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()); 151 } 152 153 public int hashCode() { 154 return ObjectUtils.nullSafeHashCode(getCodes()); 155 } 156 157 } 158 | Popular Tags |