Examples of IRSession


Examples of com.dtrules.session.IRSession

    RulesDirectory rd = new RulesDirectory(
        System.getProperty("user.dir")+"/../sampleprojects/CHIP/", "DTRules.xml");
   
    RuleSet rs = rd.getRuleSet("CHIP");
   
    IRSession s = trace.setState(rs, t);
 
    List<IREntity> entities = trace.instancesOf("client");
   
    for(IREntity e : entities){
      System.out.println(e.getName().stringValue()+" "+e.getID());
    }
   
    TraceNode column;
    List<Integer> actions;
   
    column = trace.find(380);
    actions = column.getActions();
    System.out.print("\n"+column.attributes.get("t_num")+" ");
    for(int c : actions) System.out.print(c+" ");

    column = trace.find(419);
    actions = column.getActions();
    System.out.print("\n"+column.attributes.get("t_num")+" ");
    for(int c : actions) System.out.print(c+" ");

    column = trace.find(442);
    actions = column.getActions();
    System.out.print("\n"+column.attributes.get("t_num")+" ");
    for(int c : actions) System.out.print(c+" ");

           
    if(s==null) {
      System.out.println("Could not build a session.");
      return;
    }
   
    int edepth = s.getState().edepth();
    for(int i = 0; i < edepth; i++){
      IREntity e = s.getState().getes(i);
      System.out.println(e.getName()+" "+e.getID());
    }
   
  }
View Full Code Here

Examples of com.dtrules.session.IRSession

     * @return
     * @throws RulesException
     */
    static private IRObject compile(RuleSet ruleset, SimpleTokenizer tokenizer, String v, boolean executable, int depth) throws RulesException {       
       try{
         IRSession session  = ruleset.newSession();
           RArray   result    = new RArray(0,true,executable);
           Token    token;   
       while((token=tokenizer.nextToken())!=null){
         if(token.getType()== Token.Type.STRING) {
                          IRObject rs = RString.newRString(token.strValue);
View Full Code Here

Examples of com.dtrules.session.IRSession

            }
        }
    }
   
    private void initTables() throws RulesException {
        IRSession session = rs.newSession();
        RulesAdminService admin = new RulesAdminService(session,rs.getRulesDirectory());
        List tables = admin.getDecisionTables(rs.getName());
       
        for(Object table : tables){
            RDecisionTable dt = admin.getDecisionTable(rs.getName(),(String)table);
View Full Code Here

Examples of com.dtrules.session.IRSession

            path+"repository/",      
            "DTRules.xml");
       
        RuleSet        rs      = rd.getRuleSet("SampleProject2");
       
        IRSession      session = rs.newSession();
       
        Mapping        mapping = session.getMapping();
       
        mapping.loadData(session, path+"testfiles/"+"TestCase_001.xml");
       
        session.execute(decisionTable);
   
        printReport(session, System.out);
       
      }catch(RulesException e){
        // Should any error occur, print out the message.
View Full Code Here

Examples of com.dtrules.session.IRSession

        // factored so that all the Rules Engine State is built off of the
        // DTState object in the Session.  The Rules Engine is Thread safe,
        // so multiple threads can have sessions that run against the same
        // Rule Set, and the only objects unique to a session is the DTState
        // object and objects it holds.
        IRSession      session = rs.newSession();
       
        // We are going to map the data into the session with the default mapping
        // defined by the RuleSet.  Generally a Rule Set will use only one
        // mapping file.  However, you can build other mapping files.
        Mapping        mapping = session.getMapping();
       
        // We are going to get our Data from an XML source.  The Mapping file
        // and the XML Data source is all we need to populate the Rules
        // Session.
        mapping.loadData(session, path+"testfiles/"+"TestCase_001.xml");
       
        // We will begin Execution at the main Decision Table for our Rule Set.
        // Furthermore, we are going to only execute the Decision Tables once.
        // You may, however, interact with the state of the Rules Engine, load
        // more data, and execute any of the Decision Tables as needed.  This
        // would allow one or more Rule Sets to manage the behavior of an
        // application in an on going mannor.
        session.execute(decisionTable);
   
        // Once the Decision Tables have executed, we need to extract the data
        // from the Rules engine.  We will use a modified version of the
        // printReport() method from the SamplesProject2, the Rules Development
        // Project for our application.
View Full Code Here

Examples of com.dtrules.session.IRSession

  }
 
  public String evaluate(int threadnum, ChipApp app, Job job) {
           
        try {
             IRSession      session    = app.rs.newSession();
            
             if(app.trace && (job.getId()%app.save == 0) ){
               OutputStream out = new FileOutputStream(
                   app.getOutputDirectory()+getJobName(job)+"_trace.xml");
               session.getState().setOutput(out, System.out);
               session.getState().setState(DTState.TRACE | DTState.DEBUG);
               session.getState().traceStart();
             }
            
             // Map the data from the job into the Rules Engine
             
             // First create a data map.
             Mapping     mapping  = session.getMapping();
           DataMap   datamap  = session.getDataMap(mapping,null);
          
           datamap.opentag(job,"job");
           datamap.readDO(job, "job");
          
             Case c = job.getCase();
             datamap.opentag(c,"case");
             datamap.readDO(c,"case");
               for(Client client : c.getClients()){
                 datamap.opentag(client,"client");
                 datamap.readDO(client,"client");
                   for(Income income : client.getIncomes()){
                    
                       datamap.readDO(income,"income");
                      
                   }
                 datamap.closetag();
               }
               for(Relationship r : c.getRelationships()){
                 datamap.opentag("relationship");
                   datamap.printdata("type", r.getType());
                   datamap.readDO(r.getSource(), "source");
                   datamap.readDO(r.getTarget(), "target");
                 datamap.closetag();
               }
             datamap.closetag();
            
           datamap.closetag();
          
             int    id  = job.getId();
            
             if(app.save >0 && id % app.save == 0){
               String cnt = ""+id;
                 for(;id<100000;id*=10)cnt = "0"+cnt;
                 try {
                   datamap.print(new FileOutputStream(app.getOutputDirectory()+"job_"+cnt+".xml"));
                 } catch (Exception e) {
                   System.out.println("Couldn't write to '"+app.getOutputDirectory()+"job_"+cnt+".xml'");
                 }
             }
            
           mapping.loadData(session, datamap);
          
           // Once the data is loaded, execute the rules.
             session.execute(app.getDecisionTableName());
        
             if(app.trace && (job.getId()%app.save == 0)){
                 session.getState().traceEnd();
             }
            
            
             printReport(threadnum, app, session);
          
View Full Code Here

Examples of com.dtrules.session.IRSession

  }
 
  public String evaluate(int threadnum, BookPreviewApp app, DataObj request) {
           
        try {
             IRSession      session    = app.rs.newSession();
                         
             // Map the data from the job into the Rules Engine
             
             // First create a data map.
             Mapping     mapping  = session.getMapping();
           DataMap   datamap  = session.getDataMap(mapping,"BookPreview");
          
           request.write2DataMap(datamap);
          
             int    id  = request.getId();
            
             if(app.save >0 && id % app.save == 0){
               String cnt = ""+id;
                 for(;id<100000;id*=10)cnt = "0"+cnt;
                 try {
                   datamap.print(new FileOutputStream(app.getOutputDirectory()+"BP_request_"+cnt+".xml"));
                 } catch (Exception e) {
                   System.out.println("Couldn't write to '"+app.getOutputDirectory()+"BP_request_"+cnt+".xml'");
                 }
             }
            
           mapping.loadData(session, datamap);
          
           // Once the data is loaded, execute the rules.
             session.execute(app.getDecisionTableName());            
            
             printReport(threadnum, app, session);
          
           
         } catch ( Exception ex ) {
View Full Code Here

Examples of com.dtrules.session.IRSession

     */
    @SuppressWarnings("unchecked")
    public void compile(int NumErrorsToReport, PrintStream err) {
       
        try {
            IRSession session = new RSession(ruleSet);       
            Compiler       compiler     = new Compiler(session);
                           dtcompiler   = new DTCompiler(compiler);
           
            InputStream    inDTStream   = new FileInputStream(ruleSet.getFilepath()+"/"+UDTFilename);
            OutputStream   outDTStream  = new FileOutputStream(ruleSet.getFilepath()+"/"+ruleSet.getDT_XMLName());
           
            dtcompiler.compile(inDTStream, outDTStream);
                       
            RulesDirectory  rd  = new RulesDirectory(path, rulesDirectoryXML);
            RuleSet         rs  = rd.getRuleSet(RName.getRName(ruleset));
            EntityFactory   ef  = rs.newSession().getEntityFactory();
            IREntity        dt  = ef.getDecisiontables();
            Iterator<RName> idt = ef.getDecisionTableRNameIterator();
           
            while(idt.hasNext()){
                RDecisionTable t = (RDecisionTable) dt.get(idt.next());
                t.build(session.getState());
                List<ICompilerError> errs = t.compile();
                for (ICompilerError error : errs){
                    dtcompiler.logError(
                            t.getName().stringValue(),
                            t.getFilename(),
View Full Code Here

Examples of com.dtrules.session.IRSession

        }
       
        try {
            RulesDirectory rd       = new RulesDirectory(path,file);
            RuleSet        rs       = rd.getRuleSet(RName.getRName("ebdemo"));
            IRSession      session  = rs.newSession();
            DecisionTableTypeTest test;
           
            test = new DecisionTableTypeTest(session,rs);
            test.dt.setType(RDecisionTable.Type.FIRST);
            test.dt.build(session.getState());
            test.printtable (session);
           
            test = new DecisionTableTypeTest(session,rs);
            test.dt.setType(RDecisionTable.Type.ALL);
            test.dt.build(session.getState());
            test.printtable (session);
           
           
        } catch (Exception e) {
            e.printStackTrace(System.out);
View Full Code Here

Examples of com.dtrules.session.IRSession

     */
    @SuppressWarnings({ "deprecation" })
    public void compile(int NumErrorsToReport, PrintStream err) {
       
        try {
            IRSession         session       = new RSession(ruleSet);
            Class<ICompiler>  compilerClass = ruleSet.getDefaultCompiler();
            if(compilerClass == null){
              throw new RulesException("undefined", "Excel2XML", "No default compiler has been found." +
                  "  We cannot convert and compile the XML without one");
            }
            ICompiler defaultCompiler = (ICompiler) compilerClass.newInstance();
            defaultCompiler.setSession(session);

            ICompiler      compiler     = defaultCompiler;
                           dtcompiler   = new DTCompiler(compiler);
           
            InputStream    inDTStream   = new FileInputStream(ruleSet.getFilepath()+"/"+UDTFilename);
            OutputStream   outDTStream  = new FileOutputStream(ruleSet.getFilepath()+"/"+ruleSet.getDT_XMLName());
           
            dtcompiler.compile(inDTStream, outDTStream);
                       
            RulesDirectory  rd  = new RulesDirectory(path, rulesDirectoryXML);
            RuleSet         rs  = rd.getRuleSet(RName.getRName(ruleset));
            EntityFactory   ef  = rs.newSession().getEntityFactory();
            IREntity        dt  = ef.getDecisiontables();
            Iterator<RName> idt = ef.getDecisionTableRNameIterator();
           
            while(idt.hasNext()){
                RDecisionTable t = (RDecisionTable) dt.get(idt.next());
                t.build(session.getState());
                List<IDecisionTableError> errs = t.compile();
                for (IDecisionTableError error : errs){
                    dtcompiler.logError(
                            t.getName().stringValue(),
                            t.getFilename(),
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.