#!/usr/bin/env python
import coral
import inspect

def func(x, param1, param2):
    print "This is my function."
    print "There are many like it, but this one is mine."
    print "My function is my best friend.  It is my life."
    print "I must master it as I master my life."
    print "My function, without me is useless.  Without my function,"
    print "I am useless.  I must apply my function true.  I must apply"
    print "better than other functions."
    print "I must apply him before he applies me."
    print "I will.... "
    print "My function is applied to ", x, " with param1=",param1, " param2=", param2
    return 45

coral.PresentationElement.__addOperation__(coral.PyOperation(func, "Python", inspect.getsource(func), 0))

i = 0
for o in coral.PresentationElement.__operations__():
    print "Function name: ", o.getFuncName()
    print "Function object: ", o.getFunc()
    print "Function language: ", o.getOperationLanguage()
    print "Is well-formed rule: ", o.isWFR()
    i += 1

assert(i==1)


d = coral.PresentationElement()
print
print d.func
print
print "right, let's call it."
print
d.func(99, "foobar")

# check inheritance

import coral ; metamodel=coral.lang.UML14

metamodel.Namespace.__addOperation__(coral.PyOperation(func, "Python", inspect.getsource(func), 0))

n=metamodel.Namespace()
ret = n.func(69,"foofoo")
assert(ret == 45)

p=metamodel.Package()
ret = p.func(69,"foofoo")
assert(ret == 45)
