/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Header:$
 */
/**
 *
 */
package controls;

import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.bean.ControlImplementation;
import org.apache.beehive.controls.api.context.Context;
import org.apache.beehive.controls.api.context.ControlBeanContext;
import org.apache.beehive.controls.api.context.ResourceContext;
import org.apache.beehive.controls.api.events.EventHandler;
import service.EventRecorderService;

import java.io.Serializable;

/**
 * Outer control implementation, invoked directly from page flow.
 */
@ControlImplementation
public class OuterControlImpl implements OuterControl, Serializable {
    private static final long serialVersionUID = 1L;

    @Control
    private InnerControl _innerControl;

    @Context
    private ControlBeanContext _cbc;

    @Context
    private ResourceContext _rc;

    @Context
    private EventRecorderService _lc;

    /**
     * onCreate EventHandler.
     */
    @EventHandler(field = "_cbc", eventSet = ControlBeanContext.LifeCycle.class, eventName = "onCreate")
    public void onCreate() {
        _lc.logEvent(this, EventRecorderService.EventType.ON_CREATE);
    }

    /**
     * onAcquire EventHandler.
     */
    @EventHandler(field = "_rc", eventSet = ResourceContext.ResourceEvents.class, eventName = "onAcquire")
    public void onAcquire() {
        _lc.logEvent(this, EventRecorderService.EventType.ON_ACQUIRE);
    }

    /**
     * onRelease EventHandler.
     */
    @EventHandler(field = "_rc", eventSet = ResourceContext.ResourceEvents.class, eventName = "onRelease")
    public void onRelease() {
        _lc.logEvent(this, EventRecorderService.EventType.ON_RELEASE);
    }

    /**
     * Does not invoke any InnerControl methods.
     */
    public void outerMethod() {
        _lc.logUserEvent(this, "outerMethod() invoked.");
        return;
    }

    /**
     * Invokes InnerControl methods.
     */
    public void invokeInnerControlMethod() {
        _lc.logUserEvent(this, "invokeInnerControlMethod() invoked.");
        _innerControl.innerMethod1();
        _innerControl.innerMethod2();
    }
}