001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.util.config;
018:
019: import org.compass.core.config.ConfigurationException;
020:
021: public interface ConfigurationHelper {
022:
023: /**
024: * Return the name of the node.
025: */
026: String getName();
027:
028: /**
029: * Return a string describing location of Configuration. Location can be
030: * different for different mediums (ie "file:line" for normal XML files or
031: * "table:primary-key" for DB based configurations);
032: */
033: String getLocation();
034:
035: /**
036: * Returns a string indicating which namespace this Configuration node
037: * belongs to.
038: */
039: String getNamespace() throws ConfigurationException;
040:
041: /**
042: * Return a new <code>Configuration</code> instance encapsulating the
043: * specified child node.
044: */
045: ConfigurationHelper getChild(String child);
046:
047: /**
048: * Return a <code>Configuration</code> instance encapsulating the
049: * specified child node.
050: */
051: ConfigurationHelper getChild(String child, boolean createNew);
052:
053: /**
054: * Return an <code>Array</code> of <code>Configuration</code> elements
055: * containing all node children. The array order will reflect the order in
056: * the source config file.
057: */
058: ConfigurationHelper[] getChildren();
059:
060: /**
061: * Return an <code>Array</code> of <code>Configuration</code> elements
062: * containing all node children with the specified name. The array order
063: * will reflect the order in the source config file.
064: */
065: ConfigurationHelper[] getChildren(String name);
066:
067: /**
068: * Return an array of all attribute names.
069: */
070: String[] getAttributeNames();
071:
072: /**
073: * Return the value of specified attribute.
074: */
075: String getAttribute(String paramName) throws ConfigurationException;
076:
077: /**
078: * Return the <code>int</code> value of the specified attribute contained
079: * in this node.
080: */
081: int getAttributeAsInteger(String paramName)
082: throws ConfigurationException;
083:
084: /**
085: * Returns the value of the attribute specified by its name as a
086: * <code>long</code>.
087: */
088: long getAttributeAsLong(String name) throws ConfigurationException;
089:
090: /**
091: * Return the <code>float</code> value of the specified parameter
092: * contained in this node.
093: */
094: float getAttributeAsFloat(String paramName)
095: throws ConfigurationException;
096:
097: /**
098: * Return the <code>boolean</code> value of the specified parameter
099: * contained in this node.
100: */
101: boolean getAttributeAsBoolean(String paramName)
102: throws ConfigurationException;
103:
104: /**
105: * Return the <code>String</code> value of the node.
106: */
107: String getValue() throws ConfigurationException;
108:
109: /**
110: * Return the <code>int</code> value of the node.
111: */
112: int getValueAsInteger() throws ConfigurationException;
113:
114: /**
115: * Return the <code>float</code> value of the node.
116: */
117: float getValueAsFloat() throws ConfigurationException;
118:
119: /**
120: * Return the <code>boolean</code> value of the node.
121: */
122: boolean getValueAsBoolean() throws ConfigurationException;
123:
124: /**
125: * Return the <code>long</code> value of the node.
126: */
127: long getValueAsLong() throws ConfigurationException;
128:
129: /**
130: * Returns the value of the configuration element as a <code>String</code>.
131: * If the configuration value is not set, the default value will be used.
132: */
133: String getValue(String defaultValue);
134:
135: /**
136: * Returns the value of the configuration element as an <code>int</code>.
137: * If the configuration value is not set, the default value will be used.
138: */
139: int getValueAsInteger(int defaultValue);
140:
141: /**
142: * Returns the value of the configuration element as a <code>long</code>.
143: * If the configuration value is not set, the default value will be used.
144: */
145: long getValueAsLong(long defaultValue);
146:
147: /**
148: * Returns the value of the configuration element as a <code>float</code>.
149: * If the configuration value is not set, the default value will be used.
150: */
151: float getValueAsFloat(float defaultValue);
152:
153: /**
154: * Returns the value of the configuration element as a <code>boolean</code>.
155: * If the configuration value is not set, the default value will be used.
156: */
157: boolean getValueAsBoolean(boolean defaultValue);
158:
159: /**
160: * Returns the value of the attribute specified by its name as a
161: * <code>String</code>, or the default value if no attribute by that name
162: * exists or is empty.
163: */
164: String getAttribute(String name, String defaultValue);
165:
166: /**
167: * Returns the value of the attribute specified by its name as a
168: * <code>int</code>, or the default value if no attribute by that name
169: * exists or is empty.
170: */
171: int getAttributeAsInteger(String name, int defaultValue);
172:
173: /**
174: * Returns the value of the attribute specified by its name as a
175: * <code>long</code>, or the default value if no attribute by that name
176: * exists or is empty.
177: */
178: long getAttributeAsLong(String name, long defaultValue);
179:
180: /**
181: * Returns the value of the attribute specified by its name as a
182: * <code>float</code>, or the default value if no attribute by that name
183: * exists or is empty.
184: */
185: float getAttributeAsFloat(String name, float defaultValue);
186:
187: /**
188: * Returns the value of the attribute specified by its name as a
189: * <code>boolean</code>, or the default value if no attribute by that
190: * name exists or is empty.
191: */
192: boolean getAttributeAsBoolean(String name, boolean defaultValue);
193:
194: /**
195: * Add all child <code>Configuration</code> objects from specified
196: * configuration element to current configuration element.
197: */
198: public void addAllChildrenBefore(final ConfigurationHelper other);
199: }
|