/** * Gets an instance of the {@link IssueCategoryRegistry} from a {@link Context}. Note that the context variable * used might vary depending upon how this class is being used. * * In some cases, the Context might be a part of the {@link RuleLoaderContext}, so that this registry can be used * during rule initialization. In other cases, it may be the {@link GraphRewrite} event's context. */ public static IssueCategoryRegistry instance(Context context) { IssueCategoryRegistry registry = (IssueCategoryRegistry) context.get(IssueCategoryRegistry.class); if (registry == null) { registry = new IssueCategoryRegistry(); context.put(IssueCategoryRegistry.class, registry); } return registry; }
/** * Specify additional meta-data to individual {@link Rule} instances originating from the corresponding {@link RuleProvider} instance. */ public static void enhanceRuleMetadata(RuleProvider provider, Rule rule) { if (rule instanceof Context) { Context context = (Context) rule; if (!context.containsKey(RuleMetadataType.ORIGIN)) context.put(RuleMetadataType.ORIGIN, provider.getMetadata().getOrigin()); if (!context.containsKey(RuleMetadataType.RULE_PROVIDER)) context.put(RuleMetadataType.RULE_PROVIDER, provider); if (!context.containsKey(RuleMetadataType.TAGS)) context.put(RuleMetadataType.TAGS, provider.getMetadata().getTags()); } }
@Override public void clear() { if (wrapped instanceof Context) { ((Context) wrapped).clear();; } contextMap.clear();; }
@Override public Object get(Object key) { if (wrapped instanceof Context) { return ((Context) wrapped).get(key); } return contextMap.get(key); }
@Override public void put(Object key, Object value) { if (wrapped instanceof Context) { ((Context) wrapped).put(key, value); } contextMap.put(key, value); }
if (originalRule instanceof Context && ((Context) originalRule).containsKey(RuleMetadataType.RULE_XML)) return (String) ((Context) originalRule).get(RuleMetadataType.RULE_XML);
@Override public boolean containsKey(Object key) { if (wrapped instanceof Context) { return ((Context) wrapped).containsKey(key); } return contextMap.containsKey(key); }
@Override public Object get(Object key) { if (wrapped instanceof Context) { return ((Context) wrapped).get(key); } return contextMap.get(key); }
@Override public void put(Object key, Object value) { if (wrapped instanceof Context) { ((Context) wrapped).put(key, value); } contextMap.put(key, value); }
if (originalRule instanceof Context && ((Context) originalRule).containsKey(RuleMetadataType.RULE_XML)) return (String) ((Context) originalRule).get(RuleMetadataType.RULE_XML);
@Override public boolean containsKey(Object key) { if (wrapped instanceof Context) { return ((Context) wrapped).containsKey(key); } return contextMap.containsKey(key); }
/** * Gets an instance of the {@link IssueCategoryRegistry} from a {@link Context}. Note that the context variable * used might vary depending upon how this class is being used. * * In some cases, the Context might be a part of the {@link RuleLoaderContext}, so that this registry can be used * during rule initialization. In other cases, it may be the {@link GraphRewrite} event's context. */ public static IssueCategoryRegistry instance(Context context) { IssueCategoryRegistry registry = (IssueCategoryRegistry) context.get(IssueCategoryRegistry.class); if (registry == null) { registry = new IssueCategoryRegistry(); context.put(IssueCategoryRegistry.class, registry); } return registry; }
/** * Gets the current instance of {@link RuleProviderRegistry}. */ public static RuleProviderRegistry instance(GraphRewrite event) { RuleProviderRegistry instance = (RuleProviderRegistry) event.getRewriteContext().get(RuleProviderRegistry.class); return instance; }
@Override public void beforeExecution(GraphRewrite event) { ruleExecutionInformation.clear(); this.event = event; event.getRewriteContext().put(RuleExecutionResultsListener.class, this); event.getGraphContext().registerGraphListener(new RuleExecutionGraphListener()); }
try AbstractRuleProvider ruleProvider = (AbstractRuleProvider) ruleContext.get(RuleMetadataType.RULE_PROVIDER); if (ruleProvider != null && ruleProvider.getMetadata() != null && ruleProvider.getMetadata().isDisabled()) if (ruleContext != null && ruleContext.containsKey(RuleMetadataType.AUTO_COMMIT)) autocommit = (Boolean) ruleContext.get(RuleMetadataType.AUTO_COMMIT); if (ruleContext != null) Object origin = ruleContext.get(RuleMetadataType.ORIGIN); if (origin != null) exMsg += System.lineSeparator()+" From: " + origin; Object location = ruleContext.get(org.ocpsoft.rewrite.config.RuleMetadata.PROVIDER_LOCATION); if (location != null) exMsg += System.lineSeparator()+" Defined in: " + location; AbstractRuleProvider ruleProvider = (AbstractRuleProvider) ruleContext.get(RuleMetadataType.RULE_PROVIDER); boolean halt = alwaysHaltOnFailure || ruleProvider.getMetadata().isHaltOnException(); Object halt_ = ruleContext.get(RuleMetadataType.HALT_ON_EXCEPTION); halt |= (halt_ instanceof Boolean && ((Boolean) halt_).booleanValue()); if (halt)
/** * Specify additional meta-data to individual {@link Rule} instances originating from the corresponding {@link RuleProvider} instance. */ public static void enhanceRuleMetadata(RuleProvider provider, Rule rule) { if (rule instanceof Context) { Context context = (Context) rule; if (!context.containsKey(RuleMetadataType.ORIGIN)) context.put(RuleMetadataType.ORIGIN, provider.getMetadata().getOrigin()); if (!context.containsKey(RuleMetadataType.RULE_PROVIDER)) context.put(RuleMetadataType.RULE_PROVIDER, provider); if (!context.containsKey(RuleMetadataType.TAGS)) context.put(RuleMetadataType.TAGS, provider.getMetadata().getTags()); } }
@Override public void clear() { if (wrapped instanceof Context) { ((Context) wrapped).clear();; } contextMap.clear();; }
private void setDefaultLocation(Rule rule) { if (rule instanceof Context) { Throwable throwable = new Throwable().fillInStackTrace(); StackTraceElement[] trace = throwable.getStackTrace(); StackTraceElement location = null; for (StackTraceElement element : trace) { if (!element.getClassName().startsWith("org.ocpsoft.rewrite.config")) { location = element; break; } } if (location != null && ((Context) rule).get(RuleMetadata.PROVIDER_LOCATION) == null) { ((Context) rule).put(RuleMetadata.PROVIDER_LOCATION, location.toString()); } } }
/** * Returns the {@link RuleExecutionResultsListener} for this execution of Windup. */ public static RuleExecutionResultsListener instance(GraphRewrite event) { return (RuleExecutionResultsListener) event.getRewriteContext().get(RuleExecutionResultsListener.class); }
Rule rule = StringUtils.isNotBlank(id) ? mappingTo.withId(id) : mappingTo; if (rule instanceof Context) ((Context) rule).put(RuleMetadataType.RULE_XML, XmlUtil.nodeToString(element)); context.getBuilder().addRule(rule); return null;