Examples of DmcRuleExceptionSet


Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    /**
     * @param obj The object to be initialized
     */
    public void execute(DmcObject obj) throws DmcRuleExceptionSet {
        DmcRuleExceptionSet rc = null;
        DmcClassInfo        cI = obj.getConstructionClassInfo();
        ArrayList<InitializationIF> ruleList = super.getRules(cI);

        if (ruleList != null){
            for(InitializationIF rule: ruleList){
                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleExecuted("Applying: " + rule.getRuleTitle() + " to: " + cI.name);
                try {
                    rule.execute(obj);
                } catch (DmcRuleExceptionSet e) {
                    if (rc == null)
                        rc = e;
                    else
                        rc.add(e);
                   
                    if (DmcOmni.instance().ruleTracing())
                        DmcOmni.instance().ruleFailed(e);
                   
                    if (rc.immediateHalt())
                        throw(rc);
                }
            }
        }

        for(InitializationIF rule: globalRules){
            if (DmcOmni.instance().ruleTracing())
                DmcOmni.instance().ruleExecuted("Applying global: " + rule.getRuleTitle() + " to: " + cI.name);
            try {
                rule.execute(obj);
            } catch (DmcRuleExceptionSet e) {
                if (rc == null)
                    rc = e;
                else
                    rc.add(e);

                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleFailed(e);

                 if (rc.immediateHalt())
                    throw(rc);
            }
        }
        if (rc != null)
            throw(rc);
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    /**
     * @param obj The object in which the attribute exists
     * @param attribute The attribute to be validated
     */
    public void execute(DmcObject obj, DmcAttribute<?> attribute) throws DmcRuleExceptionSet {
        DmcRuleExceptionSet rc = null;
        DmcAttributeInfo    aI = attribute.getAttributeInfo();
        DmcClassInfo        cI = obj.getConstructionClassInfo();
        ArrayList<AttributeValidationIF> ruleList = super.getRules(aI,cI);

        if (ruleList != null){
            for(AttributeValidationIF rule: ruleList){
                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleExecuted("Applying: " + rule.getRuleTitle() + " to: " + cI.name + "." + aI.name);
                try {
                    rule.execute(obj, attribute);
                } catch (DmcRuleExceptionSet e) {
                    if (rc == null)
                        rc = e;
                    else
                        rc.add(e);
                   
                    if (DmcOmni.instance().ruleTracing())
                        DmcOmni.instance().ruleFailed(e);
                   
                    if (rc.immediateHalt())
                        throw(rc);
                }
            }
        }

        ruleList = globalRules.get(aI);
        if (ruleList != null){
            for(AttributeValidationIF rule: ruleList){
                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleExecuted("Applying global: " + rule.getRuleTitle() + " to: " + cI.name + "." + aI.name);
                try {
                    rule.execute(obj, attribute);
                } catch (DmcRuleExceptionSet e) {
                    if (rc == null)
                        rc = e;
                    else
                        rc.add(e);
                   
                    if (DmcOmni.instance().ruleTracing())
                        DmcOmni.instance().ruleFailed(e);
                   
                    if (rc.immediateHalt())
                        throw(rc);
                }
            }
        }
        if (rc != null)
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    /**
     * @param obj The object to be validated:
     */
    public void execute(DmcUncheckedObject obj) throws DmcRuleExceptionSet {
        DmcRuleExceptionSet rc = null;
        DmcClassInfo        cI = DmcOmni.instance().getClassInfo(obj.getConstructionClass());
        ArrayList<UCOValidationIF> ruleList = super.getRules(cI);

        if (ruleList != null){
            for(UCOValidationIF rule: ruleList){
                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleExecuted("Applying: " + rule.getRuleTitle() + " to: " + cI.name);
                try {
                    rule.execute(obj);
                } catch (DmcRuleExceptionSet e) {
                    if (rc == null)
                        rc = e;
                    else
                        rc.add(e);
                   
                    if (DmcOmni.instance().ruleTracing())
                        DmcOmni.instance().ruleFailed(e);
                   
                    if (rc.immediateHalt())
                        throw(rc);
                }
            }
        }

        for(UCOValidationIF rule: globalRules){
            if (DmcOmni.instance().ruleTracing())
                DmcOmni.instance().ruleExecuted("Applying global: " + rule.getRuleTitle() + " to: " + cI.name);
            try {
                rule.execute(obj);
            } catch (DmcRuleExceptionSet e) {
                if (rc == null)
                    rc = e;
                else
                    rc.add(e);

                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleFailed(e);

                 if (rc.immediateHalt())
                    throw(rc);
            }
        }
        if (rc != null)
            throw(rc);
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    /**
     * @param obj The object to be validated
     */
    public void execute(DmcObject obj) throws DmcRuleExceptionSet {
        DmcRuleExceptionSet rc = null;
        DmcClassInfo        cI = obj.getConstructionClassInfo();
        ArrayList<ObjectValidationIF> ruleList = super.getRules(cI);

        if (ruleList != null){
            for(ObjectValidationIF rule: ruleList){
                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleExecuted("Applying: " + rule.getRuleTitle() + " to: " + cI.name);
                try {
                    rule.execute(obj);
                } catch (DmcRuleExceptionSet e) {
                    if (rc == null)
                        rc = e;
                    else
                        rc.add(e);
                   
                    if (DmcOmni.instance().ruleTracing())
                        DmcOmni.instance().ruleFailed(e);
                   
                    if (rc.immediateHalt())
                        throw(rc);
                }
            }
        }

        for(ObjectValidationIF rule: globalRules){
            if (DmcOmni.instance().ruleTracing())
                DmcOmni.instance().ruleExecuted("Applying global: " + rule.getRuleTitle() + " to: " + cI.name);
            try {
                rule.execute(obj);
            } catch (DmcRuleExceptionSet e) {
                if (rc == null)
                    rc = e;
                else
                    rc.add(e);

                if (DmcOmni.instance().ruleTracing())
                    DmcOmni.instance().ruleFailed(e);

                 if (rc.immediateHalt())
                    throw(rc);
            }
        }
        if (rc != null)
            throw(rc);
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

   * Executes the attribute validation rules for the specified object.
   * @param obj the object whose attributes need checking.
   * @throws DmcRuleExceptionSet
   */
  public void executeAttributeValidation(DmcObject obj) throws DmcRuleExceptionSet {
    DmcRuleExceptionSet rc = null;
   
    Iterator<DmcAttribute<?>> attrs = obj.getAttributeIterator();
    while(attrs.hasNext()){
      try {
        attributeValidators.execute(obj, attrs.next());
      } catch (DmcRuleExceptionSet e) {
        if (rc == null)
          rc = e;
        else
          rc.add(e);
       
        if (rc.immediateHalt())
          break;
      }
    }
   
    if (rc != null)
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

   
    return(rc);
  }
 
  public void loadAndCheckRules(SchemaManager sm, SchemaDefinition sd) throws DmcRuleExceptionSet {
    DmcRuleExceptionSet    rc       = null;
      DmoObjectFactory     dmofactory   = new DmoObjectFactory(sm);
      ArrayList<RuleDataDMO>  allRuleData = new ArrayList<RuleDataDMO>();
      ArrayList<RuleIF>    allRules   = new ArrayList<RuleIF>();
     
    Iterator<SchemaDefinition> schemas = sm.getSchemas();
    if (schemas != null){
      while(schemas.hasNext()){
        SchemaDefinition curr = schemas.next();
       
            Iterator<DmcUncheckedObject> ucoIT = curr.getParsedRules();
            if (ucoIT != null){
          while(ucoIT.hasNext()){
            DmcUncheckedObject   uco = ucoIT.next();
            ClassDefinition   ruleDataCD   = sm.cdef(uco.getConstructionClass());
            RuleDefinition    ruleDEF    = ruleDataCD.getRuleDefinition();
            RuleDataDMO     ruledata  = null;
            SourceInfo      source    = getSource(uco);
           
            try{
              ruledata = (RuleDataDMO) dmofactory.createObject(uco);
//              DebugInfo.debug("Parsed and instantiated:\n\n" + ruledata.toOIF());
            }
            catch(ClassNotFoundException cnf){
              // This may be thrown from TypeDefinition when trying to instantiate a
              // holder for an attribute. This would likely result from not having
              // the compiled output of a previous code generation run specified on
              // the class path for the dmogen call that's checking the rules
              StringBuffer sb = new StringBuffer();
              sb.append(cnf.getMessage() + "\n\n");
              sb.append("You probably need to augment the following classpath:\n");
              ClassLoader cl = ClassLoader.getSystemClassLoader();
                  URL[] urls = ((URLClassLoader)cl).getURLs();
                  for(URL url: urls){
                    sb.append(url.getFile() + "\n");
                  }
                  sb.append("\nwith the classpath info for the missing class.");

              DmcRuleException ex = new DmcRuleException(sb.toString(), null);
              ex.source(source);
             
              if (rc == null)
                rc = new DmcRuleExceptionSet();
              rc.add(ex);
             
              // This is a show stopper, so just fire it now.
              throw(rc);
            }
            catch(DmcValueException dve){
              // If a value for an attribute doesn't pass the basic tests, we'll
              // get one of these, just repackage it as a rule exception
              DmcRuleException ex = new DmcRuleException(dve.getMessage(), null);
              ex.source(source);

              if (rc == null)
                rc = new DmcRuleExceptionSet();
              rc.add(ex);             
            }
            catch(ResultException rex){
              // If we can't find a class or attribute, we'll get one of these
              DmcRuleException ex = new DmcRuleException(rex.getMessage(), null);
              ex.source(source);

              if (rc == null)
                rc = new DmcRuleExceptionSet();
              rc.add(ex)
             
//              System.err.println(ex.toString());
            }
           
            if (ruledata == null)
              continue;
           
            try{
              ruledata.resolveReferences(sm);
            }
            catch(DmcValueExceptionSet ex){
              System.err.println(ex.toString() + "\nFile: " + ruledata.getFile() + "  Line: " + ruledata.getLineNumber());
            }
             
            try{
              DynamicInitIF rule = (DynamicInitIF) ruleDEF.newRuleInstance();
              rule.setRuleData(ruledata);
             
              allRuleData.add(ruledata);
             
//              addThisRule((RuleIF) rule);
              allRules.add((RuleIF) rule);
            }
            catch(Exception ex){
              System.err.println(ex.toString());
            }
          }
            }
      }
     
      DmcOmni.instance().reset();
      schemas = sm.getSchemas();
      while(schemas.hasNext()){
        SchemaDefinition curr = schemas.next();
        DmcOmni.instance().addCompactSchema(curr.getCompactSchema());
      }
     
      // We add the rules after we've reinitialized the DmcOmni so that we can resolve
      // applyToClass information.
      for(RuleIF rule: allRules)
        addThisRule(rule);
     
      DebugInfo.debug("*** ALL RULE COLLECTIONS ***\n\n" + this.toString());
     
//      DebugInfo.debug("\n\n*** RULE TRACING DISABLED ***\n\n");
      DmcOmni.instance().ruleTracer(new ConsoleRuleTracer());
      DmcOmni.instance().ruleTracing(true);
     
      for(RuleDataDMO rule: allRuleData){
        SourceInfo source = new SourceInfo(rule.getFile(), rule.getLineNumber()+"", rule);
       
//        if (rule.getRuleName().equals("dmtSvNumericRange")){
//          DebugInfo.debug("HERE");
//        }
       
        try {
          this.executeAttributeValidation(rule);
         
          this.executeObjectValidation(rule);
        } catch (DmcRuleExceptionSet e) {
          e.source(source);
          if (rc == null)
            rc = e;
          else
            rc.add(e);
//          System.err.println(e.toString());
        }
      }
     
//      DebugInfo.debug(this.toString());
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

   * Executes the attribute validation rules for the specified object.
   * @param obj the object whose attributes need checking.
   * @throws DmcRuleExceptionSet
   */
  public void executeAttributeValidation(DmcObject obj) throws DmcRuleExceptionSet {
    DmcRuleExceptionSet rc = null;
   
    Iterator<DmcAttribute<?>> attrs = obj.getAttributeIterator();
    while(attrs.hasNext()){
      try {
        attributeValidators.execute(obj, attrs.next());
      } catch (DmcRuleExceptionSet e) {
        if (rc == null)
          rc = e;
        else
          rc.add(e);
       
        if (rc.immediateHalt())
          break;
      }
    }
   
    if (rc != null)
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    super(dmo);
  }

  @Override
  public void execute(DmcObject obj) throws DmcRuleExceptionSet {
    DmcRuleExceptionSet rc = null;
   
    DmcAttribute<?>  boa = obj.get(ruleDMO.getBasedOnAttribute().getObjectName().getNameString());
    if (boa != null){
      String value = boa.getSV().toString();
     
      if (ruleDMO.basedOnValueContains(value)){
        if (ruleDMO.getExcludeThisAttributeSize() > 0){
          Iterator<AttributeDefinitionREF> refs = ruleDMO.getExcludeThisAttributeREFs();
          while(refs.hasNext()){
            DmcAttributeInfo ai = DmcOmni.instance().getAttributeInfo(refs.next().getObjectName().getNameString());
            if (obj.get(ai) != null){
              if (rc == null)
                rc = new DmcRuleExceptionSet();
              rc.add(new DmcRuleException(ruleDMO.getRuleTitle() + "\nCan't have: " + ai.name, this));
            }
          }
        }
        if (ruleDMO.getIncludeThisAttributeSize() > 0){
          Iterator<AttributeDefinitionREF> refs = ruleDMO.getIncludeThisAttributeREFs();
          while(refs.hasNext()){
            DmcAttributeInfo ai = DmcOmni.instance().getAttributeInfo(refs.next().getObjectName().getNameString());
            if (obj.get(ai) == null){
              if (rc == null)
                rc = new DmcRuleExceptionSet();
              rc.add(new DmcRuleException(ruleDMO.getRuleTitle() + "\nMust have: " + ai.name, this));
            }
          }
         
        }
      }
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

    super(dmo);
  }

  @Override
  public void execute(DmcObject obj, DmcAttribute<?> attribute) throws DmcRuleExceptionSet {
    DmcRuleExceptionSet rc = null;
   
    // The attribute passed here will always be an AttributeDefinition reference; this
    // is enforced by rules. We just have to handle things differently for single versus
    // multi-valued attributes.
   
    if (attribute.getAttributeInfo().valueType == ValueTypeEnum.SINGLE){
      DmcTypeAttributeDefinitionREFSV refsv = (DmcTypeAttributeDefinitionREFSV) attribute;
      AttributeDefinitionREF ref = refsv.getSV();
     
      try {
        checkReferencedAttribute(obj, attribute, ref.getObjectName().getNameString());
      } catch (DmcRuleException e) {
        rc = new DmcRuleExceptionSet();
        rc.add(e);
      }
    }
    else{
      for(int i=0; i<attribute.getMVSize(); i++){
        AttributeDefinitionREF ref = (AttributeDefinitionREF) attribute.getMVnth(i);
       
        try {
          checkReferencedAttribute(obj, attribute, ref.getObjectName().getNameString());
        } catch (DmcRuleException e) {
          if (rc == null)
            rc = new DmcRuleExceptionSet();
          rc.add(e);
        }
       
      }
    }
   
View Full Code Here

Examples of org.dmd.dmc.rules.DmcRuleExceptionSet

        found++;
    }
   
    if (found == 0){
      // We haven't found any of the attributes - complain
      DmcRuleExceptionSet ex = new DmcRuleExceptionSet();
      possibilities = ruleDMO.getOnePossibility();
     
      ex.add(new DmcRuleException("The object must include at least one of these attributes: " + getPossibilities(), this));
      throw(ex);
    }
    else{
      // We've found at least one, but check if we only want one.
      if (ruleDMO.isAndOnlyOne() && (found>1)){
        DmcRuleExceptionSet ex = new DmcRuleExceptionSet();
        possibilities = ruleDMO.getOnePossibility();
       
        ex.add(new DmcRuleException("The object must include only one of these attributes: " + getPossibilities(), this));
        throw(ex);
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.