diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java | 285 |
1 files changed, 143 insertions, 142 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java b/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java index e54b19d90..bb3f32b74 100644 --- a/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java +++ b/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.base; - import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; @@ -38,23 +37,22 @@ import com.netscape.certsrv.base.EPropertyNotFound; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISourceConfigStore; - /** - * A class represents a in-memory configuration store. - * Note this class takes advantage of the recursive nature of - * property names. The current property prefix is kept in - * mStoreName and the mSource usually points back to another + * A class represents a in-memory configuration store. Note this class takes + * advantage of the recursive nature of property names. The current property + * prefix is kept in mStoreName and the mSource usually points back to another * occurance of the same PropConfigStore, with longer mStoreName. IE + * * <PRE> - * cms.ca0.http.service0 -> mSource=PropConfigStore -> - * cms.ca0.http -> mSource=PropConfigStore -> - * cms.ca0 -> mSource=PropConfigStore -> + * cms.ca0.http.service0 -> mSource=PropConfigStore -> + * cms.ca0.http -> mSource=PropConfigStore -> + * cms.ca0 -> mSource=PropConfigStore -> * cms -> mSource=SourceConfigStore -> Properties * </PRE> - * The chain ends when the store name is reduced down to it's original - * value. + * + * The chain ends when the store name is reduced down to it's original value. * <P> - * + * * @version $Revision$, $Date$ */ public class PropConfigStore implements IConfigStore, Cloneable { @@ -76,14 +74,13 @@ public class PropConfigStore implements IConfigStore, Cloneable { */ protected ISourceConfigStore mSource = null; - private static String mDebugType="CS.cfg"; + private static String mDebugType = "CS.cfg"; /** - * Constructs a property configuration store. This must - * be a brand new store without properties. The subclass - * must be a ISourceConfigStore. + * Constructs a property configuration store. This must be a brand new store + * without properties. The subclass must be a ISourceConfigStore. * <P> - * + * * @param storeName property store name * @exception EBaseException failed to create configuration */ @@ -93,12 +90,11 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Constructs a configuration store. The constructor is - * a helper class for substores. Source is the one - * that stores all the parameters. Each substore only - * store a substore name, and a reference to the source. + * Constructs a configuration store. The constructor is a helper class for + * substores. Source is the one that stores all the parameters. Each + * substore only store a substore name, and a reference to the source. * <P> - * + * * @param storeName store name * @param prop list of properties * @exception EBaseException failed to create configuration @@ -111,7 +107,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Returns the name of this store. * <P> - * + * * @return store name */ public String getName() { @@ -121,7 +117,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves a property from the configuration file. * <P> - * + * * @param name property name * @return property value */ @@ -130,10 +126,10 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Retrieves a property from the configuration file. Does not prepend - * the config store name to the property. + * Retrieves a property from the configuration file. Does not prepend the + * config store name to the property. * <P> - * + * * @param name property name * @return property value */ @@ -142,11 +138,10 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Puts a property into the configuration file. The - * values wont be updated to the file until save - * method is invoked. + * Puts a property into the configuration file. The values wont be updated + * to the file until save method is invoked. * <P> - * + * * @param name property name * @param value property value */ @@ -156,16 +151,17 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Removes a property from the configuration file. - * + * * @param name property name */ public void remove(String name) { ((SourceConfigStore) mSource).remove(getFullName(name)); - } + } /** * Returns an enumeration of the config store's keys, hidding the store * name. + * * @see java.util.Hashtable#elements * @see java.util.Enumeration */ @@ -178,7 +174,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves the hashtable where all the properties are kept. - * + * * @return hashtable */ public Hashtable hashtable() { @@ -199,16 +195,16 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Fills the given hash table with all key/value pairs in the current - * config store, removing the config store name prefix + * Fills the given hash table with all key/value pairs in the current config + * store, removing the config store name prefix * <P> - * + * * @param h the hashtable */ private synchronized void enumerate(Hashtable h) { Enumeration e = mSource.keys(); // We only want the keys which match the current substore name - // without the current substore prefix. This code works even + // without the current substore prefix. This code works even // if mStoreName is null. String fullName = getFullName(""); int kIndex = fullName.length(); @@ -224,7 +220,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Reads a config store from an input stream. - * + * * @param in input stream where properties are located * @exception IOException failed to load */ @@ -234,7 +230,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Stores this config store to the specified output stream. - * + * * @param out outputstream where the properties are saved * @param header optional header information to be saved */ @@ -244,7 +240,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves a property value. - * + * * @param name property key * @return property value * @exception EBaseException failed to retrieve value @@ -253,28 +249,30 @@ public class PropConfigStore implements IConfigStore, Cloneable { String str = (String) get(name); if (str == null) { - CMS.traceHashKey(mDebugType,getFullName(name),"<notpresent>"); - throw new EPropertyNotFound(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>"); + throw new EPropertyNotFound(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); } - // should we check for empty string ? + // should we check for empty string ? // if (str.length() == 0) { - // throw new EPropertyNotDefined(getName() + "." + name); + // throw new EPropertyNotDefined(getName() + "." + name); // } String ret = null; try { ret = new String(str.getBytes(), "UTF8").trim(); } catch (java.io.UnsupportedEncodingException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_UTF8_NOT_SUPPORTED")); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_UTF8_NOT_SUPPORTED")); } - CMS.traceHashKey(mDebugType,getFullName(name),ret); + CMS.traceHashKey(mDebugType, getFullName(name), ret); return ret; } /** * Retrieves a String from the configuration file. * <P> - * + * * @param name property name * @param defval the default object to return if name does not exist * @return property value @@ -287,13 +285,13 @@ public class PropConfigStore implements IConfigStore, Cloneable { } catch (EPropertyNotFound e) { val = defval; } - CMS.traceHashKey(mDebugType,getFullName(name),val,defval); + CMS.traceHashKey(mDebugType, getFullName(name), val, defval); return val; } /** * Puts property value into this configuration store. - * + * * @param name property key * @param value property value */ @@ -304,18 +302,19 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves a byte array from the configuration file. * <P> - * + * * @param name property name * @exception IllegalArgumentException if name is not set or is null. - * + * * @return property value */ public byte[] getByteArray(String name) throws EBaseException { byte[] arr = getByteArray(name, new byte[0]); if (arr.length == 0) { - CMS.traceHashKey(mDebugType,getFullName(name),"<notpresent>"); - throw new EPropertyNotFound(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>"); + throw new EPropertyNotFound(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); } return arr; } @@ -323,41 +322,39 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves a byte array from the configuration file. * <P> - * + * * @param name property name - * @param defval the default byte array to return if name does - * not exist - * + * @param defval the default byte array to return if name does not exist + * * @return property value */ - public byte[] getByteArray(String name, byte defval[]) - throws EBaseException { + public byte[] getByteArray(String name, byte defval[]) + throws EBaseException { String str = (String) get(name); - byte returnval; + byte returnval; - if (str == null || str.length() == 0) { - CMS.traceHashKey(mDebugType,getFullName(name), - "<notpresent>","<bytearray>"); - return defval; - } - else { - CMS.traceHashKey(mDebugType,getFullName(name), - "<bytearray>","<bytearray>"); - return com.netscape.osutil.OSUtil.AtoB(str); - } + if (str == null || str.length() == 0) { + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>", + "<bytearray>"); + return defval; + } else { + CMS.traceHashKey(mDebugType, getFullName(name), "<bytearray>", + "<bytearray>"); + return com.netscape.osutil.OSUtil.AtoB(str); + } } /** * Puts byte array into this configuration store. - * + * * @param name property key * @param value byte array */ public void putByteArray(String name, byte value[]) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - Base64OutputStream b64 = new Base64OutputStream(new - PrintStream(new FilterOutputStream(output))); + Base64OutputStream b64 = new Base64OutputStream(new PrintStream( + new FilterOutputStream(output))); try { b64.write(value); @@ -367,14 +364,14 @@ public class PropConfigStore implements IConfigStore, Cloneable { // internationalization problems here put(name, output.toString("8859_1")); } catch (IOException e) { - System.out.println("Warning: base-64 encoding of configuration " + - "information failed"); + System.out.println("Warning: base-64 encoding of configuration " + + "information failed"); } } /** * Retrieves boolean-based property value. - * + * * @param name property key * @return boolean value * @exception EBaseException failed to retrieve @@ -383,11 +380,13 @@ public class PropConfigStore implements IConfigStore, Cloneable { String value = (String) get(name); if (value == null) { - CMS.traceHashKey(mDebugType,getFullName(name),"<notpresent>"); - throw new EPropertyNotFound(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>"); + throw new EPropertyNotFound(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); } if (value.length() == 0) { - throw new EPropertyNotDefined(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); + throw new EPropertyNotDefined(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); } if (value.equalsIgnoreCase("true")) { @@ -395,20 +394,22 @@ public class PropConfigStore implements IConfigStore, Cloneable { } else if (value.equalsIgnoreCase("false")) { return false; } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, "boolean", "\"true\" or \"false\"")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, + "boolean", "\"true\" or \"false\"")); } } /** * Retrieves boolean-based property value. - * + * * @param name property key * @param defval default value * @return boolean value * @exception EBaseException failed to retrieve */ - public boolean getBoolean(String name, boolean defval) - throws EBaseException { + public boolean getBoolean(String name, boolean defval) + throws EBaseException { boolean val; try { @@ -418,14 +419,14 @@ public class PropConfigStore implements IConfigStore, Cloneable { } catch (EPropertyNotDefined e) { val = defval; } - CMS.traceHashKey(mDebugType,getFullName(name), - val?"true":"false", defval?"true":"false"); + CMS.traceHashKey(mDebugType, getFullName(name), val ? "true" : "false", + defval ? "true" : "false"); return val; } /** * Puts boolean value into the configuration store. - * + * * @param name property key * @param value property value */ @@ -439,7 +440,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves integer value. - * + * * @param name property key * @return property value * @exception EBaseException failed to retrieve value @@ -448,23 +449,27 @@ public class PropConfigStore implements IConfigStore, Cloneable { String value = (String) get(name); if (value == null) { - CMS.traceHashKey(mDebugType,getFullName(name),"<notpresent>"); - throw new EPropertyNotFound(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>"); + throw new EPropertyNotFound(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); } if (value.length() == 0) { - throw new EPropertyNotDefined(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); + throw new EPropertyNotDefined(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); } try { - CMS.traceHashKey(mDebugType,getFullName(name), value); + CMS.traceHashKey(mDebugType, getFullName(name), value); return Integer.parseInt(value); } catch (NumberFormatException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, "int", "number")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, + "int", "number")); } } /** * Retrieves integer value. - * + * * @param name property key * @param defval default value * @return property value @@ -480,14 +485,13 @@ public class PropConfigStore implements IConfigStore, Cloneable { } catch (EPropertyNotDefined e) { val = defval; } - CMS.traceHashKey(mDebugType,getFullName(name), - ""+val,""+defval); + CMS.traceHashKey(mDebugType, getFullName(name), "" + val, "" + defval); return val; } /** * Puts an integer value. - * + * * @param name property key * @param val property value * @exception EBaseException failed to retrieve value @@ -498,7 +502,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves big integer value. - * + * * @param name property key * @return property value * @exception EBaseException failed to retrieve value @@ -507,11 +511,13 @@ public class PropConfigStore implements IConfigStore, Cloneable { String value = (String) get(name); if (value == null) { - CMS.traceHashKey(mDebugType,getFullName(name),"<notpresent>"); - throw new EPropertyNotFound(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); + CMS.traceHashKey(mDebugType, getFullName(name), "<notpresent>"); + throw new EPropertyNotFound(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_FAILED", getName() + "." + name)); } if (value.length() == 0) { - throw new EPropertyNotDefined(CMS.getUserMessage("CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); + throw new EPropertyNotDefined(CMS.getUserMessage( + "CMS_BASE_GET_PROPERTY_NOVALUE", getName() + "." + name)); } try { if (value.startsWith("0x") || value.startsWith("0X")) { @@ -521,20 +527,22 @@ public class PropConfigStore implements IConfigStore, Cloneable { } return new BigInteger(value); } catch (NumberFormatException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, "BigInteger", "number")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_PROPERTY_1", getName() + "." + name, + "BigInteger", "number")); } } /** * Retrieves integer value. - * + * * @param name property key * @param defval default value * @return property value * @exception EBaseException failed to retrieve value */ - public BigInteger getBigInteger(String name, BigInteger defval) - throws EBaseException { + public BigInteger getBigInteger(String name, BigInteger defval) + throws EBaseException { BigInteger val; try { @@ -549,7 +557,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Puts a big integer value. - * + * * @param name property key * @param val default value */ @@ -560,37 +568,33 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Creates a new sub store. * <P> - * + * * @param name substore name * @return substore */ public IConfigStore makeSubStore(String name) { /* - String names=(String)mSource.get(getFullName(PROP_SUBSTORES)); - - if (names==null) { - names=name; - } - else { - names=names+","+name; - } - mSource.put(getFullName(PROP_SUBSTORES), name); + * String names=(String)mSource.get(getFullName(PROP_SUBSTORES)); + * + * if (names==null) { names=name; } else { names=names+","+name; } + * mSource.put(getFullName(PROP_SUBSTORES), name); */ return new PropConfigStore(getFullName(name), mSource); } /** - * Removes a sub store.<p> - * + * Removes a sub store. + * <p> + * * @param name substore name */ public void removeSubStore(String name) { // this operation is expensive!!! - + Enumeration e = mSource.keys(); // We only want the keys which match the current substore name - // without the current substore prefix. This code works even + // without the current substore prefix. This code works even // if mStoreName is null. String fullName = getFullName(name); int kIndex = fullName.length(); @@ -605,20 +609,22 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Retrieves a sub store. A substore contains a list - * of properties and substores. For example, + * Retrieves a sub store. A substore contains a list of properties and + * substores. For example, + * * <PRE> * cms.ldap.host=ds.netscape.com * cms.ldap.port=389 * </PRE> - * "ldap" is a substore in above example. If the - * substore property itself is set, this method - * will treat the value as a reference. For example, + * + * "ldap" is a substore in above example. If the substore property itself is + * set, this method will treat the value as a reference. For example, + * * <PRE> - * cms.ldap=kms.ldap + * cms.ldap = kms.ldap * </PRE> * <P> - * + * * @param name substore name * @return substore */ @@ -639,7 +645,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Retrieves a list of property names. - * + * * @return a list of string-based property names */ public Enumeration getPropertyNames() { @@ -668,7 +674,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Returns a list of sub store names. * <P> - * + * * @return list of substore names */ public Enumeration getSubStoreNames() { @@ -695,10 +701,9 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * Retrieves the source configuration store where - * the properties are stored. + * Retrieves the source configuration store where the properties are stored. * <P> - * + * * @return source configuration store */ public ISourceConfigStore getSourceConfigStore() { @@ -706,8 +711,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { } /** - * For debugging purposes. Prints properties of this - * substore. + * For debugging purposes. Prints properties of this substore. */ public void printProperties() { Enumeration keys = mSource.keys(); @@ -726,7 +730,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Converts the substore parameters. - * + * * @param name property name * @return fill property name */ @@ -739,7 +743,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { /** * Cloning of property configuration store. - * + * * @return a new configuration store */ public Object clone() { @@ -751,18 +755,15 @@ public class PropConfigStore implements IConfigStore, Cloneable { Enumeration subs = getSubStoreNames(); while (subs.hasMoreElements()) { - IConfigStore sub = (IConfigStore) - subs.nextElement(); - IConfigStore newSub = that.makeSubStore( - sub.getName()); + IConfigStore sub = (IConfigStore) subs.nextElement(); + IConfigStore newSub = that.makeSubStore(sub.getName()); Enumeration props = sub.getPropertyNames(); while (props.hasMoreElements()) { String n = (String) props.nextElement(); try { - newSub.putString(n, - sub.getString(n)); + newSub.putString(n, sub.getString(n)); } catch (EBaseException ex) { } } |