Package org.dmd.dmc.types

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


      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

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

     
      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

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

   
    @Override
    // org.dmd.dms.util.GenUtility.dumpSETType(GenUtility.java:2659)
    public Modifier add(Object v) throws DmcValueException {
        synchronized(this){
            Modifier rc = typeCheck(v);
            if (value == null)
                initValue();
       
            // If false is returned, we didn't modify the set, so return null
            if (!value.add(rc))
View Full Code Here

   
    @Override
    // org.dmd.dms.util.GenUtility.dumpSETType(GenUtility.java:2676)
    public Modifier del(Object v){
        synchronized(this){
            Modifier rc = null;
            if (value == null)
                return(rc);
           
            try {
                rc = typeCheck(v);
View Full Code Here

        synchronized(this){
            if (value == null)
                return(false);
           
            try {
                Modifier val = typeCheck(v);
                return(value.contains(val));
            } catch (DmcValueException e) {
                return(false);
            }
        }
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.