/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.aspects.patterns.singleton;

import org.jboss.aop.joinpoint.ConstructorInvocation;

/**
 * A simple implementation of a singleton.<p>
 * 
 * This advice should be PER_CLASS scoped<p>
 * 
 * e.g.
 * <pre>  
 * <aspect class="Singleton" scope="PER_CLASS"/>
 *
 * <bind pointcut="execution(POJO->new())">
 *     <advice name="constructorAdvice" aspect="Singleton"/>
 * </bind>
 * </pre>
 *
 * 
 * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
 * @version $Revision: 1.1.2.3 $
 */
public class Singleton
{
   private Object singleton;

   public synchronized Object constructorAdvice(ConstructorInvocation invocation) throws Throwable
   {
      if (singleton == null)
         singleton = invocation.invokeNext();
      return singleton;
   }
}
