1 /* 2 * Copyright 2005 :torweg free software group 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 package org.torweg.pulse.configuration; 19 20 /** 21 * abstract base class for {@code ConfigBean}s. 22 * 23 * <p> 24 * {@code ConfigBean}s are configurations parsed into 25 * JavaBeans<sup>TM</sup> which are usually managed by the local 26 * {@code PoorMansCache} (see:{@link PoorMansCache#getConfig(Class)}, 27 * {@link PoorMansCache#getBundleConfig(Class, org.torweg.pulse.bundle.Bundle)} 28 * ). 29 * </p> 30 * <p> 31 * The {@code AbstractConfigBean} is a basic implementation of the hooks 32 * needed by the {@code PoorMansCache} and is the recommended base class 33 * for all other {@code ConfigBean}s. 34 * </p> 35 * 36 * @author Thomas Weber 37 * @version $Revision: 1387 $ 38 */ 39 public abstract class AbstractConfigBean implements ConfigBean { 40 41 /** 42 * serial version UID for java.io.Serializable. 43 */ 44 private static final long serialVersionUID = -4627765664622583828L; 45 46 /** 47 * the last modification time of the underlying config file. 48 */ 49 private long lastModified = 0; 50 51 /** 52 * returns the last modification time of the underlying config file. 53 * 54 * @return the last modification time in milliseconds since the epoch 55 * @see org.torweg.pulse.configuration.ConfigBean#lastModified() 56 */ 57 public final long lastModified() { 58 return this.lastModified; 59 } 60 61 /** 62 * sets or updates the last modification time of the underlying config file. 63 * 64 * @param t 65 * the last modification time in milliseconds since the epoch 66 * @see org.torweg.pulse.configuration.ConfigBean#setLastModified(long) 67 */ 68 public final void setLastModified(final long t) { 69 this.lastModified = t; 70 } 71 72 /** 73 * utility method to instantiate a class. 74 * 75 * @param c 76 * the class 77 * @return the instance 78 */ 79 protected static final Object buildInstance(final Class<? extends Object> c) { 80 try { 81 return c.newInstance(); 82 } catch (InstantiationException e) { 83 throw new ConfigurationException("Cannot instantiate '" 84 + c.getCanonicalName() + "'.", e); 85 } catch (IllegalAccessException e) { 86 throw new ConfigurationException("Cannot instantiate '" 87 + c.getCanonicalName() + "'.", e); 88 } 89 } 90 91 /** 92 * utility method to get a class object from a given class name. 93 * 94 * @param name 95 * the class name 96 * @return the class object 97 */ 98 protected static final Class<? extends Object> buildClass(final String name) { 99 try { 100 return Class.forName(name); 101 } catch (ClassNotFoundException e) { 102 throw new ConfigurationException("Cannot find '" + name + "'.", e); 103 } 104 } 105 } 106