dom4j-1.6.1

16:35:25.360 INFO  jd.cli.Main - Decompiling dom4j-1.6.1.jar
package org.dom4j;

public abstract interface Attribute
  extends Node
{
  public abstract QName getQName();
  
  public abstract Namespace getNamespace();
  
  public abstract void setNamespace(Namespace paramNamespace);
  
  public abstract String getNamespacePrefix();
  
  public abstract String getNamespaceURI();
  
  public abstract String getQualifiedName();
  
  public abstract String getValue();
  
  public abstract void setValue(String paramString);
  
  public abstract Object getData();
  
  public abstract void setData(Object paramObject);
}

/* Location:
 * Qualified Name:     org.dom4j.Attribute
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.bean;

import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.tree.AbstractAttribute;

public class BeanAttribute
  extends AbstractAttribute
{
  private final BeanAttributeList beanList;
  private final int index;
  
  public BeanAttribute(BeanAttributeList beanList, int index)
  {
    this.beanList = beanList;
    this.index = index;
  }
  
  public QName getQName()
  {
    return beanList.getQName(index);
  }
  
  public Element getParent()
  {
    return beanList.getParent();
  }
  
  public String getValue()
  {
    Object data = getData();
    
    return data != null ? data.toString() : null;
  }
  
  public void setValue(String data)
  {
    beanList.setData(index, data);
  }
  
  public Object getData()
  {
    return beanList.getData(index);
  }
  
  public void setData(Object data)
  {
    beanList.setData(index, data);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.bean.BeanAttribute
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.bean;

import java.util.AbstractList;
import org.dom4j.Attribute;
import org.dom4j.QName;

public class BeanAttributeList
  extends AbstractList
{
  private BeanElement parent;
  private BeanMetaData beanMetaData;
  private BeanAttribute[] attributes;
  
  public BeanAttributeList(BeanElement parent, BeanMetaData beanMetaData)
  {
    this.parent = parent;
    this.beanMetaData = beanMetaData;
    attributes = new BeanAttribute[beanMetaData.attributeCount()];
  }
  
  public BeanAttributeList(BeanElement parent)
  {
    this.parent = parent;
    
    Object data = parent.getData();
    Class beanClass = data != null ? data.getClass() : null;
    beanMetaData = BeanMetaData.get(beanClass);
    attributes = new BeanAttribute[beanMetaData.attributeCount()];
  }
  
  public Attribute attribute(String name)
  {
    int index = beanMetaData.getIndex(name);
    
    return attribute(index);
  }
  
  public Attribute attribute(QName qname)
  {
    int index = beanMetaData.getIndex(qname);
    
    return attribute(index);
  }
  
  public BeanAttribute attribute(int index)
  {
    if ((index >= 0) && (index <= attributes.length))
    {
      BeanAttribute attribute = attributes[index];
      if (attribute == null)
      {
        attribute = createAttribute(parent, index);
        attributes[index] = attribute;
      }
      return attribute;
    }
    return null;
  }
  
  public BeanElement getParent()
  {
    return parent;
  }
  
  public QName getQName(int index)
  {
    return beanMetaData.getQName(index);
  }
  
  public Object getData(int index)
  {
    return beanMetaData.getData(index, parent.getData());
  }
  
  public void setData(int index, Object data)
  {
    beanMetaData.setData(index, parent.getData(), data);
  }
  
  public int size()
  {
    return attributes.length;
  }
  
  public Object get(int index)
  {
    BeanAttribute attribute = attributes[index];
    if (attribute == null)
    {
      attribute = createAttribute(parent, index);
      attributes[index] = attribute;
    }
    return attribute;
  }
  
  public boolean add(Object object)
  {
    throw new UnsupportedOperationException("add(Object) unsupported");
  }
  
  public void add(int index, Object object)
  {
    throw new UnsupportedOperationException("add(int,Object) unsupported");
  }
  
  public Object set(int index, Object object)
  {
    throw new UnsupportedOperationException("set(int,Object) unsupported");
  }
  
  public boolean remove(Object object)
  {
    return false;
  }
  
  public Object remove(int index)
  {
    BeanAttribute attribute = (BeanAttribute)get(index);
    Object oldValue = attribute.getValue();
    attribute.setValue(null);
    
    return oldValue;
  }
  
  public void clear()
  {
    int i = 0;
    for (int size = attributes.length; i < size; i++)
    {
      BeanAttribute attribute = attributes[i];
      if (attribute != null) {
        attribute.setValue(null);
      }
    }
  }
  
  protected BeanAttribute createAttribute(BeanElement element, int index)
  {
    return new BeanAttribute(this, index);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.bean.BeanAttributeList
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.bean;

import java.io.PrintStream;
import org.dom4j.Attribute;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.tree.DefaultAttribute;
import org.xml.sax.Attributes;

public class BeanDocumentFactory
  extends DocumentFactory
{
  private static BeanDocumentFactory singleton = new BeanDocumentFactory();
  
  public static DocumentFactory getInstance()
  {
    return singleton;
  }
  
  public Element createElement(QName qname)
  {
    Object bean = createBean(qname);
    if (bean == null) {
      return new BeanElement(qname);
    }
    return new BeanElement(qname, bean);
  }
  
  public Element createElement(QName qname, Attributes attributes)
  {
    Object bean = createBean(qname, attributes);
    if (bean == null) {
      return new BeanElement(qname);
    }
    return new BeanElement(qname, bean);
  }
  
  public Attribute createAttribute(Element owner, QName qname, String value)
  {
    return new DefaultAttribute(qname, value);
  }
  
  protected Object createBean(QName qname)
  {
    return null;
  }
  
  protected Object createBean(QName qname, Attributes attributes)
  {
    String value = attributes.getValue("class");
    if (value != null) {
      try
      {
        Class beanClass = Class.forName(value, true, BeanDocumentFactory.class.getClassLoader());
        
        return beanClass.newInstance();
      }
      catch (Exception e)
      {
        handleException(e);
      }
    }
    return null;
  }
  
  protected void handleException(Exception e)
  {
    System.out.println("#### Warning: couldn't create bean: " + e);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.bean.BeanDocumentFactory
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.bean;

import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.DefaultElement;
import org.dom4j.tree.NamespaceStack;
import org.xml.sax.Attributes;

public class BeanElement
  extends DefaultElement
{
  private static final DocumentFactory DOCUMENT_FACTORY = ;
  private Object bean;
  
  public BeanElement(String name, Object bean)
  {
    this(DOCUMENT_FACTORY.createQName(name), bean);
  }
  
  public BeanElement(String name, Namespace namespace, Object bean)
  {
    this(DOCUMENT_FACTORY.createQName(name, namespace), bean);
  }
  
  public BeanElement(QName qname, Object bean)
  {
    super(qname);
    this.bean = bean;
  }
  
  public BeanElement(QName qname)
  {
    super(qname);
  }
  
  public Object getData()
  {
    return bean;
  }
  
  public void setData(Object data)
  {
    bean = data;
    
    setAttributeList(null);
  }
  
  public Attribute attribute(String name)
  {
    return getBeanAttributeList().attribute(name);
  }
  
  public Attribute attribute(QName qname)
  {
    return getBeanAttributeList().attribute(qname);
  }
  
  public Element addAttribute(String name, String value)
  {
    Attribute attribute = attribute(name);
    if (attribute != null) {
      attribute.setValue(value);
    }
    return this;
  }
  
  public Element addAttribute(QName qName, String value)
  {
    Attribute attribute = attribute(qName);
    if (attribute != null) {
      attribute.setValue(value);
    }
    return this;
  }
  
  public void setAttributes(List attributes)
  {
    throw new UnsupportedOperationException("Not implemented yet.");
  }
  
  public void setAttributes(Attributes attributes, NamespaceStack namespaceStack, boolean noNamespaceAttributes)
  {
    String className = attributes.getValue("class");
    if (className != null) {
      try
      {
        Class beanClass = Class.forName(className, true, BeanElement.class.getClassLoader());
        
        setData(beanClass.newInstance());
        for (int i = 0; i < attributes.getLength(); i++)
        {
          String attributeName = attributes.getLocalName(i);
          if (!"class".equalsIgnoreCase(attributeName)) {
            addAttribute(attributeName, attributes.getValue(i));
          }
        }
      }
      catch (Exception ex)
      {
        ((BeanDocumentFactory)getDocumentFactory()).handleException(ex);
      }
    } else {
      super.setAttributes(attributes, namespaceStack, noNamespaceAttributes);
    }
  }
  
  protected DocumentFactory getDocumentFactory()
  {
    return DOCUMENT_FACTORY;
  }
  
  protected BeanAttributeList getBeanAttributeList()
  {
    return (BeanAttributeList)attributeList();
  }
  
  protected List createAttributeList()
  {
    return new BeanAttributeList(this);
  }
  
  protected List createAttributeList(int size)
  {
    return new BeanAttributeList(this);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.bean.BeanElement
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.bean;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.DocumentFactory;
import org.dom4j.QName;

public class BeanMetaData
{
  protected static final Object[] NULL_ARGS = new Object[0];
  private static Map singletonCache = new HashMap();
  private static final DocumentFactory DOCUMENT_FACTORY = BeanDocumentFactory.getInstance();
  private Class beanClass;
  private PropertyDescriptor[] propertyDescriptors;
  private QName[] qNames;
  private Method[] readMethods;
  private Method[] writeMethods;
  private Map nameMap = new HashMap();
  
  public BeanMetaData(Class beanClass)
  {
    this.beanClass = beanClass;
    if (beanClass != null) {
      try
      {
        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
        propertyDescriptors = beanInfo.getPropertyDescriptors();
      }
      catch (IntrospectionException e)
      {
        handleException(e);
      }
    }
    if (propertyDescriptors == null) {
      propertyDescriptors = new PropertyDescriptor[0];
    }
    int size = propertyDescriptors.length;
    qNames = new QName[size];
    readMethods = new Method[size];
    writeMethods = new Method[size];
    for (int i = 0; i < size; i++)
    {
      PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
      String name = propertyDescriptor.getName();
      QName qName = DOCUMENT_FACTORY.createQName(name);
      qNames[i] = qName;
      readMethods[i] = propertyDescriptor.getReadMethod();
      writeMethods[i] = propertyDescriptor.getWriteMethod();
      
      Integer index = new Integer(i);
      nameMap.put(name, index);
      nameMap.put(qName, index);
    }
  }
  
  public static BeanMetaData get(Class beanClass)
  {
    BeanMetaData answer = (BeanMetaData)singletonCache.get(beanClass);
    if (answer == null)
    {
      answer = new BeanMetaData(beanClass);
      singletonCache.put(beanClass, answer);
    }
    return answer;
  }
  
  public int attributeCount()
  {
    return propertyDescriptors.length;
  }
  
  public BeanAttributeList createAttributeList(BeanElement parent)
  {
    return new BeanAttributeList(parent, this);
  }
  
  public QName getQName(int index)
  {
    return qNames[index];
  }
  
  public int getIndex(String name)
  {
    Integer index = (Integer)nameMap.get(name);
    
    return index != null ? index.intValue() : -1;
  }
  
  public int getIndex(QName qName)
  {
    Integer index = (Integer)nameMap.get(qName);
    
    return index != null ? index.intValue() : -1;
  }
  
  public Object getData(int index, Object bean)
  {
    try
    {
      Method method = readMethods[index];
      
      return method.invoke(bean, NULL_ARGS);
    }
    catch (Exception e)
    {
      handleException(e);
    }
    return null;
  }
  
  public void setData(int index, Object bean, Object data)
  {
    try
    {
      Method method = writeMethods[index];
      Object[] args = { data };
      method.invoke(bean, args);
    }
    catch (Exception e)
    {
      handleException(e);
    }
  }
  
  protected void handleException(Exception e) {}
}

/* Location:
 * Qualified Name:     org.dom4j.bean.BeanMetaData
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j;

import java.util.Iterator;
import java.util.List;

public abstract interface Branch
  extends Node
{
  public abstract Node node(int paramInt)
    throws IndexOutOfBoundsException;
  
  public abstract int indexOf(Node paramNode);
  
  public abstract int nodeCount();
  
  public abstract Element elementByID(String paramString);
  
  public abstract List content();
  
  public abstract Iterator nodeIterator();
  
  public abstract void setContent(List paramList);
  
  public abstract void appendContent(Branch paramBranch);
  
  public abstract void clearContent();
  
  public abstract List processingInstructions();
  
  public abstract List processingInstructions(String paramString);
  
  public abstract ProcessingInstruction processingInstruction(String paramString);
  
  public abstract void setProcessingInstructions(List paramList);
  
  public abstract Element addElement(String paramString);
  
  public abstract Element addElement(QName paramQName);
  
  public abstract Element addElement(String paramString1, String paramString2);
  
  public abstract boolean removeProcessingInstruction(String paramString);
  
  public abstract void add(Node paramNode);
  
  public abstract void add(Comment paramComment);
  
  public abstract void add(Element paramElement);
  
  public abstract void add(ProcessingInstruction paramProcessingInstruction);
  
  public abstract boolean remove(Node paramNode);
  
  public abstract boolean remove(Comment paramComment);
  
  public abstract boolean remove(Element paramElement);
  
  public abstract boolean remove(ProcessingInstruction paramProcessingInstruction);
  
  public abstract void normalize();
}

/* Location:
 * Qualified Name:     org.dom4j.Branch
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j;

public abstract interface CDATA
  extends CharacterData
{}

/* Location:
 * Qualified Name:     org.dom4j.CDATA
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j;

public abstract interface CharacterData
  extends Node
{
  public abstract void appendText(String paramString);
}

/* Location:
 * Qualified Name:     org.dom4j.CharacterData
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j;

public abstract interface Comment
  extends CharacterData
{}

/* Location:
 * Qualified Name:     org.dom4j.Comment
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.DatabindableDatatype;
import com.sun.msv.datatype.SerializationContext;
import com.sun.msv.datatype.xsd.XSDatatype;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.AbstractAttribute;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.ValidationContext;

public class DatatypeAttribute
  extends AbstractAttribute
  implements SerializationContext, ValidationContext
{
  private Element parent;
  private QName qname;
  private XSDatatype datatype;
  private Object data;
  private String text;
  
  public DatatypeAttribute(QName qname, XSDatatype datatype)
  {
    this.qname = qname;
    this.datatype = datatype;
  }
  
  public DatatypeAttribute(QName qname, XSDatatype datatype, String text)
  {
    this.qname = qname;
    this.datatype = datatype;
    this.text = text;
    data = convertToValue(text);
  }
  
  public String toString()
  {
    return getClass().getName() + hashCode() + " [Attribute: name " + getQualifiedName() + " value \"" + getValue() + "\" data: " + getData() + "]";
  }
  
  public XSDatatype getXSDatatype()
  {
    return datatype;
  }
  
  public String getNamespacePrefix(String uri)
  {
    Element parentElement = getParent();
    if (parentElement != null)
    {
      Namespace namespace = parentElement.getNamespaceForURI(uri);
      if (namespace != null) {
        return namespace.getPrefix();
      }
    }
    return null;
  }
  
  public String getBaseUri()
  {
    return null;
  }
  
  public boolean isNotation(String notationName)
  {
    return false;
  }
  
  public boolean isUnparsedEntity(String entityName)
  {
    return true;
  }
  
  public String resolveNamespacePrefix(String prefix)
  {
    if (prefix.equals(getNamespacePrefix())) {
      return getNamespaceURI();
    }
    Element parentElement = getParent();
    if (parentElement != null)
    {
      Namespace namespace = parentElement.getNamespaceForPrefix(prefix);
      if (namespace != null) {
        return namespace.getURI();
      }
    }
    return null;
  }
  
  public QName getQName()
  {
    return qname;
  }
  
  public String getValue()
  {
    return text;
  }
  
  public void setValue(String value)
  {
    validate(value);
    
    text = value;
    data = convertToValue(value);
  }
  
  public Object getData()
  {
    return data;
  }
  
  public void setData(Object data)
  {
    String s = datatype.convertToLexicalValue(data, this);
    validate(s);
    text = s;
    this.data = data;
  }
  
  public Element getParent()
  {
    return parent;
  }
  
  public void setParent(Element parent)
  {
    this.parent = parent;
  }
  
  public boolean supportsParent()
  {
    return true;
  }
  
  public boolean isReadOnly()
  {
    return false;
  }
  
  protected void validate(String txt)
    throws IllegalArgumentException
  {
    try
    {
      datatype.checkValid(txt, this);
    }
    catch (DatatypeException e)
    {
      throw new IllegalArgumentException(e.getMessage());
    }
  }
  
  protected Object convertToValue(String txt)
  {
    if ((datatype instanceof DatabindableDatatype))
    {
      DatabindableDatatype bindable = datatype;
      
      return bindable.createJavaObject(txt, this);
    }
    return datatype.createValue(txt, this);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.DatatypeAttribute
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import java.io.PrintStream;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

public class DatatypeDocumentFactory
  extends DocumentFactory
{
  private static final boolean DO_INTERN_QNAME = false;
  protected static transient DatatypeDocumentFactory singleton = new DatatypeDocumentFactory();
  private static final Namespace XSI_NAMESPACE = Namespace.get("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  private static final QName XSI_SCHEMA_LOCATION = QName.get("schemaLocation", XSI_NAMESPACE);
  private static final QName XSI_NO_SCHEMA_LOCATION = QName.get("noNamespaceSchemaLocation", XSI_NAMESPACE);
  private SchemaParser schemaBuilder;
  private SAXReader xmlSchemaReader = new SAXReader();
  private boolean autoLoadSchema = true;
  
  public DatatypeDocumentFactory()
  {
    schemaBuilder = new SchemaParser(this);
  }
  
  public static DocumentFactory getInstance()
  {
    return singleton;
  }
  
  public void loadSchema(Document schemaDocument)
  {
    schemaBuilder.build(schemaDocument);
  }
  
  public void loadSchema(Document schemaDocument, Namespace targetNamespace)
  {
    schemaBuilder.build(schemaDocument, targetNamespace);
  }
  
  public DatatypeElementFactory getElementFactory(QName elementQName)
  {
    DatatypeElementFactory result = null;
    
    DocumentFactory factory = elementQName.getDocumentFactory();
    if ((factory instanceof DatatypeElementFactory)) {
      result = (DatatypeElementFactory)factory;
    }
    return result;
  }
  
  public Attribute createAttribute(Element owner, QName qname, String value)
  {
    if ((autoLoadSchema) && (qname.equals(XSI_NO_SCHEMA_LOCATION)))
    {
      Document document = owner != null ? owner.getDocument() : null;
      loadSchema(document, value);
    }
    else if ((autoLoadSchema) && (qname.equals(XSI_SCHEMA_LOCATION)))
    {
      Document document = owner != null ? owner.getDocument() : null;
      String uri = value.substring(0, value.indexOf(' '));
      Namespace namespace = owner.getNamespaceForURI(uri);
      loadSchema(document, value.substring(value.indexOf(' ') + 1), namespace);
    }
    return super.createAttribute(owner, qname, value);
  }
  
  protected void loadSchema(Document document, String schemaInstanceURI)
  {
    try
    {
      EntityResolver resolver = document.getEntityResolver();
      if (resolver == null)
      {
        String msg = "No EntityResolver available for resolving URI: ";
        throw new InvalidSchemaException(msg + schemaInstanceURI);
      }
      InputSource inputSource = resolver.resolveEntity(null, schemaInstanceURI);
      if (resolver == null) {
        throw new InvalidSchemaException("Could not resolve the URI: " + schemaInstanceURI);
      }
      Document schemaDocument = xmlSchemaReader.read(inputSource);
      loadSchema(schemaDocument);
    }
    catch (Exception e)
    {
      System.out.println("Failed to load schema: " + schemaInstanceURI);
      System.out.println("Caught: " + e);
      e.printStackTrace();
      throw new InvalidSchemaException("Failed to load schema: " + schemaInstanceURI);
    }
  }
  
  protected void loadSchema(Document document, String schemaInstanceURI, Namespace namespace)
  {
    try
    {
      EntityResolver resolver = document.getEntityResolver();
      if (resolver == null)
      {
        String msg = "No EntityResolver available for resolving URI: ";
        throw new InvalidSchemaException(msg + schemaInstanceURI);
      }
      InputSource inputSource = resolver.resolveEntity(null, schemaInstanceURI);
      if (resolver == null) {
        throw new InvalidSchemaException("Could not resolve the URI: " + schemaInstanceURI);
      }
      Document schemaDocument = xmlSchemaReader.read(inputSource);
      loadSchema(schemaDocument, namespace);
    }
    catch (Exception e)
    {
      System.out.println("Failed to load schema: " + schemaInstanceURI);
      System.out.println("Caught: " + e);
      e.printStackTrace();
      throw new InvalidSchemaException("Failed to load schema: " + schemaInstanceURI);
    }
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.DatatypeDocumentFactory
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.DatabindableDatatype;
import com.sun.msv.datatype.SerializationContext;
import com.sun.msv.datatype.xsd.XSDatatype;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.QName;
import org.dom4j.tree.DefaultElement;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.ValidationContext;

public class DatatypeElement
  extends DefaultElement
  implements SerializationContext, ValidationContext
{
  private XSDatatype datatype;
  private Object data;
  
  public DatatypeElement(QName qname, XSDatatype datatype)
  {
    super(qname);
    this.datatype = datatype;
  }
  
  public DatatypeElement(QName qname, int attributeCount, XSDatatype type)
  {
    super(qname, attributeCount);
    datatype = type;
  }
  
  public String toString()
  {
    return getClass().getName() + hashCode() + " [Element: <" + getQualifiedName() + " attributes: " + attributeList() + " data: " + getData() + " />]";
  }
  
  public XSDatatype getXSDatatype()
  {
    return datatype;
  }
  
  public String getNamespacePrefix(String uri)
  {
    Namespace namespace = getNamespaceForURI(uri);
    
    return namespace != null ? namespace.getPrefix() : null;
  }
  
  public String getBaseUri()
  {
    return null;
  }
  
  public boolean isNotation(String notationName)
  {
    return false;
  }
  
  public boolean isUnparsedEntity(String entityName)
  {
    return true;
  }
  
  public String resolveNamespacePrefix(String prefix)
  {
    Namespace namespace = getNamespaceForPrefix(prefix);
    if (namespace != null) {
      return namespace.getURI();
    }
    return null;
  }
  
  public Object getData()
  {
    if (data == null)
    {
      String text = getTextTrim();
      if ((text != null) && (text.length() > 0)) {
        if ((datatype instanceof DatabindableDatatype))
        {
          DatabindableDatatype bind = datatype;
          data = bind.createJavaObject(text, this);
        }
        else
        {
          data = datatype.createValue(text, this);
        }
      }
    }
    return data;
  }
  
  public void setData(Object data)
  {
    String s = datatype.convertToLexicalValue(data, this);
    validate(s);
    this.data = data;
    setText(s);
  }
  
  public Element addText(String text)
  {
    validate(text);
    
    return super.addText(text);
  }
  
  public void setText(String text)
  {
    validate(text);
    super.setText(text);
  }
  
  protected void childAdded(Node node)
  {
    data = null;
    super.childAdded(node);
  }
  
  protected void childRemoved(Node node)
  {
    data = null;
    super.childRemoved(node);
  }
  
  protected void validate(String text)
    throws IllegalArgumentException
  {
    try
    {
      datatype.checkValid(text, this);
    }
    catch (DatatypeException e)
    {
      throw new IllegalArgumentException(e.getMessage());
    }
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.DatatypeElement
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.xsd.XSDatatype;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.Attribute;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;

public class DatatypeElementFactory
  extends DocumentFactory
{
  private QName elementQName;
  private Map attributeXSDatatypes = new HashMap();
  private Map childrenXSDatatypes = new HashMap();
  
  public DatatypeElementFactory(QName elementQName)
  {
    this.elementQName = elementQName;
  }
  
  public QName getQName()
  {
    return elementQName;
  }
  
  public XSDatatype getAttributeXSDatatype(QName attributeQName)
  {
    return (XSDatatype)attributeXSDatatypes.get(attributeQName);
  }
  
  public void setAttributeXSDatatype(QName attributeQName, XSDatatype type)
  {
    attributeXSDatatypes.put(attributeQName, type);
  }
  
  public XSDatatype getChildElementXSDatatype(QName qname)
  {
    return (XSDatatype)childrenXSDatatypes.get(qname);
  }
  
  public void setChildElementXSDatatype(QName qname, XSDatatype dataType)
  {
    childrenXSDatatypes.put(qname, dataType);
  }
  
  public Element createElement(QName qname)
  {
    XSDatatype dataType = getChildElementXSDatatype(qname);
    if (dataType != null) {
      return new DatatypeElement(qname, dataType);
    }
    DocumentFactory factory = qname.getDocumentFactory();
    if ((factory instanceof DatatypeElementFactory))
    {
      DatatypeElementFactory dtFactory = (DatatypeElementFactory)factory;
      dataType = dtFactory.getChildElementXSDatatype(qname);
      if (dataType != null) {
        return new DatatypeElement(qname, dataType);
      }
    }
    return super.createElement(qname);
  }
  
  public Attribute createAttribute(Element owner, QName qname, String value)
  {
    XSDatatype dataType = getAttributeXSDatatype(qname);
    if (dataType == null) {
      return super.createAttribute(owner, qname, value);
    }
    return new DatatypeAttribute(qname, dataType, value);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.DatatypeElementFactory
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

public class InvalidSchemaException
  extends IllegalArgumentException
{
  public InvalidSchemaException(String reason)
  {
    super(reason);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.InvalidSchemaException
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.xsd.XSDatatype;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;

class NamedTypeResolver
{
  protected Map complexTypeMap = new HashMap();
  protected Map simpleTypeMap = new HashMap();
  protected Map typedElementMap = new HashMap();
  protected Map elementFactoryMap = new HashMap();
  protected DocumentFactory documentFactory;
  
  NamedTypeResolver(DocumentFactory documentFactory)
  {
    this.documentFactory = documentFactory;
  }
  
  void registerComplexType(QName type, DocumentFactory factory)
  {
    complexTypeMap.put(type, factory);
  }
  
  void registerSimpleType(QName type, XSDatatype datatype)
  {
    simpleTypeMap.put(type, datatype);
  }
  
  void registerTypedElement(Element element, QName type, DocumentFactory parentFactory)
  {
    typedElementMap.put(element, type);
    elementFactoryMap.put(element, parentFactory);
  }
  
  void resolveElementTypes()
  {
    Iterator iterator = typedElementMap.keySet().iterator();
    while (iterator.hasNext())
    {
      Element element = (Element)iterator.next();
      QName elementQName = getQNameOfSchemaElement(element);
      QName type = (QName)typedElementMap.get(element);
      if (complexTypeMap.containsKey(type))
      {
        DocumentFactory factory = (DocumentFactory)complexTypeMap.get(type);
        
        elementQName.setDocumentFactory(factory);
      }
      else if (simpleTypeMap.containsKey(type))
      {
        XSDatatype datatype = (XSDatatype)simpleTypeMap.get(type);
        DocumentFactory factory = (DocumentFactory)elementFactoryMap.get(element);
        if ((factory instanceof DatatypeElementFactory)) {
          ((DatatypeElementFactory)factory).setChildElementXSDatatype(elementQName, datatype);
        }
      }
    }
  }
  
  void resolveNamedTypes()
  {
    resolveElementTypes();
  }
  
  private QName getQNameOfSchemaElement(Element element)
  {
    String name = element.attributeValue("name");
    
    return getQName(name);
  }
  
  private QName getQName(String name)
  {
    return documentFactory.createQName(name);
  }
}

/* Location:
 * Qualified Name:     org.dom4j.datatype.NamedTypeResolver
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.xsd.DatatypeFactory;
import com.sun.msv.datatype.xsd.TypeIncubator;
import com.sun.msv.datatype.xsd.XSDatatype;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;
import org.dom4j.util.AttributeHelper;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.ValidationContext;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

public class SchemaParser
{
  private static final Namespace XSD_NAMESPACE = Namespace.get("xsd", "http://www.w3.org/2001/XMLSchema");
  private static final QName XSD_ELEMENT = QName.get("element", XSD_NAMESPACE);
  private static final QName XSD_ATTRIBUTE = QName.get("attribute", XSD_NAMESPACE);
  private static final QName XSD_SIMPLETYPE = QName.get("simpleType", XSD_NAMESPACE);
  private static final QName XSD_COMPLEXTYPE = QName.get("complexType", XSD_NAMESPACE);
  private static final QName XSD_RESTRICTION = QName.get("restriction", XSD_NAMESPACE);
  private static final QName XSD_SEQUENCE = QName.get("sequence", XSD_NAMESPACE);
  private static final QName XSD_CHOICE = QName.get("choice", XSD_NAMESPACE);
  private static final QName XSD_ALL = QName.get("all", XSD_NAMESPACE);
  private static final QName XSD_INCLUDE = QName.get("include", XSD_NAMESPACE);
  private DatatypeDocumentFactory documentFactory;
  private Map dataTypeCache = new HashMap();
  private NamedTypeResolver namedTypeResolver;
  private Namespace targetNamespace;
  
  public SchemaParser()
  {
    this(DatatypeDocumentFactory.singleton);
  }
  
  public SchemaParser(DatatypeDocumentFactory documentFactory)
  {
    this.documentFactory = documentFactory;
    namedTypeResolver = new NamedTypeResolver(documentFactory);
  }
  
  public void build(Document schemaDocument)
  {
    targetNamespace = null;
    internalBuild(schemaDocument);
  }
  
  public void build(Document schemaDocument, Namespace namespace)
  {
    targetNamespace = namespace;
    internalBuild(schemaDocument);
  }
  
  private synchronized void internalBuild(Document schemaDocument)
  {
    Element root = schemaDocument.getRootElement();
    if (root != null)
    {
      Iterator includeIter = root.elementIterator(XSD_INCLUDE);
      while (includeIter.hasNext())
      {
        Element includeElement = (Element)includeIter.next();
        String inclSchemaInstanceURI = includeElement.attributeValue("schemaLocation");
        
        EntityResolver resolver = schemaDocument.getEntityResolver();
        try
        {
          if (resolver == null)
          {
            String msg = "No EntityResolver available";
            throw new InvalidSchemaException(msg);
          }
          InputSource inputSource = resolver.resolveEntity(null, inclSchemaInstanceURI);
          if (inputSource == null)
          {
            String msg = "Could not resolve the schema URI: " + inclSchemaInstanceURI;
            
            throw new InvalidSchemaException(msg);
          }
          SAXReader reader = new SAXReader();
          Document inclSchemaDocument = reader.read(inputSource);
          build(inclSchemaDocument);
        }
        catch (Exception e)
        {
          System.out.println("Failed to load schema: " + inclSchemaInstanceURI);
          
          System.out.println("Caught: " + e);
          e.printStackTrace();
          throw new InvalidSchemaException("Failed to load schema: " + inclSchemaInstanceURI);
        }
      }
      Iterator iter = root.elementIterator(XSD_ELEMENT);
      while (iter.hasNext()) {
        onDatatypeElement((Element)iter.next(), documentFactory);
      }
      iter = root.elementIterator(XSD_SIMPLETYPE);
      while (iter.hasNext()) {
        onNamedSchemaSimpleType((Element)iter.next());
      }
      iter = root.elementIterator(XSD_COMPLEXTYPE);
      while (iter.hasNext()) {
        onNamedSchemaComplexType((Element)iter.next());
      }
      namedTypeResolver.resolveNamedTypes();
    }
  }
  
  private void onDatatypeElement(Element xsdElement, DocumentFactory parentFactory)
  {
    String name = xsdElement.attributeValue("name");
    String type = xsdElement.attributeValue("type");
    QName qname = getQName(name);
    
    DatatypeElementFactory factory = getDatatypeElementFactory(qname);
    if (type != null)
    {
      XSDatatype dataType = getTypeByName(type);
      if (dataType != null)
      {
        factory.setChildElementXSDatatype(qname, dataType);
      }
      else
      {
        QName typeQName = getQName(type);
        namedTypeResolver.registerTypedElement(xsdElement, typeQName, parentFactory);
      }
      return;
    }
    Element xsdSimpleType = xsdElement.element(XSD_SIMPLETYPE);
    if (xsdSimpleType != null)
    {
      XSDatatype dataType = loadXSDatatypeFromSimpleType(xsdSimpleType);
      if (dataType != null) {
        factory.setChildElementXSDatatype(qname, dataType);
      }
    }
    Element schemaComplexType = xsdElement.element(XSD_COMPLEXTYPE);
    if (schemaComplexType != null) {
      onSchemaComplexType(schemaComplexType, factory);
    }
    Iterator iter = xsdElement.elementIterator(XSD_ATTRIBUTE);
    if (iter.hasNext()) {
      do
      {
        onDatatypeAttribute(xsdElement, factory, (Element)iter.next());
      } while (iter.hasNext());
    }
  }
  
  private void onNamedSchemaComplexType(Element schemaComplexType)
  {
    Attribute nameAttr = schemaComplexType.attribute("name");
    if (nameAttr == null) {
      return;
    }
    String name = nameAttr.getText();
    QName qname = getQName(name);
    
    DatatypeElementFactory factory = getDatatypeElementFactory(qname);
    
    onSchemaComplexType(schemaComplexType, factory);
    namedTypeResolver.registerComplexType(qname, factory);
  }
  
  private void onSchemaComplexType(Element schemaComplexType, DatatypeElementFactory elementFactory)
  {
    Iterator iter = schemaComplexType.elementIterator(XSD_ATTRIBUTE);
    while (iter.hasNext())
    {
      Element xsdAttribute = (Element)iter.next();
      String name = xsdAttribute.attributeValue("name");
      QName qname = getQName(name);
      
      XSDatatype dataType = dataTypeForXsdAttribute(xsdAttribute);
      if (dataType != null) {
        elementFactory.setAttributeXSDatatype(qname, dataType);
      }
    }
    Element schemaSequence = schemaComplexType.element(XSD_SEQUENCE);
    if (schemaSequence != null) {
      onChildElements(schemaSequence, elementFactory);
    }
    Element schemaChoice = schemaComplexType.element(XSD_CHOICE);
    if (schemaChoice != null) {
      onChildElements(schemaChoice, elementFactory);
    }
    Element schemaAll = schemaComplexType.element(XSD_ALL);
    if (schemaAll != null) {
      onChildElements(schemaAll, elementFactory);
    }
  }
  
  private void onChildElements(Element element, DatatypeElementFactory fact)
  {
    Iterator iter = element.elementIterator(XSD_ELEMENT);
    while (iter.hasNext())
    {
      Element xsdElement = (Element)iter.next();
      onDatatypeElement(xsdElement, fact);
    }
  }
  
  private void onDatatypeAttribute(Element xsdElement, DatatypeElementFactory elementFactory, Element xsdAttribute)
  {
    String name = xsdAttribute.attributeValue("name");
    QName qname = getQName(name);
    XSDatatype dataType = dataTypeForXsdAttribute(xsdAttribute);
    if (dataType != null)
    {
      elementFactory.setAttributeXSDatatype(qname, dataType);
    }
    else
    {
      String type = xsdAttribute.attributeValue("type");
      System.out.println("Warning: Couldn't find XSDatatype for type: " + type + " attribute: " + name);
    }
  }
  
  private XSDatatype dataTypeForXsdAttribute(Element xsdAttribute)
  {
    String type = xsdAttribute.attributeValue("type");
    XSDatatype dataType = null;
    if (type != null)
    {
      dataType = getTypeByName(type);
    }
    else
    {
      Element xsdSimpleType = xsdAttribute.element(XSD_SIMPLETYPE);
      if (xsdSimpleType == null)
      {
        String name = xsdAttribute.attributeValue("name");
        String msg = "The attribute: " + name + " has no type attribute and does not contain a " + "<simpleType/> element";
        
        throw new Invali
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