private static <T extends TemplatableXBean> void addDependency(final T item, final LinkedHashMap<String, T> result, final Map<String, T> map) { if (!result.containsKey(item.getName())) { if (item.hasParent()) { final T parent = map.get(item.getParent()); if (parent == null) { throw new ConfigurationException("Template named \"" + item.getParent() + "\" not found"); } addDependency(parent, result, map); } result.put(item.getName(), item); } }
public boolean isInstantiatable() { return !isTemplate(); }
public static <T extends TemplatableXBean> void applyTemplate(final T target, final LinkedHashMap<String, T> xbeans) { if (!target.hasParent()) { return; } try { final T parent = xbeans.get(target.getParent()); @SuppressWarnings("unchecked") final Map<String, Object> templateProperties = PropertyUtils.describe(parent); templateProperties.remove("name"); templateProperties.remove("template"); @SuppressWarnings("unchecked") final Map<String, Object> targetProperties = PropertyUtils.describe(target); for (final Entry<String, Object> entry : targetProperties.entrySet()) { if (entry.getValue() == null) { final Object templateValue = templateProperties.get(entry.getKey()); if (templateValue != null) { if (PropertyUtils.isWriteable(target, entry.getKey())) { PropertyUtils.setProperty(target, entry.getKey(), templateValue); } } } } } catch (final InvocationTargetException e) { throw new ConfigurationException(e); } catch (final IllegalAccessException e) { throw new ConfigurationException(e); } catch (final NoSuchMethodException e) { throw new ConfigurationException(e); } }
@Override protected void validate() { super.validate(); if (isInstantiatable()) { greaterThanZero(this, "interval", getInterval()); } } }
public static <T extends TemplatableXBean> void applyTemplate(final T target, final LinkedHashMap<String, T> xbeans) { if (!target.hasParent()) { return; } try { final T parent = xbeans.get(target.getParent()); @SuppressWarnings("unchecked") final Map<String, Object> templateProperties = PropertyUtils.describe(parent); templateProperties.remove("name"); templateProperties.remove("template"); @SuppressWarnings("unchecked") final Map<String, Object> targetProperties = PropertyUtils.describe(target); for (final Entry<String, Object> entry : targetProperties.entrySet()) { if (entry.getValue() == null) { final Object templateValue = templateProperties.get(entry.getKey()); if (templateValue != null) { if (PropertyUtils.isWriteable(target, entry.getKey())) { PropertyUtils.setProperty(target, entry.getKey(), templateValue); } } } } } catch (final InvocationTargetException e) { throw new ConfigurationException(e); } catch (final IllegalAccessException e) { throw new ConfigurationException(e); } catch (final NoSuchMethodException e) { throw new ConfigurationException(e); } }
@Override protected void validate() { super.validate(); if (isInstantiatable()) { greaterThanZero(this, "interval", getInterval()); } } }
private static <T extends TemplatableXBean> void addDependency(final T item, final LinkedHashMap<String, T> result, final Map<String, T> map) { if (!result.containsKey(item.getName())) { if (item.hasParent()) { final T parent = map.get(item.getParent()); if (parent == null) { throw new ConfigurationException("Template named \"" + item.getParent() + "\" not found"); } addDependency(parent, result, map); } result.put(item.getName(), item); } }
public boolean isInstantiatable() { return !isTemplate(); }