/*====================================================================
Tnis file was produced by the OpenCCM ir3_jimpl generator.
OpenCCM: The Open CORBA Component Model Platform
Copyright (C) 2000-2002 USTL - LIFL - GOAL
Contact: openccm-team@objectweb.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA
Initial developer(s): Philippe Merle, Mathieu Vadet.
Contributor(s): ______________________________________.
====================================================================*/
 
package cisksu.basicsp;
 
/**
 **  Implementation skeleton class for the ::basicsp::BMClosedED component.
 **  Business operations MUST be completed !!!
 **/
public class BMClosedEDMonolithicImpl
       extends org.omg.CORBA.LocalObject
    implements CCM_BMClosedED,
	       CCM_ReadData,
	       CCM_DataAvailableConsumer,
	       org.omg.Components.SessionComponent
{
    // ==================================================================
    //
    // Internal State.
    //
    // ===================================================================
     
    /**
     **  Context reference.
     **/
    private CCM_BMClosedED_Context the_context_;
    private String data;
     
     private javax.swing.JFrame frame_;

    /** To refer to the GUI output area. */
    private javax.swing.JTextArea textArea_;

    // ==================================================================
    //
    // Constructor.
    //
    // ===================================================================
     
    /**
     **  The default constructor.
     **/
    public
    BMClosedEDMonolithicImpl()
    {
        //the_context_ = null;
    }
     
    // ==================================================================
    //
    // Internal methods.
    //
    // ===================================================================
     
    // ==================================================================
    //
    // Public methods.
    //
    // ===================================================================
     
    /**
     **  To obtain the context.
     **
     **  @return The context that has been previously set by 
     **          the set_ccm_context operation.
     **/
    /*public CCM_BMClosedED_Context
    getContext()
    {
        return the_context_;
	}*/
    // ==================================================================
    //
    // Methods for the OMG IDL Components::EnterpriseComponent local interface.
    //
    // ==================================================================
     
    //
    //  IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
    //
    /**
     **  Completes the component configuration.
     **
     **  @throws org.omg.Components.InvalidConfiguration
     **          Thrown if the configuration is invalid.     
     **/
    public void
    configuration_complete()
    throws org.omg.Components.InvalidConfiguration
    {
        //
        //  TODO : implement !!!
        //
	frame_ = new javax.swing.JFrame( "BMClosedED's GUI");
        // Sets its size.
        frame_.setSize(400, 300);

        // Creates a text area for displaying inputs.
        textArea_ = new javax.swing.JTextArea(40, 20);
        textArea_.setEditable(false);

        // Constructs and shows the GUI.
        javax.swing.JPanel panel = new javax.swing.JPanel(
                                       new java.awt.BorderLayout()
                                   );
        frame_.getContentPane().add(panel);
        panel.add(new javax.swing.JScrollPane(textArea_),
                  java.awt.BorderLayout.CENTER);
        frame_.pack();
        frame_.show();
    }
     
    //
    //  IDL:omg.org/Components/EnterpriseComponent/set_ccm_context:1.0
    //
    /**
     **  Set the component context.
     **
     **  @param context The context.
     **
     **  @throws org.omg.Components.CCMException
     **          Thrown if a system level error occured.
     **/
    /*public void
    set_ccm_context(org.omg.Components.CCMContext context)
    throws org.omg.Components.CCMException
    {
        the_context_ = (CCM_BMClosedED_Context)context;
	}*/

    public void
    set_session_context(org.omg.Components.SessionContext context)
    throws org.omg.Components.CCMException
    {
        the_context_ = (CCM_BMClosedED_Context)context;
    }

    /**
     * Container callback to signal that the component is activated.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_activate()
    throws org.omg.Components.CCMException
    {
        // Nothing to do currently.
    }				

    /**
     * Container callback to signal that the component is activated.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_passivate()
    throws org.omg.Components.CCMException
    {
        // Nothing to do currently.
    }				

    /**
     * Container callback to signal that the component is removed.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_remove() 
    throws org.omg.Components.CCMException
    {
	frame_.dispose();
	frame_ = null;
    }				 
    
    // ==================================================================
    //
    // Public methods for the CCM_BMClosedED local interface.
    //
    // ==================================================================
     
    //
    //  IDL:cisksu/basicsp/CCM_BMClosedED/get_dataOut:1.0
    //
    /**
     **  Implementation of the ::basicsp::CCM_BMClosedED::get_dataOut operation.
     **/
    public cisksu.basicsp.CCM_ReadData
    get_dataOut()
    {
        //
        //  TODO : implement
        //
        return this;
    }
    
    public String getData() {
 //       System.err.println("AirFrame get data is called: "+Thread.currentThread().getName());
	//System.err.println("BMClosedED.getData is called");
	//         textArea_.append("BMClosedED.getData is called" + "\n");
	return data;
    }

    //
    //  IDL:cisksu/basicsp/CCM_BMClosedED/push_inDataAvailable:1.0
    //
    /**
     **  Implementation of the ::basicsp::CCM_BMClosedED::push_inDataAvailable operation.
     **/
    int i=1;
    public void
    push_inDataAvailable(cisksu.basicsp.DataAvailable event)
    {
//	textArea_.append("BMClosedED got"+(i++)+"th  DataAvailable event" + "\n");
	//System.err.println("BMClosedED got an DataAvailable event");
	push(event);
    }
    public void push(cisksu.basicsp.DataAvailable event)
    {
//        System.err.println("AirFrame Thread: "+Thread.currentThread().getName());
	ReadData dataIn = the_context_.get_connection_dataIn();
            
	if(dataIn == null)
	{
	    System.err.println("The basicsp::BMClosedED::dataIn receptacle is not set!");
	    return;
	}
//        System.err.println("AirFrame before reading thread: "+Thread.currentThread().getName());
	data=dataIn.getData();
 //       System.err.println("AirFrame after reading thread: "+Thread.currentThread().getName());
	the_context_.push_outDataAvailable(new cisksu.basicsp.DataAvailableImpl( ));
    }
}


syntax highlighted by Code2HTML, v. 0.9