org.eclipse.osgi_3.7.2.v20120110-1415

ons bundlePermissions;
  
  SecurityRow$Decision(int decision, Condition[] postponed, SecurityRow row, BundlePermissions bundlePermissions)
  {
    this.decision = decision;
    this.postponed = postponed;
    this.row = row;
    this.bundlePermissions = bundlePermissions;
  }
  
  void handleImmutable(Condition condition, boolean isSatisfied, boolean mutable)
  {
    if ((mutable) || (!condition.isPostponed())) {
      return;
    }
    if (isSatisfied) {
      synchronized (row.bundleConditions)
      {
        Condition[] rowConditions = (Condition[])row.bundleConditions.get(bundlePermissions);
        boolean isEmpty = true;
        for (int i = 0; i < rowConditions.length; i++)
        {
          if ((rowConditions[i] == condition) && 
            (isSatisfied)) {
            rowConditions[i] = null;
          }
          isEmpty &= rowConditions[i] == null;
        }
        if (isEmpty) {
          row.bundleConditions.put(bundlePermissions, SecurityRow.SATISFIED_LIST);
        }
      }
    }
    synchronized (row.bundleConditions)
    {
      row.bundleConditions.put(bundlePermissions, SecurityRow.ABSTAIN_LIST);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.SecurityRow.Decision
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.security.Permission;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.service.condpermadmin.Condition;
import org.osgi.service.condpermadmin.ConditionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
import org.osgi.service.permissionadmin.PermissionInfo;

public final class SecurityRow
  implements ConditionalPermissionInfo
{
  static final Class<?>[] conditionMethodArgs = { Bundle.class, ConditionInfo.class };
  static Condition[] ABSTAIN_LIST = new Condition[0];
  static Condition[] SATISFIED_LIST = new Condition[0];
  static final Decision DECISION_ABSTAIN = new Decision(4, null, null, null);
  static final Decision DECISION_GRANTED = new Decision(1, null, null, null);
  static final Decision DECISION_DENIED = new Decision(2, null, null, null);
  private final SecurityAdmin securityAdmin;
  private final String name;
  private final ConditionInfo[] conditionInfos;
  private final PermissionInfoCollection permissionInfoCollection;
  private final boolean deny;
  final Map<BundlePermissions, Condition[]> bundleConditions;
  
  public SecurityRow(SecurityAdmin securityAdmin, String name, ConditionInfo[] conditionInfos, PermissionInfo[] permissionInfos, String decision)
  {
    if ((permissionInfos == null) || (permissionInfos.length == 0)) {
      throw new IllegalArgumentException("It is invalid to have empty permissionInfos");
    }
    this.securityAdmin = securityAdmin;
    this.conditionInfos = (conditionInfos == null ? new ConditionInfo[0] : conditionInfos);
    decision = decision.toLowerCase();
    boolean d = "deny".equals(decision);
    boolean a = "allow".equals(decision);
    if (!(d | a)) {
      throw new IllegalArgumentException("Invalid decision: " + decision);
    }
    deny = d;
    this.name = name;
    permissionInfoCollection = new PermissionInfoCollection(permissionInfos);
    if ((conditionInfos == null) || (conditionInfos.length == 0)) {
      bundleConditions = null;
    } else {
      bundleConditions = new HashMap();
    }
  }
  
  static SecurityRowSnapShot createSecurityRowSnapShot(String encoded)
  {
    return (SecurityRowSnapShot)createConditionalPermissionInfo(null, encoded);
  }
  
  static SecurityRow createSecurityRow(SecurityAdmin securityAdmin, String encoded)
  {
    return (SecurityRow)createConditionalPermissionInfo(securityAdmin, encoded);
  }
  
  private static ConditionalPermissionInfo createConditionalPermissionInfo(SecurityAdmin securityAdmin, String encoded)
  {
    encoded = encoded.trim();
    if (encoded.length() == 0) {
      throw new IllegalArgumentException("Empty encoded string is invalid");
    }
    char[] chars = encoded.toCharArray();
    int end = encoded.length() - 1;
    char lastChar = chars[end];
    if ((lastChar != '}') && (lastChar != '"')) {
      throw new IllegalArgumentException(encoded);
    }
    String encodedName = null;
    if (lastChar == '"')
    {
      if (chars.length < 2) {
        throw new IllegalArgumentException(encoded);
      }
      int endName = encoded.length() - 1;
      int startName = endName - 1;
      while (startName > 0)
      {
        if (chars[startName] == '"')
        {
          startName--;
          if ((startName > 0) && (chars[startName] == '\\'))
          {
            startName--;
          }
          else
          {
            startName++;
            break;
          }
        }
        startName--;
      }
      if (chars[startName] != '"') {
        throw new IllegalArgumentException(encoded);
      }
      encodedName = unescapeString(encoded.substring(startName + 1, endName));
      end = encoded.lastIndexOf('}', startName);
    }
    int start = encoded.indexOf('{');
    if ((start < 0) || (end < start)) {
      throw new IllegalArgumentException(encoded);
    }
    String decision = encoded.substring(0, start);
    decision = decision.trim();
    if ((decision.length() == 0) || ((!"deny".equalsIgnoreCase(decision)) && (!"allow".equalsIgnoreCase(decision)))) {
      throw new IllegalArgumentException(encoded);
    }
    List<ConditionInfo> condList = new ArrayList();
    List<PermissionInfo> permList = new ArrayList();
    int pos = start + 1;
    while (pos < end)
    {
      while ((pos < end) && (chars[pos] != '[') && (chars[pos] != '(')) {
        pos++;
      }
      if (pos == end) {
        break;
      }
      int startPos = pos;
      char endChar = chars[startPos] == '[' ? ']' : ')';
      while ((pos < end) && (chars[pos] != endChar))
      {
        if (chars[pos] == '"')
        {
          pos++;
          while (chars[pos] != '"')
          {
            if (chars[pos] == '\\') {
              pos++;
            }
            pos++;
          }
        }
        pos++;
      }
      int endPos = pos;
      String token = new String(chars, startPos, endPos - startPos + 1);
      if (endChar == ']') {
        condList.add(new ConditionInfo(token));
      } else {
        permList.add(new PermissionInfo(token));
      }
      pos++;
    }
    if (permList.size() == 0) {
      throw new IllegalArgumentException("No Permission infos: " + encoded);
    }
    ConditionInfo[] conds = (ConditionInfo[])condList.toArray(new ConditionInfo[condList.size()]);
    PermissionInfo[] perms = (PermissionInfo[])permList.toArray(new PermissionInfo[permList.size()]);
    if (securityAdmin == null) {
      return new SecurityRowSnapShot(encodedName, conds, perms, decision);
    }
    return new SecurityRow(securityAdmin, encodedName, conds, perms, decision);
  }
  
  static Object cloneArray(Object[] array)
  {
    if (array == null) {
      return null;
    }
    Object result = Array.newInstance(array.getClass().getComponentType(), array.length);
    System.arraycopy(array, 0, result, 0, array.length);
    return result;
  }
  
  private static void escapeString(String str, StringBuffer output)
  {
    int len = str.length();
    for (int i = 0; i < len; i++)
    {
      char c = str.charAt(i);
      switch (c)
      {
      case '"': 
      case '\\': 
        output.append('\\');
        output.append(c);
        break;
      case '\r': 
        output.append("\\r");
        break;
      case '\n': 
        output.append("\\n");
        break;
      default: 
        output.append(c);
      }
    }
  }
  
  private static String unescapeString(String str)
  {
    StringBuffer output = new StringBuffer(str.length());
    int end = str.length();
    for (int i = 0; i < end; i++)
    {
      char c = str.charAt(i);
      if (c == '\\')
      {
        i++;
        if (i < end)
        {
          c = str.charAt(i);
          switch (c)
          {
          case '"': 
          case '\\': 
            break;
          case 'r': 
            c = '\r';
            break;
          case 'n': 
            c = '\n';
            break;
          default: 
            c = '\\';
            i--;
          }
        }
      }
      output.append(c);
    }
    return output.toString();
  }
  
  public String getName()
  {
    return name;
  }
  
  public ConditionInfo[] getConditionInfos()
  {
    return (ConditionInfo[])cloneArray(conditionInfos);
  }
  
  ConditionInfo[] internalGetConditionInfos()
  {
    return conditionInfos;
  }
  
  public String getAccessDecision()
  {
    return deny ? "deny" : "allow";
  }
  
  public PermissionInfo[] getPermissionInfos()
  {
    return (PermissionInfo[])cloneArray(permissionInfoCollection.getPermissionInfos());
  }
  
  PermissionInfo[] internalGetPermissionInfos()
  {
    return permissionInfoCollection.getPermissionInfos();
  }
  
  /**
   * @deprecated
   */
  public void delete()
  {
    securityAdmin.delete(this, true);
  }
  
  Condition[] getConditions(Bundle bundle)
  {
    Condition[] conditions = new Condition[conditionInfos.length];
    for (int i = 0; i < conditionInfos.length; i++)
    {
      try
      {
        clazz = Class.forName(conditionInfos[i].getType());
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        Class<?> clazz;
        return null;
      }
      Class<?> clazz;
      Constructor<?> constructor = null;
      Method method = null;
      try
      {
        method = clazz.getMethod("getCondition", conditionMethodArgs);
        if ((method.getModifiers() & 0x8) == 0) {
          method = null;
        }
      }
      catch (NoSuchMethodException localNoSuchMethodException1) {}
      if (method == null) {
        try
        {
          constructor = clazz.getConstructor(conditionMethodArgs);
        }
        catch (NoSuchMethodException localNoSuchMethodException2)
        {
          conditions[i] = Condition.FALSE;
          continue;
        }
      }
      Object[] args = { bundle, conditionInfos[i] };
      try
      {
        if (method != null) {
          conditions[i] = ((Condition)method.invoke(null, args));
        } else {
          conditions[i] = ((Condition)constructor.newInstance(args));
        }
      }
      catch (Throwable localThrowable)
      {
        conditions[i] = Condition.FALSE;
      }
    }
    return conditions;
  }
  
  Decision evaluate(BundlePermissions bundlePermissions, Permission permission)
  {
    if ((bundleConditions == null) || (bundlePermissions == null)) {
      return evaluatePermission(permission);
    }
    synchronized (bundleConditions)
    {
      Condition[] conditions = (Condition[])bundleConditions.get(bundlePermissions);
      if (conditions == null)
      {
        conditions = getConditions(bundlePermissions.getBundle());
        bundleConditions.put(bundlePermissions, conditions);
      }
    }
    Condition[] conditions;
    if (conditions == ABSTAIN_LIST) {
      return DECISION_ABSTAIN;
    }
    if (conditions == SATISFIED_LIST) {
      return evaluatePermission(permission);
    }
    boolean empty = true;
    List<Condition> postponedConditions = null;
    Decision postponedPermCheck = null;
    for (int i = 0; i < conditions.length; i++)
    {
      Condition condition = conditions[i];
      if (condition != null)
      {
        if (!isPostponed(condition))
        {
          boolean mutable = condition.isMutable();
          if (condition.isSatisfied())
          {
            if (!mutable) {
              conditions[i] = null;
            }
          }
          else
          {
            if (!mutable) {
              synchronized (bundleConditions)
              {
                bundleConditions.put(bundlePermissions, ABSTAIN_LIST);
              }
            }
            return DECISION_ABSTAIN;
          }
        }
        else
        {
          if (postponedPermCheck == null) {
            postponedPermCheck = evaluatePermission(permission);
          }
          if (postponedPermCheck == DECISION_ABSTAIN) {
            return postponedPermCheck;
          }
          if (postponedConditions == null) {
            postponedConditions = new ArrayList(1);
          }
          postponedConditions.add(condition);
        }
        empty &= conditions[i] == null;
      }
    }
    if (empty) {
      synchronized (bundleConditions)
      {
        bundleConditions.put(bundlePermissions, SATISFIED_LIST);
      }
    }
    if (postponedPermCheck != null) {
      return new Decision(decision | 0x8, (Condition[])postponedConditions.toArray(new Condition[postponedConditions.size()]), this, bundlePermissions);
    }
    return evaluatePermission(permission);
  }
  
  private boolean isPostponed(Condition condition)
  {
    return (condition.isPostponed()) && (securityAdmin.getSupportedSecurityManager() != null);
  }
  
  private Decision evaluatePermission(Permission permission)
  {
    return permissionInfoCollection.implies(permission) ? DECISION_GRANTED : deny ? DECISION_DENIED : DECISION_ABSTAIN;
  }
  
  public String toString()
  {
    return getEncoded();
  }
  
  public String getEncoded()
  {
    return getEncoded(name, conditionInfos, internalGetPermissionInfos(), deny);
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof ConditionalPermissionInfo)) {
      return false;
    }
    return getEncoded().equals(((ConditionalPermissionInfo)obj).getEncoded());
  }
  
  public int hashCode()
  {
    return getHashCode(name, internalGetConditionInfos(), internalGetPermissionInfos(), getAccessDecision());
  }
  
  static int getHashCode(String name, ConditionInfo[] conds, PermissionInfo[] perms, String decision)
  {
    int h = 527 + decision.hashCode();
    for (int i = 0; i < conds.length; i++) {
      h = 31 * h + conds[i].hashCode();
    }
    for (int i = 0; i < perms.length; i++) {
      h = 31 * h + perms[i].hashCode();
    }
    if (name != null) {
      h = 31 * h + name.hashCode();
    }
    return h;
  }
  
  static String getEncoded(String name, ConditionInfo[] conditionInfos, PermissionInfo[] permissionInfos, boolean deny)
  {
    StringBuffer result = new StringBuffer();
    if (deny) {
      result.append("deny");
    } else {
      result.append("allow");
    }
    result.append(" { ");
    if (conditionInfos != null) {
      for (int i = 0; i < conditionInfos.length; i++) {
        result.append(conditionInfos[i].getEncoded()).append(' ');
      }
    }
    if (permissionInfos != null) {
      for (int i = 0; i < permissionInfos.length; i++) {
        result.append(permissionInfos[i].getEncoded()).append(' ');
      }
    }
    result.append('}');
    if (name != null)
    {
      result.append(" \"");
      escapeString(name, result);
      result.append('"');
    }
    return result.toString();
  }
  
  PermissionInfoCollection getPermissionInfoCollection()
  {
    return permissionInfoCollection;
  }
  
  void clearCaches()
  {
    permissionInfoCollection.clearPermissionCache();
    if (bundleConditions != null) {
      synchronized (bundleConditions)
      {
        bundleConditions.clear();
      }
    }
  }
  
  static class Decision
  {
    final int decision;
    final Condition[] postponed;
    private final SecurityRow row;
    private final BundlePermissions bundlePermissions;
    
    Decision(int decision, Condition[] postponed, SecurityRow row, BundlePermissions bundlePermissions)
    {
      this.decision = decision;
      this.postponed = postponed;
      this.row = row;
      this.bundlePermissions = bundlePermissions;
    }
    
    void handleImmutable(Condition condition, boolean isSatisfied, boolean mutable)
    {
      if ((mutable) || (!condition.isPostponed())) {
        return;
      }
      if (isSatisfied) {
        synchronized (row.bundleConditions)
        {
          Condition[] rowConditions = (Condition[])row.bundleConditions.get(bundlePermissions);
          boolean isEmpty = true;
          for (int i = 0; i < rowConditions.length; i++)
          {
            if ((rowConditions[i] == condition) && 
              (isSatisfied)) {
              rowConditions[i] = null;
            }
            isEmpty &= rowConditions[i] == null;
          }
          if (isEmpty) {
            row.bundleConditions.put(bundlePermissions, SecurityRow.SATISFIED_LIST);
          }
        }
      }
      synchronized (row.bundleConditions)
      {
        row.bundleConditions.put(bundlePermissions, SecurityRow.ABSTAIN_LIST);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.SecurityRow
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import org.osgi.service.condpermadmin.ConditionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
import org.osgi.service.permissionadmin.PermissionInfo;

public class SecurityRowSnapShot
  implements ConditionalPermissionInfo
{
  private final String name;
  private final ConditionInfo[] conditionInfos;
  private final PermissionInfo[] permissionInfos;
  private final String decision;
  
  public SecurityRowSnapShot(String name, ConditionInfo[] conditionInfos, PermissionInfo[] permissionInfos, String decision)
  {
    if ((permissionInfos == null) || (permissionInfos.length == 0)) {
      throw new IllegalArgumentException("It is invalid to have empty permissionInfos");
    }
    decision = decision.toLowerCase();
    boolean d = "deny".equals(decision);
    boolean a = "allow".equals(decision);
    if (!(d | a)) {
      throw new IllegalArgumentException("Invalid decision: " + decision);
    }
    conditionInfos = conditionInfos == null ? new ConditionInfo[0] : conditionInfos;
    this.name = name;
    
    this.conditionInfos = ((ConditionInfo[])SecurityRow.cloneArray(conditionInfos));
    this.permissionInfos = ((PermissionInfo[])SecurityRow.cloneArray(permissionInfos));
    this.decision = decision;
  }
  
  public ConditionInfo[] getConditionInfos()
  {
    return (ConditionInfo[])SecurityRow.cloneArray(conditionInfos);
  }
  
  public String getAccessDecision()
  {
    return decision;
  }
  
  public String getName()
  {
    return name;
  }
  
  public PermissionInfo[] getPermissionInfos()
  {
    return (PermissionInfo[])SecurityRow.cloneArray(permissionInfos);
  }
  
  /**
   * @deprecated
   */
  public void delete()
  {
    throw new UnsupportedOperationException();
  }
  
  public String toString()
  {
    return getEncoded();
  }
  
  public String getEncoded()
  {
    return SecurityRow.getEncoded(name, conditionInfos, permissionInfos, "deny".equalsIgnoreCase(decision));
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof ConditionalPermissionInfo)) {
      return false;
    }
    return getEncoded().equals(((ConditionalPermissionInfo)obj).getEncoded());
  }
  
  public int hashCode()
  {
    return SecurityRow.getHashCode(name, conditionInfos, permissionInfos, getAccessDecision());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.SecurityRowSnapShot
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Enumeration;

public class SecurityTable
  extends PermissionCollection
{
  private static final long serialVersionUID = -1800193310096318060L;
  static final int GRANTED = 1;
  static final int DENIED = 2;
  static final int ABSTAIN = 4;
  static final int POSTPONED = 8;
  private final SecurityRow[] rows;
  private final SecurityAdmin securityAdmin;
  
  public SecurityTable(SecurityAdmin securityAdmin, SecurityRow[] rows)
  {
    if (rows == null) {
      throw new NullPointerException("rows cannot be null!!");
    }
    this.rows = rows;
    this.securityAdmin = securityAdmin;
  }
  
  boolean isEmpty()
  {
    return rows.length == 0;
  }
  
  int evaluate(BundlePermissions bundlePermissions, Permission permission)
  {
    if (isEmpty()) {
      return 4;
    }
    boolean postponed = false;
    SecurityRow.Decision[] results = new SecurityRow.Decision[rows.length];
    int immediateDecisionIdx = -1;
    for (int i = 0; i < rows.length; i++)
    {
      try
      {
        results[i] = rows[i].evaluate(bundlePermissions, permission);
      }
      catch (Throwable localThrowable)
      {
        results[i] = SecurityRow.DECISION_ABSTAIN;
      }
      if ((decision & 0x4) == 0) {
        if ((decision & 0x8) != 0)
        {
          postponed = true;
        }
        else
        {
          if (!postponed) {
            return decision;
          }
          immediateDecisionIdx = i;
          break;
        }
      }
    }
    if (postponed)
    {
      int immediateDecision = immediateDecisionIdx < 0 ? 2 : decision;
      
      boolean allSameDecision = true;
      for (int i = immediateDecisionIdx < 0 ? results.length - 1 : immediateDecisionIdx - 1; (i >= 0) && (allSameDecision); i--) {
        if (results[i] != null) {
          if ((decision & 0x8) != 0) {
            if ((decision & immediateDecision) == 0) {
              allSameDecision = false;
            } else {
              results[i] = SecurityRow.DECISION_ABSTAIN;
            }
          }
        }
      }
      if (allSameDecision) {
        return immediateDecision;
      }
      EquinoxSecurityManager equinoxManager = securityAdmin.getSupportedSecurityManager();
      if (equinoxManager == null) {
        return 4;
      }
      equinoxManager.addConditionsForDomain(results);
    }
    return postponed ? 8 : 4;
  }
  
  SecurityRow getRow(int i)
  {
    return (rows.length <= i) || (i < 0) ? null : rows[i];
  }
  
  SecurityRow getRow(String name)
  {
    for (int i = 0; i < rows.length; i++) {
      if (name.equals(rows[i].getName())) {
        return rows[i];
      }
    }
    return null;
  }
  
  SecurityRow[] getRows()
  {
    return rows;
  }
  
  String[] getEncodedRows()
  {
    String[] encoded = new String[rows.length];
    for (int i = 0; i < rows.length; i++) {
      encoded[i] = rows[i].getEncoded();
    }
    return encoded;
  }
  
  public void add(Permission permission)
  {
    throw new SecurityException();
  }
  
  public Enumeration<Permission> elements()
  {
    return BundlePermissions.EMPTY_ENUMERATION;
  }
  
  public boolean implies(Permission permission)
  {
    return (evaluate(null, permission) & 0x1) != 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.SecurityTable
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.util.ArrayList;
import java.util.List;
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;

public class SecurityTableUpdate
  implements ConditionalPermissionUpdate
{
  private final SecurityAdmin securityAdmin;
  private final List<ConditionalPermissionInfo> rows;
  private final long timeStamp;
  
  public SecurityTableUpdate(SecurityAdmin securityAdmin, SecurityRow[] rows, long timeStamp)
  {
    this.securityAdmin = securityAdmin;
    this.timeStamp = timeStamp;
    
    this.rows = new ArrayList(rows.length);
    for (int i = 0; i < rows.length; i++) {
      this.rows.add(new SecurityRowSnapShot(rows[i].getName(), rows[i].internalGetConditionInfos(), rows[i].internalGetPermissionInfos(), rows[i].getAccessDecision()));
    }
  }
  
  public boolean commit()
  {
    return securityAdmin.commit(rows, timeStamp);
  }
  
  public List<ConditionalPermissionInfo> getConditionalPermissionInfos()
  {
    return rows;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.SecurityTableUpdate
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.profile;

public class DefaultProfileLogger$AccumPerfData
{
  public String scope;
  public long time;
  public long enters;
  
  public DefaultProfileLogger$AccumPerfData(String scope)
  {
    this.scope = scope;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.profile.DefaultProfileLogger.AccumPerfData
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.profile;

public class DefaultProfileLogger$AccumPerfScope
{
  public String scope;
  public long enter;
  
  public DefaultProfileLogger$AccumPerfScope(String scope, long enter)
  {
    this.scope = scope;
    this.enter = enter;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.profile.DefaultProfileLogger.AccumPerfScope
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.profile;

public class DefaultProfileLogger$TimeEntry
{
  public long time;
  public String id;
  public String msg;
  public String description;
  public int flag;
  final DefaultProfileLogger this$0;
  
  protected DefaultProfileLogger$TimeEntry(DefaultProfileLogger paramDefaultProfileLogger) {}
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.profile.DefaultProfileLogger.TimeEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.profile;

import java.io.File;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import java.util.TreeMap;
import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;

public class DefaultProfileLogger
  implements ProfileLogger
{
  protected static final String DEFAULTPROFILE_PROP = "osgi.defaultprofile.";
  protected static final String PROP_FILENAME = "osgi.defaultprofile.logfilename";
  protected static final String PROP_LOGSYNCHRONOUSLY = "osgi.defaultprofile.logsynchronously";
  protected static final String PROP_BUFFERSIZE = "osgi.defaultprofile.buffersize";
  protected static final String DEFAULTPROFILE_OPTION = "org.eclipse.osgi/defaultprofile/";
  protected static final String OPTION_FILENAME = "org.eclipse.osgi/defaultprofile/logfilename";
  protected static final String OPTION_LOGSYNCHRONOUSLY = "org.eclipse.osgi/defaultprofile/logsynchronously";
  protected static final String OPTION_BUFFERSIZE = "org.eclipse.osgi/defaultprofile/buffersize";
  protected boolean logSynchronously = false;
  protected long startTime = 0L;
  protected static final int DEFAULT_BUFFER_SIZE = 256;
  protected TimeEntry[] timeLogEntries = null;
  protected int timeEntriesIndex = 0;
  protected StringBuffer timelog = null;
  protected long launchTime = -1L;
  protected int bufferSize = 256;
  protected String logFileName = null;
  protected File logFile = null;
  private StringBuffer entryReport = new StringBuffer(120);
  private StringBuffer padsb = new StringBuffer(16);
  protected int indent;
  protected int timePaddingLength;
  protected Stack<AccumPerfScope> scopeStack;
  protected Map<String, AccumPerfData> scopeToAccumPerfDataMap;
  
  public DefaultProfileLogger()
  {
    initProps();
    
    int size = getBufferSize();
    timeLogEntries = new TimeEntry[size];
    timelog = new StringBuffer(4096);
    for (int i = 0; i < size; i++) {
      timeLogEntries[i] = timeEntryFactory();
    }
    timeEntriesIndex = 0;
    
    launchTime = getLaunchTime();
    if (launchTime == -1L) {
      startTime = getMainStartTime();
    } else {
      startTime = launchTime;
    }
    long freq = getTimerFrequency();
    for (timePaddingLength = 3; freq > 9L; timePaddingLength += 1) {
      freq /= 10L;
    }
    logInitMessages();
  }
  
  protected void logInitMessages()
  {
    int index = 0;
    if (launchTime != -1L)
    {
      logTime(0, "DefaultProfileLogger.init()", "launch time initialized", null);
      timeLogEntries[(index++)].time = launchTime;
    }
    logTime(0, "DefaultProfileLogger.init()", "start time initialized", null);
    timeLogEntries[(index++)].time = getMainStartTime();
  }
  
  protected long getLaunchTime()
  {
    String launchTimeString = FrameworkProperties.getProperty("launch.startMillis");
    if (launchTimeString != null) {
      return Long.parseLong(launchTimeString);
    }
    return -1L;
  }
  
  protected long getMainStartTime()
  {
    String timeString = FrameworkProperties.getProperty("eclipse.startTime");
    if (timeString != null) {
      return Long.parseLong(timeString);
    }
    return System.currentTimeMillis();
  }
  
  public void initProps()
  {
    FrameworkDebugOptions dbgOptions = null;
    if (FrameworkProperties.getProperty("osgi.debug") != null)
    {
      dbgOptions = FrameworkDebugOptions.getDefault();
      if (dbgOptions != null)
      {
        logFileName = dbgOptions.getOption("org.eclipse.osgi/defaultprofile/logfilename");
        logSynchronously = dbgOptions.getBooleanOption("org.eclipse.osgi/defaultprofile/logsynchronously", false);
        int size = dbgOptions.getIntegerOption("org.eclipse.osgi/defaultprofile/buffersize", 0);
        if (size > 0) {
          bufferSize = size;
        }
      }
    }
    String prop;
    if ((prop = FrameworkProperties.getProperty("osgi.defaultprofile.logfilename")) != null)
    {
      logFileName = prop;
      if (dbgOptions != null) {
        dbgOptions.setOption("org.eclipse.osgi/defaultprofile/logfilename", logFileName);
      }
    }
    if ((prop = FrameworkProperties.getProperty("osgi.defaultprofile.logsynchronously")) != null)
    {
      logSynchronously = Boolean.valueOf(prop).booleanValue();
      if (dbgOptions != null) {
        dbgOptions.setOption("org.eclipse.osgi/defaultprofile/logsynchronously", new Boolean(logSynchronously).toString());
      }
    }
    if ((prop = FrameworkProperties.getProperty("osgi.defaultprofile.buffersize")) != null) {
      try
      {
        int value = Integer.parseInt(prop);
        if (value > 0)
        {
          bufferSize = value;
          if (dbgOptions != null) {
            dbgOptions.setOption("org.eclipse.osgi/defaultprofile/buffersize", Integer.toString(bufferSize));
          }
        }
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
  }
  
  public synchronized void logTime(int flag, String id, String msg, String description)
  {
    if (timeEntriesIndex == timeLogEntries.length)
    {
      makeLog();
      logTime(0, "Profile.logTime()", "log entries rolled", null);
    }
    TimeEntry entry = timeLogEntries[(timeEntriesIndex++)];
    time = getTime();
    id = id;
    msg = msg;
    flag = flag;
    description = description;
    if (logSynchronously) {
      System.out.print(getProfileLog().substring(2));
    }
  }
  
  public synchronized String getProfileLog()
  {
    String log = getProfileLogReport();
    writeToProfileLogFile(log);
    return log;
  }
  
  public synchronized void accumLogEnter(String scope)
  {
    if (scopeStack == null) {
      scopeStack = new Stack();
    }
    if (scopeToAccumPerfDataMap == null) {
      scopeToAccumPerfDataMap = new TreeMap();
    }
    scopeStack.push(new AccumPerfScope(scope, getTime()));
  }
  
  public synchronized void accumLogExit(String scope)
  {
    long exit = getTime();
    if (scopeStack == null) {
      scopeStack = new Stack();
    }
    if (scopeToAccumPerfDataMap == null) {
      scopeToAccumPerfDataMap = new TreeMap();
    }
    AccumPerfScope then = (AccumPerfScope)scopeStack.pop();
    if (then == null)
    {
      System.err.println("ACCUM PERF ERROR: Scope stack empty: " + scope);
    }
    else
    {
      if (!scope.equals(scope)) {
        System.err.println("ACCUM PERF ERROR: Scope mismatch: then='" + scope + "', now='" + scope + "'");
      }
      AccumPerfData now = (AccumPerfData)scopeToAccumPerfDataMap.get(scope);
      if (now == null)
      {
        now = new AccumPerfData(scope);
        scopeToAccumPerfDataMap.put(scope, now);
      }
      time += exit - enter;
      enters += 1L;
    }
  }
  
  protected long getTime()
  {
    return System.currentTimeMillis();
  }
  
  protected long getTimerFrequency()
  {
    return 1000L;
  }
  
  protected TimeEntry findCompareEntry(int index, String id, int flag)
  {
    if (index > 0) {
      index--;
    }
    int prev = index;
    if (flag != 1) {
      while (index >= 0)
      {
        TimeEntry entry = timeLogEntries[index];
        if (id.equals(id)) {
          switch (flag)
          {
          case 0: 
            return entry;
          case 2: 
            if (flag == 1) {
              return entry;
            }
            break;
          }
        }
        index--;
      }
    }
    return timeLogEntries[prev];
  }
  
  protected String entryReport(TimeEntry entry, TimeEntry compareWith)
  {
    entryReport.setLength(0);
    if (flag == 1) {
      indent += 1;
    }
    long zeroTime = getRelativeTime(getStartTime());
    
    entryReport.append('-');
    long entryTime = getRelativeTime(time);
    long diff = entryTime - zeroTime;
    entryReport.append(pad(Long.toString(diff), timePaddingLength));
    entryReport.append(" :");
    diff = time - time;
    entryReport.append(pad(Long.toString(diff), timePaddingLength));
    entryReport.append(pad("", indent * 2));
    if (flag == 1) {
      entryReport.append(" >> ");
    } else if (flag == 2) {
      entryReport.append(" << ");
    } else if (flag == 0) {
      entryReport.append(" -- ");
    }
    entryReport.append(id);
    entryReport.append(" > ");
    entryReport.append(msg);
    if (description != null)
    {
      entryReport.append(" :: ");
      entryReport.append(description);
    }
    entryReport.append("\r\n");
    if (flag == 2) {
      indent -= 1;
    }
    return entryReport.toString();
  }
  
  protected String accumEntryReport(AccumPerfData d)
  {
    return "     " + scope + ":enters=" + enters + ";time=" + time + ";\r\n";
  }
  
  protected void makeLog()
  {
    indent = 0;
    timelog.append("\r\n");
    for (int i = 0; i < timeEntriesIndex; i++)
    {
      entry = timeLogEntries[i];
      TimeEntry cmpEntry = findCompareEntry(i, id, flag);
      timelog.append(entryReport(entry, cmpEntry));
    }
    timeEntriesIndex = 0;
    if ((scopeToAccumPerfDataMap == null) || (scopeToAccumPerfDataMap.isEmpty())) {
      return;
    }
    timelog.append("\r\n");
    timelog.append("Cumulative Log:\r\n");
    for (TimeEntry entry = scopeToAccumPerfDataMap.values().iterator(); entry.hasNext();)
    {
      AccumPerfData d = (AccumPerfData)entry.next();
      timelog.append(accumEntryReport(d));
    }
    scopeToAccumPerfDataMap.clear();
  }
  
  protected String pad(String str, int size)
  {
    padsb.setLength(0);
    int len = str.length();
    int count = size - len;
    for (int i = 0; i < count; i++) {
      padsb.append(' ');
    }
    padsb.append(str);
    return padsb.toString();
  }
  
  protected String getProfileLogReport()
  {
    if (timelog == null) {
      return "";
    }
    makeLog();
    String log = timelog.toString();
    timelog.setLength(0);
    return log;
  }
  
  /* Error */
  protected void writeToProfileLogFile(String log)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 463	org/eclipse/osgi/internal/profile/DefaultProfileLogger:getProfileLogFile	()Ljava/io/File;
    //   4: astore_2
    //   5: aload_2
    //   6: ifnonnull +4 -> 10
    //   9: return
    //   10: aconst_null
    //   11: astore_3
    //   12: new 229	java/io/FileWriter
    //   15: dup
    //   16: aload_2
    //   17: invokevirtual 415	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   20: iconst_1
    //   21: invokespecial 419	java/io/FileWriter:<init>	(Ljava/lang/String;Z)V
    //   24: astore_3
    //   25: aload_3
    //   26: aload_1
    //   27: invokevirtual 418	java/io/FileWriter:write	(Ljava/lang/String;)V
    //   30: goto +42 -> 72
    //   33: astore 4
    //   35: aload 4
    //   37: invokevirtual 420	java/io/IOException:printStackTrace	()V
    //   40: aload_3
    //   41: ifnull +43 -> 84
    //   44: aload_3
    //   45: invokevirtual 417	java/io/FileWriter:close	()V
    //   48: goto +36 -> 84
    //   51: pop
    //   52: goto +32 -> 84
    //   55: astore 5
    //   57: aload_3
    //   58: ifnull +11 -> 69
    //   61: aload_3
    //   62: invokevirtual 417	java/io/FileWriter:close	()V
    //   65: goto +4 -> 69
    //   68: pop
    //   69: aload 5
    //   71: athrow
    //   72: aload_3
    //   73: ifnull +11 -> 84
    //   76: aload_3
    //   77: invokevirtual 417	java/io/FileWriter:close	()V
    //   80: goto +4 -> 84
    //   83: pop
    //   84: return
    // Line number table:
    //   Java source line #320	-> byte code offset #0
    //   Java source line #321	-> byte code offset #5
    //   Java source line #322	-> byte code offset #9
    //   Java source line #323	-> byte code offset #10
    //   Java source line #325	-> byte code offset #12
    //   Java source line #326	-> byte code offset #25
    //   Java source line #327	-> byte code offset #33
    //   Java source line #328	-> byte code offset #35
    //   Java source line #330	-> byte code offset #40
    //   Java source line #332	-> byte code offset #44
    //   Java source line #333	-> byte code offset #51
    //   Java source line #329	-> byte code offset #55
    //   Java source line #330	-> byte code offset #57
    //   Java source line #332	-> byte code offset #61
    //   Java source line #333	-> byte code offset #68
    //   Java source line #336	-> byte code offset #69
    //   Java source line #330	-> byte code offset #72
    //   Java source line #332	-> byte code offset #76
    //   Java source line #333	-> byte code offset #83
    //   Java source line #337	-> byte code offset #84
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	85	0	this	DefaultProfileLogger
    //   0	85	1	log	String
    //   4	13	2	profileLog	File
    //   11	66	3	fw	java.io.FileWriter
    //   33	3	4	e	java.io.IOException
    //   55	15	5	localObject	Object
    //   51	1	6	localIOException1	java.io.IOException
    //   68	1	7	localIOException2	java.io.IOException
    //   83	1	8	localIOException3	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   12	30	33	java/io/IOException
    //   44	48	51	java/io/IOException
    //   12	40	55	finally
    //   61	65	68	java/io/IOException
    //   76	80	83	java/io/IOException
  }
  
  protected File getProfileLogFile()
  {
    if ((logFile == null) && 
      (logFileName != null) && (logFileName.length() > 0)) {
      logFile = new File(logFileName);
    }
    return logFile;
  }
  
  protected long getStartTime()
  {
    return startTime;
  }
  
  protected long getRelativeTime(long absoluteTime)
  {
    return absoluteTime;
  }
  
  protected int getBufferSize()
  {
    if (bufferSize < 2) {
      return 256;
    }
    return bufferSize;
  }
  
  protected TimeEntry timeEntryFactory()
  {
    return new TimeEntry();
  }
  
  protected static class AccumPerfData
  {
    public String scope;
    public long time;
    public long enters;
    
    public AccumPerfData(String scope)
    {
      this.scope = scope;
    }
  }
  
  protected static class AccumPerfScope
  {
    public String scope;
    public long enter;
    
    public AccumPerfScope(String scope, long enter)
    {
      this.scope = scope;
      this.enter = enter;
    }
  }
  
  protected class TimeEntry
  {
    public long time;
    public String id;
    public String msg;
    public String description;
    public int flag;
    
    protected TimeEntry() {}
  }
}

/* Location:
 * Qualified Name:     or
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

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-2019. Infinite Loop Ltd