jcommon-1.0.12

RGET_DEFAULT);
  }
  
  public static void setLogTarget(String logTarget)
  {
    BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.LogTarget", logTarget);
  }
  
  public static String getLogLevel()
  {
    return BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.base.LogLevel", "Info");
  }
  
  public static void setLogLevel(String level)
  {
    BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.LogLevel", level);
  }
  
  public static boolean isDisableLogging()
  {
    return BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.base.NoDefaultDebug", "false").equalsIgnoreCase("true");
  }
  
  public static void setDisableLogging(boolean disableLogging)
  {
    BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.NoDefaultDebug", String.valueOf(disableLogging));
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.log.LogConfiguration
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.log;

public class MemoryUsageMessage
{
  private final String message;
  
  public MemoryUsageMessage(String message)
  {
    this.message = message;
  }
  
  public String toString()
  {
    return message + "Free: " + Runtime.getRuntime().freeMemory() + "; " + "Total: " + Runtime.getRuntime().totalMemory();
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.log.MemoryUsageMessage
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.log;

import java.util.Arrays;

public class PadMessage
{
  private final Object text;
  private final int length;
  
  public PadMessage(Object message, int length)
  {
    text = message;
    this.length = length;
  }
  
  public String toString()
  {
    StringBuffer b = new StringBuffer();
    b.append(text);
    if (b.length() < length)
    {
      char[] pad = new char[length - b.length()];
      Arrays.fill(pad, ' ');
      b.append(pad);
    }
    return b.toString();
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.log.PadMessage
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import java.io.BufferedReader;
import java.io.IOException;

class AbstractModule$ReaderHelper
{
  private String buffer;
  private final BufferedReader reader;
  
  protected AbstractModule$ReaderHelper(BufferedReader reader)
  {
    this.reader = reader;
  }
  
  public boolean hasNext()
    throws IOException
  {
    if (buffer == null) {
      buffer = readLine();
    }
    return buffer != null;
  }
  
  public String next()
  {
    String line = buffer;
    buffer = null;
    return line;
  }
  
  public void pushBack(String line)
  {
    buffer = line;
  }
  
  protected String readLine()
    throws IOException
  {
    String line = reader.readLine();
    while ((line != null) && ((line.length() == 0) || (line.startsWith("#")))) {
      line = reader.readLine();
    }
    return line;
  }
  
  public void close()
    throws IOException
  {
    reader.close();
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.AbstractModule.ReaderHelper
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.jfree.util.ObjectUtilities;

public abstract class AbstractModule
  extends DefaultModuleInfo
  implements Module
{
  private ModuleInfo[] requiredModules;
  private ModuleInfo[] optionalModules;
  private String name;
  private String description;
  private String producer;
  private String subsystem;
  
  private static class ReaderHelper
  {
    private String buffer;
    private final BufferedReader reader;
    
    protected ReaderHelper(BufferedReader reader)
    {
      this.reader = reader;
    }
    
    public boolean hasNext()
      throws IOException
    {
      if (buffer == null) {
        buffer = readLine();
      }
      return buffer != null;
    }
    
    public String next()
    {
      String line = buffer;
      buffer = null;
      return line;
    }
    
    public void pushBack(String line)
    {
      buffer = line;
    }
    
    protected String readLine()
      throws IOException
    {
      String line = reader.readLine();
      while ((line != null) && ((line.length() == 0) || (line.startsWith("#")))) {
        line = reader.readLine();
      }
      return line;
    }
    
    public void close()
      throws IOException
    {
      reader.close();
    }
  }
  
  public AbstractModule()
  {
    setModuleClass(getClass().getName());
  }
  
  protected void loadModuleInfo()
    throws ModuleInitializeException
  {
    InputStream in = ObjectUtilities.getResourceRelativeAsStream("module.properties", getClass());
    if (in == null) {
      throw new ModuleInitializeException("File 'module.properties' not found in module package.");
    }
    loadModuleInfo(in);
  }
  
  protected void loadModuleInfo(InputStream in)
    throws ModuleInitializeException
  {
    if (in == null) {
      throw new NullPointerException("Given InputStream is null.");
    }
    try
    {
      ArrayList optionalModules = new ArrayList();
      ArrayList dependendModules = new ArrayList();
      ReaderHelper rh = new ReaderHelper(new BufferedReader(new InputStreamReader(in, "ISO-8859-1")));
      try
      {
        while (rh.hasNext())
        {
          String lastLineRead = rh.next();
          if (lastLineRead.startsWith("module-info:")) {
            readModuleInfo(rh);
          } else if (lastLineRead.startsWith("depends:")) {
            dependendModules.add(readExternalModule(rh));
          } else if (lastLineRead.startsWith("optional:")) {
            optionalModules.add(readExternalModule(rh));
          }
        }
      }
      finally
      {
        rh.close();
      }
      this.optionalModules = ((ModuleInfo[])optionalModules.toArray(new ModuleInfo[optionalModules.size()]));
      
      requiredModules = ((ModuleInfo[])dependendModules.toArray(new ModuleInfo[dependendModules.size()]));
    }
    catch (IOException ioe)
    {
      throw new ModuleInitializeException("Failed to load properties", ioe);
    }
  }
  
  private String readValue(ReaderHelper reader, String firstLine)
    throws IOException
  {
    StringBuffer b = new StringBuffer(firstLine.trim());
    boolean newLine = true;
    while (isNextLineValueLine(reader))
    {
      firstLine = reader.next();
      String trimedLine = firstLine.trim();
      if ((trimedLine.length() == 0) && (!newLine))
      {
        b.append("\n");
        newLine = true;
      }
      else
      {
        if (!newLine) {
          b.append(" ");
        }
        b.append(parseValue(trimedLine));
        newLine = false;
      }
    }
    return b.toString();
  }
  
  private boolean isNextLineValueLine(ReaderHelper reader)
    throws IOException
  {
    if (!reader.hasNext()) {
      return false;
    }
    String firstLine = reader.next();
    if (firstLine == null) {
      return false;
    }
    if (parseKey(firstLine) != null)
    {
      reader.pushBack(firstLine);
      return false;
    }
    reader.pushBack(firstLine);
    return true;
  }
  
  private void readModuleInfo(ReaderHelper reader)
    throws IOException
  {
    while (reader.hasNext())
    {
      String lastLineRead = reader.next();
      if (!Character.isWhitespace(lastLineRead.charAt(0)))
      {
        reader.pushBack(lastLineRead);
        return;
      }
      String line = lastLineRead.trim();
      String key = parseKey(line);
      if (key != null)
      {
        String b = readValue(reader, parseValue(line.trim()));
        if ("name".equals(key)) {
          setName(b);
        } else if ("producer".equals(key)) {
          setProducer(b);
        } else if ("description".equals(key)) {
          setDescription(b);
        } else if ("subsystem".equals(key)) {
          setSubSystem(b);
        } else if ("version.major".equals(key)) {
          setMajorVersion(b);
        } else if ("version.minor".equals(key)) {
          setMinorVersion(b);
        } else if ("version.patchlevel".equals(key)) {
          setPatchLevel(b);
        }
      }
    }
  }
  
  private String parseKey(String line)
  {
    int idx = line.indexOf(':');
    if (idx == -1) {
      return null;
    }
    return line.substring(0, idx);
  }
  
  private String parseValue(String line)
  {
    int idx = line.indexOf(':');
    if (idx == -1) {
      return line;
    }
    if (idx + 1 == line.length()) {
      return "";
    }
    return line.substring(idx + 1);
  }
  
  private DefaultModuleInfo readExternalModule(ReaderHelper reader)
    throws IOException
  {
    DefaultModuleInfo mi = new DefaultModuleInfo();
    while (reader.hasNext())
    {
      String lastLineRead = reader.next();
      if (!Character.isWhitespace(lastLineRead.charAt(0)))
      {
        reader.pushBack(lastLineRead);
        return mi;
      }
      String line = lastLineRead.trim();
      String key = parseKey(line);
      if (key != null)
      {
        String b = readValue(reader, parseValue(line));
        if ("module".equals(key)) {
          mi.setModuleClass(b);
        } else if ("version.major".equals(key)) {
          mi.setMajorVersion(b);
        } else if ("version.minor".equals(key)) {
          mi.setMinorVersion(b);
        } else if ("version.patchlevel".equals(key)) {
          mi.setPatchLevel(b);
        }
      }
    }
    return mi;
  }
  
  public String getName()
  {
    return name;
  }
  
  protected void setName(String name)
  {
    this.name = name;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  protected void setDescription(String description)
  {
    this.description = description;
  }
  
  public String getProducer()
  {
    return producer;
  }
  
  protected void setProducer(String producer)
  {
    this.producer = producer;
  }
  
  public ModuleInfo[] getRequiredModules()
  {
    ModuleInfo[] retval = new ModuleInfo[requiredModules.length];
    System.arraycopy(requiredModules, 0, retval, 0, requiredModules.length);
    return retval;
  }
  
  public ModuleInfo[] getOptionalModules()
  {
    ModuleInfo[] retval = new ModuleInfo[optionalModules.length];
    System.arraycopy(optionalModules, 0, retval, 0, optionalModules.length);
    return retval;
  }
  
  protected void setRequiredModules(ModuleInfo[] requiredModules)
  {
    this.requiredModules = new ModuleInfo[requiredModules.length];
    System.arraycopy(requiredModules, 0, this.requiredModules, 0, requiredModules.length);
  }
  
  public void setOptionalModules(ModuleInfo[] optionalModules)
  {
    this.optionalModules = new ModuleInfo[optionalModules.length];
    System.arraycopy(optionalModules, 0, this.optionalModules, 0, optionalModules.length);
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("Module : ");
    buffer.append(getName());
    buffer.append("\n");
    buffer.append("ModuleClass : ");
    buffer.append(getModuleClass());
    buffer.append("\n");
    buffer.append("Version: ");
    buffer.append(getMajorVersion());
    buffer.append(".");
    buffer.append(getMinorVersion());
    buffer.append(".");
    buffer.append(getPatchLevel());
    buffer.append("\n");
    buffer.append("Producer: ");
    buffer.append(getProducer());
    buffer.append("\n");
    buffer.append("Description: ");
    buffer.append(getDescription());
    buffer.append("\n");
    return buffer.toString();
  }
  
  /**
   * @deprecated
   */
  protected static boolean isClassLoadable(String name)
  {
    try
    {
      ClassLoader loader = ObjectUtilities.getClassLoader(AbstractModule.class);
      if (loader == null) {
        return false;
      }
      loader.loadClass(name);
      return true;
    }
    catch (Exception e) {}
    return false;
  }
  
  protected static boolean isClassLoadable(String name, Class context)
  {
    try
    {
      ObjectUtilities.getClassLoader(context).loadClass(name);
      return true;
    }
    catch (Exception e) {}
    return false;
  }
  
  public void configure(SubSystem subSystem)
  {
    InputStream in = ObjectUtilities.getResourceRelativeAsStream("configuration.properties", getClass());
    if (in == null) {
      return;
    }
    try
    {
      subSystem.getPackageManager().getPackageConfiguration().load(in); return;
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e) {}
    }
  }
  
  /**
   * @deprecated
   */
  protected void performExternalInitialize(String classname)
    throws ModuleInitializeException
  {
    try
    {
      ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, AbstractModule.class, ModuleInitializer.class);
      if (mi == null) {
        throw new ModuleInitializeException("Failed to load specified initializer class.");
      }
      mi.performInit();
    }
    catch (ModuleInitializeException mie)
    {
      throw mie;
    }
    catch (Exception e)
    {
      throw new ModuleInitializeException("Failed to load specified initializer class.", e);
    }
  }
  
  protected void performExternalInitialize(String classname, Class context)
    throws ModuleInitializeException
  {
    try
    {
      ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, context, ModuleInitializer.class);
      if (mi == null) {
        throw new ModuleInitializeException("Failed to load specified initializer class.");
      }
      mi.performInit();
    }
    catch (ModuleInitializeException mie)
    {
      throw mie;
    }
    catch (Exception e)
    {
      throw new ModuleInitializeException("Failed to load specified initializer class.", e);
    }
  }
  
  public String getSubSystem()
  {
    if (subsystem == null) {
      return getName();
    }
    return subsystem;
  }
  
  protected void setSubSystem(String name)
  {
    subsystem = name;
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.AbstractModule
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

public class DefaultModuleInfo
  implements ModuleInfo
{
  private String moduleClass;
  private String majorVersion;
  private String minorVersion;
  private String patchLevel;
  
  public DefaultModuleInfo() {}
  
  public DefaultModuleInfo(String moduleClass, String majorVersion, String minorVersion, String patchLevel)
  {
    if (moduleClass == null) {
      throw new NullPointerException("Module class must not be null.");
    }
    this.moduleClass = moduleClass;
    this.majorVersion = majorVersion;
    this.minorVersion = minorVersion;
    this.patchLevel = patchLevel;
  }
  
  public String getModuleClass()
  {
    return moduleClass;
  }
  
  public void setModuleClass(String moduleClass)
  {
    if (moduleClass == null) {
      throw new NullPointerException();
    }
    this.moduleClass = moduleClass;
  }
  
  public String getMajorVersion()
  {
    return majorVersion;
  }
  
  public void setMajorVersion(String majorVersion)
  {
    this.majorVersion = majorVersion;
  }
  
  public String getMinorVersion()
  {
    return minorVersion;
  }
  
  public void setMinorVersion(String minorVersion)
  {
    this.minorVersion = minorVersion;
  }
  
  public String getPatchLevel()
  {
    return patchLevel;
  }
  
  public void setPatchLevel(String patchLevel)
  {
    this.patchLevel = patchLevel;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if (!(o instanceof DefaultModuleInfo)) {
      return false;
    }
    ModuleInfo defaultModuleInfo = (ModuleInfo)o;
    if (!moduleClass.equals(defaultModuleInfo.getModuleClass())) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = moduleClass.hashCode();
    return result;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(getClass().getName());
    buffer.append("={ModuleClass=");
    buffer.append(getModuleClass());
    if (getMajorVersion() != null)
    {
      buffer.append("; Version=");
      buffer.append(getMajorVersion());
      if (getMinorVersion() != null)
      {
        buffer.append("-");
        buffer.append(getMinorVersion());
        if (getPatchLevel() != null)
        {
          buffer.append("_");
          buffer.append(getPatchLevel());
        }
      }
    }
    buffer.append("}");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.DefaultModuleInfo
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

public abstract interface Module
  extends ModuleInfo
{
  public abstract ModuleInfo[] getRequiredModules();
  
  public abstract ModuleInfo[] getOptionalModules();
  
  public abstract void initialize(SubSystem paramSubSystem)
    throws ModuleInitializeException;
  
  public abstract void configure(SubSystem paramSubSystem);
  
  public abstract String getDescription();
  
  public abstract String getProducer();
  
  public abstract String getName();
  
  public abstract String getSubSystem();
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.Module
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

public abstract interface ModuleInfo
{
  public abstract String getModuleClass();
  
  public abstract String getMajorVersion();
  
  public abstract String getMinorVersion();
  
  public abstract String getPatchLevel();
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.ModuleInfo
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import org.jfree.util.StackableException;

public class ModuleInitializeException
  extends StackableException
{
  public ModuleInitializeException() {}
  
  public ModuleInitializeException(String s, Exception e)
  {
    super(s, e);
  }
  
  public ModuleInitializeException(String s)
  {
    super(s);
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.ModuleInitializeException
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

public abstract interface ModuleInitializer
{
  public abstract void performInit()
    throws ModuleInitializeException;
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.ModuleInitializer
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import org.jfree.base.config.HierarchicalConfiguration;
import org.jfree.base.config.PropertyFileConfiguration;

public class PackageManager$PackageConfiguration
  extends PropertyFileConfiguration
{
  public void insertConfiguration(HierarchicalConfiguration config)
  {
    super.insertConfiguration(config);
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.PackageManager.PackageConfiguration
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import org.jfree.base.AbstractBoot;
import org.jfree.base.config.HierarchicalConfiguration;
import org.jfree.base.config.PropertyFileConfiguration;
import org.jfree.base.log.PadMessage;
import org.jfree.util.Configuration;
import org.jfree.util.Log;
import org.jfree.util.Log.SimpleMessage;
import org.jfree.util.ObjectUtilities;

public final class PackageManager
{
  private static final int RETURN_MODULE_LOADED = 0;
  private static final int RETURN_MODULE_UNKNOWN = 1;
  private static final int RETURN_MODULE_ERROR = 2;
  private final PackageConfiguration packageConfiguration;
  private final ArrayList modules;
  private final ArrayList initSections;
  private AbstractBoot booter;
  private static HashMap instances;
  
  public static class PackageConfiguration
    extends PropertyFileConfiguration
  {
    public void insertConfiguration(HierarchicalConfiguration config)
    {
      super.insertConfiguration(config);
    }
  }
  
  public static PackageManager createInstance(AbstractBoot booter)
  {
    if (instances == null)
    {
      instances = new HashMap();
      PackageManager manager = new PackageManager(booter);
      instances.put(booter, manager);
      return manager;
    }
    PackageManager manager = (PackageManager)instances.get(booter);
    if (manager == null)
    {
      manager = new PackageManager(booter);
      instances.put(booter, manager);
    }
    return manager;
  }
  
  private PackageManager(AbstractBoot booter)
  {
    if (booter == null) {
      throw new NullPointerException();
    }
    this.booter = booter;
    packageConfiguration = new PackageConfiguration();
    modules = new ArrayList();
    initSections = new ArrayList();
  }
  
  public boolean isModuleAvailable(ModuleInfo moduleDescription)
  {
    PackageState[] packageStates = (PackageState[])modules.toArray(new PackageState[modules.size()]);
    for (int i = 0; i < packageStates.length; i++)
    {
      PackageState state = packageStates[i];
      if (state.getModule().getModuleClass().equals(moduleDescription.getModuleClass())) {
        return state.getState() == 2;
      }
    }
    return false;
  }
  
  public void load(String modulePrefix)
  {
    if (initSections.contains(modulePrefix)) {
      return;
    }
    initSections.add(modulePrefix);
    
    Configuration config = booter.getGlobalConfig();
    Iterator it = config.findPropertyKeys(modulePrefix);
    int count = 0;
    while (it.hasNext())
    {
      String key = (String)it.next();
      if (key.endsWith(".Module"))
      {
        String moduleClass = config.getConfigProperty(key);
        if ((moduleClass != null) && (moduleClass.length() > 0))
        {
          addModule(moduleClass);
          count++;
        }
      }
    }
    Log.debug("Loaded a total of " + count + " modules under prefix: " + modulePrefix);
  }
  
  public synchronized void initializeModules()
  {
    PackageSorter.sort(modules);
    for (int i = 0; i < modules.size(); i++)
    {
      PackageState mod = (PackageState)modules.get(i);
      if (mod.configure(booter)) {
        Log.debug(new Log.SimpleMessage("Conf: ", new PadMessage(mod.getModule().getModuleClass(), 70), " [", mod.getModule().getSubSystem(), "]"));
      }
    }
    for (int i = 0; i < modules.size(); i++)
    {
      PackageState mod = (PackageState)modules.get(i);
      if (mod.initialize(booter)) {
        Log.debug(new Log.SimpleMessage("Init: ", new PadMessage(mod.getModule().getModuleClass(), 70), " [", mod.getModule().getSubSystem(), "]"));
      }
    }
  }
  
  public synchronized void addModule(String modClass)
  {
    ArrayList loadModules = new ArrayList();
    ModuleInfo modInfo = new DefaultModuleInfo(modClass, null, null, null);
    if (loadModule(modInfo, new ArrayList(), loadModules, false)) {
      for (int i = 0; i < loadModules.size(); i++)
      {
        Module mod = (Module)loadModules.get(i);
        modules.add(new PackageState(mod));
      }
    }
  }
  
  private int containsModule(ArrayList tempModules, ModuleInfo module)
  {
    if (tempModules != null)
    {
      ModuleInfo[] mods = (ModuleInfo[])tempModules.toArray(new ModuleInfo[tempModules.size()]);
      for (int i = 0; i < mods.length; i++) {
        if (mods[i].getModuleClass().equals(module.getModuleClass())) {
          return 0;
        }
      }
    }
    PackageState[] packageStates = (PackageState[])modules.toArray(new PackageState[modules.size()]);
    for (int i = 0; i < packageStates.length; i++) {
      if (packageStates[i].getModule().getModuleClass().equals(module.getModuleClass()))
      {
        if (packageStates[i].getState() == -2) {
          return 2;
        }
        return 0;
      }
    }
    return 1;
  }
  
  private void dropFailedModule(PackageState state)
  {
    if (!modules.contains(state)) {
      modules.add(state);
    }
  }
  
  private boolean loadModule(ModuleInfo moduleInfo, ArrayList incompleteModules, ArrayList modules, boolean fatal)
  {
    try
    {
      Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(moduleInfo.getModuleClass());
      Module module = (Module)c.newInstance();
      if (!acceptVersion(moduleInfo, module))
      {
        Log.warn("Module " + module.getName() + ": required version: " + moduleInfo + ", but found Version: \n" + module);
        
        PackageState state = new PackageState(module, -2);
        dropFailedModule(state);
        return false;
      }
      int moduleContained = containsModule(modules, module);
      if (moduleContained == 2)
      {
        Log.debug("Indicated failure for module: " + module.getModuleClass());
        PackageState state = new PackageState(module, -2);
        dropFailedModule(state);
        return false;
      }
      if (moduleContained == 1)
      {
        if (incompleteModules.contains(module))
        {
          Log.error(new Log.SimpleMessage("Circular module reference: This module definition is invalid: ", module.getClass()));
          
          PackageState state = new PackageState(module, -2);
          dropFailedModule(state);
          return false;
        }
        incompleteModules.add(module);
        ModuleInfo[] required = module.getRequiredModules();
        for (int i = 0; i < required.length; i++) {
          if (!loadModule(required[i], incompleteModules, modules, true))
          {
            Log.debug("Indicated failure for module: " + module.getModuleClass());
            PackageState state = new PackageState(module, -2);
            dropFailedModule(state);
            return false;
          }
        }
        ModuleInfo[] optional = module.getOptionalModules();
        for (int i = 0; i < optional.length; i++) {
          if (!loadModule(optional[i], incompleteModules, modules, true)) {
            Log.debug(new Log.SimpleMessage("Optional module: ", optional[i].getModuleClass(), " was not loaded."));
          }
        }
        if (containsModule(modules, module) == 1) {
          modules.add(module);
        }
        incompleteModules.remove(module);
      }
      return true;
    }
    catch (ClassNotFoundException cnfe)
    {
      if (fatal) {
        Log.warn(new Log.SimpleMessage("Unresolved dependency for package: ", moduleInfo.getModuleClass()));
      }
      Log.debug(new Log.SimpleMessage("ClassNotFound: ", cnfe.getMessage()));
      return false;
    }
    catch (Exception e)
    {
      Log.warn(new Log.SimpleMessage("Exception while loading module: ", moduleInfo), e);
    }
    return false;
  }
  
  private boolean acceptVersion(ModuleInfo moduleRequirement, Module module)
  {
    if (moduleRequirement.getMajorVersion() == null) {
      return true;
    }
    if (module.getMajorVersion() == null)
    {
      Log.warn("Module " + module.getName() + " does not define a major version.");
    }
    else
    {
      int compare = acceptVersion(moduleRequirement.getMajorVersion(), module.getMajorVersion());
      if (compare > 0) {
        return false;
      }
      if (compare < 0) {
        return true;
      }
    }
    if (moduleRequirement.getMinorVersion() == null) {
      return true;
    }
    if (module.getMinorVersion() == null)
    {
      Log.warn("Module " + module.getName() + " does not define a minor version.");
    }
    else
    {
      int compare = acceptVersion(moduleRequirement.getMinorVersion(), module.getMinorVersion());
      if (compare > 0) {
        return false;
      }
      if (compare < 0) {
        return true;
      }
    }
    if (moduleRequirement.getPatchLevel() == null) {
      return true;
    }
    if (module.getPatchLevel() == null)
    {
      Log.debug("Module " + module.getName() + " does not define a patch level.");
    }
    else if (acceptVersion(moduleRequirement.getPatchLevel(), module.getPatchLevel()) > 0)
    {
      Log.debug("Did not accept patchlevel: " + moduleRequirement.getPatchLevel() + " - " + module.getPatchLevel());
      
      return false;
    }
    return true;
  }
  
  private int acceptVersion(String modVer, String depModVer)
  {
    int mLength = Math.max(modVer.length(), depModVer.length());
    char[] depVerArray;
    char[] modVerArray;
    if (modVer.length() > depModVer.length())
    {
      char[] modVerArray = modVer.toCharArray();
      char[] depVerArray = new char[mLength];
      int delta = modVer.length() - depModVer.length();
      Arrays.fill(depVerArray, 0, delta, ' ');
      System.arraycopy(depVerArray, delta, depModVer.toCharArray(), 0, depModVer.length());
    }
    else if (modVer.length() < depModVer.length())
    {
      char[] depVerArray = depModVer.toCharArray();
      char[] modVerArray = new char[mLength];
      char[] b1 = new char[mLength];
      int delta = depModVer.length() - modVer.length();
      Arrays.fill(b1, 0, delta, ' ');
      System.arraycopy(b1, delta, modVer.toCharArray(), 0, modVer.length());
    }
    else
    {
      depVerArray = depModVer.toCharArray();
      modVerArray = modVer.toCharArray();
    }
    return new String(modVerArray).compareTo(new String(depVerArray));
  }
  
  public PackageConfiguration getPackageConfiguration()
  {
    return packageConfiguration;
  }
  
  public Module[] getAllModules()
  {
    Module[] mods = new Module[modules.size()];
    for (int i = 0; i < modules.size(); i++)
    {
      PackageState state = (PackageState)modules.get(i);
      mods[i] = state.getModule();
    }
    return mods;
  }
  
  public Module[] getActiveModules()
  {
    ArrayList mods = new ArrayList();
    for (int i = 0; i < modules.size(); i++)
    {
      PackageState state = (PackageState)modules.get(i);
      if (state.getState() == 2) {
        mods.add(state.getModule());
      }
    }
    return (Module[])mods.toArray(new Module[mods.size()]);
  }
  
  public void printUsedModules(PrintStream p)
  {
    Module[] allMods = getAllModules();
    ArrayList activeModules = new ArrayList();
    ArrayList failedModules = new ArrayList();
    for (int i = 0; i < allMods.length; i++) {
      if (isModuleAvailable(allMods[i])) {
        activeModules.add(allMods[i]);
      } else {
        failedModules.add(allMods[i]);
      }
    }
    p.print("Active modules: ");
    p.println(activeModules.size());
    p.println("----------------------------------------------------------");
    for (int i = 0; i < activeModules.size(); i++)
    {
      Module mod = (Module)activeModules.get(i);
      p.print(new PadMessage(mod.getModuleClass(), 70));
      p.print(" [");
      p.print(mod.getSubSystem());
      p.println("]");
      p.print("  Version: ");
      p.print(mod.getMajorVersion());
      p.print("-");
      p.print(mod.getMinorVersion());
      p.print("-");
      p.print(mod.getPatchLevel());
      p.print(" Producer: ");
      p.println(mod.getProducer());
      p.print("  Description: ");
      p.println(mod.getDescription());
    }
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.PackageManager
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import java.util.ArrayList;

class PackageSorter$SortModule
  implements Comparable
{
  private int position;
  private final PackageState state;
  private ArrayList dependSubsystems;
  
  public PackageSorter$SortModule(PackageState state)
  {
    position = -1;
    this.state = state;
  }
  
  public ArrayList getDependSubsystems()
  {
    return dependSubsystems;
  }
  
  public void setDependSubsystems(ArrayList dependSubsystems)
  {
    this.dependSubsystems = dependSubsystems;
  }
  
  public int getPosition()
  {
    return position;
  }
  
  public void setPosition(int position)
  {
    this.position = position;
  }
  
  public PackageState getState()
  {
    return state;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("SortModule: ");
    buffer.append(position);
    buffer.append(" ");
    buffer.append(state.getModule().getName());
    buffer.append(" ");
    buffer.append(state.getModule().getModuleClass());
    return buffer.toString();
  }
  
  public int compareTo(Object o)
  {
    SortModule otherModule = (SortModule)o;
    if (position > position) {
      return 1;
    }
    if (position < position) {
      return -1;
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.PackageSorter.SortModule
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.jfree.util.Log;
import org.jfree.util.Log.SimpleMessage;

public final class PackageSorter
{
  private static class SortModule
    implements Comparable
  {
    private int position;
    private final PackageState state;
    private ArrayList dependSubsystems;
    
    public SortModule(PackageState state)
    {
      position = -1;
      this.state = state;
    }
    
    public ArrayList getDependSubsystems()
    {
      return dependSubsystems;
    }
    
    public void setDependSubsystems(ArrayList dependSubsystems)
    {
      this.dependSubsystems = dependSubsystems;
    }
    
    public int getPosition()
    {
      return position;
    }
    
    public void setPosition(int position)
    {
      this.position = position;
    }
    
    public PackageState getState()
    {
      return state;
    }
    
    public String toString()
    {
      StringBuffer buffer = new StringBuffer();
      buffer.append("SortModule: ");
      buffer.append(position);
      buffer.append(" ");
      buffer.append(state.getModule().getName());
      buffer.append(" ");
      buffer.append(state.getModule().getModuleClass());
      return buffer.toString();
    }
    
    public int compareTo(Object o)
    {
      SortModule otherModule = (SortModule)o;
      if (position > position) {
        return 1;
      }
      if (position < position) {
        return -1;
      }
      return 0;
    }
  }
  
  public static void sort(List modules)
  {
    HashMap moduleMap = new HashMap();
    ArrayList errorModules = new ArrayList();
    ArrayList weightModules = new ArrayList();
    for (int i = 0; i < modules.size(); i++)
    {
      PackageState state = (PackageState)modules.get(i);
      if (state.getState() == -2)
      {
        errorModules.add(state);
      }
      else
      {
        SortModule mod = new SortModule(state);
        weightModules.add(mod);
        moduleMap.put(state.getModule().getModuleClass(), mod);
      }
    }
    SortModule[] weigths = (SortModule[])weightModules.toArray(new SortModule[weightModules.size()]);
    for (int i = 0; i < weigths.length; i++)
    {
      SortModule sortMod = weigths[i];
      sortMod.setDependSubsystems(collectSubsystemModules(sortMod.getState().getModule(), moduleMap));
    }
    boolean doneWork = true;
    while (doneWork)
    {
      doneWork = false;
      for (int i = 0; i < weigths.length; i++)
      {
        SortModule mod = weigths[i];
        int position = searchModulePosition(mod, moduleMap);
        if (position != mod.getPosition())
        {
          mod.setPosition(position);
          doneWork = true;
        }
      }
    }
    Arrays.sort(weigths);
    modules.clear();
    for (int i = 0; i < weigths.length; i++) {
      modules.add(weigths[i].getState());
    }
    for (int i = 0; i < errorModules.size(); i++) {
      modules.add(errorModules.get(i));
    }
  }
  
  private static int searchModulePosition(SortModule smodule, HashMap moduleMap)
  {
    Module module = smodule.getState().getModule();
    int position = 0;
    
    ModuleInfo[] modInfo = module.getOptionalModules();
    for (int modPos = 0; modPos < modInfo.length; modPos++)
    {
      String moduleName = modInfo[modPos].getModuleClass();
      SortModule reqMod = (SortModule)moduleMap.get(moduleName);
      if (reqMod != null) {
        if (reqMod.getPosition() >= position) {
          position = reqMod.getPosition() + 1;
        }
      }
    }
    modInfo = module.getRequiredModules();
    for (int modPos = 0; modPos < modInfo.length; modPos++)
    {
      String moduleName = modInfo[modPos].getModuleClass();
      SortModule reqMod = (SortModule)moduleMap.get(moduleName);
      if (reqMod == null) {
        Log.warn("Invalid state: Required dependency of '" + moduleName + "' had an error.");
      } else if (reqMod.getPosition() >= position) {
        position = reqMod.getPosition() + 1;
      }
    }
    String subSystem = module.getSubSystem();
    Iterator it = moduleMap.values().iterator();
    while (it.hasNext())
    {
      SortModule mod = (SortModule)it.next();
      if (mod.getState().getModule() != module)
      {
        Module subSysMod = mod.getState().getModule();
        if (!subSystem.equals(subSysMod.getSubSystem())) {
          if (smodule.getDependSubsystems().contains(subSysMod.getSubSystem())) {
            if (!isBaseModule(subSysMod, module)) {
              if (mod.getPosition() >= position) {
                position = mod.getPosition() + 1;
              }
            }
          }
        }
      }
    }
    return position;
  }
  
  private static boolean isBaseModule(Module mod, ModuleInfo mi)
  {
    ModuleInfo[] info = mod.getRequiredModules();
    for (int i = 0; i < info.length; i++) {
      if (info[i].getModuleClass().equals(mi.getModuleClass())) {
        return true;
      }
    }
    info = mod.getOptionalModules();
    for (int i = 0; i < info.length; i++) {
      if (info[i].getModuleClass().equals(mi.getModuleClass())) {
        return true;
      }
    }
    return false;
  }
  
  private static ArrayList collectSubsystemModules(Module childMod, HashMap moduleMap)
  {
    ArrayList collector = new ArrayList();
    ModuleInfo[] info = childMod.getRequiredModules();
    for (int i = 0; i < info.length; i++)
    {
      SortModule dependentModule = (SortModule)moduleMap.get(info[i].getModuleClass());
      if (dependentModule == null) {
        Log.warn(new Log.SimpleMessage("A dependent module was not found in the list of known modules.", info[i].getModuleClass()));
      } else {
        collector.add(dependentModule.getState().getModule().getSubSystem());
      }
    }
    info = childMod.getOptionalModules();
    for (int i = 0; i < info.length; i++)
    {
      Module dependentModule = (Module)moduleMap.get(info[i].getModuleClass());
      if (dependentModule == null) {
        Log.warn("A dependent module was not found in the list of known modules.");
      } else {
        collector.add(dependentModule.getSubSystem());
      }
    }
    return collector;
  }
}

/* Location:
 * Qualified Name:     org.jfree.base.modules.PackageSorter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.base.modules;

import org.jfree.util.Log;
import org.jfree.util.Log.SimpleMessage;

public class PackageState
{
  public static final int STATE_NEW = 0;
  public static final int STATE_CONFIGURED = 1;
  public static final int STATE_INITIALIZED = 2;
  public static final int STATE_ERROR = -2;
  private final Module module;
  private int state;
  
  public PackageState(Module module)
  {
    this(module, 0);
  }
  
  public PackageState(Module module, int state)
  {
    if (module == null) {
      throw new NullPointerException("Module must not be null.");
    }
    if ((state != 1) && (state != -2) && (state != 2) && (state != 0)) {
      throw new IllegalArgumentException("State is not valid");
    }
    this.module = module;
    this.state = state;
  }
  
  public boolean configure(SubSystem subSystem)
  {
    if (state == 0) {
      try
      {
        module.configu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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