Package com.dtrules.entity

Examples of com.dtrules.entity.IREntity


    public boolean def(RName name, IRObject value, boolean protect) throws RulesException {

        RName entityname = name.getEntityName();

        for (int i = entitystkptr - 1; i >= 0; i--) {
            IREntity e = entitystk[i];
            if (!e.isReadOnly() && (entityname == null || e.getName().equals(entityname))) {
                REntityEntry entry = e.getEntry(name);
                if (entry != null && (!protect || entry.writable)) {
                    if (testState(TRACE)) {
                        out.printdata("def",
                            "id",     e.getID(),
                            "entity", e.getName().stringValue(),
                            "name",   name.stringValue(),
                            value.postFix());
                    }

                    e.put(null, name, value);
                    return true;
                }
            }
        }
        return false;
View Full Code Here


     */
    static class Entityforall extends ROperator {
        Entityforall(){super("entityforall");}

        public void execute(DTState state) throws RulesException {
            IREntity entity  = state.datapop().rEntityValue()// Get the entity
            IRObject body = state.datapop();                    // Get the body
            Iterator keys = entity.getAttributeIterator();      // Get the Attribute Iterator
            while(keys.hasNext()){                         // For each attribute
                RName     n = (RName) keys.next();
                IRObject  v = entity.get(n);
                if(v!=null){
                    state.datapush(n);
                    state.datapush(v);
                    body.execute(state);
                }   
View Full Code Here

     * @param code
     * @return Returns null if no entity was found.
     * @throws RulesException
     */
    public IREntity findEntity(AutoDataMap autoDataMap, String entity, Label label, Object key) {
       IREntity e    = null;      
       IRObject iKey = iconvert(key);
       try {
           if(label.isSingular()){                          // If singular, look for an instance
               e = autoDataMap.getEntities().get(entity); //   on the entity stack.
               if(e==null){                               // None found? create one.
                   e = autoDataMap.getSession().getState().findEntity(entity+"."+entity);
                   if(e==null){
                      e = autoDataMap.getSession().createEntity(null,entity);
                      autoDataMap.getEntities().put(entity,e);   // Remember the one we created, so we
                   }  
               }                                              //   don't create another one.
           }else {
               String skey = entity+"$"+iKey.stringValue();
               if(key!=null &&
                   !(key instanceof String
                       && ((String)key).length()==0)) {                // NOTE: We are NOT allowing "" as a key here!
                                                                         // If so, construct a key for that entity
                   e = (IREntity)autoDataMap.getEntities().get(skey);    //    and look for it.
               }  
               if(e==null) {                                              // Haven't created an entity with that key?
                   e = autoDataMap.getSession().createEntity(iKey,entity);// do so.
                   if(key!=null){
                       autoDataMap.getEntities().put(skey,e);   // If we have a key, remember this entity!
                   }
               }
           }

       if(e==null)throw new RuntimeException("Failed to create the entity "+entity);
       if(key != null){
           e.addAttribute(
                   IREntity.mappingKey,
                   key.toString(),
                   iKey,
                   false,
                   true,
                   strType,
                   "", "", "","");
           e.put(null, IREntity.mappingKey, iKey);
       }
      
       return e;
       } catch (RulesException e1) {
            return null;
View Full Code Here

        try {
            RArray list = null;
            RName rname = null;
            Object object = autoDataMap.getCurrentObject();
            if(object instanceof IREntity){
                IREntity entity = (IREntity) object;
                rname = mapName(autoDataMap, labelMap, node.getLabel());
                IRObject olist = entity.get(rname);
                if(olist != null && olist.type().getId() == IRObject.iArray){
                    list = olist.rArrayValue();
                }
            }
           
View Full Code Here

    public void update(AutoDataMap autoDataMap, MapNodeAttribute node) {
        if(node.getParent() instanceof MapNodeObject){
            MapNodeObject parentNode = (MapNodeObject)node.getParent();
            Object        tgtObj     = parentNode.getTargetObject();
            if(tgtObj == null) return;
            IREntity      entity     = (IREntity) tgtObj;
            RName         attribute  = RName.getRName(node.getAttribute().getName());
            REntityEntry  entry      = entity.getEntry(attribute);
            if(entry != null && entry.writable){
                IRObject  value  = entity.get(node.getAttribute().getName());
                Object    v      = convert(value);   
                node.setData(v);
            }
        }
       
View Full Code Here

            RArray   array = state.datapop().rArrayValue();
            IRObject test  = state.datapop();
            IRObject body2 = state.datapop();
            IRObject body1 = state.datapop();
            for(IRObject obj : array) {
                IREntity e = obj.rEntityValue();
                state.entitypush(e);
                test.execute(state);
                if(state.datapop().booleanValue()){
                    body1.execute(state);
                    state.entitypop();
View Full Code Here

            }
        }

        RName rname = mapName(autoDataMap, labelMap, node.getAttribute().getName());
       
        IREntity entity = (IREntity) autoDataMap.getCurrentObject();
       
        try{                        // We are going to ignore assertion errors.
           entity.put(autoDataMap.getSession(), rname, ref);
           return ref;
        }catch(Exception e){}

        return ref;               
    }
View Full Code Here

     * for this mapping, we create one.
     */
    @Override
    public Object mapObject(AutoDataMap autoDataMap, LabelMap labelMap, MapNodeObject node) {       
       Label target = autoDataMap.getCurrentGroup().findLabel(labelMap.getTarget());
       IREntity entity = findEntity(autoDataMap, target.getSpec(),target, node.getKey());  
       node.setTargetObject(entity);
       return entity;
    }
View Full Code Here

   
   
    @Override
    public Object mapAttribute(AutoDataMap autoDataMap, LabelMap labelMap, MapNodeAttribute node) {
        RName rname = mapName(autoDataMap, labelMap, node.getAttribute().getName());
        IREntity entity   = (IREntity) autoDataMap.getCurrentObject();
        if(entity == null){
            return null;
        }
        Object data = node.getData();
        IRObject value = iconvert(data);
        try {
            entity.put(autoDataMap.getSession(), rname, value);
            value = entity.get(rname);
        } catch (RulesException e) {
           
        }       
        return value;
    }
View Full Code Here

        RTable rTable = null;
        try {
            RName rname = null;
            Object object = autoDataMap.getCurrentObject();
            if(object instanceof IREntity){
                IREntity entity = (IREntity) object;
                rname = mapName(autoDataMap, labelMap, node.getAttribute().getName() );
                IRObject olist = entity.get(rname);
                if(olist != null && olist.type().getId() == IRObject.iTable){
                    rTable = olist.rTableValue();
                }
            }
            if(rTable == null){
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.