public void setProperties(Collection<Property> props) { for (Property newProp : props) { addProperty(newProp); } }
protected C getChild(C kid) { for (C child : children) { if (child.equals(kid)) { return child; } } return null; }
public void addConfiguration(Configuration config) { setProperties(config.getProperties()); }
public EasyWrap<C> property(String name, Object value) { this.config.setProperty(name, value); return this; }
public void addConfiguration(CompoundConfiguration<C> config) { // add config's children to our own setChildren(config.getChildren()); // add config's properties to ours super.addConfiguration(config); }
@Override public int hashCode() { // add the super's and the kid's return super.hashCode() + children.hashCode(); }
public boolean removeProperty(String name) { Property prop = getProperty(name); return properties.remove(prop); }
public void cleanProperties(Configuration config) { // go thru properties to log and remove debug ones Iterator<Property> i = config.getProperties().iterator(); while (i.hasNext()) { Property prop = i.next(); try { prop.validate(); } catch (ConfigurationException ce) { if (LOG != null) { LOG.debug("ConfigurationCleaner : ", ce); LOG.warn("ConfigurationCleaner : Removing {}", prop); } i.remove(); } } }
protected void appendProperties(StringBuilder out) { if (hasProperties()) { out.append("with "); out.append(properties.size()); out.append(" properties ["); for (Property prop : properties) { out.append(prop.getKey()); out.append(" -"); out.append(prop.getType()); out.append("-> "); out.append(prop.getValue()); out.append("; "); } out.append("]"); } }
public void setPropertyMap(Map<String,Object> props) { for (Map.Entry<String,Object> entry : props.entrySet()) { setProperty(entry.getKey(), entry.getValue()); } }
protected void addChild(C newKid) { // check if we already have a matching child C child = getChild(newKid); if (child != null) { // compound children can just have the new props and kids // added to the old ones, we don't need to replace the old if (child instanceof CompoundConfiguration) { ((CompoundConfiguration)child) .addConfiguration((CompoundConfiguration)newKid); } else { // add newKid's values to childs (overwriting any dupes) child.addConfiguration(newKid); } } else { // simply adopt the new kid children.add(newKid); } }
@Override public int hashCode() { if (getKey() == null) { return super.hashCode(); } return getKey().hashCode(); }
@Override public void validate() { super.validate(); // make sure the key is not null if (getKey() == null) { throw new NullKeyException(this); } Status status = getStatus(); switch (status) { case VALID: break; default: throw new ConfigurationException(this, getError(status)); } }
public void begin(String namespace, String element, Attributes attributes) throws Exception { Configuration config = (Configuration)getDigester().peek(); for (int i=0; i < attributes.getLength(); i++) { String name = attributes.getLocalName(i); if ("".equals(name)) { name = attributes.getQName(i); } // don't treat "class" as a property if (!"class".equals(name)) { String value = attributes.getValue(i); config.setProperty(name, value); } } } }
@Override public boolean equals(Object obj) { // must be of this type and have super.equals() be true if (!(obj instanceof CompoundConfiguration) || !super.equals(obj)) { return false; } else { // they're of the same type CompoundConfiguration<C> that = (CompoundConfiguration<C>)obj; // if their children are equal, they're equal return this.children.equals(that.children); } }
@Override public void addConfiguration(Configuration config) { // copy properties super.addConfiguration(config); // copy values specific to tool configs if (config instanceof ToolConfiguration) { ToolConfiguration that = (ToolConfiguration)config; if (that.getClassname() != null) { setClassname(that.getClassname()); } if (that.getRestrictTo() != null) { setRestrictTo(that.getRestrictTo()); } } }
public void setProperty(String name, Object value) { if (name == null) { throw new NullPointerException("Property name cannot be null"); } Property prop = new Property(); prop.setName(name); prop.setValue(value); addProperty(prop); }
protected void readProperties(ExtProperties configProps, Configuration config) { ExtProperties properties = configProps.subset("property"); if (properties != null) { for (Iterator i = properties.getKeys(); i.hasNext(); ) { String name = (String)i.next(); String value = properties.getString(name); ExtProperties propProps = properties.subset(name); if (propProps.size() == 1) { // then set this as a 'simple' property config.setProperty(name, value); } else { // add it as a convertable property Property property = new Property(); property.setName(name); property.setValue(value); // set the type/converter properties setProperties(propProps, property); } } } }
@Override public boolean equals(Object obj) { if (getKey() == null || !(obj instanceof ToolConfiguration)) { return super.equals(obj); } return getKey().equals(((ToolConfiguration)obj).getKey()); }