ToolConfiguration localizationTool = new ToolConfiguration(); localizationTool.setClassname(LocalizationTool.class.getName()); localizationTool.setProperty(ToolContext.LOCALE_KEY, systemLocale); localizationTool.setProperty(LocalizationTool.BUNDLES_KEY, "messages");
private void digForDependencies(Class clazz) { clazz.getDeclaredMethods(); clazz.getDeclaredFields(); Class superClass = clazz.getSuperclass(); if (superClass != null) { digForDependencies(superClass); } }
@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 setKey(String key) { this.key = key; // ensure any non-default key is also set as a property if (key != null && !key.equals(getDefaultKey())) { setProperty(ToolContext.TOOLKEY_KEY, key); } }
ToolConfiguration tool = new ToolConfiguration(); tool.setClassname(classname); tool.setKey(key); toolbox.addTool(tool); if (!name.equals(tool.getKey())) tool.setProperty(name, toolProps.getString(name)); tool.setRestrictTo(restrictTo);
public ToolInfo createInfo() { ToolInfo info = null; Status status = getStatus(); switch (status) { case VALID: info = new ToolInfo(getKey(), getToolClass()); break; default: throw problem == null ? new ConfigurationException(this, getError(status)) : new ConfigurationException(this, getError(status), problem); } info.restrictTo(getRestrictTo()); if (getSkipSetters() != null) { info.setSkipSetters(getSkipSetters()); } // it's ok to use this here, because we know it's the // first time properties have been added to this ToolInfo Map<String,Object> properties = getPropertyMap(); // make sure key is present in properties, even for default properties properties.put(ToolContext.TOOLKEY_KEY, getKey()); info.addProperties(properties); return info; }
if (getClassname() == null) switch (getStatus()) out.append(getKey()); out.append(getClassname()); if (getRestrictTo() != null) out.append(getRestrictTo()); out.append('\''); appendProperties(out); return out.toString();
public EasyWrap tool(String key, String classname) { ToolConfiguration tool = new ToolConfiguration(); if (key != null) { tool.setKey(key); } tool.setClassname(classname); if (this.config instanceof ToolConfiguration) { ToolboxConfiguration toolbox = (ToolboxConfiguration)getParent(); toolbox.addTool(tool); return new EasyWrap(tool, toolbox); } else if (this.config instanceof ToolboxConfiguration) { ToolboxConfiguration toolbox = (ToolboxConfiguration)getConfiguration(); toolbox.addTool(tool); return new EasyWrap(tool, toolbox); } throw new IllegalStateException("Wrapping unknown "+Configuration.class.getName()+": "+getConfiguration()); } }
public void setClass(Class clazz) { setClassname(clazz.getName()); }
if (getClassname() == null) Class clazz = ClassUtils.getClass(getClassname()); digForDependencies(clazz);
if (getClassname() != null) Class clazz = getToolClass(); DefaultKey defaultKey = (DefaultKey)clazz.getAnnotation(DefaultKey.class);
for (String invalidScope : tool.getInvalidScopes()) String[] validScopes = tool.getValidScopes(); if (validScopes != null && validScopes.length > 0)
public NullKeyException(ToolConfiguration tool) { super(tool, "Key is null for tool whose class is '"+tool.getClassname()+'\''); }
/** * Returns the key set for this tool. If no key has been explicitly * set, this will return the result of {@link #getDefaultKey()}. * @return tool key */ public String getKey() { if (this.key != null) { return this.key; } return getDefaultKey(); }
addToolInfo(scope, tool.createInfo());
public InvalidScopeException(ToolboxConfiguration toolbox, ToolConfiguration tool) { super(toolbox, "Toolbox with scope '" + toolbox.getScope() + "' may not contain a " + tool.getClassname() + '.'); this.tool = tool; }
public Class getToolClass() { try { return ClassUtils.getClass(getClassname()); } catch (ClassNotFoundException cnfe) { throw new ConfigurationException(this, cnfe); } }