Package org.dmd.dmc

Examples of org.dmd.dmc.DmcObject


   * @throws DmcValueException
   * @throws ClassNotFoundException
   * @throws ClassNotFoundException 
   */
  public DmcObject createObject(DmcUncheckedObject uco) throws ResultException, DmcValueException, ClassNotFoundException {
    DmcObject      dmo  = null;
    ClassDefinition    cd  = null;
    AttributeDefinition  ad  = null;
   
    if ((cd = schema.isClass((String)uco.classes.get(0))) == null){
          ResultException ex = new ResultException();
            ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(0));
            throw(ex);
    }
   
//    DebugInfo.debug(uco.toOIF(15));
   
    dmo = cd.newDMOInstance();
   
    // Add the object class
    DmcTypeClassDefinitionREFMV cref = new DmcTypeClassDefinitionREFMV();
    cref.add(cd.getObjectName());
   
    dmo.add(DmcObject.__objectClass, cref);
   
    // And add any auxiliary classes if we have them
    for(int i=1; i<uco.classes.size(); i++){
      if ((cd = schema.isClass((String)uco.classes.get(i))) == null){
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(i));
              throw(ex);
      }
      cref.add(cd.getObjectName());
      dmo.add("objectClass", cref);
    }
   
    Iterator<String> names = uco.getAttributeNames();
    while(names.hasNext()){
      String n = names.next();
      ad = schema.adef(n);
     
      if (ad == null){
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown attribute: " + n);
              throw(ex);
      }
     
      DmcAttributeInfo ai = dmo.getAttributeInfo(n);
      if (ai == null){
        ai = ad.getAttributeInfo();
      }
     
//      DmcAttributeInfo ai = DmcOmni.instance().getInfo(ad.getDmdID());
     
      if (ai == null)
        throw(new IllegalStateException("Unknown attribute id: " + ad.getDmdID() + " for attribute: " + ad.getName()));
     
      NamedStringArray values = null;
     
      switch(ad.getValueType()){
      case SINGLE:
        values = uco.get(n);
       
        try {
          // Try to get the attribute
//          DmcAttribute<?> attr = dmo.get(ad.getName().getNameString());
          DmcAttribute<?> attr = dmo.get(ai);
         
          // If we can't find the attribute container, create it
          if (attr == null)
            attr = ad.getType().getAttributeHolder(ai);
         
          // Set the value
          attr.set(values.get(0));
         
          // Store the attribute
          dmo.set(ai, attr);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (DmcValueException e) {
          throw(e);
        }
        break;
      case MULTI:
      case HASHMAPPED:
      case TREEMAPPED:
      case HASHSET:
      case TREESET:
        values = uco.get(n);
       
        for (String attrVal: values){
          try {
            // Try to get the attribute
//            DmcAttribute<?> attr = dmo.get(ad.getName().getNameString());
            DmcAttribute<?> attr = dmo.get(ai);
           
            // If we can't find the attribute container, create it
            if (attr == null)
              attr = ad.getType().getAttributeHolder(ai);
                       
            // Add the value to the container
            attr.add(attrVal);
         
            // Store the attribute
            dmo.add(ai, attr);
          } catch (InstantiationException e) {
            e.printStackTrace();
          } catch (IllegalAccessException e) {
            e.printStackTrace();
          } catch (DmcValueException e) {
View Full Code Here


   * @return true if the reference can be resolved.
   */
  private boolean resolveIt(DmcObject referrer, DmcNamedObjectREF ref){
    boolean resolved = true;
   
    DmcObject obj = DmcOmni.instance().findNamedDMO(ref.getObjectName());
   
    // Couldn't find it - nuttin' we can do 'bout dat!
    if (obj == null){
      DmcOmni.instance().logDeadReference(referrer, this, ref.getObjectName());
     
      if (DmcOmni.instance().cleanUpDeadRefs())
        resolved = false;
    }
    else{
      // Set the object in the reference
      ref.setObject((DmcNamedObjectIF) obj);
     
      // And if backref tracking is on, inform the object that it's being tracked
      if (DmcOmni.instance().backRefTracking()){
        if (referrer.supportsBackrefTracking()){
          Modifier backrefMod = null;
         
          DmcAttribute<?> mod = this.getNew();
          mod.setAttributeInfo(getAttributeInfo());
          try {
            if (getAttributeInfo().valueType == ValueTypeEnum.SINGLE)
              mod.set(ref);
            else
              mod.add(ref);
          } catch (DmcValueException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
         
          if (getAttributeInfo().valueType == ValueTypeEnum.SINGLE)
            backrefMod = new Modifier(ModifyTypeEnum.SET,mod,referrer);
          else
            backrefMod = new Modifier(ModifyTypeEnum.ADD,mod,referrer);
         
          obj.addBackref(backrefMod);
         
//System.out.println("Resolved ref " + ref.getObjectName().getNameString() + " hash = " + System.identityHashCode(ref));
          // And tell the reference it's back reference modifier
          ref.setBackrefModifier(backrefMod);
        }
View Full Code Here

   
    @Override
    // org.dmd.dms.util.GenUtility.dumpMVType(GenUtility.java:2363)
    public DmcObject add(Object v) throws DmcValueException {
        synchronized(this){
            DmcObject rc = typeCheck(v);
            if (value == null)
                value = new ArrayList<DmcObject>();
            value.add(rc);
            return(rc);
        }
View Full Code Here

    public DmcObject del(Object v){
        synchronized(this){
            if (value == null)
                return(null);
   
            DmcObject key = null;
            DmcObject rc = null;
            try {
                key = typeCheck(v);
            } catch (DmcValueException e) {
                throw(new IllegalStateException("Incompatible type passed to del():" + getName(),e));
            }
View Full Code Here

                throw(new IllegalStateException("Attribute: " + getAttributeInfo().name + " is not indexed. You can't use setMVnth()."));
           
            if ( (index < 0) || (index >= getAttributeInfo().indexSize))
                throw(new IllegalStateException("Index " + index + " for attribute: " + getAttributeInfo().name + " is out of range: 0 <= index < " + getAttributeInfo().indexSize));
           
            DmcObject rc = null;
           
            if (v != null)
                rc = typeCheck(v);
           
            if (value == null){
View Full Code Here

        synchronized(this){
            if (value == null)
                return(false);

            try {
                DmcObject val = typeCheck(v);
                return(value.contains(val));
            } catch (DmcValueException e) {
                return(false);
            }
        }
View Full Code Here

    }
   
    @Override
    // org.dmd.dms.util.GenUtility.dumpSVType(GenUtility.java:2010)
    public DmcObject set(Object v) throws DmcValueException {
        DmcObject 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

   * @throws ResultException
   * @throws Exception
   */
  public DmwWrapper deserialize(DmcInputStreamIF dis) throws Exception {
    DmwWrapper rc = null;
    DmcObject dmo = null;
       
    // READ: the number of classes in the objectClass
    int classCount = dis.readInt();
   
    // READ: the construction class ID
    int classID = dis.readInt();
   
    // Try to find the class in the schema
    ClassDefinition cd = schema.isClass(classID);
   
    if (cd == null)
      throw new IllegalStateException("Unknown class ID: " + classID + " ensure that you have loaded the required schemas.");
   
    // Instantiate the object
    rc = cd.newInstance();
    dmo = rc.getDmcObject();
       
    // Add the auxiliary classes if they exist
    if (classCount > 1){
      for(int i=1; i<classCount; i++){
        classID = dis.readInt();
        cd = schema.isClass(classID);
        dmo.addAux(new ClassDefinitionREF(cd.getDMO()));
      }
    }
   
    // READ: the number of attributes
    int     attrCount = dis.readAttributeCount();
   
    for(int i=0; i<attrCount; i++){
      DmcAttribute<?> attr = dis.getAttributeInstance();
     
      // READ: the current attribute
      attr.deserializeIt(dis);
     
      if (attr.getAttributeInfo().valueType == ValueTypeEnum.SINGLE)
        dmo.set(attr.getAttributeInfo(), attr);
      else
        dmo.add(attr.getAttributeInfo(), attr);
    }
   
    return(rc);
 
View Full Code Here

   * @throws ResultException
   * @throws Exception
   */
  public DmwWrapper deserializeWithConversion(DmcInputStreamIF dis) throws Exception {
    DmwWrapper rc = null;
    DmcObject dmo = null;
       
    // READ: the number of classes in the objectClass
    int classCount = dis.readInt();
   
    // READ: the construction class ID
    int classID = dis.readInt();
   
    // Try to find the class in the schema
    ClassDefinition cd = schema.isClass(classID);
   
    if (cd == null)
      throw new IllegalStateException("Unknown class ID: " + classID + " ensure that you have loaded the required schemas.");
   
    // Instantiate the object
    rc = cd.newInstance();
    dmo = rc.getDmcObject();
   
//DebugInfo.debug("*** INSTANTIATED: " + cd.getConstructionClassName());
       
    // Add the auxiliary classes if they exist
    if (classCount > 1){
      for(int i=1; i<classCount; i++){
        classID = dis.readInt();
        cd = schema.isClass(classID);
        dmo.addAux(new ClassDefinitionREF(cd.getDMO()));
      }
    }
   
    // READ: the number of attributes
    int     attrCount = dis.readAttributeCount();
//DebugInfo.debug("*** attribute count: " + attrCount);
   
    ClassSpecificInfo csi = classRI.get(dmo.getConstructionClassInfo().id);
   
    for(int i=0; i<attrCount; i++){
      DmcAttribute<?> attr = dis.getAttributeInstance();
     
//DebugInfo.debug("*** ATTRIBUTE: " + attr.getName());

      AttributeReadInterceptor ari = attrRI.get(attr.getAttributeInfo());
     
      // If we don't have a global attribute interceptor, see if there's a class specific one
      if ( (ari == null) && (csi != null) )
        ari = csi.getInterceptor(attr);
     
      if (ari == null)
        attr.deserializeIt(dis);
      else
        ari.handleAttribute(dis, attr);
     
      if (attr.getAttributeInfo().valueType == ValueTypeEnum.SINGLE)
        dmo.set(attr.getAttributeInfo(), attr);
      else
        dmo.add(attr.getAttributeInfo(), attr);
    }
   
    ObjectReadInterceptor ori = objRI.get(dmo.getConstructionClassInfo());
    if (ori != null)
      ori.handleObject(dmo);
   
    return(rc);
 
View Full Code Here

  public void add(DmcNamedObjectIF obj){
    data.put(obj.getObjectName(), obj);
  }
 
  public boolean delete(DmcObjectNameIF objname){
    DmcObject obj = (DmcObject) data.get(objname);
   
    if (obj == null)
      return(false);
   
    obj.youAreDeleted();
   
    data.remove(objname);
   
    return(true);
  }
View Full Code Here

TOP

Related Classes of org.dmd.dmc.DmcObject

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.