org.eclipse.e4.core.contexts_1.2.0.v20121221-192508

16:42:55.888 INFO  jd.cli.Main - Decompiling org.eclipse.e4.core.contexts_1.2.0.v20121221-192508.jar
package org.eclipse.e4.core.contexts;

import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

@Qualifier
@Documented
@Target({java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Active {}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.Active
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

public abstract class ContextFunction
  implements IContextFunction
{
  public abstract Object compute(IEclipseContext paramIEclipseContext);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.ContextFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

import java.lang.annotation.Annotation;
import org.eclipse.e4.core.di.IInjector;
import org.eclipse.e4.core.di.InjectionException;
import org.eclipse.e4.core.di.InjectorFactory;
import org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier;
import org.eclipse.e4.core.internal.contexts.ContextObjectSupplier;
import org.eclipse.e4.core.internal.contexts.EclipseContext;

public final class ContextInjectionFactory
{
  private static final IInjector injector = ;
  
  public static void inject(Object object, IEclipseContext context)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    injector.inject(object, supplier);
  }
  
  public static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    return injector.invoke(object, qualifier, supplier);
  }
  
  public static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context, Object defaultValue)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    return injector.invoke(object, qualifier, defaultValue, supplier);
  }
  
  public static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context, IEclipseContext localContext, Object defaultValue)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    PrimaryObjectSupplier tempSupplier = ContextObjectSupplier.getObjectSupplier(localContext, injector);
    return injector.invoke(object, qualifier, defaultValue, supplier, tempSupplier);
  }
  
  public static void uninject(Object object, IEclipseContext context)
    throws InjectionException
  {
    ((EclipseContext)context).removeListenersTo(object);
  }
  
  public static <T> T make(Class<T> clazz, IEclipseContext context)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    return (T)injector.make(clazz, supplier);
  }
  
  public static <T> T make(Class<T> clazz, IEclipseContext context, IEclipseContext staticContext)
    throws InjectionException
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    PrimaryObjectSupplier tempSupplier = ContextObjectSupplier.getObjectSupplier(staticContext, injector);
    return (T)injector.make(clazz, supplier, tempSupplier);
  }
  
  public static void setDefault(IEclipseContext context)
  {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    injector.setDefaultSupplier(supplier);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.ContextInjectionFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

import java.util.WeakHashMap;
import org.eclipse.e4.core.internal.contexts.EclipseContext;
import org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public final class EclipseContextFactory
{
  public static IEclipseContext create()
  {
    return new EclipseContext(null);
  }
  
  public static IEclipseContext create(String name)
  {
    IEclipseContext result = create();
    result.set("debugString", name);
    return result;
  }
  
  private static WeakHashMap<BundleContext, IEclipseContext> serviceContexts = new WeakHashMap();
  
  public static IEclipseContext getServiceContext(BundleContext bundleContext)
  {
    synchronized (serviceContexts)
    {
      IEclipseContext result = (IEclipseContext)serviceContexts.get(bundleContext);
      if (result == null)
      {
        result = new EclipseContextOSGi(bundleContext);
        result.set("debugString", "OSGi context for bundle: " + bundleContext.getBundle().getSymbolicName());
        serviceContexts.put(bundleContext, result);
      }
      return result;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.EclipseContextFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

public abstract interface IContextFunction
{
  public static final String SERVICE_NAME = IContextFunction.class.getName();
  public static final String SERVICE_CONTEXT_KEY = "service.context.key";
  
  public abstract Object compute(IEclipseContext paramIEclipseContext);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.IContextFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

public abstract interface IEclipseContext
{
  public abstract boolean containsKey(String paramString);
  
  public abstract boolean containsKey(Class<?> paramClass);
  
  public abstract Object get(String paramString);
  
  public abstract <T> T get(Class<T> paramClass);
  
  public abstract Object getLocal(String paramString);
  
  public abstract <T> T getLocal(Class<T> paramClass);
  
  public abstract void remove(String paramString);
  
  public abstract void remove(Class<?> paramClass);
  
  public abstract void runAndTrack(RunAndTrack paramRunAndTrack);
  
  public abstract void set(String paramString, Object paramObject);
  
  public abstract <T> void set(Class<T> paramClass, T paramT);
  
  public abstract void modify(String paramString, Object paramObject);
  
  public abstract <T> void modify(Class<T> paramClass, T paramT);
  
  public abstract void declareModifiable(String paramString);
  
  public abstract void declareModifiable(Class<?> paramClass);
  
  public abstract void processWaiting();
  
  public abstract IEclipseContext createChild();
  
  public abstract IEclipseContext createChild(String paramString);
  
  public abstract IEclipseContext getParent();
  
  public abstract void setParent(IEclipseContext paramIEclipseContext);
  
  public abstract void activate();
  
  public abstract void deactivate();
  
  public abstract void activateBranch();
  
  public abstract IEclipseContext getActiveChild();
  
  public abstract IEclipseContext getActiveLeaf();
  
  public abstract void dispose();
  
  public abstract <T> T getActive(Class<T> paramClass);
  
  public abstract Object getActive(String paramString);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.IEclipseContext
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.contexts;

public abstract class RunAndTrack
{
  public abstract boolean changed(IEclipseContext paramIEclipseContext);
  
  /* Error */
  protected synchronized void runExternalCode(Runnable runnable)
  {
    // Byte code:
    //   0: invokestatic 39	org/eclipse/e4/core/internal/contexts/EclipseContext:getCalculatedComputations	()Ljava/util/Stack;
    //   3: astore_2
    //   4: aload_2
    //   5: aconst_null
    //   6: invokevirtual 38	java/util/Stack:push	(Ljava/lang/Object;)Ljava/lang/Object;
    //   9: pop
    //   10: aload_1
    //   11: invokeinterface 40 1 0
    //   16: goto +11 -> 27
    //   19: astore_3
    //   20: aload_2
    //   21: invokevirtual 37	java/util/Stack:pop	()Ljava/lang/Object;
    //   24: pop
    //   25: aload_3
    //   26: athrow
    //   27: aload_2
    //   28: invokevirtual 37	java/util/Stack:pop	()Ljava/lang/Object;
    //   31: pop
    //   32: return
    // Line number table:
    //   Java source line #50	-> byte code offset #0
    //   Java source line #51	-> byte code offset #4
    //   Java source line #53	-> byte code offset #10
    //   Java source line #54	-> byte code offset #16
    //   Java source line #55	-> byte code offset #20
    //   Java source line #56	-> byte code offset #25
    //   Java source line #55	-> byte code offset #27
    //   Java source line #57	-> byte code offset #32
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	33	0	this	RunAndTrack
    //   0	33	1	runnable	Runnable
    //   3	25	2	computationStack	java.util.Stack<org.eclipse.e4.core.internal.contexts.Computation>
    //   19	7	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   10	19	19	finally
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.contexts.RunAndTrack
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import java.util.Set;

public abstract class Computation
{
  protected int hashCode;
  
  protected abstract int calcHashCode();
  
  public abstract boolean equals(Object paramObject);
  
  public abstract void handleInvalid(ContextChangeEvent paramContextChangeEvent, Set<EclipseContext.Scheduled> paramSet);
  
  public int hashCode()
  {
    return hashCode;
  }
  
  protected void init()
  {
    hashCode = calcHashCode();
  }
  
  public boolean isValid()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.Computation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import org.eclipse.e4.core.contexts.IEclipseContext;

public final class ContextChangeEvent
{
  public static final int INITIAL = 0;
  public static final int ADDED = 1;
  public static final int REMOVED = 2;
  public static final int DISPOSE = 3;
  public static final int UNINJECTED = 4;
  public static final int UPDATE = 5;
  public static final int RECALC = 6;
  private Object[] args;
  private IEclipseContext context;
  private int eventType;
  private String key;
  private Object oldValue;
  
  ContextChangeEvent(IEclipseContext context, int eventType, Object[] args, String name, Object oldValue)
  {
    this.context = context;
    key = name;
    this.eventType = eventType;
    this.args = args;
    this.oldValue = oldValue;
  }
  
  public Object[] getArguments()
  {
    return args;
  }
  
  public IEclipseContext getContext()
  {
    return context;
  }
  
  public int getEventType()
  {
    return eventType;
  }
  
  public String getName()
  {
    return key;
  }
  
  public Object getOldValue()
  {
    return oldValue;
  }
  
  public int hashCode()
  {
    int result = 1;
    
    result = 31 * result + eventType;
    result = 31 * result + (key == null ? 0 : key.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    ContextChangeEvent other = (ContextChangeEvent)obj;
    if (eventType != eventType) {
      return false;
    }
    if (key == null)
    {
      if (key != null) {
        return false;
      }
    }
    else if (!key.equals(key)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.ContextChangeEvent
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import java.lang.ref.Reference;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.suppliers.IRequestor;
import org.eclipse.e4.core.internal.di.Requestor;

public class ContextObjectSupplier$ContextInjectionListener
  extends RunAndTrackExt
{
  private final Object[] result;
  private final String[] keys;
  private final boolean[] active;
  private final IRequestor requestor;
  private final IEclipseContext context;
  
  public ContextObjectSupplier$ContextInjectionListener(IEclipseContext context, Object[] result, String[] keys, boolean[] active, IRequestor requestor, boolean group)
  {
    super(group);
    this.result = result;
    this.keys = keys;
    this.active = active;
    this.requestor = requestor;
    this.context = context;
  }
  
  public Reference<Object> getReference()
  {
    if ((requestor instanceof Requestor)) {
      return ((Requestor)requestor).getReference();
    }
    return super.getReference();
  }
  
  public boolean update(IEclipseContext eventsContext, int eventType, Object[] extraArguments)
  {
    if (eventType == 0)
    {
      for (int i = 0; i < keys.length; i++) {
        if (keys[i] != null)
        {
          IEclipseContext targetContext = active[i] != 0 ? context.getActiveLeaf() : context;
          if (ContextObjectSupplier.ECLIPSE_CONTEXT_NAME.equals(keys[i]))
          {
            result[i] = targetContext;
            IEclipseContext parent = targetContext.getParent();
            if (parent == null) {
              targetContext.get(ContextObjectSupplier.ECLIPSE_CONTEXT_NAME);
            }
          }
          else if (targetContext.containsKey(keys[i]))
          {
            result[i] = targetContext.get(keys[i]);
          }
        }
      }
      return true;
    }
    if (eventType == 3)
    {
      if (eventsContext == context)
      {
        ContextObjectSupplier originatingSupplier = (ContextObjectSupplier)eventsContext.getLocal(ContextObjectSupplier.class);
        requestor.disposed(originatingSupplier);
        return false;
      }
    }
    else if (eventType == 4)
    {
      if (eventsContext == context)
      {
        ContextObjectSupplier originatingSupplier = (ContextObjectSupplier)eventsContext.getLocal(ContextObjectSupplier.class);
        return requestor.uninject(extraArguments[0], originatingSupplier);
      }
    }
    else
    {
      if (!requestor.isValid()) {
        return false;
      }
      requestor.resolveArguments(false);
      requestor.execute();
    }
    return true;
  }
  
  public boolean changed(IEclipseContext eventsContext)
  {
    return true;
  }
  
  public int hashCode()
  {
    int hashRresult = 1;
    hashRresult = 31 * hashRresult + (context == null ? 0 : context.hashCode());
    hashRresult = 31 * hashRresult + (requestor == null ? 0 : requestor.hashCode());
    return hashRresult;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    ContextInjectionListener other = (ContextInjectionListener)obj;
    if (context == null)
    {
      if (context != null) {
        return false;
      }
    }
    else if (!context.equals(context)) {
      return false;
    }
    if (requestor == null)
    {
      if (requestor != null) {
        return false;
      }
    }
    else if (!requestor.equals(requestor)) {
      return false;
    }
    return true;
  }
  
  public String toString()
  {
    return requestor.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.ContextObjectSupplier.ContextInjectionListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Stack;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.Active;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.di.IInjector;
import org.eclipse.e4.core.di.suppliers.IObjectDescriptor;
import org.eclipse.e4.core.di.suppliers.IRequestor;
import org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier;
import org.eclipse.e4.core.internal.di.Requestor;

public class ContextObjectSupplier
  extends PrimaryObjectSupplier
{
  protected static final String ECLIPSE_CONTEXT_NAME = IEclipseContext.class.getName();
  private final IEclipseContext context;
  
  public static class ContextInjectionListener
    extends RunAndTrackExt
  {
    private final Object[] result;
    private final String[] keys;
    private final boolean[] active;
    private final IRequestor requestor;
    private final IEclipseContext context;
    
    public ContextInjectionListener(IEclipseContext context, Object[] result, String[] keys, boolean[] active, IRequestor requestor, boolean group)
    {
      super();
      this.result = result;
      this.keys = keys;
      this.active = active;
      this.requestor = requestor;
      this.context = context;
    }
    
    public Reference<Object> getReference()
    {
      if ((requestor instanceof Requestor)) {
        return ((Requestor)requestor).getReference();
      }
      return super.getReference();
    }
    
    public boolean update(IEclipseContext eventsContext, int eventType, Object[] extraArguments)
    {
      if (eventType == 0)
      {
        for (int i = 0; i < keys.length; i++) {
          if (keys[i] != null)
          {
            IEclipseContext targetContext = active[i] != 0 ? context.getActiveLeaf() : context;
            if (ContextObjectSupplier.ECLIPSE_CONTEXT_NAME.equals(keys[i]))
            {
              result[i] = targetContext;
              IEclipseContext parent = targetContext.getParent();
              if (parent == null) {
                targetContext.get(ContextObjectSupplier.ECLIPSE_CONTEXT_NAME);
              }
            }
            else if (targetContext.containsKey(keys[i]))
            {
              result[i] = targetContext.get(keys[i]);
            }
          }
        }
        return true;
      }
      if (eventType == 3)
      {
        if (eventsContext == context)
        {
          ContextObjectSupplier originatingSupplier = (ContextObjectSupplier)eventsContext.getLocal(ContextObjectSupplier.class);
          requestor.disposed(originatingSupplier);
          return false;
        }
      }
      else if (eventType == 4)
      {
        if (eventsContext == context)
        {
          ContextObjectSupplier originatingSupplier = (ContextObjectSupplier)eventsContext.getLocal(ContextObjectSupplier.class);
          return requestor.uninject(extraArguments[0], originatingSupplier);
        }
      }
      else
      {
        if (!requestor.isValid()) {
          return false;
        }
        requestor.resolveArguments(false);
        requestor.execute();
      }
      return true;
    }
    
    public boolean changed(IEclipseContext eventsContext)
    {
      return true;
    }
    
    public int hashCode()
    {
      int hashRresult = 1;
      hashRresult = 31 * hashRresult + (context == null ? 0 : context.hashCode());
      hashRresult = 31 * hashRresult + (requestor == null ? 0 : requestor.hashCode());
      return hashRresult;
    }
    
    public boolean equals(Object obj)
    {
      if (this == obj) {
        return true;
      }
      if (obj == null) {
        return false;
      }
      if (getClass() != obj.getClass()) {
        return false;
      }
      ContextInjectionListener other = (ContextInjectionListener)obj;
      if (context == null)
      {
        if (context != null) {
          return false;
        }
      }
      else if (!context.equals(context)) {
        return false;
      }
      if (requestor == null)
      {
        if (requestor != null) {
          return false;
        }
      }
      else if (!requestor.equals(requestor)) {
        return false;
      }
      return true;
    }
    
    public String toString()
    {
      return requestor.toString();
    }
  }
  
  public ContextObjectSupplier(IEclipseContext context, IInjector injector)
  {
    this.context = context;
  }
  
  public IEclipseContext getContext()
  {
    return context;
  }
  
  public void get(IObjectDescriptor[] descriptors, Object[] actualArgs, IRequestor requestor, boolean initial, boolean track, boolean group)
  {
    String[] keys = new String[descriptors.length];
    boolean[] active = new boolean[descriptors.length];
    for (int i = 0; i < descriptors.length; i++)
    {
      String key = getKey(descriptors[i]);
      if (actualArgs[i] == IInjector.NOT_A_VALUE) {
        keys[i] = key;
      } else if (ECLIPSE_CONTEXT_NAME.equals(key)) {
        keys[i] = ECLIPSE_CONTEXT_NAME;
      } else {
        keys[i] = null;
      }
      if (descriptors[i] == null) {
        active[i] = false;
      } else {
        active[i] = descriptors[i].hasQualifier(Active.class);
      }
    }
    if ((requestor != null) && (track))
    {
      if (initial)
      {
        trackable = new ContextInjectionListener(context, actualArgs, keys, active, requestor, group);
        context.runAndTrack(trackable);
      }
      else
      {
        fillArgs(actualArgs, keys, active);
      }
    }
    else if (descriptors.length > 0)
    {
      pauseRecording();
      try
      {
        fillArgs(actualArgs, keys, active);
      }
      finally
      {
        resumeRecording();
      }
    }
  }
  
  private void fillArgs(Object[] actualArgs, String[] keys, boolean[] active)
  {
    for (int i = 0; i < keys.length; i++) {
      if (keys[i] != null)
      {
        IEclipseContext targetContext = active[i] != 0 ? context.getActiveLeaf() : context;
        if (ECLIPSE_CONTEXT_NAME.equals(keys[i])) {
          actualArgs[i] = targetContext;
        } else if (targetContext.containsKey(keys[i])) {
          actualArgs[i] = targetContext.get(keys[i]);
        }
      }
    }
  }
  
  private String getKey(IObjectDescriptor descriptor)
  {
    if (descriptor.hasQualifier(Named.class))
    {
      Named namedAnnotation = (Named)descriptor.getQualifier(Named.class);
      return namedAnnotation.value();
    }
    Type elementType = descriptor.getDesiredType();
    return typeToString(elementType);
  }
  
  private String typeToString(Type type)
  {
    if (type == null) {
      return null;
    }
    if ((type instanceof Class)) {
      return ((Class)type).getName();
    }
    if ((type instanceof ParameterizedType))
    {
      Type rawType = ((ParameterizedType)type).getRawType();
      return typeToString(rawType);
    }
    return null;
  }
  
  public synchronized void pauseRecording()
  {
    Stack<Computation> current = EclipseContext.getCalculatedComputations();
    current.push(null);
  }
  
  public synchronized void resumeRecording()
  {
    Stack<Computation> current = EclipseContext.getCalculatedComputations();
    Computation plug = (Computation)current.pop();
    if (plug != null) {
      throw new IllegalArgumentException("Internal error in nested computation processing");
    }
  }
  
  public static ContextObjectSupplier getObjectSupplier(IEclipseContext context, IInjector injector)
  {
    if (context == null) {
      return null;
    }
    ContextObjectSupplier supplier = (ContextObjectSupplier)((EclipseContext)context).internalGet((EclipseContext)context, ContextObjectSupplier.class.getName(), true);
    if (supplier != null) {
      return supplier;
    }
    ContextObjectSupplier objectSupplier = new ContextObjectSupplier(context, injector);
    context.set(ContextObjectSupplier.class, objectSupplier);
    return objectSupplier;
  }
  
  public WeakReference<Object> makeReference(Object object)
  {
    if ((context instanceof EclipseContext)) {
      return ((EclipseContext)context).trackedWeakReference(object);
    }
    return super.makeReference(object);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.ContextObjectSupplier
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import org.eclipse.e4.core.internal.contexts.osgi.ContextsActivator;

public final class DebugHelper
{
  private static final String PLUGIN_NAME = "org.eclipse.e4.core.contexts";
  private static final String OPTION_DEBUG = "org.eclipse.e4.core.contexts/debug";
  private static final String OPTION_DEBUG_NAMES = "org.eclipse.e4.core.contexts/debug/names";
  private static final String OPTION_DEBUG_LISTENERS = "org.eclipse.e4.core.contexts/debug/listeners";
  public static boolean DEBUG = false;
  public static boolean DEBUG_NAMES = false;
  public static boolean DEBUG_LISTENERS = false;
  
  static
  {
    try
    {
      DEBUG = ContextsActivator.getBooleanDebugOption("org.eclipse.e4.core.contexts/debug", false);
      DEBUG_NAMES = ContextsActivator.getBooleanDebugOption("org.eclipse.e4.core.contexts/debug/names", false);
      DEBUG_LISTENERS = ContextsActivator.getBooleanDebugOption("org.eclipse.e4.core.contexts/debug/listeners", false);
    }
    catch (NoClassDefFoundError localNoClassDefFoundError) {}
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.DebugHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;

class EclipseContext$1
  extends RunAndTrack
{
  EclipseContext$1(EclipseContext paramEclipseContext1, String paramString1, EclipseContext paramEclipseContext2, String paramString2) {}
  
  public boolean changed(IEclipseContext context)
  {
    IEclipseContext activeContext = this$0.getActiveLeaf();
    Object result = activeContext.get(val$name);
    val$originatingContext.set(val$internalName, result);
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.EclipseContext.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

class EclipseContext$Scheduled
{
  public TrackableComputationExt runnable;
  public ContextChangeEvent event;
  
  public EclipseContext$Scheduled(TrackableComputationExt runnable, ContextChangeEvent event)
  {
    this.runnable = runnable;
    this.event = event;
  }
  
  public int hashCode()
  {
    return 31 * (31 + event.hashCode()) + runnable.hashCode();
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    Scheduled other = (Scheduled)obj;
    if (!event.equals(event)) {
      return false;
    }
    return runnable.equals(runnable);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.internal.contexts.EclipseContext.Scheduled
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.internal.contexts;

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.di.IInjector;
import org.eclipse.e4.core.internal.contexts.osgi.ContextDebugHelper;

public class EclipseContext
  implements IEclipseContext
{
  public static final String PARENT = "parentContext";
  public static final String DEBUG_STRING = "debugString";
  
  static class Scheduled
  {
    public TrackableComputationExt runnable;
    public ContextChangeEvent event;
    
    public Scheduled(TrackableComputationExt runnable, ContextChangeEvent event)
    {
      this.runnable = runnable;
      this.event = event;
    }
    
    public int hashCode()
    {
      return 31 * (31 + event.hashCode()) + runnable.hashCode();
    }
    
    public boolean equals(Object obj)
    {
      if (this == obj) {
        return true;
      }
      if (obj == null) {
        return false;
      }
      if (getClass() != obj.getClass()) {
        return false;
      }
      Scheduled other = (Scheduled)obj;
      if (!event.equals(event)) {
        return false;
      }
      return runnable.equals(runnable);
    }
  }
  
  private WeakGroupedListenerList weakListeners = new WeakGroupedListenerList();
  private Map<String, ValueComputation> localValueComputations = Collections.synchronizedMap(new HashMap());
  protected final Map<String, Object> localValues = Collections.synchronizedMap(new HashMap());
  private ArrayList<String> modifiable;
  private List<Computation> waiting;
  private Set<WeakReference<EclipseContext>> children = new HashSet();
  private Set<IContextDisposalListener> notifyOnDisposal = new HashSet();
  private static ThreadLocal<Stack<Computation>> currentComputation = new ThreadLocal();
  private ReferenceQueue<Object> referenceQueue = new ReferenceQueue();
  private Map<Reference<?>, TrackableComputationExt> activeComputations = Collections.synchronizedMap(new HashMap());
  private Set<TrackableComputationExt> activeRATs = Collections.synchronizedSet(new HashSet());
  private static final Object[] nullArgs = new Object[1];
  public static final String ACTIVE_CHILD = "activeChildContext";
  private static final IEclipseContextDebugger debugAddOn = ContextDebugHelper.getDebugger();
  
  public EclipseContext(IEclipseContext parent)
  {
    setParent(parent);
    if (parent == null) {
      waiting = Collections.synchronizedList(new ArrayList());
    }
    if (debugAddOn != null) {
      debugAddOn.notify(this, IEclipseContextDebugger.EventType.CONSTRUCTED, null);
    }
  }
  
  private static final Set<EclipseContext> noChildren = new HashSet(0);
  private static final String ACTIVE_VARIABLE = "org.eclipse.ui.active_";
  
  public Set<EclipseContext> getChildren()
  {
    synchronized (children)
    {
      if (children.size() == 0) {
        return noChildren;
      }
      Set<EclipseContext> result = new HashSet(children.size());
      for (Iterator<WeakReference<EclipseContext>> i = children.iterator(); i.hasNext();)
      {
        EclipseContext referredContext = (EclipseContext)((WeakReference)i.next()).get();
        if (referredContext == null) {
          i.remove();
        } else {
          result.add(referredContext);
        }
      }
    }
    Set<EclipseContext> result;
    return result;
  }
  
  public boolean containsKey(String name)
  {
    trackAccess(name);
    return containsKey(name, false);
  }
  
  public boolean containsKey(String name, boolean localOnly)
  {
    if (isSetLocally(name)) {
      return true;
    }
    if (localOnly) {
      return false;
    }
    EclipseContext parent = getParent();
    if ((parent != null) && (parent.containsKey(name, localOnly))) {
      return true;
    }
    return false;
  }
  
  public void dispose()
  {
    for (EclipseContext childContext : getChildren()) {
      childContext.dispose();
    }
    activeComputations.clear();
    activeRATs.clear();
    
    ContextChangeEvent event = new ContextChangeEvent(this, 3, null, null, null);
    Object scheduled = new LinkedHashSet();
    Set<Computation> allComputations = getListeners();
    weakListeners.clear();
    for (Computation computation : allComputations) {
      computation.handleInvalid(event, (Set)scheduled);
    }
    processScheduled((Set)scheduled);
    synchronized (notifyOnDisposal)
    {
      for (Iterator localIterator3 = notifyOnDisposal.iterator(); localIterator3.hasNext();)
      {
        listener = (IContextDisposalListener)localIterator3.next();
        ((IContextDisposalListener)listener).disposed(this);
      }
    }
    for (Object listener = localValueComputations.values().iterator(); ((Iterator)listener).hasNext();)
    {
      ValueComputation computation = (ValueComputation)((Iterator)listener).next();
      computation.dipose();
    }
    localValueComputations.clear();
    
    EclipseContext parent = getParent();
    EclipseContext rootContext = null;
    if (parent != null)
    {
      rootContext = getRoot();
      if (this == parent.getActiveChild()) {
        parent.set("activeChildContext", null);
      }
    }
    localValues.clear();
    if (parent != null)
    {
      parent.removeChild(this);
      if (rootContext != null) {
        rootContext.cleanup();
      }
    }
    if (debugAddOn != null) {
      debugAddOn.notify(this, IEclipseContextDebugger.EventType.DISPOSED, null);
    }
  }
  
  public Object get(String name)
  {
    trackAccess(name);
    return internalGet(this, name, false);
  }
  
  public Object getLocal(String name)
  {
    trackAccess(name);
    return internalGet(this, name, true);
  }
  
  public Object internalGet(EclipseContext originatingContext, String name, boolean local)
  {
    if (this == originatingContext)
    {
      ValueComputation valueComputation = (ValueComputation)localValueComputations.get(name);
      if (valueComputation != null) {
        return valueComputation.get();
      }
    }
    Object result = null;
    if (localValues.containsKey(name))
    {
      result = localValues.get(name);
      if (result == null) {
        return null;
      }
    }
    else
    {
      result = lookup(name, originatingContext);
    }
    if (result != null)
    {
      if ((result instanceof IContextFunction))
      {
        ValueComputation valueComputation = new ValueComputation(name, originatingContext, (IContextFunction)result);
        
        result = valueComputation.get();
        localValueComputations.put(name, valueComputation);
      }
      return result;
    }
    if (!local)
    {
      IEclipseContext parent = (IEclipseContext)localValues.get("parentContext");
      if (parent != null) {
        return ((EclipseContext)parent).internalGet(originatingContext, name, local);
      }
    }
    return null;
  }
  
  public void invalidate(String name, int eventType, Object oldValue, Object newValue, Set<Scheduled> scheduled)
  {
    ContextChangeEvent event = null;
    ValueComputation computation = (ValueComputation)localValueComputations.get(name);
    if (computation != null)
    {
      event = new ContextChangeEvent(this, eventType, null, name, oldValue);
      if (computation.shouldRemove(event))
      {
        localValueComputations.remove(name);
        weakListeners.remove(computation);
      }
      computation.handleInvalid(event, scheduled);
    }
    Set<Computation> namedComputations = weakListeners.getListeners(name);
    if ((namedComputations != null) && (namedComputations.size() > 0))
    {
      if (event == null) {
        event = new ContextChangeEvent(this, eventType, null, name, oldValue);
      }
      for (Computation listener : namedComputations) {
        listener.handleInvalid(event, scheduled);
      }
    }
    for (EclipseContext childContext : getChildren()) {
      if ((eventType != 1) || (!childContext.isLocalEquals(name, newValue))) {
        childContext.invalidate(name, eventType, oldValue, newValue, scheduled);
      }
    }
  }
  
  protected boolean isLocalEquals(String name, Object newValue)
  {
    if (!localValues.containsKey(name)) {
      return false;
    }
    return localValues.get(name) == newValue;
  }
  
  private boolean isSetLocally(String name)
  {
    return localValues.containsKey(name);
  }
  
  public void remove(String name)
  {
    if (isSetLocally(name))
    {
      Object oldValue = localValues.remove(name);
      Set<Scheduled> scheduled = new LinkedHashSet();
      invalidate(name, 2, oldValue, IInjector.NOT_A_VALUE, scheduled);
      processScheduled(scheduled);
    }
  }
  
  public void runAndTrack(RunAndTrack runnable)
  {
    TrackableComputationExt computation = new TrackableComputationExt(runnable, this);
    ContextChangeEvent event = new ContextChangeEvent(this, 0, null, null, null);
    boolean result = computation.update(event);
    if (result)
    {
      Reference<Object> ref = computation.getReference();
      if (ref != null) {
        activeComputations.put(ref, computation);
      } else {
        activeRATs.add(computation);
      }
    }
  }
  
  public void removeRAT(Computation computation)
  {
    weakListeners.remove(computation);
    activeRATs.remove(computation);
  }
  
  protected void processScheduled(Set<Scheduled> scheduledList)
  {
    for (Iterator<Scheduled> i = scheduledList.iterator(); i.hasNext();)
    {
      Scheduled scheduled = (Scheduled)i.next();
      runnable.update(event);
    }
  }
  
  public void set(String name, Object value)
  {
    if ("parentContext".equals(name))
    {
      setParent((IEclipseContext)value);
      return;
    }
    boolean containsKey = localValues.containsKey(name);
    Object oldValue = localValues.put(name, value);
    if ((!containsKey) || (value != oldValue))
    {
      Set<Scheduled> scheduled = new LinkedHashSet();
      invalidate(name, 1, oldValue, value, scheduled);
      processScheduled(scheduled);
    }
    Reference<?> ref = referenceQueue.poll();
    if (ref != null)
    {
      ContextChangeEvent event = new ContextChangeEvent(this, 4, nullArgs, null, null);
      for (; ref != null; ref = referenceQueue.poll())
      {
        TrackableComputationExt obsoleteComputation = (TrackableComputationExt)activeComputations.remove(ref);
        if (obsoleteComputation != null) {
          obsoleteComputation.update(event);
        }
      }
    }
  }
  
  public void modify(String name, Object value)
  {
    Set<Scheduled> scheduled = new LinkedHashSet();
    if (!internalModify(name, value, scheduled)) {
      set(name, value);
    }
    processScheduled(scheduled);
  }
  
  public boolean internalModify(String name, Object value, Set<Scheduled> scheduled)
  {
    boolean containsKey = localValues.containsKey(name);
    if (containsKey)
    {
      if (!checkModifiable(name))
      {
        String tmp = "Variable " + name + " is not modifiable in the context " + toString();
        throw new IllegalArgumentException(tmp);
      }
      Object oldValue = localValues.put(name, value);
      if (value != oldValue) {
        invalidate(name, 1, oldValue, value, scheduled);
      }
      return true;
    }
    EclipseContext parent = getParent();
    if (parent != null) {
      return parent.internalModify(name, value, scheduled);
    }
    return false;
  }
  
  public EclipseContext getParent()
  {
    return (EclipseContext)localValues.get("parentContext");
  }
  
  public void setParent(IEclipseContext parent)
  {
    EclipseContext parentContext = (EclipseContext)localValues.get("parentContext");
    if (parent == parentContext) {
      return;
    }
    if (parentContext != null) {
      parentContext.removeChild(this);
    }
    Set<Scheduled> scheduled = new LinkedHashSet();
    handleReparent((EclipseContext)parent, scheduled);
    localValues.put("parentContext", parent);
    if (parent != null) {
      ((EclipseContext)parent).addChild(this);
    }
    processScheduled(scheduled);
  }
  
  public String toString()
  {
    Object debugString = localValues.get("debugString");
    return (debugString instanceof String) ? (String)debugString : "Anonymous Context";
  }
  
  private void
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd