Package org.dmd.dmc.types

Examples of org.dmd.dmc.types.Modifier


            Iterator<VALUE> it = getMV();
            while(it.hasNext()){
              VALUE current = it.next();
              DmcAttribute<?> mod = getNew();
              mod.add(current);
              mods.add(new Modifier(ModifyTypeEnum.ADD, mod));
            }
          }
          else{
            for(int index=0; index<getMVSize(); index++){
              if (getMVnth(index) != null){
                DmcAttribute<?> mod = getNew();
                mod.setMVnth(index,getMVnth(index));
                mods.add(new Modifier(ModifyTypeEnum.NTH, mod, index));
              }
            }
          }
        }
      }
      else{
        if (!adapter.hasValue())
          mods.add(new Modifier(ModifyTypeEnum.REM, attrInfo));
        else{
          // Have to determine the delta
          if (attrInfo.indexSize == 0){
            Iterator<?> eit = existingValue.getMV();
            while(eit.hasNext()){
              Object current = eit.next();
              if (!contains(current)){
                // The value no longer exists, delete it
                DmcAttribute<?> mod = getNew();
                mod.add(current);
                mods.add(new Modifier(ModifyTypeEnum.DEL, mod));
              }
            }
            Iterator<VALUE> it = getMV();
            while(it.hasNext()){
              VALUE current = it.next();
              if (!existingValue.contains(current)){
                // The existing value is missing this value, add it
                DmcAttribute<?> mod = getNew();
                mod.add(current);
                mods.add(new Modifier(ModifyTypeEnum.ADD, mod));
              }
            }
          }
          else{
            for(int index=0; index<getMVSize(); index++){
              Object existing = existingValue.getMVnth(index);
              Object current  = getMVnth(index);
              boolean replace = false;
             
              if (existing == null){
                if (current != null)
                  replace = true;
              }
              else{
                if (current == null)
                  replace = true;
                else{
                  if (!existing.equals(current))
                    replace = true;
                }
              }
             
              if (replace){
                DmcAttribute<?> mod = getNew();
                mod.setMVnth(index,current);
                mods.add(new Modifier(ModifyTypeEnum.NTH, mod, index));
              }
            }
          }
        }
      }
View Full Code Here


    }
   
    @Override
    // org.dmd.dms.util.GenUtility.dumpSVType(GenUtility.java:2010)
    public Modifier set(Object v) throws DmcValueException {
        Modifier rc = typeCheck(v);
        // We only return a value if the value actually changed. This supports
        // the applyModifier() mechanism on DmcObject where we only return true
        // if something changed as a result of the modifier
        if (value == null)
            value = rc;
View Full Code Here

          if (DmcOmni.instance().backRefTracking() && DmcOmni.instance().trackThisAttribute(attr.ID)){
            if (attr instanceof DmcTypeNamedObjectREF){
              // We're modifying a reference attribute, so track that puppy
              DmcObject obj = ((DmcObject)((DmcNamedObjectREF<?>)attr.getSV()).getObject());
              if (obj != null){
                Modifier backrefMod = new Modifier(ModifyTypeEnum.SET,attr,this);
                obj.addBackref(backrefMod);
               
                // Let the reference know the backref modifier - this allows us to
                // easily remove the backref if the reference is deleted
                ((DmcNamedObjectREF<?>)attr.getSV()).setBackrefModifier(backrefMod);
              }
            }
          }
        }
      }
      else{
        getModifier().add(new Modifier(ModifyTypeEnum.SET, attr));
      }
     
//    if ( (getContainer() != null) && (getContainer().getListenerManager() == null) ){
//      // TODO implement attribute change listener hooks
//    }
View Full Code Here

                // We're modifying a reference attribute, so track that puppy
                DmcAttribute<?> mod = attr.getNew();
                mod.setAttributeInfo(ai);
                mod.add(getLastValue());
               
                Modifier backrefMod = new Modifier(ModifyTypeEnum.ADD,mod,this);
                ((DmcObject)((DmcNamedObjectREF<?>)getLastValue()).getObject()).addBackref(backrefMod);
               
                // Let the reference know the backref modifier - this allows us to
                // easily remove the backref if the reference is deleted
                ((DmcNamedObjectREF<?>)getLastValue()).setBackrefModifier(backrefMod);
              }
            }
          }
        }
      }
     
      if (getModifier() != null){
        if (getLastValue() == null){
          // Last value can be null in the case of SET attributes since we don't
          // actually add a value to the SET if it already exists. However, in other
          // cases, this is a code error - so pitch a fit!
          if ( (ai.valueType != ValueTypeEnum.HASHMAPPED) && (ai.valueType != ValueTypeEnum.TREEMAPPED)){
            // This is okay
          }
          else if ( (ai.valueType != ValueTypeEnum.HASHSET) && (ai.valueType != ValueTypeEnum.TREESET)){
            throw(new IllegalStateException("Last value shouldn't be null."));
          }
        }
        else{
          // Get an attribute value holder of the same type and hang on to the last
          // value that was added to it
          DmcAttribute<?> mod = attr.getNew();
          mod.setAttributeInfo(ai);
         
          mod.add(getLastValue());
          getModifier().add(new Modifier(ModifyTypeEnum.ADD, mod));
        }
      }
     
     
//    if ( (getContainer() != null) && (getContainer().getListenerManager() == null) ){
View Full Code Here

   * @param value The value to be deleted.
   */
  protected void delFromEmptyAttribute(DmcAttribute<?> mod, Object value){
    try {
      mod.add(value);
      getModifier().add(new Modifier(ModifyTypeEnum.DEL, mod));   
    } catch (DmcValueException e) {
      if ( (mod.getAttributeInfo().valueType == ValueTypeEnum.HASHMAPPED) ||
           (mod.getAttributeInfo().valueType == ValueTypeEnum.TREEMAPPED) ){
        throw(new IllegalStateException("Changes to the Modifier shouldn't throw an exception. This is a MAPPED attribute and typeCheck () should accept just the key value as well as the mapped type itself.", e));
      }
View Full Code Here

        try {
          DmcAttribute<?> mod = attr.getNew();
          mod.setAttributeInfo(ai);
         
          mod.add(value);
          getModifier().add(new Modifier(ModifyTypeEnum.DEL, mod));
        } catch (DmcValueException e) {
          throw(new IllegalStateException("Changes to the Modifier shouldn't throw an exception.", e));
        }
      }
     
View Full Code Here

    synchronized (attributes) {
      T attr = (T) attributes.remove(ai.id);
     
      if (getModifier() != null){
        try {
          getModifier().add(new Modifier(ModifyTypeEnum.REM, ai));
        } catch (DmcValueException e) {
          throw(new IllegalStateException("Changes to the Modifier shouldn't throw an exception.", e));
        }
      }
     
View Full Code Here

   * @param mod The appropriately typed attribute holder.
   * @param value The value to be deleted.
   */
  protected void nthNullFromEmptyAttribute(DmcAttributeInfo ai, int idx){
    try {
      getModifier().add(new Modifier(ModifyTypeEnum.NTH, ai, idx));   
    } catch (DmcValueException e) {
      throw(new IllegalStateException("Changes to the Modifier shouldn't throw an exception.", e));
    }
  }
View Full Code Here

                // We're modifying a reference attribute, so track that puppy
                DmcAttribute<?> mod = attr.getNew();
                mod.setAttributeInfo(ai);
                mod.add(getLastValue());
               
                Modifier backrefMod = new Modifier(ModifyTypeEnum.NTH,mod,this,index);
                ((DmcObject)((DmcNamedObjectREF<?>)getLastValue()).getObject()).addBackref(backrefMod);
               
                ((DmcNamedObjectREF<?>)getLastValue()).setBackrefModifier(backrefMod);
              }
            }
            if (attr instanceof DmcTypeNamedObjectREF){
              // And now some tricky stuff. Due to the fact that the nth() mechanisms can
              // result in a previous value being removed and replaced in one operation,
              // we have to take this into account when tracking back references. Any
              // previous value for this index is passed in to us from the generated
              // nth() method so that we can clean up the back reference if required.
              if (previous != null){
                DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>) previous;
                if (ref.getObject() != null){
                  if (ref.getBackrefModifier() != null)
                    ((DmcObject)ref.getObject()).removeBackref(ref.getBackrefModifier());
                }
              }
            }
          }
        }
      }
     
      if (getModifier() != null){
        if (getLastValue() == null){
          // Last value can be null in the case of indexed multi-valued attributes since this
          // is how we remove an indexed value.
          if ( (ai.indexSize == 0) || (ai.valueType != ValueTypeEnum.MULTI))
            throw(new IllegalStateException("Code gen error! The nth() interface is not applicable to attribute: " + ai.name + " of valueType: " + ai.valueType));
          getModifier().add(new Modifier(ModifyTypeEnum.NTH, ai, index));
        }
        else{
          // Get an attribute value holder of the same type and hang on to the last
          // value that was added to it
          DmcAttribute<?> mod = attr.getNew();
          mod.setAttributeInfo(ai);
         
          mod.setMVnth(index, getLastValue());
          getModifier().add(new Modifier(ModifyTypeEnum.NTH, mod, index));
        }
      }
     
     
      // If there are no longer values stored in the attribute, remove it
View Full Code Here

        sb.append("References to: " + ((DmcNamedObjectIF)this).getObjectName() + " (" + System.identityHashCode(this)+ ")\n");
       
        Iterator<Modifier> modit = mods.getMV();
        if (modit != null){
          while(modit.hasNext()){
            Modifier mod = modit.next();
            DmcNamedObjectIF referrer   = mod.getReferringObject();
            DmcObject     obj    = (DmcObject) referrer;
            DmcAttribute<?> attr = mod.getAttribute();
            if (attr.getAttributeInfo().valueType == ValueTypeEnum.SINGLE)
              sb.append("  (" + obj.getConstructionClassName() + ") " + referrer.getObjectName() + " via SV " + attr.getName() + "\n");
            else{
              if (attr.getAttributeInfo().indexSize == 0)
                sb.append("  (" + obj.getConstructionClassName() + ") " +  referrer.getObjectName() + " via MV " + attr.getName() + "\n");
              else
                sb.append("  (" + obj.getConstructionClassName() + ") " +  referrer.getObjectName() + " via INDEX " + mod.getIndex() + " " + attr.getName() + "\n");
            }
          }
        }
        return(sb.toString());
      }
View Full Code Here

TOP

Related Classes of org.dmd.dmc.types.Modifier

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.