Package com.dtrules.entity

Examples of com.dtrules.entity.IREntity


                throw new RulesException("undefined", "PerformCatchError",
                        "The table '"+table.stringValue()+"' is undefined");
            }catch(RulesException e){
                IRSession     session       = state.getSession();
                EntityFactory ef            = session.getEntityFactory();  
                IREntity      errorEntity   = ef.findRefEntity(error).clone(session).rEntityValue();
                state.entitypush(errorEntity);
               
                // If any of the following puts fail (because the given entity doesn't define them), then
                // simply carry on your merry way.  The user can define these fields if they need them,
                // and they don't need to define them if they don't need them.
               
                try { errorEntity.put(n("errortype"),     p(e.getErrortype()));                         }catch(RulesException ex){}
                try { errorEntity.put(n("location"),      p(e.getLocation()));                          }catch(RulesException ex){}
                try { errorEntity.put(n("message"),       p(e.getMessage()));                           }catch(RulesException ex){}
                try { errorEntity.put(n("decisionTable"), p(e.getDecisionTable()));                     }catch(RulesException ex){}
                try { errorEntity.put(n("formal"),        p(e.getErrortype()));                         }catch(RulesException ex){}
                try { errorEntity.put(n("postfix"),       p(e.getPostfix()));                           }catch(RulesException ex){}
                try { errorEntity.put(n("filename"),      p(e.getFilename()));                          }catch(RulesException ex){}
                try { errorEntity.put(n("section"),       p(e.getSection()));                           }catch(RulesException ex){}
                try { errorEntity.put(n("number"),        RInteger.getRIntegerValue(e.getNumber()));    }catch(RulesException ex){}
               
            }
        }
View Full Code Here


         * Add all the reference entities to the session list
         * of entities.
         */
        Iterator<RName> ie = ef.referenceEntities.keySet().iterator();
        while(ie.hasNext()){
            IREntity e  = ef.findRefEntity(ie.next());
            String   id = e.getID()+"";
            if(entityInstances.containsKey(id)){
                throw new RulesException("duplicate","new RSession()","Duplicate id "+id+" found between:\n"
                        +e.getName()+" and "+entityInstances.get(id).getName());
            }
            entityInstances.put(id,e);
        }
        try {
            dtstate.entitypush(ROperator.getPrimitives());
            dtstate.entitypush(ef.decisiontables);
        } catch (RulesException e) {
            throw new RulesException("Initialization Error",
                    "RSession",
                    "Failed to initialize dtstate in init(): "+e.toString());
        }
    }
View Full Code Here

     */
  public IREntity createEntity(Object id, RName name) throws RulesException{
      if(id==null){
          id = getUniqueID()+"";
      }
    IREntity ref = ef.findRefEntity(name);
        if(ref==null){
            throw new RulesException("undefined","session.createEntity","An attempt ws made to create the entity "+name.stringValue()+"\n" +
                    "This entity isn't defined in the EDD");
        }
  
        if(ref.isReadOnly()) return ref;
       
        if(getState().testState(DTState.TRACE)){
          IREntity e = entityInstances.get(id);
            if(e==null){
             
              try { // Try and make the uniqueId match.  But ignore errors.
          int eid = Integer.parseInt(id.toString());
          if(uniqueID!=eid) uniqueID = eid;
        } catch (NumberFormatException e1) {
          e1.printStackTrace();
        }

              e = (REntity) ref.clone(this);
             
              dtstate.traceInfo(
                  "createentity",
                  "name", e.getName().stringValue(),
                  "id",   ""+e.getID(),
                  null);

              entityInstances.put(id,e);
            }
            return e;
View Full Code Here

      IRObject n2 = state.datapop();
      IRObject v1 = state.datapop();
      IRObject n1 = state.datapop();
     
      for(IRObject ie : array){
        IREntity e = ie.rEntityValue();
       
        if(n3.type().getId() != RNull.type.getId()){
          IRObject v = e.get(n3.rNameValue());
          if(!v.equals(v3)){
            continue;
          }
        }
        if(n2.type().getId() != RNull.type.getId()){
          IRObject v = e.get(n2.rNameValue());
          if(!v.equals(v2)){
            continue;
          }
        }
        if(n1.type().getId() != RNull.type.getId()){
          IRObject v = e.get(n1.rNameValue());
          if(!v.equals(v1)){
            continue;
          }
        }
        state.datapush(e);
View Full Code Here

       
        types = new HashMap<RName, IRType>();
        Iterator<RName> entities = ef.getEntityRNameIterator();
        while(entities.hasNext()){
            RName     name    = entities.next();
            IREntity  entity  = ef.findRefEntity(name);
            Iterator<RName> attribs = entity.getAttributeIterator();
            addType(entity,entity.getName(),IRObject.iEntity);
            while(attribs.hasNext()){
                RName        attribname = attribs.next();
                REntityEntry entry      = entity.getEntry(attribname);
                addType(entity,attribname,entry.type.getId());
            }
        }
       
        Iterator<RName> tables = ef.getDecisionTableRNameIterator();
View Full Code Here

     
      Iterator<RName> es = this.map.entities.keySet().iterator();
      while(es.hasNext()){
        RName  ename = (RName) es.next();            
         try {
        IREntity e     = findEntity(ename.stringValue().toLowerCase(),null,null);
        state.entitypush(e);
       } catch (RulesException e) {
              state.traceInfo("error", "Failed to initialize the Entity Stack (Failed on "+ename+")\n"+e);
          throw new RuntimeException(e)
       }
View Full Code Here

   * @return
   * @throws RulesException
   */
  IREntity findEntity( String entity, String code, EntityInfo info) throws RulesException{
     String number = (String) this.map.entityinfo.get(entity);
     IREntity e;
     if(number==null){
       number = "*";
     }
     if(number.equals("1")){
      e = (IREntity)entities.get(entity);
View Full Code Here

      String eName = info.name;
      if (eName == null || eName.length() <= 0)
      {
        eName =  (String) attribs.get("name");
      }
      IREntity e = findEntity(eName, code, info);     // Look up the entity I should create.
        if(e!=null){                  // I hope to goodness I can find it!
          attribs.put("create entity","true")
          if(code.length()!=0) {
            e.put(null, IREntity.mappingKey,RString.newRString(code));
          }else{
            e.put(null, IREntity.mappingKey,RString.newRString("v"+ (++codeCnt)));
          }
       
          state.entitypush(e);
        if(state.testState(DTState.TRACE)){
              state.traceTagBegin("mapCreateEntity", "name",info.name,"data_id",code);
View Full Code Here

      // Look and see if we have an attribute name defined.
       
          RName a = RName.getRName(attr);                
          IRObject value;
                    
                    IREntity enclosingEntity = session.getState().findEntity(a);
                    if(enclosingEntity!=null){
                       
                   
              int type = enclosingEntity.getEntry(a).type.getId();
             
              if(type == IRObject.iInteger){
                value = RInteger.getRIntegerValue(body.length()==0? "0" : body);
              } else if (type == IRObject.iDouble) {
                value = RDouble.getRDoubleValue(body.length()==0? "0" : body);
View Full Code Here

      listname   = RName.getRName(info.list);
    }
        // First add this entity to any list found on the entity stack.
        for(int i=0; i< state.edepth(); i++){
            // Look for all Array Lists on the Entity Stack that look like lists of this Entity
            IREntity entity = state.getes(i);
            IRObject elist = entity.get(listname);
            if(elist!=null && elist.type().getId()==IRObject.iArray){
                // If not a member of this list, then add it.
                if(!((RArray)elist).contains(e)){
                   ((RArray)elist).add(e);
                }
            }
        }
        // Then update the reference to this entity that might be on the Entity Stack.
        // DON'T go wild.  Only look at the top entity (or you may overwrite a reference
        //     you'd rather leave alone.
        // DON'T mess with any entity's self reference though!  That is BAD.
        int i=state.edepth()-1;
      if(((IREntity)state.getes(i)).get(e.getName())!=null){
            IREntity refto = state.getes(i);
            if(! refto.getName().equals(e.getName()))           // Update a reference to an Entity of the same name,
           ((IREntity)state.getes(i)).put(null, e.getName(), e)//  but only if it isn't a self reference.
       
      }
    
      return e;
View Full Code Here

TOP

Related Classes of com.dtrules.entity.IREntity

Copyright © 2018 www.massapicom. 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.