001 /* 002 * $Id: DatabaseBasicMessage.java 348369 2005-11-23 04:51:04Z niallp $ 003 * $Revision: 348369 $ 004 * $Date: 2005-11-23 04:51:04 +0000 (Wed, 23 Nov 2005) $ 005 * 006 * ==================================================================== 007 * 008 * Copyright 2003-2005 The Apache Software Foundation 009 * 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * 022 */ 023 024 package org.apache.commons.resources.impl; 025 026 027 028 029 030 /** 031 * BasicMessage to allow standard ORM 032 * configuration (no complex keys). 033 * 034 * @author James Mitchell 035 * 036 */ 037 public class DatabaseBasicMessage extends BasicMessage { 038 039 /** 040 * Default Constructor. 041 */ 042 public DatabaseBasicMessage() { 043 super(); 044 } 045 046 /** 047 * Construct a message for a specified Locale 048 * with the specified replacement values. 049 * 050 * @param locale Locale for this message 051 * @param key Message key for this message 052 * @param values Array of replacement values 053 */ 054 public DatabaseBasicMessage(String locale, String key, Object[] values) { 055 super(key, values); 056 this.locale = locale; 057 058 } 059 060 private String locale = null; 061 062 /** 063 * Return the locale for the message. 064 * 065 * @return Returns the locale. 066 */ 067 public String getLocale() { 068 return locale; 069 } 070 071 /** 072 * Set the locale for the message. 073 * 074 * @param locale The locale to set. 075 */ 076 public void setLocale(String locale) { 077 this.locale = locale; 078 } 079 080 /** 081 * Set a replacement value for the message. 082 * 083 * @param value The replacement value. 084 */ 085 public void setValue(String value) { 086 setValues(new String[]{value}); 087 } 088 089 /** 090 * Return the replacement value for the message. 091 * 092 * @return The replacement value. 093 */ 094 public String getValue() { 095 Object[] values = getValues(); 096 if (values == null || values.length < 1) { 097 throw new IllegalStateException("The retrived value for msg " + 098 getKey() + "was null"); 099 } 100 if (values.length > 1) { 101 throw new IllegalStateException("There were more than one values " + 102 "retrived value for msg " + 103 getKey()); 104 } 105 return (String)getValues()[0]; 106 } 107 108 /** 109 * Compare this message to another. 110 * 111 * @param obj The message to compare. 112 * @return 'true' if the messages are equal. 113 */ 114 public boolean equals(Object obj) { 115 if (obj instanceof DatabaseBasicMessage){ 116 if (((DatabaseBasicMessage)obj).getKey().equals(getKey()) && 117 ((DatabaseBasicMessage)obj).getLocale().equals(this.locale)){ 118 return true; 119 } 120 } 121 return false; 122 } 123 124 /** 125 * Return the hashcode for the message. 126 * 127 * @return The message's hash code. 128 */ 129 public int hashCode() { 130 return super.hashCode(); 131 } 132 }