/*
 * Copyright (c) 2006-2009 by Dirk Riehle, http://dirkriehle.com
 *
 * This file is part of the Wahlzeit rating application.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package com.amos.project4.controllers;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.util.ArrayList;

import com.amos.project4.models.AbstractViewModel;
import com.amos.project4.views.AbstractControlledView;

public abstract class AbstractController implements  PropertyChangeListener {   
    
	private ArrayList<AbstractControlledView> registeredViews;
    private ArrayList<AbstractViewModel> registeredModels;
    protected Object evt_object;

    public AbstractController() {
        registeredViews = new ArrayList<AbstractControlledView>();
        registeredModels = new ArrayList<AbstractViewModel>();
    }


    public void addModel(AbstractViewModel model) {
        registeredModels.add(model);
        model.addPropertyChangeListener(this);
    }

    public void removeModel(AbstractViewModel model) {
        registeredModels.remove(model);
        model.removePropertyChangeListener(this);
    }

    public void addView(AbstractControlledView view) {
        registeredViews.add(view);
    }

    public void removeView(AbstractControlledView view) {
        registeredViews.remove(view);
    }


    //  Use this to observe property changes from registered models
    //  and propagate them on to all the views.
    public void propertyChange(PropertyChangeEvent evt) {
    	evt_object = evt.getNewValue();
    	for (AbstractControlledView view: registeredViews) {
            view.modelPropertyChange(evt);
        }
    }


    /**
     * This is a convenience method that subclasses can call upon
     * to fire property changes back to the models. This method
     * uses reflection to inspect each of the model classes
     * to determine whether it is the owner of the property
     * in question. If it isn't, a NoSuchMethodException is thrown,
     * which the method ignores.
     *
     * @param propertyName = The name of the property.
     * @param newValue = An object that represents the new value
     * of the property.
     */
    protected void setModelProperty(String propertyName, Object newValue) {
        for (AbstractViewModel model: registeredModels) {
            try {

                Method method = model.getClass().
                    getMethod("set"+propertyName, new Class[] {
                                                      newValue.getClass()
                                                  }


                             );
                method.invoke(model, newValue);

            } catch (Exception ex) {
                //  Handle exception.
            }
        }
    }
}
@@ -3,128 +3,78 @@
 %0A * 
-Copyright (c) 2006-2009 by Dirk Riehle, http://dirkriehle.com%0A *%0A * This file is part of the Wahlzeit rating application
+%0A * This file is part of the software project %22Social Media and Datev%22
 .%0A *
@@ -3374,8 +3374,9 @@
 %0A    %7D%0A%7D
+%0A

Update AbstractController.java