@Override
 public synchronized void setEnabled(String uid, boolean isEnabled) {
   ruleEngine.setRuleEnabled(uid, isEnabled);
   if (disabledRulesStorage != null)
     if (isEnabled) {
       disabledRulesStorage.remove(uid);
     } else {
       disabledRulesStorage.put(uid, isEnabled);
     }
 }
 protected void setDisabledRuleStorage(Storage<Boolean> disabledRulesStorage) {
   this.disabledRulesStorage = disabledRulesStorage;
   for (Rule rule : ruleEngine.getRules()) {
     String uid = rule.getUID();
     if (ruleEngine.getRuleStatus(uid).equals(RuleStatus.DISABLED)) {
       disabledRulesStorage.put(uid, false);
     } else {
       disabledRulesStorage.remove(uid);
     }
   }
 }
 @Override
 public Boolean isEnabled(String ruleUID) {
   if (disabledRulesStorage != null && disabledRulesStorage.get(ruleUID) != null) {
     return Boolean.FALSE;
   }
   return ruleEngine.hasRule(ruleUID)
       ? !ruleEngine.getRuleStatus(ruleUID).equals(RuleStatus.DISABLED)
       : null;
 }
 @Override
 public synchronized Rule remove(String key) {
   Rule rule = super.remove(key);
   if (ruleEngine.removeRule(key)) {
     postEvent(RuleEventFactory.createRuleRemovedEvent(rule, SOURCE));
   }
   if (disabledRulesStorage != null) {
     disabledRulesStorage.remove(key);
   }
   return rule;
 }
 @Override
 public synchronized Rule update(Rule element) {
   Rule old = null;
   if (element != null) {
     old = super.update(element); // update storage with new rule and return old rule
     if (old != null) {
       postEvent(RuleEventFactory.createRuleUpdatedEvent(element, old, SOURCE));
       String rUID = element.getUID();
       if (disabledRulesStorage != null && disabledRulesStorage.get(rUID) != null) {
         ruleEngine.setRuleEnabled(rUID, false);
       }
       ruleEngine.updateRule(element); // update memory map
     }
   }
   return old;
 }
 @Override
 protected synchronized void removeProvider(Provider<Rule> provider) {
   Collection<Rule> rules = provider.getAll();
   for (Iterator<Rule> it = rules.iterator(); it.hasNext(); ) {
     Rule rule = it.next();
     String uid = rule.getUID();
     if (ruleEngine.removeRule(uid)) {
       postEvent(RuleEventFactory.createRuleRemovedEvent(rule, SOURCE));
     }
     if (disabledRulesStorage != null) {
       disabledRulesStorage.remove(uid);
     }
   }
   if (provider instanceof ManagedRuleProvider) {
     hasManagedRuleProvider = false;
   }
   super.removeProvider(provider);
 }
 @Override
 public synchronized void add(Rule element) {
   if (element == null) {
     throw new IllegalArgumentException("The added rule must not be null!");
   }
   String rUID = element.getUID();
   if (!hasManagedRuleProvider) {
     throw new IllegalStateException(
         "ManagedProvider is not available. The rule '"
             + (rUID != null ? rUID : element)
             + "' can't be added!");
   }
   Rule ruleToPersist;
   if (rUID != null && disabledRulesStorage != null && disabledRulesStorage.get(rUID) != null) {
     ruleToPersist = ruleEngine.addRule(element, false);
   } else {
     ruleToPersist = ruleEngine.addRule(element, true);
   }
   super.add(ruleToPersist);
   postEvent(RuleEventFactory.createRuleAddedEvent(ruleToPersist, SOURCE));
 }
 @Override
 protected synchronized void addProvider(Provider<Rule> provider) {
   if (provider instanceof ManagedRuleProvider) {
     hasManagedRuleProvider = true;
   }
   Collection<Rule> rules = provider.getAll();
   for (Iterator<Rule> it = rules.iterator(); it.hasNext(); ) {
     Rule rule = it.next();
     try {
       String rUID = rule.getUID();
       if (rUID != null
           && disabledRulesStorage != null
           && disabledRulesStorage.get(rUID) != null) {
         ruleEngine.addRule(rule, false);
       } else {
         ruleEngine.addRule(rule, true);
       }
     } catch (Exception e) {
       logger.error(
           "Can't add rule: " + rule.getUID() + " into rule engine from provider " + provider, e);
     }
   }
   super.addProvider(provider);
 }