int object_id1 = aP.getObjectId().intValue(); Collection class_name1 = aP.getClassNames(); int object_id2 = pP.getObjectId().intValue(); Collection class_name2 = pP.getClassNames(); int association_id = aInst.getAssociationId().intValue();
    public void executeRelateAction( RelateAction a, Context c ) throws LemRuntimeException {        // check both ends of the association to see if the classes are of        // correct type        boolean valid_active, valid_passive;        valid_active = valid_passive = false;        Instance active = null;        Instance passive = null;        runtime.Object obj = null;                runtime.Object aP = (runtime.Object)(( ObjectReferenceVariable ) c.getVariable( a.getActiveObjectName() )).getValue();        runtime.Object pP = (runtime.Object)(( ObjectReferenceVariable ) c.getVariable( a.getPassiveObjectName() )).getValue();                // retrieve the names of the classes participating in the association        metamodel.Class aP_class = a.getAssociation().getActivePerspective().getDomainClass();        metamodel.Class pP_class = a.getAssociation().getPassivePerspective().getDomainClass();                Collection ac = aP.getInstances();        Collection pc = pP.getInstances();                        Iterator i = ac.iterator();        while ( i.hasNext() && !( valid_passive || valid_active ) ) {            active = ( Instance ) i.next();            if ( active.getInstanceClass() == aP_class )                valid_active = true;            else if ( ( active.getInstanceClass() == pP_class ) && !( a.getVerbClause() ) )                valid_passive = true;        }                if ( !( valid_active || valid_passive ) )            throw new LemRuntimeException( "Objects does not have the required instances for association " + a.getAssociation().getName() );        i = pc.iterator();                while ( i.hasNext() && !( valid_passive && valid_active ) ) {                        passive = ( Instance ) i.next();            if ( passive.getInstanceClass() == pP_class )                                                valid_passive = true;            else if ( ( passive.getInstanceClass() == aP_class ) && !( a.getVerbClause() ) )                valid_active = true;        }        if ( !( valid_active && valid_passive ) )            throw new LemRuntimeException( "Objects does not have the required instances for association " + a.getAssociation().getName() );                AssociationInstance aInst = new AssociationInstance( a.getAssociation() );        aInst.setActiveInstance( active );        aInst.setPassiveInstance( passive );                // creating clause is present        if(a.getLinkObjectName() != null) {            CreateAction ca = new CreateAction();            LinkedList l = new LinkedList();            l.add(a.getAssociation().getAssociationClassRole().getAssociationClass());            ca.setClasses((Collection)l);            obj = executeCreateAction(ca, c);            if(obj == null)                throw new LemRuntimeException("Exception occurred in creating link object.");            aInst.setLinkObjectInstance(obj);        }                if ( c.containsAssociationInstance( aInst ) != null )            throw new LemRuntimeException( "The association already exist between the two objects" );        c.addAssociationInstance( aInst );                // create a new LemEvent and notify all listeners        int object_id1 = aP.getObjectId().intValue();        Collection class_name1 = aP.getClassNames();                int object_id2 = pP.getObjectId().intValue();           Collection class_name2 = pP.getClassNames();                int association_id = aInst.getAssociationId().intValue();        if(obj == null)            new LemRelationshipCreationEvent( object_id1, class_name1, object_id2, class_name2, association_id ).notifyAll( c );        else             new LemRelationshipCreationEvent( object_id1, class_name1, object_id2, class_name2, association_id, obj.getObjectId().intValue()).notifyAll( c );                }