/** * Set this value from the given string. If the given string is null or * empty and a default is defined, the default is used. If the given * string(or default) is an alias key, it will be converted to the * corresponding value internally. * <br> * If this Value is being set to a non-default value for the first time * (as designated by <code>originalString</code> being null), then the * value is remembered as <em>original</em>. This original value is used * for equality and hashCode computation if this Value is * {@link #isDynamic() dynamic}. * */ public void setString(String val) { assertChangeable(); String str = unalias(val); try { setInternalString(str); if (originalValue == null && val != null && !isDefault(val)) { originalValue = getString(); } } catch (ParseException pe) { throw pe; } catch (RuntimeException re) { throw new ParseException(prop + ": " + val, re); } }
public <T extends Value> T addValue(T val) { _vals.add(val); val.addListener(this); return val; }
/** * Use {@link #getOriginalValue() original value} instead of * {@link #getString() current value} because they are one and the same * for non-dynamic Values and ensures that modifying dynamic Values do not * impact equality or hashCode contract. */ public boolean equals(Object other) { if (other == this) return true; if (!(other instanceof Value)) return false; Value o = (Value) other; String thisStr = (isDynamic()) ? getOriginalValue() : getString(); String thatStr = (isDynamic()) ? o.getOriginalValue() : o.getString(); return (isDynamic() == o.isDynamic()) && Objects.equals(prop, o.getProperty()) && Objects.equals(thisStr, thatStr); }
/** * Return a stringified version of this value. If the current value has * a short alias key, the alias key is returned. */ public String getString() { return alias(getInternalString()); }
/** * Use {@link #getOriginalValue() original value} instead of * {@link #getString() current value} because they are one and the same * for non-dynamic Values and ensures that modifying dynamic Values do not * impact equality or hashCode contract. */ public int hashCode() { String str = (isDynamic()) ? getOriginalValue() : getString(); int strHash = (str == null) ? 0 : str.hashCode(); int propHash = (prop == null) ? 0 : prop.hashCode(); return strHash ^ propHash; }
/** * Adds <code>o</code> to <code>map</code> under key for <code>val</code>. * Use this method instead of attempting to add the value directly because * this will account for the property prefix. */ private void setValue(Map map, Value val) { Object key = val.getLoadKey(); if (key == null) { List<String> keys = val.getPropertyKeys(); for (String k : keys) { if (hasKnownPrefix(k)) { key = k; break; } } if (key == null) { key = "openjpa." + val.getProperty(); } } Object external = val.isHidden() ? Value.INVISIBLE : val instanceof ObjectValue ? val.getString() : val.get(); map.put(key, external); }
/** * Set this value as an object. * <br> * If this Value is being set to a non-default value for the first time * (as designated by <code>originalString</code> being null), then the * value is remembered as <em>original</em>. This original value is used * for equality and hashCode computation if this Value is * {@link #isDynamic() dynamic}. * */ public void setObject(Object obj) { // if setting to null set as string to get defaults into play if (obj == null && def != null) setString(null); else { try { setInternalObject(obj); if (originalValue == null && obj != null && !isDefault(obj)) { originalValue = getString(); } } catch (ParseException pe) { throw pe; } catch (RuntimeException re) { throw new ParseException(prop + ": " + obj, re); } } }
if (o instanceof String) { if ((!Objects.equals((String) o, val.getString())) && (!Objects.equals((String) o, Value.INVISIBLE))) val.setString((String) o); } else { ser &= o instanceof Serializable; val.setObject(o); Configurations.removeProperty(val.getProperty(), remaining);
/** * Unalias the given setting. */ public String unalias(String str) { return unalias(str, aliases, false); }
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, _props) || val.getDefault() == null || !val.getDefault().equals(newString)) setValue(_props, val); } }
final Object[] params; String alias = val.alias(clsName); String[] aliases = val.getAliases(); String[] keys; if (aliases.length == 0) if (keys.length == 0) { msg = "invalid-plugin"; params = new Object[]{ val.getProperty(), alias, e.toString(), }; } else if ((closest = StringDistance.getClosestLevenshteinDistance (alias, keys, 0.5f)) == null) { msg = "invalid-plugin-aliases"; params = new Object[]{ val.getProperty(), alias, e.toString(), new TreeSet(Arrays.asList(keys)), }; } else { msg = "invalid-plugin-aliases-hint"; params = new Object[]{ val.getProperty(), alias, e.toString(), new TreeSet(Arrays.asList(keys)), closest, };
String prop = val.getProperty(); prop = prop.substring(prop.lastIndexOf('.') + 1); pd.setDisplayName(findLocalized(prop + "-name", true, val.getScope())); pd.setShortDescription(findLocalized(prop + "-desc", true, val.getScope())); pd.setExpert("true".equals(findLocalized(prop + "-expert", false, val.getScope()))); String type = findLocalized(prop + "-type", true, val.getScope()); if (type != null) pd.setValue(ATTRIBUTE_TYPE, type); String cat = findLocalized(prop + "-cat", false, val.getScope()); if (cat != null) pd.setValue(ATTRIBUTE_CATEGORY, cat); val.getScope()); if (order != null) pd.setValue(ATTRIBUTE_ORDER, order); if (val.getAliases() != null) { aliases = Arrays.asList(val.getAliases()); for (int i = 0; i < aliases.size(); i += 2) allowed.add(aliases.get(i)); + "-values", false, val.getScope()), ",", 0); for (int i = 0; i < vals.length; i++) if (!aliases.contains(vals[i]))
/** * Performs an equality check based on equality of values. * {@link Value#equals(Object) Equality} of Values varies if the Value is * {@link Value#isDynamic() dynamic}. */ 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; }
str = val.getString(); if ((str != null && (storeDefaults || !str.equals(val.getDefault())))) setValue(clone, val);
public void valueChanged(Value val) { if (val != null && val.matches("DataCacheTimeout")) { _cacheTimeout = Integer.MIN_VALUE; } }
/** * Gets the original value. Original value denotes the Stringified form of * this Value, from which it has been set, if ever. If this Value has never * been set to a non-default value, then returns the default value, which * itself can be null. * * @since 1.1.0 */ public String getOriginalValue() { return (originalValue == null) ? getDefault() : originalValue; }
/** * @return the cluster */ public Cluster getCluster() { if (cluster != null) { return cluster; } String clusterName = getValue(CLUSTER_NAME_PROP).getString(); String clusterConnection = getValue(HOST_LIST_PROP).getString(); cluster = HFactory.getOrCreateCluster(clusterName, new CassandraHostConfigurator(clusterConnection)); return cluster; }
/** * Alias the given setting. */ public String alias(String str) { return alias(str, aliases, false); }
/** * Get the serializer configured * * @return */ public EmbeddedSerializer getSerializer() { if (serializer != null) { return serializer; } String className = getValue(SERIALIZER_PROP).getOriginalValue(); try { serializer = (EmbeddedSerializer) createInstance(className, JavaSerializer.class.getName()); } catch (Exception e) { throw new UserException(String.format( "Unable to load class '%s' as an instance of %s", className, EmbeddedSerializer.class), e); } return serializer; }
/** * Adds <code>o</code> to <code>map</code> under key for <code>val</code>. * Use this method instead of attempting to add the value directly because * this will account for the property prefix. */ private void setValue(Map map, Value val) { Object key = val.getLoadKey(); if (key == null) { List<String> keys = val.getPropertyKeys(); for (String k : keys) { if (hasKnownPrefix(k)) { key = k; break; } } if (key == null) { key = "openjpa." + val.getProperty(); } } Object external = val.isHidden() ? Value.INVISIBLE : val instanceof ObjectValue ? val.getString() : val.get(); map.put(key, external); }