gt:             if (handle instanceof Classifier) {
context: // $Id: FacadeMDRImpl.java 132 2010-09-26 23:32:33Z marcusvnac $
  // Copyright (c) 2005-2008 The Regents of the University of California. All
  // Rights Reserved. Permission to use, copy, modify, and distribute this
  // software and its documentation without fee, and without a written
  // agreement is hereby granted, provided that the above copyright notice
  // and this paragraph appear in all copies. This software program and
  // documentation are copyrighted by The Regents of the University of
  // California. The software program and documentation are supplied "AS
  // IS", without any accompanying services from The Regents. The Regents
  // does not warrant that the operation of the program will be
  // uninterrupted or error-free. The end-user understands that the program
  // was developed for research purposes and is advised not to rely
  // exclusively on the program for any reason. IN NO EVENT SHALL THE
  // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
  // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
  // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
  // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
  // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
  // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
  // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
  // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  
  package org.argouml.model.mdr;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Set;
  
  import javax.jmi.model.MofClass;
  import javax.jmi.model.Reference;
  import javax.jmi.reflect.InvalidObjectException;
  import javax.jmi.reflect.RefBaseObject;
  import javax.jmi.reflect.RefClass;
  import javax.jmi.reflect.RefFeatured;
  import javax.jmi.reflect.RefObject;
  import javax.jmi.reflect.RefPackage;
  
  //#if defined(LOGGING)
  //@#$LPS-LOGGING:GranularityType:Import
  import org.apache.log4j.Logger;
  //#endif
  import org.argouml.model.CoreFactory;
  import org.argouml.model.Facade;
  import org.argouml.model.InvalidElementException;
  import org.omg.uml.behavioralelements.activitygraphs.ActionState;
  import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
  import org.omg.uml.behavioralelements.activitygraphs.CallState;
  import org.omg.uml.behavioralelements.activitygraphs.ClassifierInState;
  import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
  import org.omg.uml.behavioralelements.activitygraphs.Partition;
  import org.omg.uml.behavioralelements.activitygraphs.SubactivityState;
  import org.omg.uml.behavioralelements.collaborations.AssociationEndRole;
  import org.omg.uml.behavioralelements.collaborations.AssociationRole;
  import org.omg.uml.behavioralelements.collaborations.ClassifierRole;
  import org.omg.uml.behavioralelements.collaborations.Collaboration;
  import org.omg.uml.behavioralelements.collaborations.CollaborationInstanceSet;
  import org.omg.uml.behavioralelements.collaborations.Interaction;
  import org.omg.uml.behavioralelements.collaborations.InteractionInstanceSet;
  import org.omg.uml.behavioralelements.collaborations.Message;
  import org.omg.uml.behavioralelements.commonbehavior.Action;
  import org.omg.uml.behavioralelements.commonbehavior.ActionSequence;
  import org.omg.uml.behavioralelements.commonbehavior.Argument;
  import org.omg.uml.behavioralelements.commonbehavior.AttributeLink;
  import org.omg.uml.behavioralelements.commonbehavior.CallAction;
  import org.omg.uml.behavioralelements.commonbehavior.ComponentInstance;
  import org.omg.uml.behavioralelements.commonbehavior.CreateAction;
  import org.omg.uml.behavioralelements.commonbehavior.DataValue;
  import org.omg.uml.behavioralelements.commonbehavior.DestroyAction;
  import org.omg.uml.behavioralelements.commonbehavior.Instance;
  import org.omg.uml.behavioralelements.commonbehavior.Link;
  import org.omg.uml.behavioralelements.commonbehavior.LinkEnd;
  import org.omg.uml.behavioralelements.commonbehavior.LinkObject;
  import org.omg.uml.behavioralelements.commonbehavior.NodeInstance;
  import org.omg.uml.behavioralelements.commonbehavior.Reception;
  import org.omg.uml.behavioralelements.commonbehavior.ReturnAction;
  import org.omg.uml.behavioralelements.commonbehavior.SendAction;
  import org.omg.uml.behavioralelements.commonbehavior.Signal;
  import org.omg.uml.behavioralelements.commonbehavior.Stimulus;
  import org.omg.uml.behavioralelements.commonbehavior.SubsystemInstance;
  import org.omg.uml.behavioralelements.commonbehavior.TerminateAction;
  import org.omg.uml.behavioralelements.commonbehavior.UmlException;
  import org.omg.uml.behavioralelements.commonbehavior.UninterpretedAction;
  import org.omg.uml.behavioralelements.statemachines.CallEvent;
  import org.omg.uml.behavioralelements.statemachines.ChangeEvent;
  import org.omg.uml.behavioralelements.statemachines.CompositeState;
  import org.omg.uml.behavioralelements.statemachines.Event;
  import org.omg.uml.behavioralelements.statemachines.FinalState;
  import org.omg.uml.behavioralelements.statemachines.Guard;
  import org.omg.uml.behavioralelements.statemachines.Pseudostate;
  import org.omg.uml.behavioralelements.statemachines.SignalEvent;
  import org.omg.uml.behavioralelements.statemachines.SimpleState;
  import org.omg.uml.behavioralelements.statemachines.State;
  import org.omg.uml.behavioralelements.statemachines.StateMachine;
  import org.omg.uml.behavioralelements.statemachines.StateVertex;
  import org.omg.uml.behavioralelements.statemachines.StubState;
  import org.omg.uml.behavioralelements.statemachines.SubmachineState;
  import org.omg.uml.behavioralelements.statemachines.SynchState;
  import org.omg.uml.behavioralelements.statemachines.TimeEvent;
  import org.omg.uml.behavioralelements.statemachines.Transition;
  import org.omg.uml.behavioralelements.usecases.Actor;
  import org.omg.uml.behavioralelements.usecases.Extend;
  import org.omg.uml.behavioralelements.usecases.ExtensionPoint;
  import org.omg.uml.behavioralelements.usecases.Include;
  import org.omg.uml.behavioralelements.usecases.UseCase;
  import org.omg.uml.foundation.core.Abstraction;
  import org.omg.uml.foundation.core.Artifact;
  import org.omg.uml.foundation.core.AssociationClass;
  import org.omg.uml.foundation.core.AssociationEnd;
  import org.omg.uml.foundation.core.Attribute;
  import org.omg.uml.foundation.core.BehavioralFeature;
  import org.omg.uml.foundation.core.Binding;
  import org.omg.uml.foundation.core.Classifier;
  import org.omg.uml.foundation.core.Comment;
  import org.omg.uml.foundation.core.Component;
  import org.omg.uml.foundation.core.Constraint;
  import org.omg.uml.foundation.core.DataType;
  import org.omg.uml.foundation.core.Dependency;
  import org.omg.uml.foundation.core.Element;
  import org.omg.uml.foundation.core.ElementResidence;
  import org.omg.uml.foundation.core.Enumeration;
  import org.omg.uml.foundation.core.EnumerationLiteral;
  import org.omg.uml.foundation.core.Feature;
  import org.omg.uml.foundation.core.Flow;
  import org.omg.uml.foundation.core.GeneralizableElement;
  import org.omg.uml.foundation.core.Generalization;
  import org.omg.uml.foundation.core.Interface;
  import org.omg.uml.foundation.core.Method;
  import org.omg.uml.foundation.core.ModelElement;
  import org.omg.uml.foundation.core.Namespace;
  import org.omg.uml.foundation.core.Node;
  import org.omg.uml.foundation.core.Operation;
  import org.omg.uml.foundation.core.Parameter;
  import org.omg.uml.foundation.core.Permission;
  import org.omg.uml.foundation.core.Primitive;
  import org.omg.uml.foundation.core.Relationship;
  import org.omg.uml.foundation.core.Stereotype;
  import org.omg.uml.foundation.core.StructuralFeature;
  import org.omg.uml.foundation.core.TagDefinition;
  import org.omg.uml.foundation.core.TaggedValue;
  import org.omg.uml.foundation.core.TemplateArgument;
  import org.omg.uml.foundation.core.TemplateParameter;
  import org.omg.uml.foundation.core.UmlAssociation;
  import org.omg.uml.foundation.core.UmlClass;
  import org.omg.uml.foundation.core.Usage;
  import org.omg.uml.foundation.datatypes.ActionExpression;
  import org.omg.uml.foundation.datatypes.AggregationKind;
  import org.omg.uml.foundation.datatypes.AggregationKindEnum;
  import org.omg.uml.foundation.datatypes.CallConcurrencyKind;
  import org.omg.uml.foundation.datatypes.CallConcurrencyKindEnum;
  import org.omg.uml.foundation.datatypes.ChangeableKind;
  import org.omg.uml.foundation.datatypes.ChangeableKindEnum;
  import org.omg.uml.foundation.datatypes.Expression;
  import org.omg.uml.foundation.datatypes.Multiplicity;
  import org.omg.uml.foundation.datatypes.MultiplicityRange;
  import org.omg.uml.foundation.datatypes.OrderingKind;
  import org.omg.uml.foundation.datatypes.OrderingKindEnum;
  import org.omg.uml.foundation.datatypes.ParameterDirectionKind;
  import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
  import org.omg.uml.foundation.datatypes.PseudostateKind;
  import org.omg.uml.foundation.datatypes.ScopeKind;
  import org.omg.uml.foundation.datatypes.ScopeKindEnum;
  import org.omg.uml.foundation.datatypes.VisibilityKind;
  import org.omg.uml.foundation.datatypes.VisibilityKindEnum;
  import org.omg.uml.modelmanagement.ElementImport;
  import org.omg.uml.modelmanagement.Model;
  import org.omg.uml.modelmanagement.Subsystem;
  import org.omg.uml.modelmanagement.UmlPackage;
  
  /**
   * Model Facade implementation.
   *
   * This class provides read-only access to model data in the repository.
   * Factories and setters are in separate UML package specific classes.
   * <p>
   * Most methods in this class can throw the run-time exception
   * {@link org.argouml.model.InvalidElementException}.
   * <p>
   * Unless otherwise noted by the Javadoc, all methods in this class implement
   * methods from the interface {@link Facade}.
   */
  class FacadeMDRImpl implements Facade {
      //#if defined(LOGGING)
      //@#$LPS-LOGGING:GranularityType:Field
      /**
       * Logger.
       */
      private static final Logger LOG = Logger.getLogger(FacadeMDRImpl.class);
      //#endif
      private MDRModelImplementation modelImpl;
  
      // Shorthand notation for convenience
      private static final javax.jmi.model.AggregationKindEnum MOF_COMPOSITE =
          javax.jmi.model.AggregationKindEnum.COMPOSITE;
  
      /**
       * Constructor.
       *
       * @param impl
       *            The model implementation
       */
      public FacadeMDRImpl(MDRModelImplementation impl) {
          modelImpl = impl;
      }
      
      public String getUmlVersion() {
          return "1.4";
      }
  
      public boolean isAAbstraction(Object handle) {
          return handle instanceof Abstraction;
      }
  
      public boolean isAAction(Object handle) {
          return handle instanceof Action;
      }
  
      public boolean isAActionExpression(Object handle) {
          return handle instanceof ActionExpression;
      }
  
      public boolean isAActionSequence(Object handle) {
          return handle instanceof ActionSequence;
      }
  
      public boolean isAActionState(Object handle) {
          return handle instanceof ActionState;
      }
  
      public boolean isACallState(Object handle) {
          return handle instanceof CallState;
      }
  
      public boolean isAObjectFlowState(Object handle) {
          return handle instanceof ObjectFlowState;
      }
  
      public boolean isASubactivityState(Object handle) {
          return handle instanceof SubactivityState;
      }
  
      public boolean isAActor(Object handle) {
          return handle instanceof Actor;
      }
  
      public boolean isAAggregationKind(Object handle) {
          return handle instanceof AggregationKind;
      }
  
      public boolean isAArgument(Object modelElement) {
          return modelElement instanceof Argument;
      }
  
      public boolean isAArtifact(Object modelElement) {
          return modelElement instanceof Artifact;
      }
      
      public boolean isAAssociation(Object handle) {
          return handle instanceof UmlAssociation;
      }
  
      public boolean isAAssociationEnd(Object handle) {
          return handle instanceof AssociationEnd;
      }
  
      public boolean isAAssociationRole(Object handle) {
          return handle instanceof AssociationRole;
      }
  
      public boolean isAAssociationEndRole(Object handle) {
          return handle instanceof AssociationEndRole;
      }
  
      public boolean isAAttribute(Object handle) {
          return handle instanceof Attribute;
      }
  
      public boolean isAAttributeLink(Object handle) {
          return handle instanceof AttributeLink;
      }
      
      public boolean isAsynchronous(Object handle) {
          if (handle instanceof Action) {
              try {
                  return ((Action) handle).isAsynchronous();
              } catch (InvalidObjectException e) {
                  throw new InvalidElementException(e);
              }
          }
          return illegalArgumentBoolean(handle);
      }
  
      
      public boolean isAbstract(Object handle) {
          try {
              if (handle instanceof Operation) {
                  return ((Operation) handle).isAbstract();
              }
              if (handle instanceof GeneralizableElement) {
                  return ((GeneralizableElement) handle).isAbstract();
              }
              if (handle instanceof UmlAssociation) {
                  return ((UmlAssociation) handle).isAbstract();
              }
              if (handle instanceof Reception) {
                  return ((Reception) handle).isAbstract();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          if (isAUMLElement(handle)) {
              return false;
          } else {
              return illegalArgumentBoolean(handle);
          }
      }
  
      
      public boolean isAActivityGraph(Object handle) {
          return handle instanceof ActivityGraph;
      }
  
      public boolean isABehavioralFeature(Object handle) {
          return handle instanceof BehavioralFeature;
      }
      
      public boolean isABinding(Object handle) {
          return handle instanceof Binding;
      }
      
      public boolean isACallAction(Object handle) {
          return handle instanceof CallAction;
      }
  
      public boolean isACallEvent(Object handle) {
          return handle instanceof CallEvent;
      }
  
      public boolean isAChangeEvent(Object handle) {
          return handle instanceof ChangeEvent;
      }
  
      public boolean isAClass(Object handle) {
          return handle instanceof UmlClass;
      }
  
      public boolean isAAssociationClass(Object handle) {
          return handle instanceof AssociationClass;
      }
  
      public boolean isAClassifier(Object handle) {
          return handle instanceof Classifier;
      }
  
      public boolean isAClassifierInState(Object handle) {
          return handle instanceof ClassifierInState;
      }
  
      public boolean isAClassifierRole(Object handle) {
          return handle instanceof ClassifierRole;
      }
  
      public boolean isAComment(Object handle) {
          return handle instanceof Comment;
      }
  
      public boolean isACollaboration(Object handle) {
          return handle instanceof Collaboration;
      }
  
      public boolean isACollaborationInstanceSet(Object handle) {
          return handle instanceof CollaborationInstanceSet;
      }
  
      public boolean isAComponent(Object handle) {
          return handle instanceof Component;
      }
  
      public boolean isAComponentInstance(Object handle) {
          return handle instanceof ComponentInstance;
      }
  
      public boolean isAConstraint(Object handle) {
          return handle instanceof Constraint;
      }
  
      public boolean isACreateAction(Object handle) {
          return handle instanceof CreateAction;
      }
  
      public boolean isADataType(Object handle) {
          return handle instanceof DataType;
      }
  
      public boolean isADataValue(Object handle) {
          return handle instanceof DataValue;
      }
  
      public boolean isADependency(Object handle) {
          return handle instanceof Dependency;
      }
  
      public boolean isADestroyAction(Object handle) {
          return handle instanceof DestroyAction;
      }
  
      public boolean isACompositeState(Object handle) {
          return handle instanceof CompositeState;
      }
  
      public boolean isAElement(Object handle) {
          return handle instanceof Element;
      }
  
      public boolean isAElementImport(Object handle) {
          return handle instanceof ElementImport;
      }
  
      public boolean isAElementResidence(Object handle) {
          return handle instanceof ElementResidence;
      }
  
      public boolean isAEvent(Object handle) {
          return handle instanceof Event;
      }
  
      public boolean isAException(Object handle) {
          return handle instanceof UmlException;
      }
  
      public boolean isAExpression(Object handle) {
          return handle instanceof Expression;
      }
  
      public boolean isAExtend(Object handle) {
          return handle instanceof Extend;
      }
  
      public boolean isAExtensionPoint(Object handle) {
          return handle instanceof ExtensionPoint;
      }
  
      public boolean isAFeature(Object handle) {
          return handle instanceof Feature;
      }
  
      public boolean isAFinalState(Object handle) {
          return handle instanceof FinalState;
      }
  
      public boolean isAFlow(Object handle) {
          return handle instanceof Flow;
      }
  
      public boolean isAGuard(Object handle) {
          return handle instanceof Guard;
      }
  
      public boolean isAGeneralizableElement(Object handle) {
          return handle instanceof GeneralizableElement;
      }
  
      public boolean isAGeneralization(Object handle) {
          return handle instanceof Generalization;
      }
  
      public boolean isAInclude(Object handle) {
          return handle instanceof Include;
      }
  
      public boolean isAInstance(Object handle) {
          return handle instanceof Instance;
      }
  
      public boolean isAInteraction(Object handle) {
          return handle instanceof Interaction;
      }
  
      public boolean isAInteractionInstanceSet(Object handle) {
          return handle instanceof InteractionInstanceSet;
      }
      
      public boolean isAInterface(Object handle) {
          return handle instanceof Interface;
      }
  
      public boolean isALink(Object handle) {
          return handle instanceof Link;
      }
  
      public boolean isALinkEnd(Object handle) {
          return handle instanceof LinkEnd;
      }
  
      public boolean isALinkObject(Object handle) {
          return handle instanceof LinkObject;
      }
      
      public boolean isAMessage(Object handle) {
          return handle instanceof Message;
      }
  
      public boolean isAMethod(Object handle) {
          return handle instanceof Method;
      }
  
      public boolean isAModel(Object handle) {
          return handle instanceof Model;
      }
  
      public boolean isAModelElement(Object handle) {
          return handle instanceof ModelElement;
      }
  
      public boolean isAMultiplicity(Object handle) {
          return handle instanceof Multiplicity;
      }
  
      public boolean isAMultiplicityRange(Object handle) {
          return handle instanceof MultiplicityRange;
      }
  
      public boolean isANamedElement(Object handle) {
          return handle instanceof ModelElement;
      }
      
      public boolean isANamespace(Object handle) {
          return handle instanceof Namespace;
      }
  
      public boolean isANaryAssociation(Object handle) {
          if (handle instanceof UmlAssociation) {
              return (getConnections(handle).size() > 2);
          }
          return false;
      }
  
      public boolean isANode(Object handle) {
          return handle instanceof Node;
      }
  
      public boolean isANodeInstance(Object handle) {
          return handle instanceof NodeInstance;
      }
  
      public boolean isAOperation(Object handle) {
          return handle instanceof Operation;
      }
  
      public boolean isAObject(Object handle) {
          return handle
              instanceof org.omg.uml.behavioralelements.commonbehavior.Object;
      }
  
      public boolean isAParameter(Object handle) {
          return handle instanceof Parameter;
      }
  
      public boolean isAPartition(Object handle) {
          return handle instanceof Partition;
      }
  
      public boolean isAPackageImport(Object handle) {
          return handle instanceof Permission;
      }
      
      public boolean isAPackage(Object handle) {
          return handle instanceof UmlPackage;
      }
      
      public boolean isAPrimitiveType(Object handle) {
          return handle instanceof Primitive;
      }
  
      public boolean isAPseudostate(Object handle) {
          return handle instanceof Pseudostate;
      }
  
      public boolean isAPseudostateKind(Object handle) {
          return handle instanceof PseudostateKind;
      }
  
  
      public Object getKind(Object handle) {
          try {
              if (handle instanceof Pseudostate) {
                  return ((Pseudostate) handle).getKind();
              }
              if (handle instanceof Parameter) {
                  return ((Parameter) handle).getKind();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentObject(handle);
      }
  
  
      public Object getReceiver(Object handle) {
          try {
              if (handle instanceof Stimulus) {
                  return ((Stimulus) handle).getReceiver();
              }
              if (handle instanceof Message) {
                  return ((Message) handle).getReceiver();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentObject(handle);
      }
  
  
      public Object getLink(Object handle) {
          try {
              if (handle instanceof LinkEnd) {
                  return ((LinkEnd) handle).getLink();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentObject(handle);
      }
  
  
      public boolean equalsPseudostateKind(Object ps1, Object ps2) {
          try {
              if (isAPseudostateKind(ps1)) {
                  return ((PseudostateKind) ps1).equals(ps2);
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(ps1);
      }
  
  
      public boolean isAReception(Object handle) {
          return handle instanceof Reception;
      }
  
      public boolean isAReturnAction(Object handle) {
          return handle instanceof ReturnAction;
      }
  
      public boolean isARelationship(Object handle) {
          return handle instanceof Relationship;
      }
  
      public boolean isASendAction(Object handle) {
          return handle instanceof SendAction;
      }
  
      public boolean isASignal(Object handle) {
          return handle instanceof Signal;
      }
  
      public boolean isASignalEvent(Object handle) {
          return handle instanceof SignalEvent;
      }
  
      public boolean isASimpleState(Object handle) {
          return handle instanceof SimpleState;
      }
  
      public boolean isAStateMachine(Object handle) {
          return handle instanceof StateMachine;
      }
  
      public boolean isAStimulus(Object handle) {
          return handle instanceof Stimulus;
      }
  
      public boolean isAStateVertex(Object handle) {
          return handle instanceof StateVertex;
      }
  
      public boolean isAStereotype(Object handle) {
          return handle instanceof Stereotype;
      }
  
      public boolean isAStructuralFeature(Object handle) {
          return handle instanceof StructuralFeature;
      }
  
      public boolean isAState(Object handle) {
          return handle instanceof State;
      }
  
      public boolean isAStubState(Object handle) {
          return handle instanceof StubState;
      }
  
      public boolean isASubmachineState(Object handle) {
          return handle instanceof SubmachineState;
      }
  
      public boolean isASubsystem(Object handle) {
          return handle instanceof Subsystem;
      }
  
      public boolean isASubsystemInstance(Object handle) {
          return handle instanceof SubsystemInstance;
      }
      
      public boolean isASynchState(Object handle) {
          return handle instanceof SynchState;
      }
  
      public boolean isATaggedValue(Object handle) {
          return handle instanceof TaggedValue;
      }
      
      public boolean isATemplateArgument(Object handle) {
          return handle instanceof TemplateArgument;
      }
      
      public boolean isATemplateParameter(Object handle) {
          return handle instanceof TemplateParameter;
      }
      
      public boolean isATransition(Object handle) {
          return handle instanceof Transition;
      }
  
      public boolean isATimeEvent(Object handle) {
          return handle instanceof TimeEvent;
      }
  
      
      public boolean isAUMLElement(Object handle) {
          return handle instanceof Element 
                  || handle instanceof ElementImport
                  || handle instanceof ElementResidence
                  || handle instanceof Expression
                  || handle instanceof Multiplicity
                  || handle instanceof MultiplicityRange
                  || handle instanceof TemplateArgument
                  || handle instanceof TemplateParameter;
      }
  
  
      public boolean isAUninterpretedAction(Object handle) {
          return handle instanceof UninterpretedAction;
      }
  
      public boolean isAUsage(Object handle) {
          return handle instanceof Usage;
      }
  
      public boolean isAUseCase(Object handle) {
          return handle instanceof UseCase;
      }
  
      
      public boolean isAVisibilityKind(Object handle) {
          return handle instanceof VisibilityKind;
      }
  
  
      public boolean isActive(Object handle) {
          try {
              if (handle instanceof UmlClass) {
                  return ((UmlClass) handle).isActive();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isConcurrent(Object handle) {
          try {
              if (handle instanceof CompositeState) {
                  return ((CompositeState) handle).isConcurrent();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isAConcurrentRegion(Object handle) {
          try {
              if ((handle instanceof CompositeState)
                      && (getContainer(handle) != null)) {
                  return (isConcurrent(getContainer(handle)));
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return false;
      }
  
  
      public boolean isConstructor(Object handle) {
          try {
              Operation operation = null;
              if (handle instanceof Method) {
                  operation = ((Method) handle).getSpecification();
                  if (operation == null) {
                      // This is not a well formed model in a strict sense. 
                      // See the multiplicity in UML 1.3 Figure 2-5.
                      return false;
                  }
              } else if (handle instanceof Operation) {
                  operation = (Operation) handle;
              } else {
                  return illegalArgumentBoolean(handle);
              }
              
              for (Object stereo : getStereotypes(operation)) {
                  if (modelImpl.getExtensionMechanismsHelper()
                          .isStereotypeInh(stereo, "create", 
                                  "BehavioralFeature")) {
                      return true;
                  }
              }
              return false;
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isFrozen(Object handle) {
          try {
              if (handle instanceof ChangeableKind) {
                  ChangeableKind ck = (ChangeableKind) handle;
                  return ChangeableKindEnum.CK_FROZEN.equals(ck);
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isComposite(Object handle) {
          try {
              if (handle instanceof AssociationEnd) {
                  return AggregationKindEnum.AK_COMPOSITE
                  .equals(((AssociationEnd) handle).getAggregation());
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isAggregate(Object handle) {
          try {
              if (handle instanceof AssociationEnd) {
                  return AggregationKindEnum.AK_AGGREGATE
                          .equals(((AssociationEnd) handle).getAggregation());
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isInitialized(Object handle) {
          try {
              if (handle instanceof Attribute) {
                  Expression init = ((Attribute) handle).getInitialValue();
                  
                  if (init != null && init.getBody() != null
                          && init.getBody().trim().length() > 0) {
                      return true;
                  }
                  return false;
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
      
      public boolean isInternal(Object handle) {
          try {
              if (handle instanceof Transition) {
                  Object state = getState(handle);
                  Object end0 = getSource(handle);
                  Object end1 = getTarget(handle);
                  if (end0 != null) {
                      return ((state == end0) && (state == end1));
                  }
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isLeaf(Object handle) {
          try {
              if (handle instanceof GeneralizableElement) {
                  return ((GeneralizableElement) handle).isLeaf();
              }
              if (handle instanceof Operation) {
                  return ((Operation) handle).isLeaf();
              }
              if (handle instanceof Reception) {
                  return ((Reception) handle).isLeaf();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          if (isAUMLElement(handle)) {
              return false;
          } else {
              return illegalArgumentBoolean(handle);
          }
      }
  
  
      public boolean isRoot(Object handle) {
          try {
              if (handle instanceof GeneralizableElement) {
                  return ((GeneralizableElement) handle).isRoot();
              }
              if (handle instanceof Operation) {
                  return ((Operation) handle).isRoot();
              }
              if (handle instanceof Reception) {
                  return ((Reception) handle).isRoot();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          if (isAUMLElement(handle)) {
              return false;
          } else {
              return illegalArgumentBoolean(handle);
          }
      }
  
  
      public boolean isSpecification(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  return ((ModelElement) handle).isSpecification();
              }
              if (handle instanceof ElementImport) {
                  return ((ElementImport) handle).isSpecification();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
      public boolean isNavigable(Object handle) {
          try {
              if (handle instanceof AssociationEnd) {
                  return ((AssociationEnd) handle).isNavigable();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isPrimaryObject(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  for (TaggedValue tv 
                          : ((ModelElement) handle).getTaggedValue()) {
                      TagDefinition type = tv.getType();
                      if (type != null 
                              && GENERATED_TAG.equals(type.getTagType())) {
                          return false;
                      }
                  }
                  return true;
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isPackage(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  ModelElement element = (ModelElement) handle;
                  return VisibilityKindEnum.VK_PACKAGE.equals(
                          element.getVisibility());
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentBoolean(handle);
      }
  
  
      public boolean isPrivate(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  ModelElement elem = (ModelElement) handle;
                  return VisibilityKindEnum.VK_PRIVATE
                      .equals(elem.getVisibility());
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isPublic(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  ModelElement elem = (ModelElement) handle;
                  return VisibilityKindEnum.VK_PUBLIC
                      .equals(elem.getVisibility());
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isQuery(Object handle) {
          try {
              if (handle instanceof BehavioralFeature) {
                  return ((BehavioralFeature) handle).isQuery();
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isProtected(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  ModelElement elem = (ModelElement) handle;
                  return VisibilityKindEnum.VK_PROTECTED
                      .equals(elem.getVisibility());
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isRealize(Object handle) {
          return isStereotype(handle, CoreFactory.REALIZE_STEREOTYPE);
      }
  
  
      public boolean isReturn(Object handle) {
          return hasReturnParameterDirectionKind(handle);
      }
  
  
      public boolean isSingleton(Object handle) {
          return isStereotype(handle, "singleton");
      }
  
  
      public boolean isStereotype(Object handle, String stereotypeName) {
          try {
              if (handle instanceof ModelElement) {
                  Collection stereotypes =
                      ((ModelElement) handle).getStereotype();
                  Iterator it = stereotypes.iterator();
                  Stereotype stereotype;
                  while (it.hasNext()) {
                      stereotype = (Stereotype) it.next();
                      if (stereotypeName.equals(stereotype.getName())) {
                          return true;
                      }
                  }
                  return false;
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isATerminateAction(Object handle) {
          return handle instanceof TerminateAction;
      }
  
  
      public boolean isTop(Object handle) {
          try {
              if (isACompositeState(handle)) {
                  return ((CompositeState) handle).getStateMachine() != null;
              }
              return illegalArgumentBoolean(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isType(Object handle) {
          return isStereotype(handle, "type");
      }
  
      public boolean isUtility(Object handle) {
          return isStereotype(handle, "utility");
      }
  
  
      public Object getAssociation(Object handle) {
          try {
              if (handle instanceof AssociationEnd) {
                  return ((AssociationEnd) handle).getAssociation();
              }
              if (handle instanceof Link) {
                  return ((Link) handle).getAssociation();
              }
              return illegalArgumentObject(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Object getAssociationEnd(Object handle, Object assoc) {
          try {
              if (handle instanceof Classifier 
                      && assoc instanceof UmlAssociation) {
                  Classifier classifier = (Classifier) handle;
                  Iterator it = getAssociationEnds(classifier).iterator();
                  while (it.hasNext()) {
                      AssociationEnd end = (AssociationEnd) it.next();
                      if (((UmlAssociation) assoc).getConnection()
                              .contains(end)) {
                          return end;
                      }
                  }
                  return null;
              }
              throw new IllegalArgumentException("handle: " + handle + ",assoc: "
                      + assoc);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Collection getAssociationEnds(Object handle) {
          try {
              if (handle instanceof Classifier) {
                  return ((org.omg.uml.UmlPackage) ((ModelElement) handle).refOutermostPackage()).getCore()
                          .getAParticipantAssociation().getAssociation(
                                  (Classifier) handle);
              }
              return illegalArgumentCollection(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Collection getAssociationRoles(Object handle) {
          try {
              if (handle instanceof UmlAssociation) {
                  return ((org.omg.uml.UmlPackage) ((ModelElement) handle).refOutermostPackage()).getCollaborations()
                          .getABaseAssociationRole().getAssociationRole(
                                  (UmlAssociation) handle);
              }
              return illegalArgumentCollection(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
      public List getAttributes(Object handle) {
          try {
              if (handle instanceof Classifier) {
                  return getStructuralFeatures(handle);
              }
              return illegalArgumentList(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Collection<String> getBaseClasses(Object handle) {
          try {
              if (isAStereotype(handle)) {
                  return ((Stereotype) handle).getBaseClass();
              }
              return illegalArgumentCollection(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Object getBase(Object handle) {
          try {
              if (handle instanceof AssociationEndRole) {
                  return ((AssociationEndRole) handle).getBase();
              } else if (handle instanceof AssociationRole) {
                  return ((AssociationRole) handle).getBase();
              } else if (handle instanceof Extend) {
                  return ((Extend) handle).getBase();
              } else if (handle instanceof Include) {
                  return ((Include) handle).getBase();
              } else if (handle instanceof ClassifierRole) {
                  // TODO: this returns a Collection, not a single Object
                  // Is this what the callers expect?
                  return ((ClassifierRole) handle).getBase();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentObject(handle);
      }
  
  
      public Collection<Classifier> getBases(Object handle) {
          try {
              if (handle instanceof ClassifierRole) {
                  return ((ClassifierRole) handle).getBase();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentCollection(handle);
      }
  
  
      public Collection getBehaviors(Object handle) {
          try {
              if (handle instanceof ModelElement) {
                  ModelElement me = (ModelElement) handle;
                  return ((org.omg.uml.UmlPackage) me.refOutermostPackage())
                          .getStateMachines().getABehaviorContext().getBehavior(
                                  me);
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentCollection(handle);
      }
  
  
      public Object getBehavioralFeature(Object handle) {
          try {
              if (handle instanceof Parameter) {
                  return ((Parameter) handle).getBehavioralFeature();
              }
              return illegalArgumentCollection(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Object getBody(Object handle) {
          try {
              if (handle instanceof Comment) {
                  // Text was stored in name in UML 1.3
                  return ((Comment) handle).getBody();
              }
              if (handle instanceof Constraint) {
                  return ((Constraint) handle).getBody();
              }
              if (handle instanceof Expression) {
                  return ((Expression) handle).getBody();
              }
              if (handle instanceof Method) {
                  return ((Method) handle).getBody();
              }
              return illegalArgumentObject(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public int getBound(Object handle) {
          try {
              if (handle instanceof SynchState) {
                  return ((SynchState) handle).getBound();
              }
              return illegalArgumentInt(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      @SuppressWarnings("deprecation")
      public Object getChangeability(Object handle) {
          try {
              if (handle instanceof StructuralFeature) {
                  return ((StructuralFeature) handle).getChangeability();
              }
              if (handle instanceof AssociationEnd) {
                  return ((AssociationEnd) handle).getChangeability();
              }
              return illegalArgumentObject(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public boolean isReadOnly(Object handle) {
          ChangeableKind ck;
          try {
              if (handle instanceof StructuralFeature) {
                  ck = ((StructuralFeature) handle).getChangeability();
              } else if (handle instanceof AssociationEnd) {
                  ck = ((AssociationEnd) handle).getChangeability();
              } else {
                  return illegalArgumentBoolean(handle);
              }
              return ChangeableKindEnum.CK_FROZEN.equals(ck);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
      public Object getSpecific(Object handle) {
          try {
              if (handle instanceof Generalization) {
                  return ((Generalization) handle).getChild();
              }
              return illegalArgumentObject(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
      
  
      public Collection<GeneralizableElement> getChildren(Object handle) {
          try {
              return modelImpl.getCoreHelper().getChildren(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Collection getClassifierRoles(Object handle) {
          try {
              if (handle instanceof Feature) {
                  return ((org.omg.uml.UmlPackage) ((ModelElement) handle).refOutermostPackage()).getCollaborations()
                          .getAClassifierRoleAvailableFeature()
                          .getClassifierRole((Feature) handle);
              }
              if (handle instanceof Classifier) {
                  return ((org.omg.uml.UmlPackage) ((ModelElement) handle).refOutermostPackage()).getCollaborations()
                          .getAClassifierRoleBase().getClassifierRole(
                                  (Classifier) handle);
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentCollection(handle);
      }
  
  
      public Object getClassifier(Object handle) {
          try {
              if (isAAssociationEnd(handle)) {
                  return ((AssociationEnd) handle).getParticipant();
              }
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
          return illegalArgumentObject(handle);
      }
  
  
      public Collection<Classifier> getClassifiers(Object handle) {
          try {
              if (handle instanceof Instance) {
                  return ((Instance) handle).getClassifier();
              }
              return illegalArgumentCollection(handle);
          } catch (InvalidObjectException e) {
              throw new InvalidElementException(e);
          }
      }
  
  
      public Collection getClassifiersInState(Object handle) {
          try {
  