Package com.dtrules.entity

Examples of com.dtrules.entity.IREntity


      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()==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


   *
   * @param name
   */
  public REntity findcreateRefEntity(boolean readonly, RName name)throws RulesException {
    if(!referenceEntities.containsKey(name)){
      IREntity entity = new REntity(getUniqueID(), readonly, name);
      referenceEntities.put(name,entity);
    }
    return (REntity) referenceEntities.get(name);
  }
View Full Code Here

    @Override
    public String toString() {
    Iterator ikeys = referenceEntities.keySet().iterator();
    StringBuffer buff = new StringBuffer();
    while(ikeys.hasNext()){
      IREntity e = referenceEntities.get(ikeys.next());
      buff.append(e.getName().toString());
      buff.append("\r\n");
      Iterator iattribs = e.getAttributeIterator();
      while(iattribs.hasNext()){
        RName        entryname  = (RName)iattribs.next();
        REntityEntry entry      = e.getEntry(entryname);
        buff.append("   ");
        buff.append(entryname);
        if(entry.defaultvalue!=null){
          buff.append("  --  default value: ");
          buff.append(entry.defaultvalue.toString());
View Full Code Here

    public void writeAttributes(XMLPrinter xout) throws RulesException {
       RName entities[]= new RName[0];
       entities = referenceEntities.keySet().toArray(entities);
       Arrays.sort(entities);
       for ( RName key : entities ){
           IREntity entity = referenceEntities.get(key);
           {
               String access  = entity.isReadOnly()?"r":"rw";
               String comment = entity.getComment();
               String name    = key.stringValue();
               xout.opentag("entity","name",name,"access",access,"comment",comment);
           }
           RName attributes [] = new RName[0];
           attributes = entity.getAttributeSet().toArray(attributes);
           Arrays.sort(attributes);
           for (RName attribute : attributes){
               REntityEntry entry = entity.getEntry(attribute);
              
               String name          = attribute.stringValue();
               String type          = entry.getTypeValue();
               String subtype       = entry.getSubtype();
               String access        = (entry.readable ? "r":"") + (entry.writable ? "w":"");
View Full Code Here

      if(defaultstr.equalsIgnoreCase("null")) defaultstr="";
     
        switch(type){
            case IRObject.iEntity : {
                if(defaultstr.length()==0)return RNull.getRNull();
                IREntity e = ef.findcreateRefEntity(false,RName.getRName(defaultstr));
                if(e==null)throw new RulesException(
                        "ParsingError",
                        "EntityFactory.computeDefaultValue()",
                        "Entity Factory does not define an entity '"+defaultstr+"'");
                return e;
            }
            case IRObject.iArray : {
                if(defaultstr.length()==0) return new RArray(ef.getUniqueID(), true,false);
                RArray rval;
                try{
                     RArray v = (RArray) RString.compile(session, defaultstr, false);     // We assume any values are surrounded by brackets, and regardless make
                    
                     rval = v.get(0).getNonExecutable().rArrayValue();             // sure they are non-executable.
                }catch(RulesException e){
                    throw new RulesException("ParsingError","EntityFactory.computeDefaultValue()","Bad format for an array. \r\n"+
                            "\r\nWe tried to interpret the string \r\n'"+defaultstr+"'\r\nas an array, but could not.\r\n"+e.toString());
                }
                return rval;
            }
          case IRObject.iString :
                if(defaultstr.length()==0)return RNull.getRNull();
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,
                   IRObject.iString,
                   "", "", "","");
           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() == 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

            }
        }

        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

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.