/*******************************************************************************
 * Copyright © 2008-14, All Rights Reserved
 * Texas Center for Applied Technology
 * Texas A&M Engineering Experiment Station
 * The Texas A&M University System
 * College Station, Texas, USA 77843
 *
 * Proprietary information, not for redistribution.
 ******************************************************************************/

package edu.tamu.tcat.osgi.services.util;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
 * A base implementation to use for bundle activators. This exposes access to
 * framework/system properties and has an accessor for the current {@link BundleContext}
 * which can be used to look up OSGi services.
 */
public class ActivatorBase implements BundleActivator
{
   /**
    * @since 1.1
    */
   protected BundleContext context;
   
   /**
    * @since 1.1
    */
   protected static ActivatorBase instance;

   public ActivatorBase()
   {
      instance = this;
   }

   public BundleContext getContext()
   {
      return context;
   }

   @Override
   public void start(BundleContext bundleContext) throws Exception
   {
      context = bundleContext;
   }

   @Override
   public void stop(BundleContext bundleContext) throws Exception
   {
      context = null;
   }

   /*
    * Access all properties through the context in case they are defined as bundle properties
    * (will fallback to system properties). See context.getProperty().
    */
   public String getProperty(String name, String defaultValue)
   {
      String value = getContext().getProperty(name);
      return (value != null) ? value : defaultValue;
   }

   /*
    * This method is not public. The problem is that subclasses must each define a static
    * accessor for 'instance' to avoid warnings about static access to the wrong class.
    * 
    * If a subclass 'Activator' - used internally in a bundle in which it is defined - is
    * invoked by 'Activator.getDefault()' intending to invoke this method (which is static in its
    * superclass), the method is not actually on 'Activator', but on this class, 'ActivatorBase'.
    * To alleviate this problem, the static accessor must be defined explicitly on any subclass
    * on which this functionality is necessary.
    * 
    * This method is left protected rather than being removed to retain this notice, and also to
    * allow subclasses to invoke it in implementing their own 'getDefault()' even though 'instance'
    * is 'protected' and directly available to subclasses.
    * 
    * In a subclass implementation, the declared return type may either be this type,
    * 'ActivatorBase', or that specific activator sub-type, which allows access to further methods
    * defined in the sub-type.
    */
   protected static ActivatorBase getDefault()
   {
      return instance;
   }
}

@@ -762,2121 +762,2086 @@
 .%0A *
-/%0Apublic class ActivatorBase implements BundleActivator%0A%7B%0A   /**%0A    * @since 1.1%0A    */%0A   protected BundleContext context;%0A   %0A   /**%0A    * @since 1.1%0A    */%0A   protected static ActivatorBase instance;%0A%0A   public ActivatorBase()%0A   %7B%0A      instance = this;%0A   %7D%0A%0A   public BundleContext getContext()%0A   %7B%0A      return context;%0A   %7D%0A%0A   @Override%0A   public void start(BundleContext bundleContext) throws Exception%0A   %7B%0A      context = bundleContext;%0A   %7D%0A%0A   @Override%0A   public void stop(BundleContext bundleContext) throws Exception%0A   %7B%0A      context = null;%0A   %7D%0A%0A   /*%0A    * Access all properties through the context in case they are defined as bundle properties%0A    * (will fallback to system properties). See context.getProperty().%0A    */%0A   public String getProperty(String name, String defaultValue)%0A   %7B%0A      String value = getContext().getProperty(name);%0A      return (value != null) ? value : defaultValue;%0A   %7D%0A%0A   /*%0A    * This method is not public. The problem is that subclasses must each define a static%0A    * accessor for 'instance' to avoid warnings about static access to the wrong class.%0A    * %0A    * If a subclass 'Activator' - used internally in a bundle in which it is defined - is%0A    * invoked by 'Activator.getDefault()' intending to invoke this method (which is static in its%0A    * superclass), the method is not actually on 'Activator', but on this class, 'ActivatorBase'.%0A    * To alleviate this problem, the static accessor must be defined explicitly on any subclass%0A    * on which this functionality is necessary.%0A    * %0A    * This method is left protected rather than being removed to retain this notice, and also to%0A    * allow subclasses to invoke it in implementing their own 'getDefault()' even though 'instance'%0A    * is 'protected' and directly available to subclasses.%0A    * %0A    * In a subclass implementation, the declared return type may either be this type,%0A    * 'ActivatorBase', or that specific activator sub-type, which allows access to further methods%0A    * defined in the sub-type.%0A    */%0A   protected static ActivatorBase getDefault()%0A   %7B%0A      return instanc
+ %3Cp%3E%0A * This implementation contains no static fields or methods because they are inherently%0A * unsafe in this particular environment of bundle activators; i.e. a static field would%0A * be a JVM singleton if multiple activators extend from this same base type.%0A */%0A/*%0A * This base class does not maintain any static 'instance' fields.%0A * The problem is that subclasses must each define a static accessor for 'instance' not%0A * only to avoid warnings about static access to the wrong class but also because the static%0A * instance in the base class *is a singleton for the JVM* and is overwritten by the last%0A * bundle to load that uses this as a base class.%0A * %0A * If a subclass 'Activator' - used internally in a bundle in which it is defined - needs%0A * a static accessor to return itslef, it must maintain that static field to refer to%0A * the correct instance and a static accessor must be defined explicitly on any subclass%0A * on which this functionality is necessary.%0A * %0A * The pattern to use should be to declare a static field, a constructor which assigns%0A * 'this' to that field, and a static accessor for the field:%0A * %3Cpre%3E%0A   private Activator instance;%0A   public Activator() %7B%0A      instance = this;%0A   %7D%0A   public static Activator getDefault() %7B%0A      return instance;%0A   %7D%0A * %3C/pre%3E%0A */%0Apublic class ActivatorBase implements BundleActivator%0A%7B%0A   /**%0A    * @since 1.1%0A    */%0A   protected BundleContext context;%0A   %0A   public BundleContext getContext()%0A   %7B%0A      return context;%0A   %7D%0A%0A   @Override%0A   public void start(BundleContext bundleContext) throws Exception%0A   %7B%0A      context = bundleContext;%0A   %7D%0A%0A   @Override%0A   public void stop(BundleContext bundleContext) throws Exception%0A   %7B%0A      context = null;%0A   %7D%0A%0A   /*%0A    * Access all properties through the context in case they are defined as bundle properties%0A    * (will fallback to system properties). See context.getProperty().%0A    */%0A   public String getProperty(String name, String defaultValue)%0A   %7B%0A      String value = getContext().getProperty(name);%0A      return (value != null) ? value : defaultValu
 e;%0A 

Remove static field and method due to critical data overwrite issues