Ejemplo n.º 1
0
 private void handleCreateEvent(object[] parameters)
 {
     if (parameters.Length < 2)
     {
         throw new ParameterException("The create event needs at least 2 parameters.");
     }
     else
     {
         RuntimeClassBase source           = (RuntimeClassBase)parameters [0];
         string           association_name = (string)parameters [1];
         Association      association      = this.instances_map[source].getAssociation(association_name);
         if (association.allowedToAdd())
         {
             int      constructor_parameters_length = parameters.Length - 2;
             object[] constructor_parameters        = new object[constructor_parameters_length];
             Array.Copy(parameters, 2, constructor_parameters, 0, constructor_parameters_length);
             InstanceWrapper new_instance_wrapper = this.createInstance(association.getClassName(), constructor_parameters);
             association.addInstance(new_instance_wrapper);
             source.addEvent(
                 new Event(name: "instance_created", parameters: new object[] { association_name })
                 );
         }
         else
         {
             source.addEvent(
                 new Event(name: "instance_creation_error", parameters: new object[] { association_name })
                 );
         }
     }
 }
Ejemplo n.º 2
0
 private void handleAssociateEvent(object[] parameters)
 {
     if (parameters.Length != 3)
     {
         throw new ParameterException("The associate_instance event needs 3 parameters.");
     }
     else
     {
         RuntimeClassBase       source       = (RuntimeClassBase)parameters [0];
         List <InstanceWrapper> to_copy_list = this.getInstances(source, this.processAssociationReference((string)parameters [1]));
         if (to_copy_list.Count != 1)
         {
             throw new AssociationReferenceException("Invalid source association reference.");
         }
         InstanceWrapper             wrapped_to_copy_instance = to_copy_list [0];
         List <Tuple <string, int> > dest_list = this.processAssociationReference((string)parameters [2]);
         if (dest_list.Count == 0)
         {
             throw new AssociationReferenceException("Invalid destination association reference.");
         }
         Tuple <string, int> last_tuple = dest_list [dest_list.Count - 1];
         if (last_tuple.Item2 != -1)
         {
             throw new AssociationReferenceException("Last association name in association reference should not be accompanied by an index.");
         }
         dest_list.RemoveAt(dest_list.Count - 1);
         foreach (InstanceWrapper i in this.getInstances(source, dest_list))
         {
             i.getAssociation(last_tuple.Item1).addInstance(wrapped_to_copy_instance);
         }
     }
 }
Ejemplo n.º 3
0
        public InstanceWrapper createInstance(string class_name, object[] construct_params)
        {
            InstanceWrapper iw = this.instantiate(class_name, construct_params);

            if (iw != null)
            {
                this.instances_map[iw.getInstance()] = iw;
            }
            return(iw);
        }
Ejemplo n.º 4
0
 public void addInstance(InstanceWrapper instance)
 {
     if (this.allowedToAdd())
     {
         this.instances.Add(instance);
     }
     else
     {
         throw new AssociationException("Not allowed to add the instance to the association.");
     }
 }