| Method from org.apache.openjpa.lib.conf.ConfigurationImpl Detail: |
public BooleanValue addBoolean(String property) {
BooleanValue val = new BooleanValue(property);
addValue(val);
val.setDefault("false");
return val;
}
Add the given value to the set of configuration properties. |
public DoubleValue addDouble(String property) {
DoubleValue val = new DoubleValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public FileValue addFile(String property) {
FileValue val = new FileValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public IntValue addInt(String property) {
IntValue val = new IntValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public ObjectValue addObject(String property) {
ObjectValue val = new ObjectValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public PluginValue addPlugin(String property,
boolean singleton) {
PluginValue val = new PluginValue(property, singleton);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public PluginListValue addPluginList(String property) {
PluginListValue val = new PluginListValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public void addPropertyChangeListener(PropertyChangeListener listener) {
if (_changeSupport == null)
_changeSupport = new PropertyChangeSupport(this);
_changeSupport.addPropertyChangeListener(listener);
}
|
public StringValue addString(String property) {
StringValue val = new StringValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public StringListValue addStringList(String property) {
StringListValue val = new StringListValue(property);
addValue(val);
return val;
}
Add the given value to the set of configuration properties. |
public Value addValue(Value val) {
_vals.add(val);
val.setListener(this);
return val;
}
|
public Object clone() {
try {
Constructor cons = getClass().getConstructor
(new Class[]{ boolean.class });
ConfigurationImpl clone = (ConfigurationImpl) cons.newInstance
(new Object[]{ Boolean.FALSE });
clone.fromProperties(toProperties(true));
clone._props = (_props == null) ? null : new HashMap(_props);
clone._globals = _globals;
return clone;
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new ParseException(e);
}
}
|
public final void close() {
ProductDerivations.beforeClose(this);
preClose();
ObjectValue val;
for (int i = 0; i < _vals.size(); i++) {
if (_vals.get(i) instanceof Closeable) {
try { ((Closeable) _vals.get(i)).close(); }
catch (Exception e) {}
continue;
}
if (!(_vals.get(i) instanceof ObjectValue))
continue;
val = (ObjectValue) _vals.get(i);
if (val.get() instanceof Closeable) {
try {
((Closeable) val.get()).close();
} catch (Exception e) {
}
}
}
}
Closes all closeable values and plugins. |
public boolean equals(Object other) {
if (other == this)
return true;
if (other == null)
return false;
if (!getClass().equals(other.getClass()))
return false;
// compare properties
ConfigurationImpl conf = (ConfigurationImpl) other;
if (_vals.size() != conf.getValues().length)
return false;
Iterator values = _vals.iterator();
while (values.hasNext()) {
Value v = (Value)values.next();
Value thatV = conf.getValue(v.getProperty());
if (!v.equals(thatV)) {
return false;
}
}
return true;
}
Performs an equality check based on equality of values.
Equality of Values varies if the Value is
dynamic . |
public void fromProperties(Map map) {
if (map == null || map.isEmpty())
return;
if (isReadOnly())
throw new IllegalStateException(_loc.get("read-only").getMessage());
// if the only previous call was to load defaults, forget them.
// this way we preserve the original formatting of the user's props
// instead of the defaults. this is important for caching on
// configuration objects
if (_globals) {
_props = null;
_globals = false;
}
// copy the input to avoid mutation issues
if (map instanceof HashMap)
map = (Map) ((HashMap) map).clone();
else if (map instanceof Properties)
map = (Map) ((Properties) map).clone();
else
map = new LinkedHashMap(map);
Map remaining = new HashMap(map);
boolean ser = true;
Value val;
Object o;
for (int i = 0; i < _vals.size(); i++) {
val = (Value) _vals.get(i);
o = get(map, val, true);
if (o == null)
continue;
if (o instanceof String) {
if (!StringUtils.equals((String) o, val.getString()))
val.setString((String) o);
} else {
ser &= o instanceof Serializable;
val.setObject(o);
}
Configurations.removeProperty(val.getProperty(), remaining);
}
// convention is to point product at a resource with the
// < prefix >.properties System property; remove that property so we
// we don't warn about it
Configurations.removeProperty("properties", remaining);
// now warn if there are any remaining properties that there
// is an unhandled prop, and remove the unknown properties
Map.Entry entry;
for (Iterator itr = remaining.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
Object key = entry.getKey();
if (key != null) {
warnInvalidProperty((String) key);
map.remove(key);
}
}
// cache properties
if (_props == null && ser)
_props = map;
}
|
public BeanInfo[] getAdditionalBeanInfo() {
return new BeanInfo[0];
}
|
public BeanDescriptor getBeanDescriptor() {
return new BeanDescriptor(getClass());
}
|
public Log getConfigurationLog() {
return getLog("openjpa.Runtime");
}
Returns the logging channel openjpa.Runtime by default. |
public int getDefaultEventIndex() {
return 0;
}
|
public int getDefaultPropertyIndex() {
return 0;
}
|
public EventSetDescriptor[] getEventSetDescriptors() {
return new EventSetDescriptor[0];
}
|
public Image getIcon(int kind) {
return null;
}
|
public String getId() {
return id.get();
}
|
public String getLog() {
return logFactoryPlugin.getString();
}
|
public Log getLog(String category) {
return getLogFactory().getLog(category);
}
|
public LogFactory getLogFactory() {
if (logFactoryPlugin.get() == null)
logFactoryPlugin.instantiate(LogFactory.class, this);
return (LogFactory) logFactoryPlugin.get();
}
|
public synchronized MethodDescriptor[] getMethodDescriptors() {
if (_mds != null)
return _mds;
PropertyDescriptor[] pds = getPropertyDescriptors();
List descs = new ArrayList();
for (int i = 0; i < pds.length; i++) {
Method write = pds[i].getWriteMethod();
Method read = pds[i].getReadMethod();
if (read != null && write != null) {
descs.add(new MethodDescriptor(write));
descs.add(new MethodDescriptor(read));
}
}
_mds = (MethodDescriptor[]) descs.
toArray(new MethodDescriptor[descs.size()]);
return _mds;
}
|
public String getProductName() {
return _product;
}
|
public String getPropertiesResource() {
return _auto;
}
|
public synchronized PropertyDescriptor[] getPropertyDescriptors() {
if (_pds != null)
return _pds;
_pds = new PropertyDescriptor[_vals.size()];
List failures = null;
Value val;
for (int i = 0; i < _vals.size(); i++) {
val = (Value) _vals.get(i);
try {
_pds[i] = getPropertyDescriptor(val);
} catch (MissingResourceException mre) {
if (failures == null)
failures = new ArrayList();
failures.add(val.getProperty());
} catch (IntrospectionException ie) {
if (failures == null)
failures = new ArrayList();
failures.add(val.getProperty());
}
}
if (failures != null)
throw new ParseException(_loc.get("invalid-property-descriptors",
failures));
return _pds;
}
|
public Value getValue(String property) {
if (property == null)
return null;
// search backwards so that custom values added after construction
// are found quickly, since this will be the std way of accessing them
Value val;
for (int i = _vals.size() - 1; i >= 0; i--) {
val = (Value) _vals.get(i);
if (val.getProperty().equals(property))
return val;
}
return null;
}
|
public Value[] getValues() {
return (Value[]) _vals.toArray(new Value[_vals.size()]);
}
|
public int hashCode() {
Iterator values = _vals.iterator();
int hash = 0;
while (values.hasNext()) {
Value v = (Value)values.next();
hash += v.hashCode();
}
return hash;
}
Computes hash code based on the hashCodes of the values.
HashCode of a Value varies if the Value is
dynamic . |
public void instantiateAll() {
StringWriter errs = null;
PrintWriter stack = null;
Value val;
String getterName;
Method getter;
Object getterTarget;
for (int i = 0; i < _vals.size(); i++) {
val = (Value) _vals.get(i);
getterName = val.getInstantiatingGetter();
if (getterName == null)
continue;
getterTarget = this;
if (getterName.startsWith("this.")) {
getterName = getterName.substring("this.".length());
getterTarget = val;
}
try {
getter = getterTarget.getClass().getMethod(getterName,
(Class[]) null);
getter.invoke(getterTarget, (Object[]) null);
} catch (Throwable t) {
if (t instanceof InvocationTargetException)
t = ((InvocationTargetException) t).getTargetException();
if (errs == null) {
errs = new StringWriter();
stack = new PrintWriter(errs);
} else
errs.write(SEP);
t.printStackTrace(stack);
stack.flush();
}
}
if (errs != null)
throw new RuntimeException(_loc.get("get-prop-errs",
errs.toString()).getMessage());
}
|
protected boolean isInvalidProperty(String propName) {
// handle warnings for openjpa.SomeString, but not for
// openjpa.some.subpackage.SomeString, since it might be valid for some
// specific implementation of OpenJPA
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
for (int i = 0; i < prefixes.length; i++) {
if (propName.toLowerCase().startsWith(prefixes[i])
&& propName.length() > prefixes[i].length() + 1
&& propName.indexOf('.", prefixes[i].length())
== prefixes[i].length()
&& propName.indexOf('.", prefixes[i].length() + 1) == -1)
return true;
}
return false;
}
Returns true if the specified property name should raise a warning
if it is not found in the list of known properties. |
public boolean isReadOnly() {
return _readOnlyState==INIT_STATE_FROZEN;
}
|
public boolean loadGlobals() {
MultiClassLoader loader = (MultiClassLoader) AccessController
.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
loader.addClassLoader((ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getContextClassLoaderAction()));
loader.addClassLoader(getClass().getClassLoader());
ConfigurationProvider provider = ProductDerivations.loadGlobals(loader);
if (provider != null)
provider.setInto(this);
// let system properties override other globals
try {
fromProperties(new HashMap(
(Properties) AccessController.doPrivileged(
J2DoPrivHelper.getPropertiesAction())));
} catch (SecurityException se) {
// security manager might disallow
}
_globals = true;
if (provider == null) {
Log log = getConfigurationLog();
if (log.isTraceEnabled())
log.trace(_loc.get("no-default-providers"));
return false;
}
return true;
}
Automatically load global values from the system's
ProductDerivation s, and from System properties. |
protected void preClose() {
}
|
public void readExternal(ObjectInput in) throws ClassNotFoundException, IOException {
fromProperties((Map) in.readObject());
_props = (Map) in.readObject();
_globals = in.readBoolean();
}
|
public void removePropertyChangeListener(PropertyChangeListener listener) {
if (_changeSupport != null)
_changeSupport.removePropertyChangeListener(listener);
}
|
public boolean removeValue(Value val) {
if (!_vals.remove(val))
return false;
val.setListener(null);
return true;
}
|
public void setId(String id) {
this.id.set(id);
}
|
public void setLog(String log) {
logFactoryPlugin.setString(log);
}
|
public void setLogFactory(LogFactory logFactory) {
logFactoryPlugin.set(logFactory);
}
|
public void setProductName(String name) {
_product = name;
}
|
public void setProperties(String resourceName) throws IOException {
ProductDerivations.load(resourceName, null,
getClass().getClassLoader()).setInto(this);
_auto = resourceName;
}
This method loads the named resource as a properties file. It is
useful for auto-configuration tools so users can specify a
properties value with the name of a resource. |
public void setPropertiesFile(File file) throws IOException {
ProductDerivations.load(file, null, getClass().getClassLoader()).
setInto(this);
_auto = file.toString();
}
This method loads the named file as a properties file. It is
useful for auto-configuration tools so users can specify a
propertiesFile value with the name of a file. |
public void setReadOnly(int newState) {
if (newState >= _readOnlyState) {
_readOnlyState = newState;
}
}
|
public Map toProperties(boolean storeDefaults) {
// clone properties before making any modifications; we need to keep
// the internal properties instance consistent to maintain equals and
// hashcode contracts
Map clone;
if (_props == null)
clone = new HashMap();
else if (_props instanceof Properties)
clone = (Map) ((Properties) _props).clone();
else
clone = new HashMap(_props);
// if no existing properties or the properties should contain entries
// with default values, add values to properties
if (_props == null || storeDefaults) {
Value val;
String str;
for (int i = 0; i < _vals.size(); i++) {
// if key in existing properties, we already know value is up
// to date
val = (Value) _vals.get(i);
if (_props != null && Configurations.containsProperty
(val.getProperty(), _props))
continue;
str = val.getString();
if (str != null && (storeDefaults
|| !str.equals(val.getDefault())))
put(clone, val, str);
}
if (_props == null)
_props = new HashMap(clone);
}
return clone;
}
|
public static String toXMLName(String propName) {
if (propName == null)
return null;
StringBuffer buf = new StringBuffer();
char c;
for (int i = 0; i < propName.length(); i++) {
c = propName.charAt(i);
// convert sequences of all-caps to downcase with dashes around
// them. put a trailing cap that is followed by downcase into the
// downcase word.
if (i != 0 && Character.isUpperCase(c)
&& (Character.isLowerCase(propName.charAt(i-1))
|| (i > 1 && i < propName.length() - 1
&& Character.isUpperCase(propName.charAt(i-1))
&& Character.isLowerCase(propName.charAt(i+1)))))
buf.append('-");
// surround sequences of digits with dashes.
if (i != 0
&& ((!Character.isLetter(c) && Character.isLetter(propName
.charAt(i - 1)))
|| (Character.isLetter(c) && !Character.isLetter(propName
.charAt(i - 1)))))
buf.append('-");
buf.append(Character.toLowerCase(c));
}
return buf.toString();
}
Convert propName to a lowercase-with-hyphens-style string.
This algorithm is only designed for mixes of uppercase and lowercase
letters and lone digits. A more sophisticated conversion should probably
be handled by a proper parser generator or regular expressions. |
public void valueChanged(Value val) {
if (_changeSupport == null && _props == null)
return;
String newString = val.getString();
if (_changeSupport != null)
_changeSupport.firePropertyChange(val.getProperty(), null,
newString);
// keep cached props up to date
if (_props != null) {
if (newString == null)
Configurations.removeProperty(val.getProperty(), _props);
else if (Configurations.containsProperty(val.getProperty(), _props)
|| val.getDefault() == null
|| !val.getDefault().equals(newString))
put(_props, val, newString);
}
}
|
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(toProperties(true));
out.writeObject(_props);
out.writeBoolean(_globals);
}
|