All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.caucho.config.gen.CandiAspectBeanFactory Maven / Gradle / Ivy

/*
 * Copyright (c) 1998-2018 Caucho Technology -- all rights reserved
 *
 * This file is part of Resin(R) Open Source
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * Resin Open Source is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Resin Open Source 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, or any warranty
 * of NON-INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Resin Open Source; if not, write to the
 *
 *   Free Software Foundation, Inc.
 *   59 Temple Place, Suite 330
 *   Boston, MA 02111-1307  USA
 *
 * @author Scott Ferguson
 */
package com.caucho.config.gen;

import java.io.IOException;
import java.util.HashMap;

import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;

import com.caucho.config.inject.InjectManager;
import com.caucho.inject.Module;
import com.caucho.java.JavaWriter;

/**
 * Manages aspect factories for a bean.
 */
@Module
public class CandiAspectBeanFactory implements AspectBeanFactory {
  private InjectManager _manager;
  
  private AnnotatedType _beanType;
  private AspectFactory _factory;
  
  public CandiAspectBeanFactory(InjectManager manager,
                                AnnotatedType beanType)
  {
    _manager = manager;
    
    _beanType = beanType;
    _factory = createAspectFactory();
  }
  
  /**
   * Returns the bean type.
   */
  @Override
  public AnnotatedType getBeanType()
  {
    return _beanType;
  }
  
  /**
   * Returns the generated bean name
   */
  @Override
  public String getGeneratedClassName()
  {
    return getBeanType().getJavaClass().getSimpleName() + "__ResinWebBean";
  }

  @Override
  public String getInstanceClassName()
  {
    // ioc/0c5b
    return getBeanType().getJavaClass().getSimpleName();
  }

  /**
   * Returns the head aspect factory
   */
  @Override
  public AspectFactory getHeadAspectFactory()
  {
    return _factory;
  }
  
  /**
   * Returns true for a proxied instance
   */
  @Override
  public boolean isProxy()
  {
    // ioc/0c5b
    return true;
  }
  
  /**
   * Returns the bean instance Java reference.
   */
  @Override
  public String getBeanInstance()
  {
    // ioc/0c5b
    // return "this";
    return "_bean";
  }
  
  /**
   * Returns the interceptor instance Java reference.
   */
  @Override
  public String getInterceptorInstance()
  {
    return getBeanInstance();
  }
  
  /**
   * Returns the bean super reference.
   */
  @Override
  public String getBeanSuper()
  {
    // ioc/0c5b
    // return "super";
    return "_bean";
  }
  
  /**
   * Returns the proxy Java reference.
   */
  @Override
  public String getBeanProxy()
  {
    return "this";
  }
  
  /**
   * Returns the beanInfo variable for shared bean instance information
   */
  @Override
  public String getBeanInfo()
  {
    return "this";
  }
  
  /**
   * Creates a new aspect for a method.
   */
  @Override
  public AspectGenerator create(AnnotatedMethod method)
  {
    return _factory.create(method, false); 
  }
  
  protected AspectFactory createAspectFactory()
  {
    InjectManager manager = _manager;
    
    AspectFactory next = new MethodTailFactory(this);
    
    next = new InterceptorFactory(this, next, manager);
    next = new CacheFactory(this, next);
    next = new XaFactory(this, next);
    next = new LockFactory(this, next);
    next = new AsynchronousFactory(this, next);
    next = new SecurityFactory(this, next);
    
    return new CandiMethodHeadFactory(this, next);
  }

  @Override
  public boolean isEnhanced()
  {
    if (_factory != null)
      return _factory.isEnhanced();
    else
      return false;
  }

  @Override
  public void generateInject(JavaWriter out, HashMap map) 
    throws IOException
  {
    if (_factory != null)
      _factory.generateInject(out, map);
  }

  @Override
  public void generatePostConstruct(JavaWriter out, HashMap map) 
    throws IOException
  {
    if (_factory != null)
      _factory.generatePostConstruct(out, map);
  }

  @Override
  public void generatePreDestroy(JavaWriter out, HashMap map) 
    throws IOException
  {
    if (_factory != null)
      _factory.generatePreDestroy(out, map);
  }

  @Override
  public void generateEpilogue(JavaWriter out, HashMap map) 
    throws IOException
  {
    if (_factory != null)
      _factory.generateEpilogue(out, map);
  }
  
  public String toString()
  {
    return getClass().getSimpleName() + "[" + _beanType + "]"; 
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy