Examples of Modifier


Examples of org.dmd.dmc.types.Modifier

        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

Examples of org.dmd.dmc.types.Modifier

    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

Examples of org.dmd.dmc.types.Modifier

   * @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

Examples of org.dmd.dmc.types.Modifier

                // 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

Examples of org.dmd.dmc.types.Modifier

        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

Examples of org.dmd.dmc.types.Modifier

      DmcTypeModifierMV mods = getBackref();
      if (mods != null){
        Iterator<Modifier> modit = mods.getMV();
        if (modit != null){
          while(modit.hasNext()){
            Modifier mod = modit.next();
            rc.add((DmcObject)mod.getReferringObject());
          }
        }
      }
      return(rc);
    }
View Full Code Here

Examples of org.dmd.dmc.types.Modifier

      DmcTypeModifierMV mods = getBackref();
      if (mods != null){
        Iterator<Modifier> modit = mods.getMV();
        if (modit != null){
          while(modit.hasNext()){
            Modifier mod = modit.next();
            if (mod.getAttributeID() == ai.id)
              rc.add((DmcObject)mod.getReferringObject());
          }
        }
      }
      return(rc);
    }
View Full Code Here

Examples of org.dmd.dmc.types.Modifier

            // NOTE: we wouldn't do the backref tracking in the case of DMP
            // messages (which are marked as supportsBackrefTracking false).
            if (supportsBackrefTracking()){
//              if (DmcOmni.instance().backRefTracking() && (attr.ID > 200)){
              if (DmcOmni.instance().backRefTracking() && DmcOmni.instance().trackThisAttribute(attr.ID)){
                Modifier backrefMod = new Modifier(ModifyTypeEnum.SET,attr,this);
                resolvedObject.addBackref(backrefMod);
               
                // Let the reference know the backref modifier - this allows us to
                // easily remove the backref if the reference is deleted
                ref.setBackrefModifier(backrefMod);
              }
            }

          }
          else{
            Iterator<DmcNamedObjectREF> refs = reference.getMV();
            if (refs != null){
              int currIndex = -1;
              while(refs.hasNext()){
                currIndex++;
                DmcNamedObjectREF ref = refs.next();
               
                // Note: ref may be null if this is an indexed attribute and
                // there is no value at the current index
                if ( (ref == null) || ref.isResolved())
                  continue;
               
                DmcNamedObjectIF    obj       = rx.findNamedObject(ref.getObjectName(),attr.ID);
                DmcObject       resolvedObject   = null;
               
                if (obj == null){
                  DmcValueException ex = new DmcValueException("Could not resolve reference to: " + ref.getObjectName() + " via attribute: " + attr.getName());
                  if (errors == null)
                    errors = new DmcValueExceptionSet();
                  errors.add(ex);
                  continue;
                }
                else{
                  try{
                    if (obj instanceof DmcContainerIF){
                      resolvedObject = ((DmcContainerIF)obj).getDmcObject();
                      ref.setObject((DmcNamedObjectIF) ((DmcContainerIF)obj).getDmcObject());
                    }
                    else{
                      resolvedObject = (DmcObject)obj;
                      ref.setObject(obj);
                    }
                  }
                  catch(ClassCastException e){
                    DmcValueException ex = new DmcValueException("Attribute " + attr.getName() + " is of type: " + attr.getAttributeInfo().type + " and you've tried to set it to " + obj.getObjectName() + " which is of type " + resolvedObject.getConstructionClassName());
                    if (errors == null)
                      errors = new DmcValueExceptionSet();
                    errors.add(ex);
                    continue;
                  }
                 
                  if (resolvedObject == null)
                    System.out.println("HERE");
                 
                 
                  // NOTE: we wouldn't do the backref tracking in the case of DMP
                  // messages (which are marked as supportsBackrefTracking false).
                  if (supportsBackrefTracking()){
//                    if (DmcOmni.instance().backRefTracking() && (attr.ID > 200)){
                    if (DmcOmni.instance().backRefTracking() && DmcOmni.instance().trackThisAttribute(attr.ID)){
                      if (attr.getAttributeInfo().indexSize == 0){
                        // We're modifying a reference attribute, so track that puppy
                        DmcAttribute<?> mod = attr.getNew();
                        mod.setAttributeInfo(attr.getAttributeInfo());
                        try {
                          if (ref instanceof DmcExtendedReferenceIF)
                            mod.add(ref);
                          else
                            mod.add(resolvedObject);
                        } catch (DmcValueException e) {
                          throw(new IllegalStateException("Creating backref for MV attribute during object resolution shouldn't throw exception.",e));
                        }
                       
                        Modifier backrefMod = new Modifier(ModifyTypeEnum.ADD,mod,this);
                        resolvedObject.addBackref(backrefMod);
                       
                        // Let the reference know the backref modifier - this allows us to
                        // easily remove the backref if the reference is deleted
                        ref.setBackrefModifier(backrefMod);
                      }
                      else{
                        DmcAttribute<?> mod = attr.getNew();
                        mod.setAttributeInfo(attr.getAttributeInfo());
                        try {
                          if (ref instanceof DmcExtendedReferenceIF)
                            mod.setMVnth(currIndex, null);
                          else
                            mod.setMVnth(currIndex, null);
                        } catch (DmcValueException e) {
                          throw(new IllegalStateException("Creating backref for indexed attribute during object resolution shouldn't throw exception.",e));
                        }
                       
                        Modifier backrefMod = new Modifier(ModifyTypeEnum.NTH,mod,this,currIndex);
                        resolvedObject.addBackref(backrefMod);
                       
                        ref.setBackrefModifier(backrefMod);
                      }
                    }
View Full Code Here

Examples of org.dmd.dmc.types.Modifier

     
      DmcAttribute<?> existing = null;
     
      Iterator<Modifier> modifiers = mods.getMV();
      while(modifiers.hasNext()){
        Modifier mod = modifiers.next();
        existing = get(mod.getAttributeName());
       
        // HACK: have to rationalize the attrInfo thing
        if (existing != null)
          existing.getAttributeInfo();
       
        switch(mod.getModifyType()){
        case ADD:
          if (existing == null){
            Iterator<Object> it = (Iterator<Object>) mod.getAttribute().getMV();
            Object value = it.next();
            if (value instanceof DmcNamedObjectREF){
              // we do things a little different for object refs because it relies on the lastValue
              // to create the backref modifier
              existing = mod.getAttribute().getNew();
             
              DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>)value;
              Object lastValue = existing.add(ref);
              setLastValue(lastValue);
             
              add(existing.getAttributeInfo(),existing);
            }
            else{
              // NOTE: we add a clone of the attribute since, if we don't, we wind
              // up storing the attribute instance that's in the modifier and adding
              // stuff to it!
              add(mod.getAttributeName(), mod.getAttribute().cloneIt());
            }
            anyChange = true;
          }
          else{
            Iterator<Object> it = (Iterator<Object>) mod.getAttribute().getMV();
            Object value = it.next();
            // NOTE: there will only ever be one value in the attribute and we have
            // to use an Iterator to get the value out.
 
            if ((value instanceof DmcNamedObjectREF) && !(value instanceof DmcExtendedReferenceIF)){
              // If the attribute is an object reference, we have to determine
              // whether we have the object or just its name - and perform the
              // add() accordingly.
              DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>)value;
              Object lastValue = existing.add(ref);
             
              if (lastValue != null){
                setLastValue(lastValue);
                anyChange = true;
                add(existing.getAttributeInfo(),existing);
              }
            }
            else{
              if ( existing.add(value) != null)
                anyChange = true;
            }
          }
          break;
        case DEL:
          if (existing == null){
            // The attribute being modified doesn't exist
            // TODO what to do with the deletion of a value from a non-existent attribute???
          }
          else{
            // NOTE: there will only ever be one value in the attribute and we have
            // to use an Iterator to get the value out.
            Iterator<Object> it = (Iterator<Object>) mod.getAttribute().getMV();
            Object value = it.next();
           
            if ( (value instanceof DmcNamedObjectREF) && !(value instanceof DmcExtendedReferenceIF)){           
              // If the attribute is an object reference, we have to determine
              // whether we have the object or just its name - and perform the
              // del() accordingly.
              DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>)value;
             
              setLastValue(ref);
              anyChange = true;
              del(existing.getAttributeInfo(), value);
            }
            else{
              if (value instanceof DmcMappedAttributeIF){
                if (existing.del(((DmcMappedAttributeIF)value).getKey()) != null)
                  anyChange = true;
              }

              else if ( existing.del(value) != null){
                anyChange = true;
              }
            }
           
            if (existing.getMVSize() == 0){
              rem(existing.getAttributeInfo());
            }
          }
          break;
        case SET:
          if (existing == null){
            set(mod.getAttributeName(),mod.getAttribute());
            anyChange = true;
          }
          else{
            Object value = mod.getAttribute().getSV();
           
            if (value instanceof DmcNamedObjectREF){
              // We had a value in this attribute to start with, so clean
              // up the back reference before we apply the new value
              ((DmcTypeNamedObjectREF<?, ?>)existing).removeBackReferences();
             
              DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>)value;
              if (existing.set(ref) != null){
                set(existing.getAttributeInfo(),existing);
                anyChange = true;
              }
            }
            else{
              if (existing.set(mod.getAttribute().getSV()) != null)
                anyChange = true;
            }
          }
          break;
        case NTH:
          // When a value is nulled, the modifier just contains the attribute info, not
          // a value holding attribute.
          int index = mod.getIndex();
          Object value = null;
         
          if (mod.getAttribute() != null)
            value = mod.getAttribute().getMVnth(index);
         
          if (existing == null){
            // NOTE: we add a clone of the attribute since, if we don't, we wind
            // up storing the attribute instance that's in the modifier and adding
            // stuff to it!
            if (value != null){
              setLastValue(value);
              nth(mod.getAttribute().getAttributeInfo(),index,mod.getAttribute().cloneIt(),null);
              anyChange = true;
            }
          }
          else{
            Object previous = existing.getMVnth(index);
           
            if (value == null){
              // We're removing the value at the current slot
             
              // We currently have a value and we're nulling it so there's been a change
              if (previous != null){
                existing.setMVnth(index, value);
                setLastValue(value);
                nth(existing.getAttributeInfo(), index, existing, previous);
                anyChange = true;
              }
            }
            else{

//              if ((value instanceof DmcNamedObjectREF) && !(value instanceof DmcExtendedReferenceIF)){
              if (value instanceof DmcNamedObjectREF){
                // If the attribute is an object reference, we have to determine
                // whether we have the object or just its name - and perform the
                // add() accordingly.
                DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>)value;
               
                if (existing.setMVnth(index, ref) != null){
                  setLastValue(ref);
                  nth(existing.getAttributeInfo(), index, existing, previous);
                  anyChange = true;
                }
               
              }
              else{
                if ( existing.setMVnth(index,value) != null)
                  anyChange = true;
              }
             
            }
           
            if (!existing.hasValue()){
              rem(existing.getAttributeInfo());
            }

          }
          break;
        case REM:
          if (rem(mod.getAttributeName()) != null)
            anyChange = true;
          break;
        }
      }
     
View Full Code Here

Examples of org.dmd.dmc.types.Modifier

        // The unique set of attributes affected by the modifcations
        HashSet<DmcAttributeInfo> mayBeChanged = new HashSet<DmcAttributeInfo>();
       
      Iterator<Modifier> modifiers = mods.getMV();
      while(modifiers.hasNext()){
        Modifier mod = modifiers.next();
        mayBeChanged.add(mod.getAttributeInfo());
      }
     
      for(DmcAttribute<?> attr: attributes.values()){
        if (mayBeChanged.contains(attr.getAttributeInfo())){
          // Store a clone of the affected attribute
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.