Examples of DmcObject


Examples of org.dmd.dmc.DmcObject

   * @throws DmcValueException
   * @throws ClassNotFoundException
   * @throws ClassNotFoundException 
   */
  public DmcObject createObject(DmcUncheckedObject uco) throws ResultException, DmcValueException, ClassNotFoundException {
    DmcObject      dmo  = null;
    AttributeDefinition  ad  = null;
    ClassDefinition    cd  = schema.cdef(uco.getConstructionClass());
    Class<?>      dmoClass;
   
    if (cd == null){
          ResultException ex = new ResultException();
            ex.result.addResult(Result.ERROR,"Unknown class: " + uco.getConstructionClass());
            ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
            throw(ex);
    }

        if (cd.getClassType() == ClassTypeEnum.ABSTRACT){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.ERROR,"Can't instantiate an ABSTRACT class: " + cd.getDmoImport());
            ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
            throw(ex);         
        }

        try{
          synchronized (this) {
              dmoClass = Class.forName(cd.getDmoImport());
      }
        }
        catch(Exception e){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.FATAL,"Couldn't load Java class: " + cd.getDmoImport());
            ex.result.lastResult().moreMessages(e.getMessage());
            ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
            throw(ex);
        }
       
        try{
          dmo = (DmcObject) dmoClass.newInstance();
        }
        catch(Exception e){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.FATAL,"Couldn't instantiate Java class: " + cd.getDmoImport());
          ex.result.lastResult().moreMessages("This may be because the class doesn't have a constructor that takes no arguments.");
          ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
          throw(ex);
        }
       
   
    // Add the object class
    DmcTypeClassDefinitionREFMV cref = new DmcTypeClassDefinitionREFMV();
    cref.add(cd.getObjectName());
   
    // 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);
    }
   
    dmo.add(DmcObject.__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());
         
          // 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());
           
            // 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

Examples of org.dmd.dmc.DmcObject

   
    @Override
    // org.dmd.dms.util.GenUtility.dumpSETType(GenUtility.java:2659)
    public DmcObject add(Object v) throws DmcValueException {
        synchronized(this){
            DmcObject 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

Examples of org.dmd.dmc.DmcObject

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

Examples of org.dmd.dmc.DmcObject

        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

Examples of org.dmd.dmc.DmcObject

    return null;
  }

  @Override
  public DmcObject getDMOInstance(DmcInputStreamIF dis) throws Exception {
    DmcObject rc = 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.");
   
    // Tricky stuff: we always try to instantiate the wrapper for the object so that
    // we can support the DMW environment i.e. the DMO will have a handle to its
    // container. If something goes wrong, we fall back to directly instantiating
    // the DMO.
    DmwWrapper wrapper = null;
    try {
      wrapper = cd.newInstance();
    }
    catch(Exception ex){
      // Just fall back to instantiating the DMO
    }
   
    if (wrapper == null)
      rc = cd.newDMOInstance();
    else
      rc = wrapper.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);
        rc.addAux(new ClassDefinitionREF(cd.getDMO()));
      }
    }
   
    return(rc);
  }
View Full Code Here

Examples of org.dmd.dmc.DmcObject

        if (cd == null)
          throw(new IllegalStateException("The class definition for " + this.getClass().getName() + " has not been initialized. You must manage the associated schema."));
       
    // Now that the objectClass is stored in the DmcObject as a DmcTypeClassDefinitionREF, we
    // just "resolve" the reference to point to this ClassDefinition
    DmcObject dmo = obj;
    Iterator<ClassDefinitionREF> ocl = dmo.getObjectClass();
    if (ocl != null){
      ClassDefinitionREF cdr = ocl.next();
      if (cdr != null){
        cdr.setObject((ClassDefinitionDMO) cd.getDmcObject());
      }
View Full Code Here

Examples of org.dmd.dmc.DmcObject

  @SuppressWarnings("unchecked")
  public CAST getNext(){
    if (it == null)
      throw(new IllegalStateException("Trying to getNext() on an empty DmwObjectIterator"));
   
    DmcObject obj = it.next();
    return((CAST) obj.getContainer());
  }
View Full Code Here

Examples of org.dmd.dmc.DmcObject

   * @throws DmcValueException
   * @throws ClassNotFoundException 
   */
  public DmwWrapper createWrapper(DmcUncheckedObject uco) throws ResultException, DmcValueException, ClassNotFoundException {
    DmwWrapper       rc = null;
    DmcObject      dmo  = null;
    ClassDefinition    cd  = null;
    AttributeDefinition  ad  = null;
   
    if ((cd = schema.isClass((String)uco.classes.get(0))) == null){
      DebugInfo.debug("UncheckedObject:\n\n" + uco.toOIF());
          ResultException ex = new ResultException();
            ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(0));
            throw(ex);
    }
   
   
    rc  = cd.newInstance();
    dmo = rc.getDmcObject();
           
    // 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){
        DebugInfo.debug("UncheckedObject AUX:\n\n" + uco.toOIF());
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(i));
              throw(ex);
      }
      rc.addAux(cd);
    }
       
    Iterator<String> names = uco.getAttributeNames();
    while(names.hasNext()){
      String n = names.next();
      DmcAttributeInfo ai = dmo.getAttributeInfo(n);
     
      ad = schema.adef(n);
     
      if (ad == null){
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown attribute: " + n);
              throw(ex);
      }
     
      // If the DMO doesn't directly support the attribute i.e. it's not in it
      // attribute info map, the attribute must be associated with an auxiliary class.
      // So, we have to get the DmcAttributeInfo from the attribute definition.
      if (ai == null){
        ai = DmcOmni.instance().getInfo(ad.getDmdID());
        if (ai == null){
              ResultException ex = new ResultException();
                ex.result.addResult(Result.ERROR,"Could not retrieve DmcAttributeInfo for: " + n);
                throw(ex);
        }
      }
     
      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());
         
          // 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) {
          e.setAttributeName(ad.getName().getNameString());
          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());
           
            // 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

Examples of org.dmd.dmc.DmcObject

  public CAST getNext(){
    if (it == null)
      throw(new IllegalStateException("Trying to getNext() on an empty DmwContainerIterator"));
   
    REF ref = it.next();
    DmcObject obj = (DmcObject) ref.getObject();
    if (obj == null)
      throw(new IllegalStateException("Trying to getNext() on an unresolved reference to: " + ref.getKeyAsString() + " from DmwContainerIterator"));
     
    return((CAST) obj.getContainer());
  }
View Full Code Here

Examples of org.dmd.dmc.DmcObject

  ///////////////////////////////////////////////////////////////////////////
  // DmcNameResolverIF implementation
 
  @Override
  public DmcObject findNamedDMO(DmcObjectName name) {
    DmcObject rc = null;
    DmwNamedObjectWrapper wrapper = theCache.get(name);
   
    // If we can't find the object in the cache, fall back to the schema
    if (wrapper == null)
      rc = DmwOmni.instance().findNamedDMO(name);
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.