Java tutorial
/******************************************************************************* * Copyright (c) 2009 David Harrison. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl-3.0.html * * Contributors: * David Harrison - initial API and implementation ******************************************************************************/ package com.sfs.beans; import java.util.Enumeration; import java.util.HashMap; import java.util.ResourceBundle; import org.apache.commons.lang.StringUtils; /** * The Class SQLBean. * * @author David Harrison 3rd September 2004 */ public class SQLBean implements java.io.Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The sql values. */ private HashMap<String, String> sqlValues = new HashMap<String, String>(); /** * Instantiates a new sQL bean. * * @param sqlPropertiesName the sql properties name */ public SQLBean(final String sqlPropertiesName) { /** * Loads SQL commands into memory from properties file **/ if (sqlPropertiesName != null) { ResourceBundle sqlBundle = ResourceBundle.getBundle(sqlPropertiesName); Enumeration<String> keySet = sqlBundle.getKeys(); while (keySet.hasMoreElements()) { String sqlKey = keySet.nextElement(); String sqlValue = sqlBundle.getString(sqlKey); sqlKey = StringUtils.replace(sqlKey, ".", "/"); if (sqlValue == null) { sqlValue = ""; } this.setValue(sqlKey, sqlValue); } } } /** * Gets the value. * * @param index the index * * @return the value */ public final String getValue(final String index) { if (sqlValues.containsKey(index)) { return sqlValues.get(index); } else { return ""; } } /** * Sets the value. * * @param index the index * @param value the value */ private void setValue(final String index, final String value) { if (StringUtils.isNotBlank(index) && StringUtils.isNotBlank(value)) { sqlValues.put(index, value); } } }