/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.demo;

import java.util.GregorianCalendar;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.enterprise.inject.Default;
import javax.inject.Inject;

/**
 *
 * @author hyl
 */
@Decorator
public class HelloDecorator implements HelloInterface {

    /**
     * 这里注入默认的实现类
     */
    @Default
    @Inject
    @Delegate
    private HelloInterface bean;

    @Override
    public String greeting() {
        System.out.println("Decorator...");
        // 这里覆盖默认的实现类，类似于代理
        GregorianCalendar ca = new GregorianCalendar();

        if (ca.get(GregorianCalendar.AM_PM) == 0) {
            return bean.greeting() + "morning! ";
        } else {
            return bean.greeting() + "afternoon! ";
        }
    }

}
