Package modTransf.model.java

Source Code of modTransf.model.java.JavaObjectModelHelper

//Source file: H:\\TEMP\\generated\\ispuml\\isp\\JmiModelUtil.java

package modTransf.model.java;

import modTransf.model.ModelHelper;
import modTransf.model.ModelHelperBase;
import modTransf.model.ModelException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collection;
import java.lang.Class;

  /**
   * A ModelUtil implementation suitable for graph of java object.
   * @author Cedric Dumoulin
   * @version 1.0
   */
public class JavaObjectModelHelper extends ModelHelperBase implements ModelHelper
{

  /**
   * The list of owned objects.
   */
protected List ownedObjects = new ArrayList();

  /**
   * The list of objects declared as model roots.
   * This is the user reponsability to register roots.
   */
protected List modelRoots = new ArrayList();

/** The stereotype mnr */
protected StereotypeMngr stereotypeMngr;

  /**
   * Constructor.
   * Create an Helper with no native model.
   */
  public JavaObjectModelHelper()
  {
  super(null);
  }

    /**
     * Constructor.
     * Create an Helper with provided model as native model.
     * This is not really useful as there is no underlying model !
     */
  public JavaObjectModelHelper(Object nativeModel)
  {
  super(nativeModel);
  }


    /**
     * Is this ModelUtil owner of the specified object ?
     * If a model is owner of an object, it means that the methods of the
     * model can called on the object.
     * This method return true if this ModelUtil implementation can manage the
     * specified object (method of this class can be called on the object).
     * @param object The object to test.
     * @return true if the associated model is owner of the object, false otherwise.
     */
  public boolean isOwnerOf( Object object )
  {
  return ownedObjects.contains(object);
  }

   /**
    * @param object
    * @param instanceName
    * @return boolean
    * @roseuid 3F26F54000F7
    */
   public boolean isInstanceOf(Object object, String instanceName)
   {
   try
     {
     Class type = getClass().forName(instanceName);
     return type.isInstance(object);
     }
    catch( ClassNotFoundException ex )
     {
     return false;
     }

   }

   /**
    *
    * @param object
    * @param instanceName
    * @return
    */
  public boolean isOfClass(Object object, String instanceName)
     throws ModelException
  {
  return object.getClass().getName().equals( instanceName);
  }

   /**
    * Is the object the model outermost package ?
    * @param object
    * @return boolean
    * @deprecated ?? Replaced with nativeModel
    */
   public boolean isModelOutermostPackage(Object object)
   {
     if( nativeModel == null )
       return false;

   return object == nativeModel;
   }

  /*
   * Get the roots of the model. Roots are concepts that are not contains or
   * owned by other concepts.
   * @return Collection
   */
   public Collection getModelRoots()
     throws ModelException
   {
     return modelRoots;
   }

   /**
    * Get all the instances of the specified type or one of its subtype.
    * @param conceptType
    * @return Collection
    */
   public Collection getAllOfType(String conceptType)
   {
     throw new UnsupportedOperationException( "Not implemented." );
   }

   /**
    * Get all instance of the specified type. Subtype are not taken into account.
    * @param conceptType
    * @return Collection
    */
   public Collection getAllOfClass(String conceptType)
   {
     throw new UnsupportedOperationException( "Not implemented." );
   }

   /**
    * Register a root to the model. The added root must belong to the model.
    * @param root Object
    */
   public void addModelRoot(Object root)
   {
     modelRoots.add(root);
   }


   /**
    * Create an instance of specified model element.
    * @param instanceName Name of the instance to create.
    * @return
    * @throws InstantiationException If the model element can't be created.
    */
  public Object createInstance( String conceptName )
     throws InstantiationException
  {
   try
     {
     Class type = getClass().forName(conceptName);
     Object res = type.newInstance();
     ownedObjects.add(res);
     return res;
     }
    catch( Exception ex )
     {
       ex.printStackTrace();
     throw new InstantiationException("Can't create concept '" + conceptName + "', "
                    + ex.getMessage() );
     }
  }

   /* ********************* */
   /*  UML related methods  */
   /* ********************* */

   /**
    * @param object
    * @param stereotype
    * @return boolean
    * @roseuid 3F26F5400151
    */
   public boolean isStereotyped(Object object, String stereotype)
   {
     if( stereotypeMngr == null )
       return false;

     return stereotypeMngr.isStereotyped(object, stereotype);
   }

   /**
    * @param object
    * @return List
    * @roseuid 3F26F5400197
    */
   public List getStereotypes(Object object)
   {
     if( stereotypeMngr == null )
       return Collections.EMPTY_LIST;

     return stereotypeMngr.getStereotypes(object);
   }

   /**
    * @param object
    * @param stereotype
    * @roseuid 3F26F54001BF
    */
   public void addStereotype(Object object, String stereotype)
     throws ModelException
   {
     if( stereotypeMngr == null )
       stereotypeMngr = new StereotypeMngr();

     stereotypeMngr.addStereotype(object, stereotype);
   }

   /**
    * Get the value of the tagged value associated to the stereotype.
    * @param object The object
    * @param stereotype Name of the stereotype to which the value belong
    * @param attributeName The name of the stereotype attribute (tagged value)
    * @return The value of the stereotype attribute (tagged value).
    * @throws ModelException
    */
   public Object getStereotypeTaggedValue(Object object, String stereotype, String attributeName)
     throws ModelException
   {
     if( stereotypeMngr == null )
       return null;

     return stereotypeMngr.getStereotypeTaggedValue(object, stereotype, attributeName);
   }

   /**
    *
    * Set the value of the tagged value associated to the stereotype.
    * @param object The object
    * @param stereotype Name of the stereotype to which the value belong
    * @param attributeName The name of the stereotype attribute (tagged value)
    * @param value The value to be set
    * @throws ModelException
    */
   public void setStereotypeTaggedValue(Object object, String stereotype, String attributeName, Object value)
     throws ModelException
   {
     if( stereotypeMngr == null )
       stereotypeMngr = new StereotypeMngr();

     stereotypeMngr.setStereotypeTaggedValue(object, stereotype, attributeName, value);
   }

  public void setNativeModel(Object nativeModel)
  {
    this.nativeModel = nativeModel;
  }

  /**
   * deleteInstance
   *
   * @param instance Object
   */
  public void deleteInstance(Object instance)
  {
    throw new UnsupportedOperationException("Not yet implemented.");
  }

  /**
   * invokeMethod
   *
   * @param object Object
   * @param name String
   * @param args Object[]
   * @return Object
   */
  public Object invokeMethod(Object object, String name, Object[] args)
  {
    throw new UnsupportedOperationException("Not yet implemented.");
  }

}
TOP

Related Classes of modTransf.model.java.JavaObjectModelHelper

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.