org.apache.batik.pdf_1.6.0.v201105071520

16:40:54.196 INFO  jd.cli.Main - Decompiling org.apache.batik.pdf_1.6.0.v201105071520.jar
package org.apache.avalon.framework;

public class CascadingError
  extends Error
  implements CascadingThrowable
{
  private final Throwable m_throwable;
  
  public CascadingError(String message, Throwable throwable)
  {
    super(message);
    m_throwable = throwable;
  }
  
  public final Throwable getCause()
  {
    return m_throwable;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.CascadingError
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

public class CascadingException
  extends Exception
  implements CascadingThrowable
{
  private final Throwable m_throwable;
  
  public CascadingException(String message)
  {
    this(message, null);
  }
  
  public CascadingException(String message, Throwable throwable)
  {
    super(message);
    m_throwable = throwable;
  }
  
  public final Throwable getCause()
  {
    return m_throwable;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.CascadingException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

public class CascadingRuntimeException
  extends RuntimeException
  implements CascadingThrowable
{
  private final Throwable m_throwable;
  
  public CascadingRuntimeException(String message, Throwable throwable)
  {
    super(message);
    m_throwable = throwable;
  }
  
  public final Throwable getCause()
  {
    return m_throwable;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.CascadingRuntimeException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

public abstract interface CascadingThrowable
{
  public abstract Throwable getCause();
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.CascadingThrowable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

import java.util.Map;

public abstract class Enum
{
  private final String m_name;
  
  protected Enum(String name)
  {
    this(name, null);
  }
  
  protected Enum(String name, Map map)
  {
    m_name = name;
    if (null != map) {
      map.put(name, this);
    }
  }
  
  public final boolean equals(Object other)
  {
    if (null == other) {
      return false;
    }
    return (other == this) || ((other.getClass().getName().equals(getClass().getName())) && (m_name.equals(m_name)));
  }
  
  public int hashCode()
  {
    return m_name.hashCode();
  }
  
  public final String getName()
  {
    return m_name;
  }
  
  public String toString()
  {
    return getClass().getName() + "[" + m_name + "]";
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.Enum
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.StringTokenizer;

public final class ExceptionUtil
{
  private static final String LINE_SEPARATOR = System.getProperty("line.separator");
  private static final String GET_CAUSE_NAME = "getCause";
  private static final Class[] GET_CAUSE_PARAMTYPES = new Class[0];
  
  public static String printStackTrace(Throwable throwable)
  {
    return printStackTrace(throwable, 0, true);
  }
  
  public static String printStackTrace(Throwable throwable, boolean printCascading)
  {
    return printStackTrace(throwable, 0, printCascading);
  }
  
  public static String printStackTrace(Throwable throwable, int depth)
  {
    int dp = depth;
    String[] lines = captureStackTrace(throwable);
    if ((0 == dp) || (dp > lines.length)) {
      dp = lines.length;
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < dp; i++)
    {
      sb.append(lines[i]);
      sb.append(LINE_SEPARATOR);
    }
    return sb.toString();
  }
  
  public static String printStackTrace(Throwable throwable, int depth, boolean printCascading)
  {
    return printStackTrace(throwable, depth, printCascading, true);
  }
  
  public static String printStackTrace(Throwable throwable, int depth, boolean printCascading, boolean useReflection)
  {
    String result = printStackTrace(throwable, depth);
    if (!printCascading) {
      return result;
    }
    StringBuffer sb = new StringBuffer();
    sb.append(result);
    
    Throwable cause = getCause(throwable, useReflection);
    while (null != cause)
    {
      sb.append("rethrown from");
      sb.append(LINE_SEPARATOR);
      sb.append(printStackTrace(cause, depth));
      
      cause = getCause(cause, useReflection);
    }
    return sb.toString();
  }
  
  public static Throwable getCause(Throwable throwable, boolean useReflection)
  {
    if ((throwable instanceof CascadingThrowable)) {
      return ((CascadingThrowable)throwable).getCause();
    }
    if (useReflection) {
      try
      {
        Class clazz = throwable.getClass();
        Method method = clazz.getMethod("getCause", GET_CAUSE_PARAMTYPES);
        
        return (Throwable)method.invoke(throwable, null);
      }
      catch (Throwable t)
      {
        return null;
      }
    }
    return null;
  }
  
  public static String[] captureStackTrace(Throwable throwable)
  {
    StringWriter sw = new StringWriter();
    throwable.printStackTrace(new PrintWriter(sw, true));
    return splitStringInternal(sw.toString(), LINE_SEPARATOR);
  }
  
  /**
   * @deprecated
   */
  public static String[] splitString(String string, String onToken)
  {
    return splitStringInternal(string, onToken);
  }
  
  private static String[] splitStringInternal(String string, String onToken)
  {
    StringTokenizer tokenizer = new StringTokenizer(string, onToken);
    String[] result = new String[tokenizer.countTokens()];
    for (int i = 0; i < result.length; i++) {
      result[i] = tokenizer.nextToken();
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.ExceptionUtil
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

import java.util.Map;

public abstract class ValuedEnum
  extends Enum
{
  private final int m_value;
  
  protected ValuedEnum(String name, int value)
  {
    this(name, value, null);
  }
  
  protected ValuedEnum(String name, int value, Map map)
  {
    super(name, map);
    m_value = value;
  }
  
  public final int getValue()
  {
    return m_value;
  }
  
  public final boolean isEqualTo(ValuedEnum other)
  {
    return m_value == m_value;
  }
  
  public final boolean isGreaterThan(ValuedEnum other)
  {
    return m_value > m_value;
  }
  
  public final boolean isGreaterThanOrEqual(ValuedEnum other)
  {
    return m_value >= m_value;
  }
  
  public final boolean isLessThan(ValuedEnum other)
  {
    return m_value < m_value;
  }
  
  public final boolean isLessThanOrEqual(ValuedEnum other)
  {
    return m_value <= m_value;
  }
  
  public String toString()
  {
    return getClass().getName() + "[" + getName() + "=" + m_value + "]";
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.ValuedEnum
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework;

import java.io.Serializable;
import java.util.StringTokenizer;

public final class Version
  implements Serializable
{
  private int m_major;
  private int m_minor;
  private int m_micro;
  
  public static Version getVersion(String version)
    throws NumberFormatException, IllegalArgumentException
  {
    StringTokenizer tokenizer = new StringTokenizer(version, ".");
    String[] levels = new String[tokenizer.countTokens()];
    for (int i = 0; i < levels.length; i++) {
      levels[i] = tokenizer.nextToken();
    }
    if ((0 == levels.length) || (3 < levels.length)) {
      throw new IllegalArgumentException("Malformed version string " + version);
    }
    int major = Integer.parseInt(levels[0]);
    
    int minor = 0;
    if (1 < levels.length) {
      minor = Integer.parseInt(levels[1]);
    }
    int micro = 0;
    if (2 < levels.length) {
      micro = Integer.parseInt(levels[2]);
    }
    return new Version(major, minor, micro);
  }
  
  public Version(int major, int minor, int micro)
  {
    m_major = major;
    m_minor = minor;
    m_micro = micro;
  }
  
  public int getMajor()
  {
    return m_major;
  }
  
  public int getMinor()
  {
    return m_minor;
  }
  
  public int getMicro()
  {
    return m_micro;
  }
  
  public boolean equals(Version other)
  {
    if (m_major != m_major) {
      return false;
    }
    if (m_minor != m_minor) {
      return false;
    }
    if (m_micro != m_micro) {
      return false;
    }
    return true;
  }
  
  public boolean equals(Object other)
  {
    if ((other instanceof Version)) {
      return equals((Version)other);
    }
    return false;
  }
  
  public boolean complies(Version other)
  {
    if (m_major != m_major) {
      return false;
    }
    if (m_minor < m_minor) {
      return false;
    }
    if ((m_minor == m_minor) && (m_micro < m_micro)) {
      return false;
    }
    return true;
  }
  
  public String toString()
  {
    return m_major + "." + m_minor + "." + m_micro;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.Version
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.activity;

public abstract interface Disposable
{
  public abstract void dispose();
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.activity.Disposable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.activity;

public abstract interface Executable
{
  public abstract void execute()
    throws Exception;
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.activity.Executable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.activity;

public abstract interface Initializable
{
  public abstract void initialize()
    throws Exception;
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.activity.Initializable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.activity;

public abstract interface Startable
{
  public abstract void start()
    throws Exception;
  
  public abstract void stop()
    throws Exception;
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.activity.Startable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.activity;

public abstract interface Suspendable
{
  public abstract void suspend();
  
  public abstract void resume();
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.activity.Suspendable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

public abstract class AbstractConfiguration
  implements Configuration
{
  protected abstract String getPrefix()
    throws ConfigurationException;
  
  public int getValueAsInteger()
    throws ConfigurationException
  {
    String value = getValue().trim();
    try
    {
      if (value.startsWith("0x")) {
        return Integer.parseInt(value.substring(2), 16);
      }
      if (value.startsWith("0o")) {
        return Integer.parseInt(value.substring(2), 8);
      }
      if (value.startsWith("0b")) {
        return Integer.parseInt(value.substring(2), 2);
      }
      return Integer.parseInt(value);
    }
    catch (Exception nfe)
    {
      String message = "Cannot parse the value \"" + value + "\" as an integer in the configuration element \"" + getName() + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public int getValueAsInteger(int defaultValue)
  {
    try
    {
      return getValueAsInteger();
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public long getValueAsLong()
    throws ConfigurationException
  {
    String value = getValue().trim();
    try
    {
      if (value.startsWith("0x")) {
        return Long.parseLong(value.substring(2), 16);
      }
      if (value.startsWith("0o")) {
        return Long.parseLong(value.substring(2), 8);
      }
      if (value.startsWith("0b")) {
        return Long.parseLong(value.substring(2), 2);
      }
      return Long.parseLong(value);
    }
    catch (Exception nfe)
    {
      String message = "Cannot parse the value \"" + value + "\" as a long in the configuration element \"" + getName() + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public long getValueAsLong(long defaultValue)
  {
    try
    {
      return getValueAsLong();
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public float getValueAsFloat()
    throws ConfigurationException
  {
    String value = getValue().trim();
    try
    {
      return Float.parseFloat(value);
    }
    catch (Exception nfe)
    {
      String message = "Cannot parse the value \"" + value + "\" as a float in the configuration element \"" + getName() + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public float getValueAsFloat(float defaultValue)
  {
    try
    {
      return getValueAsFloat();
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public boolean getValueAsBoolean()
    throws ConfigurationException
  {
    String value = getValue().trim();
    if (isTrue(value)) {
      return true;
    }
    if (isFalse(value)) {
      return false;
    }
    String message = "Cannot parse the value \"" + value + "\" as a boolean in the configuration element \"" + getName() + "\" at " + getLocation();
    
    throw new ConfigurationException(message);
  }
  
  public boolean getValueAsBoolean(boolean defaultValue)
  {
    try
    {
      return getValueAsBoolean();
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public String getValue(String defaultValue)
  {
    try
    {
      return getValue();
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public int getAttributeAsInteger(String name)
    throws ConfigurationException
  {
    String value = getAttribute(name).trim();
    try
    {
      if (value.startsWith("0x")) {
        return Integer.parseInt(value.substring(2), 16);
      }
      if (value.startsWith("0o")) {
        return Integer.parseInt(value.substring(2), 8);
      }
      if (value.startsWith("0b")) {
        return Integer.parseInt(value.substring(2), 2);
      }
      return Integer.parseInt(value);
    }
    catch (Exception nfe)
    {
      String message = "Cannot parse the value \"" + value + "\" as an integer in the attribute \"" + name + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public int getAttributeAsInteger(String name, int defaultValue)
  {
    try
    {
      return getAttributeAsInteger(name);
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public long getAttributeAsLong(String name)
    throws ConfigurationException
  {
    String value = getAttribute(name);
    try
    {
      if (value.startsWith("0x")) {
        return Long.parseLong(value.substring(2), 16);
      }
      if (value.startsWith("0o")) {
        return Long.parseLong(value.substring(2), 8);
      }
      if (value.startsWith("0b")) {
        return Long.parseLong(value.substring(2), 2);
      }
      return Long.parseLong(value);
    }
    catch (Exception nfe)
    {
      String message = "Cannot parse the value \"" + value + "\" as a long in the attribute \"" + name + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public long getAttributeAsLong(String name, long defaultValue)
  {
    try
    {
      return getAttributeAsLong(name);
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public float getAttributeAsFloat(String name)
    throws ConfigurationException
  {
    String value = getAttribute(name);
    try
    {
      return Float.parseFloat(value);
    }
    catch (Exception e)
    {
      String message = "Cannot parse the value \"" + value + "\" as a float in the attribute \"" + name + "\" at " + getLocation();
      
      throw new ConfigurationException(message);
    }
  }
  
  public float getAttributeAsFloat(String name, float defaultValue)
  {
    try
    {
      return getAttributeAsFloat(name);
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public boolean getAttributeAsBoolean(String name)
    throws ConfigurationException
  {
    String value = getAttribute(name);
    if (isTrue(value)) {
      return true;
    }
    if (isFalse(value)) {
      return false;
    }
    String message = "Cannot parse the value \"" + value + "\" as a boolean in the attribute \"" + name + "\" at " + getLocation();
    
    throw new ConfigurationException(message);
  }
  
  private boolean isTrue(String value)
  {
    return (value.equalsIgnoreCase("true")) || (value.equalsIgnoreCase("yes")) || (value.equalsIgnoreCase("on")) || (value.equalsIgnoreCase("1"));
  }
  
  private boolean isFalse(String value)
  {
    return (value.equalsIgnoreCase("false")) || (value.equalsIgnoreCase("no")) || (value.equalsIgnoreCase("off")) || (value.equalsIgnoreCase("0"));
  }
  
  public boolean getAttributeAsBoolean(String name, boolean defaultValue)
  {
    try
    {
      return getAttributeAsBoolean(name);
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public String getAttribute(String name, String defaultValue)
  {
    try
    {
      return getAttribute(name);
    }
    catch (ConfigurationException ce) {}
    return defaultValue;
  }
  
  public Configuration getChild(String name)
  {
    return getChild(name, true);
  }
  
  public Configuration getChild(String name, boolean createNew)
  {
    Configuration[] children = getChildren(name);
    if (children.length > 0) {
      return children[0];
    }
    if (createNew) {
      return new DefaultConfiguration(name, "-");
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.AbstractConfiguration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

public abstract interface Configurable
{
  public abstract void configure(Configuration paramConfiguration)
    throws ConfigurationException;
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.Configurable
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

public abstract interface Configuration
{
  public abstract String getName();
  
  public abstract String getLocation();
  
  public abstract String getNamespace()
    throws ConfigurationException;
  
  public abstract Configuration getChild(String paramString);
  
  public abstract Configuration getChild(String paramString, boolean paramBoolean);
  
  public abstract Configuration[] getChildren();
  
  public abstract Configuration[] getChildren(String paramString);
  
  public abstract String[] getAttributeNames();
  
  public abstract String getAttribute(String paramString)
    throws ConfigurationException;
  
  public abstract int getAttributeAsInteger(String paramString)
    throws ConfigurationException;
  
  public abstract long getAttributeAsLong(String paramString)
    throws ConfigurationException;
  
  public abstract float getAttributeAsFloat(String paramString)
    throws ConfigurationException;
  
  public abstract boolean getAttributeAsBoolean(String paramString)
    throws ConfigurationException;
  
  public abstract String getValue()
    throws ConfigurationException;
  
  public abstract int getValueAsInteger()
    throws ConfigurationException;
  
  public abstract float getValueAsFloat()
    throws ConfigurationException;
  
  public abstract boolean getValueAsBoolean()
    throws ConfigurationException;
  
  public abstract long getValueAsLong()
    throws ConfigurationException;
  
  public abstract String getValue(String paramString);
  
  public abstract int getValueAsInteger(int paramInt);
  
  public abstract long getValueAsLong(long paramLong);
  
  public abstract float getValueAsFloat(float paramFloat);
  
  public abstract boolean getValueAsBoolean(boolean paramBoolean);
  
  public abstract String getAttribute(String paramString1, String paramString2);
  
  public abstract int getAttributeAsInteger(String paramString, int paramInt);
  
  public abstract long getAttributeAsLong(String paramString, long paramLong);
  
  public abstract float getAttributeAsFloat(String paramString, float paramFloat);
  
  public abstract boolean getAttributeAsBoolean(String paramString, boolean paramBoolean);
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.Configuration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import org.apache.avalon.framework.CascadingException;

public class ConfigurationException
  extends CascadingException
{
  public ConfigurationException(String message)
  {
    this(message, null);
  }
  
  public ConfigurationException(String message, Throwable throwable)
  {
    super(message, throwable);
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.ConfigurationException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

public class ConfigurationUtil
{
  public static Element toElement(Configuration configuration)
  {
    try
    {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.newDocument();
      
      return createElement(document, configuration);
    }
    catch (ParserConfigurationException pce)
    {
      throw new IllegalStateException(pce.toString());
    }
  }
  
  public static boolean equals(Configuration c1, Configuration c2)
  {
    return (c1.getName().equals(c2.getName())) && (areValuesEqual(c1, c2)) && (areAttributesEqual(c1, c2)) && (areChildrenEqual(c1, c2));
  }
  
  private static boolean areChildrenEqual(Configuration c1, Configuration c2)
  {
    Configuration[] kids1 = c1.getChildren();
    ArrayList kids2 = new ArrayList(Arrays.asList(c2.getChildren()));
    if (kids1.length != kids2.size()) {
      return false;
    }
    for (int i = 0; i < kids1.length; i++) {
      if (!findMatchingChild(kids1[i], kids2)) {
        return false;
      }
    }
    return kids2.isEmpty();
  }
  
  private static boolean findMatchingChild(Configuration c, ArrayList matchAgainst)
  {
    Iterator i = matchAgainst.iterator();
    while (i.hasNext()) {
      if (equals(c, (Configuration)i.next()))
      {
        i.remove();
        return true;
      }
    }
    return false;
  }
  
  private static boolean areAttributesEqual(Configuration c1, Configuration c2)
  {
    String[] names1 = c1.getAttributeNames();
    String[] names2 = c2.getAttributeNames();
    if (names1.length != names2.length) {
      return false;
    }
    for (int i = 0; i < names1.length; i++)
    {
      String name = names1[i];
      String value1 = c1.getAttribute(name, null);
      String value2 = c2.getAttribute(name, null);
      if (!value1.equals(value2)) {
        return false;
      }
    }
    return true;
  }
  
  private static boolean areValuesEqual(Configuration c1, Configuration c2)
  {
    String value1 = c1.getValue(null);
    String value2 = c2.getValue(null);
    return ((value1 == null) && (value2 == null)) || ((value1 != null) && (value1.equals(value2)));
  }
  
  private static Element createElement(Document document, Configuration configuration)
  {
    Element element = document.createElement(configuration.getName());
    
    String content = configuration.getValue(null);
    if (null != content)
    {
      Text child = document.createTextNode(content);
      element.appendChild(child);
    }
    String[] names = configuration.getAttributeNames();
    for (int i = 0; i < names.length; i++)
    {
      String name = names[i];
      String value = configuration.getAttribute(name, null);
      element.setAttribute(name, value);
    }
    Configuration[] children = configuration.getChildren();
    for (int i = 0; i < children.length; i++)
    {
      Element child = createElement(document, children[i]);
      element.appendChild(child);
    }
    return element;
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.ConfigurationUtil
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

public class DefaultConfiguration
  extends AbstractConfiguration
  implements Serializable
{
  protected static final Configuration[] EMPTY_ARRAY = new Configuration[0];
  private final String m_name;
  private final String m_location;
  private final String m_namespace;
  private final String m_prefix;
  private HashMap m_attributes;
  private ArrayList m_children;
  private String m_value;
  private boolean m_readOnly;
  
  public DefaultConfiguration(String name)
  {
    this(name, null, "", "");
  }
  
  public DefaultConfiguration(String name, String location)
  {
    this(name, location, "", "");
  }
  
  public DefaultConfiguration(String name, String location, String ns, String prefix)
  {
    m_name = name;
    m_location = location;
    m_namespace = ns;
    m_prefix = prefix;
  }
  
  public String getName()
  {
    return m_name;
  }
  
  public String getNamespace()
    throws ConfigurationException
  {
    if (null != m_namespace) {
      return m_namespace;
    }
    throw new ConfigurationException("No namespace (not even default \"\") is associated with the configuration element \"" + getName() + "\" at " + getLocation());
  }
  
  protected String getPrefix()
    throws ConfigurationException
  {
    if (null != m_prefix) {
      return m_prefix;
    }
    throw new ConfigurationException("No prefix (not even default \"\") is associated with the configuration element \"" + getName() + "\" at " + getLocation());
  }
  
  public String getLocation()
  {
    return m_location;
  }
  
  public String getValue(String defaultValue)
  {
    if (null != m_value) {
      return m_value;
    }
    return defaultValue;
  }
  
  public String getValue()
    throws ConfigurationException
  {
    if (null != m_value) {
      return m_value;
    }
    throw new ConfigurationException("No value is associated with the configuration element \"" + getName() + "\" at " + getLocation());
  }
  
  public String[] getAttributeNames()
  {
    if (null == m_attributes) {
      return new String[0];
    }
    return (String[])m_attributes.keySet().toArray(new String[0]);
  }
  
  public Configuration[] getChildren()
  {
    if (null == m_children) {
      return new Configuration[0];
    }
    return (Configuration[])m_children.toArray(new Configuration[0]);
  }
  
  public String getAttribute(String name)
    throws ConfigurationException
  {
    String value = null != m_attributes ? (String)m_attributes.get(name) : null;
    if (null != value) {
      return value;
    }
    throw new ConfigurationException("No attribute named \"" + name + "\" is " + "associated with the configuration element \"" + getName() + "\" at " + getLocation());
  }
  
  public Configuration getChild(String name, boolean createNew)
  {
    if (null != m_children)
    {
      int size = m_children.size();
      for (int i = 0; i < size; i++)
      {
        Configuration configuration = (Configuration)m_children.get(i);
        if (name.equals(configuration.getName())) {
          return configuration;
        }
      }
    }
    if (createNew) {
      return new DefaultConfiguration(name, "-");
    }
    return null;
  }
  
  public Configuration[] getChildren(String name)
  {
    if (null == m_children) {
      return new Configuration[0];
    }
    ArrayList children = new ArrayList();
    int size = m_children.size();
    for (int i = 0; i < size; i++)
    {
      Configuration configuration = (Configuration)m_children.get(i);
      if (name.equals(configuration.getName())) {
        children.add(configuration);
      }
    }
    return (Configuration[])children.toArray(new Configuration[0]);
  }
  
  /**
   * @deprecated
   */
  public void appendValueData(String value)
  {
    checkWriteable();
    if (null == m_value) {
      m_value = value;
    } else {
      m_value += value;
    }
  }
  
  public void setValue(String value)
  {
    checkWriteable();
    
    m_value = value;
  }
  
  public void setAttribute(String name, String value)
  {
    checkWriteable();
    if (null == m_attributes) {
      m_attributes = new HashMap();
    }
    m_attributes.put(name, value);
  }
  
  /**
   * @deprecated
   */
  public String addAttribute(String name, String value)
  {
    checkWriteable();
    if (null == m_attributes) {
      m_attributes = new HashMap();
    }
    return (String)m_attributes.put(name, value);
  }
  
  public void addChild(Configuration configuration)
  {
    checkWriteable();
    if (null == m_children) {
      m_children = new ArrayList();
    }
    m_children.add(configuration);
  }
  
  public void addAll(Configuration other)
  {
    checkWriteable();
    
    setValue(other.getValue(null));
    addAllAttributes(other);
    addAllChildren(other);
  }
  
  public void addAllAttributes(Configuration other)
  {
    checkWriteable();
    
    String[] attributes = other.getAttributeNames();
    for (int i = 0; i < attributes.length; i++)
    {
      String name = attributes[i];
      String value = other.getAttribute(name, null);
      setAttribute(name, value);
    }
  }
  
  public void addAllChildren(Configuration other)
  {
    checkWriteable();
    
    Configuration[] children = other.getChildren();
    for (int i = 0; i < children.length; i++) {
      addChild(children[i]);
    }
  }
  
  public void removeChild(Configuration configuration)
  {
    checkWriteable();
    if (null == m_children) {
      return;
    }
    m_children.remove(configuration);
  }
  
  public int getChildCount()
  {
    if (null == m_children) {
      return 0;
    }
    return m_children.size();
  }
  
  public void makeReadOnly()
  {
    m_readOnly = true;
  }
  
  protected final void checkWriteable()
    throws IllegalStateException
  {
    if (m_readOnly) {
      throw new IllegalStateException("Configuration is read only and can not be modified");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.DefaultConfiguration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

public class DefaultConfigurationBuilder
{
  private SAXConfigurationHandler m_handler;
  private XMLReader m_parser;
  
  public DefaultConfigurationBuilder()
  {
    this(false);
  }
  
  public DefaultConfigurationBuilder(boolean enableNamespaces)
  {
    try
    {
      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
      if (enableNamespaces) {
        saxParserFactory.setNamespaceAware(true);
      }
      SAXParser saxParser = saxParserFactory.newSAXParser();
      setParser(saxParser.getXMLReader());
    }
    catch (Exception se)
    {
      throw new Error("Unable to setup SAX parser" + se);
    }
  }
  
  public DefaultConfigurationBuilder(XMLReader parser)
  {
    setParser(parser);
  }
  
  private void setParser(XMLReader parser)
  {
    m_parser = parser;
    
    m_handler = getHandler();
    
    m_parser.setContentHandler(m_handler);
    m_parser.setErrorHandler(m_handler);
  }
  
  protected SAXConfigurationHandler getHandler()
  {
    try
    {
      if (m_parser.getFeature("http://xml.org/sax/features/namespaces")) {
        return new NamespacedSAXConfigurationHandler();
      }
    }
    catch (Exception e) {}
    return new SAXConfigurationHandler();
  }
  
  public Configuration buildFromFile(String filename)
    throws SAXException, IOException, ConfigurationException
  {
    return buildFromFile(new File(filename));
  }
  
  public Configuration buildFromFile(File file)
    throws SAXException, IOException, ConfigurationException
  {
    synchronized (this)
    {
      m_handler.clear();
      m_parser.parse(file.toURL().toString());
      return m_handler.getConfiguration();
    }
  }
  
  public Configuration build(InputStream inputStream)
    throws SAXException, IOException, ConfigurationException
  {
    return build(new InputSource(inputStream));
  }
  
  public Configuration build(String uri)
    throws SAXException, IOException, ConfigurationException
  {
    return build(new InputSource(uri));
  }
  
  public Configuration build(InputSource input)
    throws SAXException, IOException, ConfigurationException
  {
    synchronized (this)
    {
      m_handler.clear();
      m_parser.parse(input);
      return m_handler.getConfiguration();
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.DefaultConfigurationBuilder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.NamespaceSupport;

public class DefaultConfigurationSerializer
{
  private SAXTransformerFactory m_tfactory;
  private Properties m_format = new Properties();
  
  public void setIndent(boolean indent)
  {
    if (indent) {
      m_format.put("indent", "yes");
    } else {
      m_format.put("indent", "no");
    }
  }
  
  protected ContentHandler createContentHandler(Result result)
  {
    try
    {
      TransformerHandler handler = getTransformerFactory().newTransformerHandler();
      
      m_format.put("method", "xml");
      handler.setResult(result);
      handler.getTransformer().setOutputProperties(m_format);
      
      return handler;
    }
    catch (Exception e)
    {
      throw new RuntimeException(e.toString());
    }
  }
  
  protected SAXTransformerFactory getTransformerFactory()
  {
    if (m_tfactory == null) {
      m_tfactory = ((SAXTransformerFactory)TransformerFactory.newInstance());
    }
    return m_tfactory;
  }
  
  public void serialize(ContentHandler handler, Configuration source)
    throws SAXException, ConfigurationException
  {
    handler.startDocument();
    serializeElement(handler, new NamespaceSupport(), source);
    handler.endDocument();
  }
  
  protected void serializeElement(ContentHandler handler, NamespaceSupport namespaceSupport, Configuration element)
    throws SAXException, ConfigurationException
  {
    namespaceSupport.pushContext();
    
    AttributesImpl attr = new AttributesImpl();
    String[] attrNames = element.getAttributeNames();
    if (null != attrNames) {
      for (int i = 0; i < attrNames.length; i++) {
        attr.addAttribute("", attrNames[i], attrNames[i], "CDATA", element.getAttribute(attrNames[i], ""));
      }
    }
    String nsURI = element.getNamespace();
    String nsPrefix = "";
    if ((element instanceof AbstractConfiguration)) {
      nsPrefix = ((AbstractConfiguration)element).getPrefix();
    }
    boolean nsWasDeclared = false;
    
    String existingURI = namespaceSupport.getURI(nsPrefix);
    if ((existingURI == null) || (!existingURI.equals(nsURI)))
    {
      nsWasDeclared = true;
      if ((!nsPrefix.equals("")) || (!nsURI.equals(""))) {
        if (nsPrefix.equals("")) {
          attr.addAttribute("", "xmlns", "xmlns", "CDATA", nsURI);
        } else {
          attr.addAttribute("", "xmlns:" + nsPrefix, "xmlns:" + nsPrefix, "CDATA", nsURI);
        }
      }
      handler.startPrefixMapping(nsPrefix, nsURI);
      namespaceSupport.declarePrefix(nsPrefix, nsURI);
    }
    String localName = element.getName();
    String qName = element.getName();
    if ((nsPrefix == null) || (nsPrefix.length() == 0)) {
      qName = localName;
    } else {
      qName = nsPrefix + ":" + localName;
    }
    handler.startElement(nsURI, localName, qName, attr);
    
    String value = element.getValue(null);
    if (null == value)
    {
      Configuration[] children = element.getChildren();
      for (int i = 0; i < children.length; i++) {
        serializeElement(handler, namespaceSupport, children[i]);
      }
    }
    else
    {
      handler.characters(value.toCharArray(), 0, value.length());
    }
    handler.endElement(nsURI, localName, qName);
    if (nsWasDeclared) {
      handler.endPrefixMapping(nsPrefix);
    }
    namespaceSupport.popContext();
  }
  
  public void serializeToFile(String filename, Configuration source)
    throws SAXException, IOException, ConfigurationException
  {
    serializeToFile(new File(filename), source);
  }
  
  public void serializeToFile(File file, Configuration source)
    throws SAXException, IOException, ConfigurationException
  {
    OutputStream outputStream = null;
    try
    {
      outputStream = new FileOutputStream(file);
      serialize(outputStream, source);
    }
    finally
    {
      if (outputStream != null) {
        outputStream.close();
      }
    }
  }
  
  public void serialize(OutputStream outputStream, Configuration source)
    throws SAXException, IOException, ConfigurationException
  {
    serialize(createContentHandler(new StreamResult(outputStream)), source);
  }
  
  public void serialize(String uri, Configuration source)
    throws SAXException, IOException, ConfigurationException
  {
    OutputStream outputStream = null;
    try
    {
      outputStream = new URL(uri).openConnection().getOutputStream();
      serialize(outputStream, source);
    }
    finally
    {
      if (outputStream != null) {
        outputStream.close();
      }
    }
  }
  
  public String serialize(Configuration source)
    throws SAXException, ConfigurationException
  {
    StringWriter writer = new StringWriter();
    
    serialize(createContentHandler(new StreamResult(writer)), source);
    
    return writer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.avalon.framework.configuration.DefaultConfigurationSerializer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.avalon.framework.configuration;

import java.ut
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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