예제 #1
0
 def _isTypeOf(value1, value2):
     if isinstance(value2, JavaClass):
         value2 = ModelioMetamodel.getMClass(value2)
     try:
         return value1.getMClass() is value2
     except:
         return False
예제 #2
0
 def _newIsTypeOfMETA(metaInterface):
     meta_class = ModelioMetamodel.getMClass(metaInterface)
     def isTypeOfMETA(value):
         try:
             return value.getMClass() is meta_class
         except:
             return False
     return isTypeOfMETA
예제 #3
0
def isTypeOf(element,mclassOrMInterface):
  """ Check if the element has exactly the type specified, not one of
      its subtype. Use isKindOf to test if the type is exactly the one 
      specified.
      EXAMPLES
        print isTypeOf(instanceNamed(DataType,"string"),DataType)
        print isTypeOf(instanceNamed(DataType,"string"),Element)
  """
  if isinstance(mclassOrMInterface,JavaClass):
    mclassOrMInterface = Metamodel.getMClass(mclassOrMInterface)
  return element.getMClass() is mclassOrMInterface
예제 #4
0
def isTypeOf(element, mclassOrMInterface):
    """ Check if the element has exactly the type specified, not one of
      its subtype. Use isKindOf to test if the type is exactly the one 
      specified.
      EXAMPLES
        print isTypeOf(instanceNamed(DataType,"string"),DataType)
        print isTypeOf(instanceNamed(DataType,"string"),Element)
  """
    if isinstance(mclassOrMInterface, JavaClass):
        mclassOrMInterface = Metamodel.getMClass(mclassOrMInterface)
    return element.getMClass() is mclassOrMInterface
예제 #5
0
def getMClass(nameOrMInterfaceOrElement):
  """ Return the MClass corresponding to a name, a java interface
      or an element.
      (Class | String | Element) -> MClass
      EXAMPLES:
        print getMClass(UseCase)
        print getMClass("UseCase")
        print getMClass(myUseCase1)
  """
  if isinstance(nameOrMInterfaceOrElement,Element):
    return nameOrMInterfaceOrElement.getMClass()
  else:
    return Metamodel.getMClass(nameOrMInterfaceOrElement)
예제 #6
0
def getMClass(nameOrMInterfaceOrElement):
    """ Return the MClass corresponding to a name, a java interface
      or an element.
      (Class | String | Element) -> MClass
      EXAMPLES:
        print getMClass(UseCase)
        print getMClass("UseCase")
        print getMClass(myUseCase1)
  """
    if isinstance(nameOrMInterfaceOrElement, Element):
        return nameOrMInterfaceOrElement.getMClass()
    else:
        return Metamodel.getMClass(nameOrMInterfaceOrElement)
예제 #7
0
 def named(cls, name):
     return ModelioMetamodel.getMClass(name).getJavaInterface()
예제 #8
0
    def _addFeaturesToAllMetaInterfaces():

        def _new(cls, *args, **kwargs):
            method = getattr(cls.metaFactory, 'create' + cls.metaName)
            return method(*args, **kwargs)

        def _allInstances(cls):
            """
            Return the set of all instances of a given metaclass or java meta
            interface.

            Provides both the direct instances but also instances of all
            subclasses. :return: The set all all instances, direct or indirect.
            :rtype: Set[MObject]
            """
            return pyalaocl.asSet(_theSession().findByClass(cls))


        def _named(cls, name):
            """
            Return the only instance that have the given name.
            If there is more than one instance then raise an exception Invalid
            (MClass|Class)*String -> MObject|NameError
            """
            r = _theSession().findByAtt(cls, 'Name', name)
            if len(r) == 1:
                return r[0]
            elif len(r) == 0:
                raise pyalaocl.Invalid('No %s named "%s"' % (cls, name))
            else:
                raise pyalaocl.Invalid(
                    'More than one element named %s (%s elements)' \
                    % (name, str(len(r))))

        def _selectByAttribute(cls, attribute, value):
            """
            Return the list of all the instances that have the
            property set to the given value.
            NOTE: Not sure how to deal with property that are not string.
            (MClass|Class)*String*String -> List(MObject)
            EXAMPLES
              selectedInstances(DataType,"Name","string")
            """
            return pyalaocl.asSet(
                _theSession().findByAtt(cls, attribute, value))

        # for some reason it is not possible to inject elements into MClasses

        # TODO: log print '    Injecting class methods/attributes in ' \
        #      + 'Modelio MetaInterfaces (%s) ...' \
        #        % MetaInterface.allInstances().size(),
        for mi in MetaInterface.allInstances():
            # FIXME: these properties should be registered with symbol manager
            mi.metaClass = ModelioMetamodel.getMClass(mi)
            mi.metaInterface = mi
            mi.metaFullName = mi.getCanonicalName()
            mi.metaPackage = '.'.join(mi.metaFullName.split('.')[:-1])
            mi.metaName = mi.metaClass.name
            mi.metaIsAbstract = mi.metaClass.isAbstract()

            meta_super = mi.metaClass.super
            mi.metaSuper = \
                None if meta_super is None else meta_super.javaInterface
            mi.metaSubs = mi.metaClass.getSub(False).javaInterface.asSet()
            mi.metaAllSub = mi.metaClass.getSub(True).javaInterface.asSet()
            mi.metaCmsNode = mi.metaClass.isCmsNode()
            mi.metaFactory = _getFactory(mi)
            if mi.metaFactory is not None:
                mi.new = classmethod(_new)
            mi.allInstances = classmethod(_allInstances)
            mi.named = classmethod(_named)
            mi.selectByAttribute = classmethod(_selectByAttribute)
예제 #9
0
 def named(cls, name):
     return ModelioMetamodel.getMClass(name)