org.eclipse.pde.core_3.7.1.v20120103_r372

eclipse.pde.internal.core.schema.SchemaAttributeHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import java.util.Vector;
import org.eclipse.pde.core.ModelChangedEvent;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;

public class SchemaComplexType
  extends SchemaType
  implements ISchemaComplexType
{
  private static final long serialVersionUID = 1L;
  public static final String P_COMPOSITOR = "compositorProperty";
  private boolean mixed;
  private ISchemaCompositor compositor;
  private Vector attributes = new Vector();
  
  public SchemaComplexType(ISchema schema)
  {
    this(schema, null);
  }
  
  public SchemaComplexType(ISchema schema, String typeName)
  {
    super(schema, typeName != null ? typeName : "__anonymous__");
  }
  
  public void addAttribute(ISchemaAttribute attribute)
  {
    addAttribute(attribute, null);
  }
  
  public void addAttribute(ISchemaAttribute attribute, ISchemaAttribute afterSibling)
  {
    int index = -1;
    if (afterSibling != null) {
      index = attributes.indexOf(afterSibling);
    }
    if (index != -1) {
      attributes.add(index + 1, attribute);
    } else {
      attributes.addElement(attribute);
    }
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 1, new Object[] { attribute }, null));
  }
  
  public void moveAttributeTo(ISchemaAttribute attribute, ISchemaAttribute sibling)
  {
    int index = attributes.indexOf(attribute);
    int newIndex;
    int newIndex;
    if ((sibling != null) && (attributes.contains(sibling))) {
      newIndex = attributes.indexOf(sibling);
    } else {
      newIndex = attributes.size() - 1;
    }
    if (index > newIndex) {
      for (int i = index; i > newIndex; i--) {
        attributes.set(i, attributes.elementAt(i - 1));
      }
    } else if (index < newIndex) {
      for (int i = index; i < newIndex; i++) {
        attributes.set(i, attributes.elementAt(i + 1));
      }
    } else {
      return;
    }
    attributes.set(newIndex, attribute);
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 3, new Object[] { attribute.getParent() }, null));
  }
  
  public ISchemaAttribute getAttribute(String name)
  {
    for (int i = 0; i < attributes.size(); i++)
    {
      ISchemaAttribute attribute = (ISchemaAttribute)attributes.elementAt(i);
      if (attribute.getName().equals(name)) {
        return attribute;
      }
    }
    return null;
  }
  
  public int getAttributeCount()
  {
    return attributes.size();
  }
  
  public ISchemaAttribute[] getAttributes()
  {
    ISchemaAttribute[] result = new ISchemaAttribute[attributes.size()];
    attributes.copyInto(result);
    return result;
  }
  
  public ISchemaCompositor getCompositor()
  {
    return compositor;
  }
  
  public boolean isMixed()
  {
    return mixed;
  }
  
  public void removeAttribute(ISchemaAttribute attribute)
  {
    attributes.removeElement(attribute);
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 2, new Object[] { attribute }, null));
  }
  
  public void setCompositor(ISchemaCompositor newCompositor)
  {
    Object oldValue = compositor;
    compositor = newCompositor;
    getSchema().fireModelObjectChanged(this, "compositorProperty", oldValue, compositor);
  }
  
  public void setMixed(boolean newMixed)
  {
    mixed = newMixed;
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.println(indent + "<complexType>");
    String indent2 = indent + "   ";
    SchemaCompositor compositor = (SchemaCompositor)getCompositor();
    if (compositor != null) {
      compositor.write(indent2, writer);
    }
    for (int i = 0; i < attributes.size(); i++)
    {
      ISchemaAttribute attribute = (ISchemaAttribute)attributes.elementAt(i);
      attribute.write(indent2, writer);
    }
    writer.println(indent + "</complexType>");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaComplexType
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import java.util.Vector;
import org.eclipse.pde.core.IWritable;
import org.eclipse.pde.core.ModelChangedEvent;
import org.eclipse.pde.internal.core.PDECoreMessages;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;

public class SchemaCompositor
  extends RepeatableSchemaObject
  implements ISchemaCompositor
{
  private static final long serialVersionUID = 1L;
  public static final String P_KIND = "p_kind";
  private int kind;
  private Vector children = new Vector();
  
  public SchemaCompositor(ISchemaObject parent, int kind)
  {
    super(parent, "");
    this.kind = kind;
    switch (kind)
    {
    case 0: 
      fName = PDECoreMessages.SchemaCompositor_all;
      break;
    case 1: 
      fName = PDECoreMessages.SchemaCompositor_choice;
      break;
    case 3: 
      fName = PDECoreMessages.SchemaCompositor_group;
      break;
    case 2: 
      fName = PDECoreMessages.SchemaCompositor_sequence;
    }
  }
  
  public SchemaCompositor(ISchemaObject parent, String id, int kind)
  {
    super(parent, id);
    this.kind = kind;
  }
  
  public void addChild(ISchemaObject child)
  {
    children.addElement(child);
    child.setParent(this);
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 1, new Object[] { child }, null));
  }
  
  public void moveChildToSibling(ISchemaObject element, ISchemaObject sibling)
  {
    int index = children.indexOf(element);
    int newIndex;
    int newIndex;
    if ((sibling != null) && (children.contains(sibling))) {
      newIndex = children.indexOf(sibling);
    } else {
      newIndex = children.size() - 1;
    }
    if (index > newIndex) {
      for (int i = index; i > newIndex; i--) {
        children.set(i, children.elementAt(i - 1));
      }
    } else if (index < newIndex) {
      for (int i = index; i < newIndex; i++) {
        children.set(i, children.elementAt(i + 1));
      }
    } else {
      return;
    }
    children.set(newIndex, element);
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 3, new Object[] { this }, null));
  }
  
  public void addChild(ISchemaObject newChild, ISchemaObject afterSibling)
  {
    int index = -1;
    if (afterSibling != null) {
      index = children.indexOf(afterSibling);
    }
    if (index != -1) {
      children.add(index + 1, newChild);
    } else {
      children.addElement(newChild);
    }
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 1, new Object[] { newChild }, null));
  }
  
  public int getChildCount()
  {
    return children.size();
  }
  
  public ISchemaObject[] getChildren()
  {
    ISchemaObject[] result = new ISchemaObject[children.size()];
    children.copyInto(result);
    return result;
  }
  
  public void setParent(ISchemaObject parent)
  {
    super.setParent(parent);
    for (int i = 0; i < children.size(); i++)
    {
      ISchemaObject child = (ISchemaObject)children.get(i);
      child.setParent(this);
    }
  }
  
  public int getKind()
  {
    return kind;
  }
  
  public void removeChild(ISchemaObject child)
  {
    children.removeElement(child);
    getSchema().fireModelChanged(new ModelChangedEvent(getSchema(), 2, new Object[] { child }, null));
  }
  
  public void setKind(int kind)
  {
    if (this.kind != kind)
    {
      Integer oldValue = new Integer(this.kind);
      this.kind = kind;
      switch (kind)
      {
      case 0: 
        fName = PDECoreMessages.SchemaCompositor_all;
        break;
      case 1: 
        fName = PDECoreMessages.SchemaCompositor_choice;
        break;
      case 3: 
        fName = PDECoreMessages.SchemaCompositor_group;
        break;
      case 2: 
        fName = PDECoreMessages.SchemaCompositor_sequence;
      }
      getSchema().fireModelObjectChanged(this, "p_kind", oldValue, new Integer(kind));
    }
  }
  
  public void updateReferencesFor(ISchemaElement element, int kind)
  {
    for (int i = children.size() - 1; i >= 0; i--)
    {
      Object child = children.elementAt(i);
      if ((child instanceof SchemaElementReference))
      {
        SchemaElementReference ref = (SchemaElementReference)child;
        String refName = ref.getReferenceName();
        switch (kind)
        {
        case 1: 
          if (!element.getName().equals(refName)) {
            continue;
          }
          ref.setReferencedObject(element);
          getSchema().fireModelObjectChanged(ref, null, null, null);
          
          break;
        case 2: 
          if (!element.getName().equals(refName)) {
            continue;
          }
          removeChild(ref);
          getSchema().fireModelObjectChanged(this, null, ref, null);
          
          break;
        case 3: 
          if (ref.getReferencedElement() == element)
          {
            ref.setReferenceName(element.getName());
          }
          else if (element.getName().equals(refName))
          {
            ref.setReferencedObject(element);
            getSchema().fireModelObjectChanged(ref, null, null, null);
          }
          break;
        }
      }
      else
      {
        SchemaCompositor compositor = (SchemaCompositor)child;
        compositor.updateReferencesFor(element, kind);
      }
    }
  }
  
  public void write(String indent, PrintWriter writer)
  {
    String tag = null;
    switch (kind)
    {
    case 1: 
      tag = "choice";
      break;
    case 0: 
    case 2: 
    case 3: 
      tag = "sequence";
    }
    if (tag == null) {
      return;
    }
    writer.print(indent + "<" + tag);
    if ((getMinOccurs() != 1) || (getMaxOccurs() != 1))
    {
      String min = getMinOccurs();
      String max = 
        getMaxOccurs();
      writer.print(" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\"");
    }
    writer.println(">");
    String indent2 = indent + "   ";
    for (int i = 0; i < children.size(); i++)
    {
      Object obj = children.elementAt(i);
      if ((obj instanceof IWritable)) {
        ((IWritable)obj).write(indent2, writer);
      }
    }
    writer.println(indent + "</" + tag + ">");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaCompositor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;

public class SchemaDescriptor
  implements ISchemaDescriptor
{
  private String fPoint;
  private URL fSchemaURL;
  private Schema fSchema;
  private long fLastModified;
  private boolean fEditable;
  
  public SchemaDescriptor(String extPointID, URL schemaURL)
  {
    fPoint = extPointID;
    fSchemaURL = schemaURL;
    if (fSchemaURL != null)
    {
      File file = new File(fSchemaURL.getFile());
      if (file.exists()) {
        fLastModified = file.lastModified();
      }
    }
  }
  
  public SchemaDescriptor(IFile file, boolean editable)
  {
    this(new File(file.getLocation().toOSString()));
    fEditable = editable;
  }
  
  public SchemaDescriptor(File file)
  {
    try
    {
      if (file.exists())
      {
        fSchemaURL = file.toURL();
        fLastModified = file.lastModified();
      }
    }
    catch (MalformedURLException localMalformedURLException) {}
  }
  
  public String getPointId()
  {
    if (fPoint != null) {
      return fPoint;
    }
    return fSchema == null ? null : fSchema.getQualifiedPointId();
  }
  
  public ISchema getSchema(boolean abbreviated)
  {
    if ((fSchema == null) && (fSchemaURL != null))
    {
      if (fEditable) {
        fSchema = new EditableSchema(this, fSchemaURL, abbreviated);
      } else {
        fSchema = new Schema(this, fSchemaURL, abbreviated);
      }
      fSchema.load();
    }
    return fSchema;
  }
  
  public URL getSchemaURL()
  {
    return fSchemaURL;
  }
  
  public boolean isStandalone()
  {
    return true;
  }
  
  public long getLastModified()
  {
    return fLastModified;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import java.net.URL;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.ischema.ISchemaRepeatable;
import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
import org.eclipse.pde.internal.core.ischema.ISchemaType;
import org.eclipse.pde.internal.core.util.SchemaUtil;
import org.eclipse.pde.internal.core.util.XMLComponentRegistry;

public class SchemaElement
  extends RepeatableSchemaObject
  implements ISchemaElement
{
  private static final long serialVersionUID = 1L;
  public static final String P_ICON_NAME = "iconName";
  public static final String P_LABEL_PROPERTY = "labelProperty";
  public static final String P_TYPE = "type";
  private String labelProperty;
  private ISchemaType type;
  private String iconName;
  private boolean fTranslatable;
  private boolean fDeprecated;
  
  public SchemaElement(ISchemaObject parent, String name)
  {
    super(parent, name);
  }
  
  private String calculateChildRepresentation(ISchemaObject object, boolean addLinks)
  {
    String child = "";
    if ((object instanceof ISchemaCompositor))
    {
      child = calculateCompositorRepresentation((ISchemaCompositor)object, addLinks);
      if ((!child.equals("EMPTY")) && (child.length() > 0)) {
        child = "(" + child + ")";
      }
    }
    else
    {
      child = object.getName();
      if (addLinks) {
        child = "<a href=\"#e." + child + "\">" + child + "</a>";
      }
    }
    int minOccurs = 1;
    int maxOccurs = 1;
    if ((object instanceof ISchemaRepeatable))
    {
      minOccurs = ((ISchemaRepeatable)object).getMinOccurs();
      maxOccurs = ((ISchemaRepeatable)object).getMaxOccurs();
    }
    if (minOccurs == 0)
    {
      if (maxOccurs == 1) {
        child = child + "?";
      } else {
        child = child + "*";
      }
    }
    else if ((minOccurs == 1) && 
      (maxOccurs > 1)) {
      child = child + "+";
    }
    return child;
  }
  
  private String calculateCompositorRepresentation(ISchemaCompositor compositor, boolean addLinks)
  {
    int kind = compositor.getKind();
    ISchemaObject[] children = compositor.getChildren();
    if (children.length == 0) {
      return "EMPTY";
    }
    String text = kind == 3 ? "(" : "";
    for (int i = 0; i < children.length; i++)
    {
      ISchemaObject object = children[i];
      String child = calculateChildRepresentation(object, addLinks);
      
      text = text + child;
      if (i < children.length - 1) {
        if (kind == 2) {
          text = text + " , ";
        } else if (kind == 1) {
          text = text + " | ";
        }
      }
    }
    if (kind == 3) {
      text = text + ")";
    }
    return text;
  }
  
  public ISchemaAttribute getAttribute(String name)
  {
    if ((type != null) && ((type instanceof ISchemaComplexType))) {
      return ((ISchemaComplexType)type).getAttribute(name);
    }
    return null;
  }
  
  public int getAttributeCount()
  {
    if ((type != null) && ((type instanceof ISchemaComplexType))) {
      return ((ISchemaComplexType)type).getAttributeCount();
    }
    return 0;
  }
  
  public ISchemaAttribute[] getAttributes()
  {
    if ((type != null) && ((type instanceof ISchemaComplexType))) {
      return ((ISchemaComplexType)type).getAttributes();
    }
    return new ISchemaAttribute[0];
  }
  
  public String[] getAttributeNames()
  {
    ISchemaAttribute[] attributes = getAttributes();
    String[] names = new String[attributes.length];
    for (int i = 0; i < attributes.length; i++) {
      names[i] = attributes[i].getName();
    }
    return names;
  }
  
  public String getDTDRepresentation(boolean addLinks)
  {
    String text = "";
    if (type == null)
    {
      text = text + "EMPTY";
    }
    else
    {
      if ((type instanceof ISchemaComplexType))
      {
        ISchemaComplexType complexType = (ISchemaComplexType)type;
        ISchemaCompositor compositor = complexType.getCompositor();
        if (compositor != null) {
          text = text + calculateChildRepresentation(compositor, addLinks);
        } else if (getAttributeCount() != 0) {
          text = text + "EMPTY";
        }
      }
      if (text.length() == 0) {
        text = text + "(#PCDATA)";
      }
    }
    if ((text.length() > 0) && 
      (!text.equals("EMPTY")) && (text.charAt(0) != '(')) {
      text = "(" + text + ")";
    }
    return text;
  }
  
  public String getIconProperty()
  {
    if (iconName != null) {
      return iconName;
    }
    ISchemaAttribute[] attributes = getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      if (isValidIconProperty(attributes[i])) {
        return attributes[i].getName();
      }
    }
    return null;
  }
  
  public String getLabelProperty()
  {
    if (labelProperty != null) {
      return labelProperty;
    }
    ISchemaAttribute[] attributes = getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      if (isValidLabelProperty(attributes[i])) {
        return attributes[i].getName();
      }
    }
    return null;
  }
  
  private boolean isValidLabelProperty(ISchemaAttribute a)
  {
    return (a.getKind() == 0) && (a.getType().getName().equals(ISchemaAttribute.TYPES[1])) && (a.isTranslatable());
  }
  
  private boolean isValidIconProperty(ISchemaAttribute a)
  {
    return a.getKind() == 2;
  }
  
  public ISchemaType getType()
  {
    return type;
  }
  
  public void setParent(ISchemaObject parent)
  {
    super.setParent(parent);
    if (type != null)
    {
      type.setSchema(getSchema());
      if ((type instanceof ISchemaComplexType))
      {
        ISchemaComplexType ctype = (ISchemaComplexType)type;
        ISchemaCompositor comp = ctype.getCompositor();
        if (comp != null) {
          comp.setParent(this);
        }
      }
    }
    if (getAttributeCount() > 0)
    {
      ISchemaAttribute[] atts = getAttributes();
      for (int i = 0; i < atts.length; i++)
      {
        ISchemaAttribute att = atts[i];
        att.setParent(this);
      }
    }
  }
  
  public void setIconProperty(String newIconName)
  {
    String oldValue = iconName;
    iconName = newIconName;
    getSchema().fireModelObjectChanged(this, "iconName", oldValue, iconName);
  }
  
  public void setTranslatableProperty(boolean translatable)
  {
    boolean oldValue = fTranslatable;
    fTranslatable = translatable;
    getSchema().fireModelObjectChanged(this, "translatable", Boolean.valueOf(oldValue), Boolean.valueOf(translatable));
  }
  
  public void setDeprecatedProperty(boolean deprecated)
  {
    boolean oldValue = fDeprecated;
    fDeprecated = deprecated;
    getSchema().fireModelObjectChanged(this, "deprecated", Boolean.valueOf(oldValue), Boolean.valueOf(deprecated));
  }
  
  public void setLabelProperty(String labelProperty)
  {
    String oldValue = this.labelProperty;
    this.labelProperty = labelProperty;
    getSchema().fireModelObjectChanged(this, "labelProperty", oldValue, labelProperty);
  }
  
  public void setType(ISchemaType newType)
  {
    Object oldValue = type;
    type = newType;
    getSchema().fireModelObjectChanged(this, "type", oldValue, type);
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.print(indent + "<element name=\"" + getName() + "\"");
    ISchemaType type = getType();
    if ((type instanceof SchemaSimpleType)) {
      writer.print(" type=\"" + type.getName() + "\"");
    }
    writer.println(">");
    String indent2 = indent + "   ";
    String realDescription = getWritableDescription();
    if (realDescription.length() == 0) {
      realDescription = null;
    }
    String extendedProperties = getExtendedAttributes();
    if ((realDescription != null) || (iconName != null) || (labelProperty != null) || (extendedProperties != null) || (isDeprecated()) || (hasTranslatableContent()))
    {
      String indent3 = indent2 + "   ";
      String indent4 = indent3 + "   ";
      writer.println(indent2 + "<annotation>");
      if ((iconName != null) || (labelProperty != null) || (extendedProperties != null) || (isDeprecated()) || (hasTranslatableContent()))
      {
        writer.println(indent3 + (getSchema().getSchemaVersion() >= 3.4D ? "<appinfo>" : "<appInfo>"));
        writer.print(indent4 + "<meta.element");
        if (labelProperty != null) {
          writer.print(" labelAttribute=\"" + labelProperty + "\"");
        }
        if (iconName != null) {
          writer.print(" icon=\"" + iconName + "\"");
        }
        if (hasTranslatableContent()) {
          writer.print(" translatable=\"true\"");
        }
        if (isDeprecated()) {
          writer.print(" deprecated=\"true\"");
        }
        if (extendedProperties != null) {
          writer.print(extendedProperties);
        }
        writer.println("/>");
        writer.println(indent3 + (getSchema().getSchemaVersion() >= 3.4D ? "</appinfo>" : "</appInfo>"));
      }
      if (realDescription != null)
      {
        writer.println(indent3 + "<documentation>");
        if (getDescription() != null) {
          writer.println(indent4 + realDescription);
        }
        writer.println(indent3 + "</documentation>");
      }
      writer.println(indent2 + "</annotation>");
    }
    if ((type instanceof SchemaComplexType))
    {
      SchemaComplexType complexType = (SchemaComplexType)type;
      complexType.write(indent2, writer);
    }
    writer.println(indent + "</element>");
  }
  
  public boolean hasTranslatableContent()
  {
    return fTranslatable;
  }
  
  public boolean isDeprecated()
  {
    return fDeprecated;
  }
  
  public String getExtendedAttributes()
  {
    return null;
  }
  
  public String getDescription()
  {
    if (super.getDescription() != null) {
      return super.getDescription();
    }
    ISchema schema = getSchema();
    if ((schema == null) || (schema.getURL() == null)) {
      return null;
    }
    String hashkey = schema.getURL().hashCode() + "_" + getName();
    String description = XMLComponentRegistry.Instance().getDescription(hashkey, 4);
    if (description == null)
    {
      SchemaElementHandler handler = new SchemaElementHandler(getName());
      SchemaUtil.parseURL(schema.getURL(), handler);
      description = handler.getDescription();
      XMLComponentRegistry.Instance().putDescription(hashkey, description, 4);
    }
    return description;
  }
  
  public int compareTo(Object arg0)
  {
    if ((arg0 instanceof ISchemaElement)) {
      return getName().compareToIgnoreCase(((ISchemaElement)arg0).getName());
    }
    return -1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaElement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.util.LinkedList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public class SchemaElementHandler
  extends BaseSchemaHandler
{
  private String fElementName;
  private String fTargetElementName;
  private StringBuffer fDescription;
  private static final String[] DESC_NESTED_ELEM = { "documentation", 
    "annotation", "element" };
  private static final String NAME_ATTR = "name";
  
  public SchemaElementHandler(String targetElementName)
  {
    setTargetElementName(targetElementName);
  }
  
  public void setTargetElementName(String targetElement)
  {
    fTargetElementName = targetElement;
  }
  
  protected void reset()
  {
    super.reset();
    fDescription = new StringBuffer();
    fElementName = null;
  }
  
  public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
  {
    super.startElement(uri, localName, qName, attributes);
    if (qName.compareTo(DESC_NESTED_ELEM[2]) == 0) {
      fElementName = attributes.getValue("name");
    }
  }
  
  public void characters(char[] ch, int start, int length)
    throws SAXException
  {
    if (onTarget()) {
      for (int i = 0; i < length; i++) {
        fDescription.append(ch[(start + i)]);
      }
    }
  }
  
  protected boolean onTarget()
  {
    if (fElementList.size() >= DESC_NESTED_ELEM.length)
    {
      for (int i = 0; i < DESC_NESTED_ELEM.length; i++)
      {
        String currentElement = (String)fElementList.get(i);
        if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) {
          return false;
        }
      }
      if ((fElementName == null) || (fElementName.compareTo(fTargetElementName) != 0)) {
        return false;
      }
      return true;
    }
    return false;
  }
  
  public String getDescription()
  {
    return fDescription.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaElementHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Vector;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.pde.core.ISourceObject;
import org.eclipse.pde.internal.core.PDECoreMessages;
import org.eclipse.pde.internal.core.ischema.IMetaElement;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
import org.eclipse.pde.internal.core.ischema.ISchemaType;
import org.w3c.dom.Comment;
import org.w3c.dom.Node;

public class SchemaElementReference
  extends PlatformObject
  implements ISchemaElement, IMetaElement, ISchemaObjectReference, ISourceObject, Serializable
{
  private static final long serialVersionUID = 1L;
  private ISchemaElement element;
  private ISchemaCompositor compositor;
  private String referenceName;
  public static final String P_MAX_OCCURS = "max_occurs";
  public static final String P_MIN_OCCURS = "min_occurs";
  public static final String P_REFERENCE_NAME = "reference_name";
  private int minOccurs = 1;
  private int maxOccurs = 1;
  private Vector comments;
  private int[] range;
  
  public SchemaElementReference(ISchemaCompositor compositor, String ref)
  {
    referenceName = ref;
    this.compositor = compositor;
  }
  
  public ISchemaAttribute getAttribute(String name)
  {
    if (element == null) {
      return null;
    }
    return element.getAttribute(name);
  }
  
  public int getAttributeCount()
  {
    if (element == null) {
      return 0;
    }
    return element.getAttributeCount();
  }
  
  public ISchemaAttribute[] getAttributes()
  {
    if (element == null) {
      return new ISchemaAttribute[0];
    }
    return element.getAttributes();
  }
  
  public String[] getAttributeNames()
  {
    if (element == null) {
      return new String[0];
    }
    return element.getAttributeNames();
  }
  
  public ISchemaCompositor getCompositor()
  {
    return compositor;
  }
  
  public String getDescription()
  {
    if (element == null) {
      return "";
    }
    return element.getDescription();
  }
  
  public String getDTDRepresentation(boolean addLinks)
  {
    if (element == null) {
      return PDECoreMessages.SchemaElementReference_refElementMissing;
    }
    return element.getDTDRepresentation(addLinks);
  }
  
  public String getIconProperty()
  {
    if (element == null) {
      return "";
    }
    return element.getIconProperty();
  }
  
  public String getLabelProperty()
  {
    if (element == null) {
      return "";
    }
    return element.getLabelProperty();
  }
  
  public int getMaxOccurs()
  {
    return maxOccurs;
  }
  
  public int getMinOccurs()
  {
    return minOccurs;
  }
  
  public String getName()
  {
    return referenceName;
  }
  
  public ISchemaObject getParent()
  {
    return compositor;
  }
  
  public void setParent(ISchemaObject parent) {}
  
  public ISchemaElement getReferencedElement()
  {
    return element;
  }
  
  public ISchemaObject getReferencedObject()
  {
    return element;
  }
  
  public Class getReferencedObjectClass()
  {
    return ISchemaElement.class;
  }
  
  public String getReferenceName()
  {
    return referenceName;
  }
  
  public ISchema getSchema()
  {
    if (element != null)
    {
      ISchema schema = element.getSchema();
      if (schema != null)
      {
        ISchemaDescriptor desc = schema.getSchemaDescriptor();
        if (!(desc instanceof IncludedSchemaDescriptor)) {
          return schema;
        }
      }
    }
    return getCompositorsSchema();
  }
  
  public ISchema getCompositorsSchema()
  {
    if (compositor != null) {
      return compositor.getSchema();
    }
    return null;
  }
  
  public ISchemaType getType()
  {
    if (element == null) {
      return null;
    }
    return element.getType();
  }
  
  public boolean isLinked()
  {
    return getReferencedObject() != null;
  }
  
  public void setCompositor(ISchemaCompositor newCompositor)
  {
    compositor = newCompositor;
  }
  
  public void setMaxOccurs(int newMaxOccurs)
  {
    Integer oldValue = new Integer(maxOccurs);
    maxOccurs = newMaxOccurs;
    ISchema schema = getCompositorsSchema();
    if (schema != null) {
      schema.fireModelObjectChanged(this, "max_occurs", oldValue, new Integer(maxOccurs));
    }
  }
  
  public void setMinOccurs(int newMinOccurs)
  {
    Integer oldValue = new Integer(minOccurs);
    minOccurs = newMinOccurs;
    ISchema schema = getCompositorsSchema();
    if (schema != null) {
      schema.fireModelObjectChanged(this, "min_occurs", oldValue, new Integer(minOccurs));
    }
  }
  
  public void setReferencedObject(ISchemaObject referencedObject)
  {
    if ((referencedObject instanceof ISchemaElement)) {
      element = ((ISchemaElement)referencedObject);
    } else {
      element = null;
    }
  }
  
  public void setReferenceName(String name)
  {
    String oldValue = referenceName;
    referenceName = name;
    ISchema schema = getCompositorsSchema();
    if (schema != null) {
      schema.fireModelObjectChanged(this, "reference_name", oldValue, name);
    }
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writeComments(writer);
    writer.print(indent + "<element");
    writer.print(" ref=\"" + getReferenceName() + "\"");
    if ((getMinOccurs() != 1) || (getMaxOccurs() != 1))
    {
      String min = getMinOccurs();
      String max = 
        getMaxOccurs();
      writer.print(" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\"");
    }
    writer.println("/>");
  }
  
  public void addComments(Node node)
  {
    comments = addComments(node, comments);
  }
  
  public Vector addComments(Node node, Vector result)
  {
    for (Node prev = node.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) {
      if (prev.getNodeType() != 3)
      {
        if (!(prev instanceof Comment)) {
          break;
        }
        String comment = prev.getNodeValue();
        if (result == null) {
          result = new Vector();
        }
        result.add(comment);
      }
    }
    return result;
  }
  
  void writeComments(PrintWriter writer)
  {
    writeComments(writer, comments);
  }
  
  void writeComments(PrintWriter writer, Vector source)
  {
    if (source == null) {
      return;
    }
    for (int i = 0; i < source.size(); i++)
    {
      String comment = (String)source.elementAt(i);
      writer.println("<!--" + comment + "-->");
    }
  }
  
  public int getStartLine()
  {
    return range == null ? -1 : range[0];
  }
  
  public int getStopLine()
  {
    return range == null ? -1 : range[1];
  }
  
  void bindSourceLocation(Node node, Hashtable lineTable)
  {
    if (lineTable == null) {
      return;
    }
    Integer[] data = (Integer[])lineTable.get(node);
    if (data != null) {
      range = new int[] { data[0].intValue(), data[1].intValue() };
    }
  }
  
  public boolean hasTranslatableContent()
  {
    return false;
  }
  
  public boolean isDeprecated()
  {
    return false;
  }
  
  public int compareTo(Object arg0)
  {
    if (element == null) {
      return -1;
    }
    if (arg0 == null) {
      return -1;
    }
    return element.compareTo(arg0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaElementReference
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import org.eclipse.pde.internal.core.ischema.ISchemaEnumeration;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;

public class SchemaEnumeration
  extends SchemaObject
  implements ISchemaEnumeration
{
  private static final long serialVersionUID = 1L;
  
  public SchemaEnumeration(ISchemaObject parent, String name)
  {
    super(parent, name);
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.println(indent + "<enumeration value=\"" + getName() + "\">");
    String description = getDescription();
    if (description != null) {
      description.trim();
    }
    if ((description != null) && (description.length() > 0))
    {
      String indent2 = indent + "   ";
      String indent3 = indent2 + "   ";
      writer.println(indent2 + "<annotation>");
      writer.println(indent3 + "<documentation>");
      writer.println(indent3 + description);
      writer.println(indent3 + "</documentation>");
      writer.println(indent2 + "</annotation>");
    }
    writer.println(indent + "</enumeration>");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaEnumeration
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;

public class SchemaInclude
  extends SchemaObject
  implements ISchemaInclude
{
  private static final long serialVersionUID = 1L;
  private String fLocation;
  private ISchema fIncludedSchema;
  private boolean fAbbreviated;
  
  public SchemaInclude(ISchemaObject parent, String location, boolean abbreviated)
  {
    super(parent, location);
    fLocation = location;
    fAbbreviated = abbreviated;
  }
  
  public String getLocation()
  {
    return fLocation;
  }
  
  public void setLocation(String location)
    throws CoreException
  {
    String oldValue = fLocation;
    fLocation = location;
    fIncludedSchema = null;
    getSchema().fireModelObjectChanged(this, "location", oldValue, location);
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.print(indent);
    writer.println("<include schemaLocation=\"" + fLocation + "\"/>");
  }
  
  public ISchema getIncludedSchema()
  {
    ISchemaDescriptor descriptor = getSchema().getSchemaDescriptor();
    if (fAbbreviated)
    {
      SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
      fIncludedSchema = registry.getIncludedSchema(descriptor, fLocation);
    }
    else if (fIncludedSchema == null)
    {
      fIncludedSchema = createInternalSchema(descriptor, fLocation);
    }
    return fIncludedSchema;
  }
  
  private ISchema createInternalSchema(ISchemaDescriptor desc, String location)
  {
    try
    {
      URL schemaURL = IncludedSchemaDescriptor.computeURL(desc, location);
      if (schemaURL == null) {
        return null;
      }
      Schema ischema = new Schema(null, schemaURL, fAbbreviated);
      ischema.load();
      return ischema;
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public void dispose()
  {
    if ((fIncludedSchema != null) && (!fIncludedSchema.isDisposed()))
    {
      fIncludedSchema.dispose();
      fIncludedSchema = null;
    }
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof ISchemaInclude))
    {
      ISchemaInclude other = (ISchemaInclude)obj;
      if (fLocation != null) {
        return fLocation.equals(other.getLocation());
      }
      return other.getLocation() == null;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaInclude
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.Serializable;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.util.PDEXMLHelper;

public abstract class SchemaObject
  extends PlatformObject
  implements ISchemaObject, Serializable
{
  private static final long serialVersionUID = 1L;
  protected String fName;
  private String fDescription;
  private transient ISchemaObject fParent;
  
  public SchemaObject(ISchemaObject parent, String name)
  {
    fParent = parent;
    fName = name;
  }
  
  public String getDescription()
  {
    return fDescription;
  }
  
  public String getName()
  {
    return fName;
  }
  
  public ISchemaObject getParent()
  {
    return fParent;
  }
  
  public void setParent(ISchemaObject parent)
  {
    fParent = parent;
  }
  
  public ISchema getSchema()
  {
    ISchemaObject object = this;
    while (object.getParent() != null) {
      object = object.getParent();
    }
    return (ISchema)object;
  }
  
  public String getWritableDescription()
  {
    String lineDelimiter = System.getProperty("line.separator");
    String description = PDEXMLHelper.getWritableString(getDescription());
    String platformDescription = description.replaceAll("\\r\\n|\\r|\\n", lineDelimiter);
    
    return platformDescription;
  }
  
  public void setDescription(String newDescription)
  {
    String oldValue = fDescription;
    fDescription = newDescription;
    getSchema().fireModelObjectChanged(this, "description", oldValue, fDescription);
  }
  
  public void setName(String newName)
  {
    String oldValue = fName;
    fName = newName;
    getSchema().fireModelObjectChanged(this, "name", oldValue, fName);
  }
  
  public String toString()
  {
    if (fName != null) {
      return fName;
    }
    return super.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.SchemaObject
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.schema;

import java.io.File;
import java.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

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