org.eclipse.pde.core_3.7.1.v20120103_r372

uble version = Double.parseDouble(targetVersion);
              if (version >= 3.4D) {
                bundle.setHeader("Bundle-ActivationPolicy", "lazy");
              } else {
                bundle.setHeader("Eclipse-LazyStart", "true");
              }
            }
          }
          else {
            bundle.setHeader("Bundle-ActivationPolicy", "lazy");
          }
        }
        else {
          removeActivation = true;
        }
      }
      if ((description.getHost() != null) && (before.getHost() == null)) {
        removeActivation = true;
      }
      if (removeActivation)
      {
        bundle.setHeader("Eclipse-AutoStart", null);
        bundle.setHeader("Bundle-ActivationPolicy", null);
        bundle.setHeader("Eclipse-LazyStart", null);
      }
      IPath localization = description.getLocalization();
      if (!isEqual(localization, before.getLocalization())) {
        if (localization == null) {
          bundle.setHeader("Bundle-Localization", null);
        } else {
          bundle.setHeader("Bundle-Localization", localization.toString());
        }
      }
      IBundleModel bundleModel = bundle.getModel();
      if ((bundleModel instanceof WorkspaceBundleModel))
      {
        WorkspaceBundleModel wbm = (WorkspaceBundleModel)bundleModel;
        if (wbm.isDirty()) {
          fModel.setDirty(true);
        }
      }
      BundleProjectDescription bpd = (BundleProjectDescription)description;
      Map extraHeaders = bpd.getExtraHeaders();
      Iterator iterator = extraHeaders.entrySet().iterator();
      while (iterator.hasNext())
      {
        Map.Entry entry = (Map.Entry)iterator.next();
        String name = (String)entry.getKey();
        String value = (String)entry.getValue();
        if ((value != null) && (value.trim().length() == 0)) {
          value = " ";
        }
        if (!isEqual(value, bundle.getHeader(name))) {
          bundle.setHeader(name, value);
        }
      }
    }
  }
  
  private String getTargetVersion(String targetVersion)
  {
    if (targetVersion == null) {
      return TargetPlatformHelper.getTargetVersionString();
    }
    return targetVersion;
  }
  
  protected static String[] getLibraryNames(IBundleProjectDescription description)
  {
    IBundleClasspathEntry[] libs = description.getBundleClasspath();
    if ((libs != null) && (libs.length > 0))
    {
      Set names = new LinkedHashSet();
      for (int i = 0; i < libs.length; i++)
      {
        IPath lib = libs[i].getLibrary();
        String libName = ".";
        if (lib != null) {
          libName = lib.toString();
        }
        names.add(libName);
      }
      return (String[])names.toArray(new String[names.size()]);
    }
    return null;
  }
  
  private void configureBundleClasspath(IBundleProjectDescription description, IBundleProjectDescription before)
    throws CoreException
  {
    IBundleClasspathEntry[] cp = description.getBundleClasspath();
    if (!isEqual(cp, before.getBundleClasspath()))
    {
      IPluginBase pluginBase = fModel.getPluginBase();
      IPluginLibrary[] libraries = pluginBase.getLibraries();
      if ((libraries != null) && (libraries.length > 0)) {
        for (int i = 0; i < libraries.length; i++) {
          pluginBase.remove(libraries[i]);
        }
      }
      String[] names = getLibraryNames(description);
      if (names != null)
      {
        if ((names.length == 1) && (".".equals(names[0]))) {
          return;
        }
        for (int i = 0; i < names.length; i++)
        {
          IPluginLibrary library = fModel.getPluginFactory().createLibrary();
          library.setName(names[i]);
          library.setExported(false);
          pluginBase.add(library);
        }
      }
    }
  }
  
  private void configureBuildPropertiesFile(IBundleProjectDescription description, IBundleProjectDescription before)
    throws CoreException
  {
    IProject project = description.getProject();
    IFile file = PDEProject.getBuildProperties(project);
    WorkspaceBuildModel model = new WorkspaceBuildModel(file);
    IBuildModelFactory factory = model.getFactory();
    
    IBuildEntry binEntry = model.getBuild().getEntry("bin.includes");
    if (binEntry == null)
    {
      binEntry = factory.createEntry("bin.includes");
      model.getBuild().add(binEntry);
    }
    boolean modified = fillBinIncludes(project, binEntry, description, before);
    modified = createSourceOutputBuildEntries(model, factory, description, before) | modified;
    if (modified) {
      model.save();
    }
  }
  
  private boolean fillBinIncludes(IProject project, IBuildEntry binEntry, IBundleProjectDescription description, IBundleProjectDescription before)
    throws CoreException
  {
    boolean modified = false;
    if (!binEntry.contains("META-INF/"))
    {
      modified = true;
      binEntry.addToken("META-INF/");
    }
    String[] names = getLibraryNames(description);
    String[] prevNames = getLibraryNames(before);
    if (!isEqual(names, prevNames))
    {
      if (prevNames != null) {
        for (int i = 0; i < prevNames.length; i++) {
          if (binEntry.contains(prevNames[i]))
          {
            modified = true;
            binEntry.removeToken(prevNames[i]);
          }
        }
      }
      if (names != null) {
        for (int i = 0; i < names.length; i++) {
          if (!binEntry.contains(names[i]))
          {
            modified = true;
            
            String name = names[i];
            IPath path = new Path(names[i]);
            String extension = path.getFileExtension();
            if ((extension == null) && 
              (!name.endsWith("/"))) {
              name = name + "/";
            }
            binEntry.addToken(name);
          }
        }
      }
    }
    IPath[] paths = description.getBinIncludes();
    IPath[] prevPaths = before.getBinIncludes();
    if (!isEqual(paths, prevPaths))
    {
      if (prevPaths != null) {
        for (int i = 0; i < prevPaths.length; i++)
        {
          String token = prevPaths[i].toString();
          if (binEntry.contains(token))
          {
            binEntry.removeToken(token);
            modified = true;
          }
        }
      }
      if (paths != null) {
        for (int i = 0; i < paths.length; i++)
        {
          String name = paths[i].toString();
          if (!binEntry.contains(name))
          {
            binEntry.addToken(name);
            modified = true;
          }
        }
      }
    }
    return modified;
  }
  
  private boolean createSourceOutputBuildEntries(WorkspaceBuildModel model, IBuildModelFactory factory, IBundleProjectDescription description, IBundleProjectDescription before)
    throws CoreException
  {
    boolean modified = false;
    IBundleClasspathEntry[] folders = description.getBundleClasspath();
    IBundleClasspathEntry[] prev = before.getBundleClasspath();
    if (!isEqual(folders, prev))
    {
      modified = true;
      
      String[] oldNames = getLibraryNames(before);
      IBuild build = model.getBuild();
      if (oldNames != null) {
        for (int i = 0; i < oldNames.length; i++)
        {
          removeBuildEntry(build, "source." + oldNames[i]);
          removeBuildEntry(build, "output." + oldNames[i]);
        }
      }
      if ((folders != null) && (folders.length > 0)) {
        for (int i = 0; i < folders.length; i++)
        {
          String libraryName = null;
          IPath libPath = folders[i].getLibrary();
          if (libPath == null) {
            libraryName = ".";
          } else {
            libraryName = folders[i].getLibrary().toString();
          }
          IPath srcFolder = folders[i].getSourcePath();
          if (srcFolder != null)
          {
            IBuildEntry entry = getBuildEntry(build, factory, "source." + libraryName);
            if (!srcFolder.isEmpty()) {
              entry.addToken(srcFolder.addTrailingSeparator().toString());
            } else {
              entry.addToken(".");
            }
          }
          IPath outFolder = folders[i].getBinaryPath();
          if ((srcFolder != null) && (outFolder == null))
          {
            IJavaProject project = JavaCore.create(description.getProject());
            outFolder = project.getOutputLocation().removeFirstSegments(1);
          }
          if (outFolder != null)
          {
            IBuildEntry entry = getBuildEntry(build, factory, "output." + libraryName);
            String token = null;
            if (!outFolder.isEmpty()) {
              token = outFolder.addTrailingSeparator().toString();
            } else {
              token = ".";
            }
            if (!entry.contains(token)) {
              entry.addToken(token);
            }
          }
        }
      }
    }
    return modified;
  }
  
  private IBuildEntry getBuildEntry(IBuild build, IBuildModelFactory factory, String key)
    throws CoreException
  {
    IBuildEntry entry = build.getEntry(key);
    if (entry == null)
    {
      entry = factory.createEntry(key);
      build.add(entry);
    }
    return entry;
  }
  
  private void removeBuildEntry(IBuild build, String key)
    throws CoreException
  {
    IBuildEntry entry = build.getEntry(key);
    if (entry != null) {
      build.remove(entry);
    }
  }
}

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

import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.project.IRequiredBundleDescription;

public class RequiredBundleDescription
  extends RequirementSpecification
  implements IRequiredBundleDescription
{
  public RequiredBundleDescription(String name, VersionRange range, boolean reexport, boolean optional)
  {
    super(name, range, reexport, optional);
  }
}

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

import org.eclipse.osgi.service.resolver.VersionRange;

public abstract class RequirementSpecification
{
  private String fName;
  private VersionRange fRange;
  private boolean fExport;
  private boolean fOptional;
  
  RequirementSpecification(String name, VersionRange range, boolean export, boolean optional)
  {
    fName = name;
    fRange = range;
    fExport = export;
    fOptional = optional;
  }
  
  public String getName()
  {
    return fName;
  }
  
  public VersionRange getVersionRange()
  {
    return fRange;
  }
  
  public boolean isExported()
  {
    return fExport;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof RequirementSpecification))
    {
      RequirementSpecification spec = (RequirementSpecification)obj;
      return (getName().equals(spec.getName())) && (isExported() == spec.isExported()) && (isOptional() == spec.isOptional()) && (equalOrNull(getVersionRange(), spec.getVersionRange()));
    }
    return false;
  }
  
  public int hashCode()
  {
    int code = getClass().hashCode() + fName.hashCode();
    if (fRange != null) {
      code += fRange.hashCode();
    }
    if (fExport) {
      code++;
    }
    if (fOptional) {
      code += 2;
    }
    return code;
  }
  
  private boolean equalOrNull(Object o1, Object o2)
  {
    if (o1 == null) {
      return o2 == null;
    }
    if (o2 == null) {
      return o1 == null;
    }
    return o1.equals(o2);
  }
  
  public boolean isOptional()
  {
    return fOptional;
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append(fName);
    buf.append(' ');
    if (fRange != null) {
      buf.append(fRange);
    }
    if (fOptional) {
      buf.append(" optional");
    }
    if (fExport) {
      buf.append(" re-export");
    }
    return buf.toString();
  }
}

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

import java.io.StringReader;
import java.util.LinkedList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class BaseSchemaHandler
  extends DefaultHandler
{
  protected LinkedList fElementList;
  
  public BaseSchemaHandler()
  {
    reset();
  }
  
  protected void reset()
  {
    fElementList = new LinkedList();
  }
  
  public void startDocument()
    throws SAXException
  {
    reset();
  }
  
  public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
  {
    fElementList.addFirst(qName);
  }
  
  public void endElement(String uri, String localName, String qName)
    throws SAXException
  {
    if (fElementList.size() != 0) {
      fElementList.removeFirst();
    } else {
      throw new SAXException("Serious error.  XML document is not well-formed");
    }
  }
  
  public InputSource resolveEntity(String publicId, String systemId)
    throws SAXException
  {
    return new InputSource(new StringReader(""));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.BaseSchemaHandler
 * 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.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaEnumeration;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.ischema.ISchemaRestriction;
import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;

public class ChoiceRestriction
  extends SchemaObject
  implements ISchemaRestriction
{
  private static final long serialVersionUID = 1L;
  private ISchemaSimpleType baseType;
  private Vector children;
  public static final String P_CHOICES = "choices";
  
  public ChoiceRestriction(ISchema schema)
  {
    super(schema, "__choice__");
  }
  
  public ChoiceRestriction(ChoiceRestriction source)
  {
    this(source.getSchema());
    children = new Vector();
    Object[] choices = source.getChildren();
    for (int i = 0; i < choices.length; i++) {
      children.add(new SchemaEnumeration(this, ((ISchemaEnumeration)choices[i]).getName()));
    }
  }
  
  public ISchemaSimpleType getBaseType()
  {
    return baseType;
  }
  
  public Object[] getChildren()
  {
    return children != null ? children.toArray() : new Object[0];
  }
  
  public String[] getChoicesAsStrings()
  {
    if (children == null) {
      return new String[0];
    }
    Vector result = new Vector();
    for (int i = 0; i < children.size(); i++)
    {
      ISchemaEnumeration enumeration = (ISchemaEnumeration)children.get(i);
      result.addElement(enumeration.getName());
    }
    String[] choices = new String[result.size()];
    result.copyInto(choices);
    return choices;
  }
  
  public ISchemaObject getParent()
  {
    if (baseType != null) {
      return baseType.getSchema();
    }
    return super.getParent();
  }
  
  public boolean isValueValid(Object value)
  {
    if (children == null) {
      return false;
    }
    String svalue = value.toString();
    for (int i = 0; i < children.size(); i++)
    {
      ISchemaEnumeration enumeration = (ISchemaEnumeration)children.get(i);
      if (enumeration.getName().equals(svalue)) {
        return true;
      }
    }
    return false;
  }
  
  public void setBaseType(ISchemaSimpleType baseType)
  {
    this.baseType = baseType;
  }
  
  public void setChildren(Vector children)
  {
    Vector oldValue = this.children;
    this.children = children;
    if (getParent() != null) {
      getSchema().fireModelObjectChanged(this, "choices", oldValue, children);
    }
  }
  
  public String toString()
  {
    if (children == null) {
      return "";
    }
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < children.size(); i++)
    {
      Object child = children.get(i);
      if ((child instanceof ISchemaEnumeration))
      {
        ISchemaEnumeration enumeration = (ISchemaEnumeration)child;
        if (i > 0) {
          buffer.append(", ");
        }
        buffer.append(enumeration.getName());
      }
    }
    return buffer.toString();
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.println(indent + "<restriction base=\"" + baseType.getName() + "\">");
    for (int i = 0; i < children.size(); i++)
    {
      Object child = children.get(i);
      if ((child instanceof ISchemaEnumeration))
      {
        ISchemaEnumeration enumeration = (ISchemaEnumeration)child;
        enumeration.write(indent + "   ", writer);
      }
    }
    writer.println(indent + "</restriction>");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.ChoiceRestriction
 * 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.IDocumentSection;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;

public class DocumentSection
  extends SchemaObject
  implements IDocumentSection, Comparable
{
  private static final long serialVersionUID = 1L;
  public static final String[] DOC_SECTIONS = { "since", "examples", "apiinfo", "implementation", "copyright" };
  private String sectionId;
  
  public DocumentSection(ISchemaObject parent, String sectionId, String name)
  {
    super(parent, name);
    this.sectionId = sectionId;
  }
  
  public String getSectionId()
  {
    return sectionId;
  }
  
  public void write(String indent, PrintWriter writer)
  {
    String description = getWritableDescription();
    if ((description == null) || (description.equals(""))) {
      return;
    }
    String indent2 = indent + "   ";
    String indent3 = indent2 + "   ";
    writer.println(indent + "<annotation>");
    writer.println(indent2 + (getSchema().getSchemaVersion() >= 3.4D ? "<appinfo>" : "<appInfo>"));
    writer.println(indent3 + "<meta.section type=\"" + sectionId + "\"/>");
    writer.println(indent2 + (getSchema().getSchemaVersion() >= 3.4D ? "</appinfo>" : "</appInfo>"));
    writer.println(indent2 + "<documentation>");
    writer.println(indent3 + description);
    writer.println(indent2 + "</documentation>");
    writer.println(indent + "</annotation>");
  }
  
  public boolean equals(Object obj)
  {
    if (((obj instanceof DocumentSection)) && (((DocumentSection)obj).getSectionId().equalsIgnoreCase(sectionId))) {
      return true;
    }
    return false;
  }
  
  public int compareTo(Object arg0)
  {
    if ((arg0 instanceof DocumentSection))
    {
      int otherIndex = getIndex(((DocumentSection)arg0).getSectionId());
      int thisIndex = getIndex(sectionId);
      if (otherIndex == thisIndex) {
        return 0;
      }
      if (otherIndex == -1) {
        return -1;
      }
      return thisIndex - otherIndex;
    }
    return -1;
  }
  
  private int getIndex(String sectionId)
  {
    if (sectionId == null) {
      return -1;
    }
    for (int i = 0; i < DOC_SECTIONS.length; i++) {
      if (DOC_SECTIONS[i].equals(sectionId)) {
        return i;
      }
    }
    return -1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.DocumentSection
 * 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.core.IEditable;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;

public class EditableSchema
  extends Schema
  implements IEditable
{
  private boolean dirty;
  
  public EditableSchema(ISchemaDescriptor schemaDescriptor, URL url, boolean abbreviated)
  {
    super(schemaDescriptor, url, abbreviated);
  }
  
  public EditableSchema(String pluginId, String pointId, String name, boolean abbreviated)
  {
    super(pluginId, pointId, name, abbreviated);
  }
  
  public void fireModelChanged(IModelChangedEvent event)
  {
    if (isNotificationEnabled()) {
      dirty = true;
    }
    super.fireModelChanged(event);
  }
  
  public boolean isDirty()
  {
    return dirty;
  }
  
  public boolean isEditable()
  {
    return true;
  }
  
  public void save(PrintWriter writer)
  {
    write("", writer);
    dirty = false;
  }
  
  public void setDirty(boolean newDirty)
  {
    dirty = newDirty;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.schema.EditableSchema
 * 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.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;

public class IncludedSchemaDescriptor
  implements ISchemaDescriptor
{
  private URL fSchemaURL;
  private String fSchemaLocation;
  private Schema fSchema;
  private long fLastModified;
  
  public IncludedSchemaDescriptor(URL schemaURL)
  {
    fSchemaURL = schemaURL;
    File file = new File(fSchemaURL.getFile());
    if (file.exists()) {
      fLastModified = file.lastModified();
    }
  }
  
  public static URL computeURL(ISchemaDescriptor parentDesc, String schemaLocation)
    throws MalformedURLException
  {
    URL parentURL = parentDesc == null ? null : parentDesc.getSchemaURL();
    if (schemaLocation.startsWith("schema://"))
    {
      IPath path = new Path(schemaLocation.substring(9));
      return getPluginRelativePath(path.segment(0), path.removeFirstSegments(1), parentURL);
    }
    if (parentURL == null) {
      return null;
    }
    IPath path = new Path(parentURL.getPath());
    path = path.removeLastSegments(1).append(schemaLocation);
    return new URL(parentURL.getProtocol(), parentURL.getHost(), path.toString());
  }
  
  private static URL getPluginRelativePath(String pluginID, IPath path, URL parentURL)
  {
    URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString());
    if (url == null)
    {
      IPluginModelBase model = PluginRegistry.findModel(pluginID);
      if (model != null) {
        url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path);
      }
    }
    try
    {
      if ((url == null) && (parentURL != null))
      {
        String parentFile = parentURL.getFile();
        if (parentFile == null) {
          return null;
        }
        int lastSep = parentFile.lastIndexOf(File.separatorChar);
        parentFile = parentFile.substring(0, lastSep + 1);
        
        File file = new File(parentFile + "../../" + pluginID + "/" + path.toString());
        if ((file.exists()) && (file.isFile())) {
          url = file.toURL();
        }
      }
    }
    catch (MalformedURLException localMalformedURLException) {}
    return url;
  }
  
  public boolean isEnabled()
  {
    return true;
  }
  
  public String getPointId()
  {
    int dotLoc = fSchemaLocation.lastIndexOf('.');
    if (dotLoc != -1) {
      return fSchemaLocation.substring(0, dotLoc);
    }
    return null;
  }
  
  public URL getSchemaURL()
  {
    return fSchemaURL;
  }
  
  public ISchema getSchema(boolean abbreviated)
  {
    if ((fSchema == null) && (fSchemaURL != null))
    {
      fSchema = new Schema(this, fSchemaURL, abbreviated);
      fSchema.load();
    }
    return fSchema;
  }
  
  public boolean isStandalone()
  {
    return false;
  }
  
  public long getLastModified()
  {
    return fLastModified;
  }
}

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

import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.ischema.ISchemaRepeatable;

public abstract class RepeatableSchemaObject
  extends SchemaObject
  implements ISchemaRepeatable
{
  private static final long serialVersionUID = 1L;
  public static final String P_MIN_OCCURS = "min_occurs";
  public static final String P_MAX_OCCURS = "max_occurs";
  private int minOccurs = 1;
  private int maxOccurs = 1;
  
  public RepeatableSchemaObject(ISchemaObject parent, String name)
  {
    super(parent, name);
  }
  
  public int getMaxOccurs()
  {
    return maxOccurs;
  }
  
  public int getMinOccurs()
  {
    return minOccurs;
  }
  
  public boolean isRequired()
  {
    return minOccurs > 0;
  }
  
  public boolean isUnbounded()
  {
    return maxOccurs == Integer.MAX_VALUE;
  }
  
  public void setMaxOccurs(int newMaxOccurs)
  {
    Integer oldValue = new Integer(maxOccurs);
    maxOccurs = newMaxOccurs;
    getSchema().fireModelObjectChanged(this, "max_occurs", oldValue, new Integer(maxOccurs));
  }
  
  public void setMinOccurs(int newMinOccurs)
  {
    Integer oldValue = new Integer(minOccurs);
    minOccurs = newMinOccurs;
    getSchema().fireModelObjectChanged(this, "min_occurs", oldValue, new Integer(minOccurs));
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.IModelChangedListener;
import org.eclipse.pde.core.ModelChangedEvent;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PluginModelManager;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.internal.core.XMLDefaultHandler;
import org.eclipse.pde.internal.core.ischema.IDocumentSection;
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.ISchemaDescriptor;
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
import org.eclipse.pde.internal.core.ischema.ISchemaEnumeration;
import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
import org.eclipse.pde.internal.core.ischema.ISchemaRootElement;
import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
import org.eclipse.pde.internal.core.ischema.ISchemaType;
import org.eclipse.pde.internal.core.util.PDEXMLHelper;
import org.eclipse.pde.internal.core.util.SAXParserWrapper;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class Schema
  extends PlatformObject
  implements ISchema
{
  private URL fURL;
  private ListenerList fListeners = new ListenerList();
  private Vector fElements = new Vector();
  private Vector fDocSections = new Vector();
  private Vector fIncludes;
  private String fPointID;
  private String fPluginID;
  private ISchemaDescriptor fSchemaDescriptor;
  private boolean fLoaded;
  private Vector fReferences;
  private String fDescription;
  private double fTargetVersion;
  private String fName = "";
  private boolean fNotificationEnabled;
  public static final String INDENT = "   ";
  private boolean fDisposed;
  private boolean fValid;
  private boolean fAbbreviated;
  
  public Schema(String pluginId, String pointId, String name, boolean abbreviated)
  {
    fPluginID = pluginId;
    fPointID = pointId;
    fName = name;
    fAbbreviated = abbreviated;
  }
  
  public Schema(ISchemaDescriptor schemaDescriptor, URL url, boolean abbreviated)
  {
    fSchemaDescriptor = schemaDescriptor;
    fURL = url;
    fAbbreviated = abbreviated;
  }
  
  public void addDocumentSection(IDocumentSection docSection)
  {
    fDocSections.addElement(docSection);
    fireModelChanged(new ModelChangedEvent(this, 1, new Object[] { docSection }, null));
  }
  
  public void addElement(ISchemaElement element)
  {
    addElement(element, null);
  }
  
  public void addElement(ISchemaElement element, ISchemaElement afterElement)
  {
    int index = -1;
    if (afterElement != null) {
      index = fElements.indexOf(afterElement);
    }
    if (index != -1) {
      fElements.add(index + 1, element);
    } else {
      fElements.add(element);
    }
    fireModelChanged(new ModelChangedEvent(this, 1, new Object[] { element }, null));
  }
  
  public void addInclude(ISchemaInclude include)
  {
    if (fIncludes == null) {
      fIncludes = new Vector();
    }
    fIncludes.add(include);
    fireModelChanged(new ModelChangedEvent(this, 1, new Object[] { include }, null));
  }
  
  public void removeInclude(ISchemaInclude include)
  {
    if (fIncludes == null) {
      return;
    }
    fIncludes.remove(include);
    fireModelChanged(new ModelChangedEvent(this, 2, new Object[] { include }, null));
  }
  
  public void addModelChangedListener(IModelChangedListener listener)
  {
    fListeners.add(listener);
  }
  
  private void collectElements(ISchemaCompositor compositor, Vector result)
  {
    Object[] children = compositor.getChildren();
    for (int i = 0; i < children.length; i++)
    {
      Object child = children[i];
      if ((child instanceof ISchemaCompositor))
      {
        collectElements((ISchemaCompositor)child, result);
      }
      else if ((child instanceof ISchemaObjectReference))
      {
        ISchemaObjectReference ref = (ISchemaObjectReference)child;
        Object referenced = ref.getReferencedObject();
        if ((referenced instanceof ISchemaElement)) {
          result.addElement(referenced);
        }
      }
    }
  }
  
  public void dispose()
  {
    if (fIncludes != null) {
      for (int i = 0; i < fIncludes.size(); i++)
      {
        ISchemaInclude include = (ISchemaInclude)fIncludes.get(i);
        include.dispose();
      }
    }
    reset();
    fDisposed = true;
  }
  
  public ISchemaElement findElement(String name)
  {
    if (!isLoaded()) {
      load();
    }
    for (int i = 0; i < fElements.size(); i++)
    {
      ISchemaElement element = (ISchemaElement)fElements.elementAt(i);
      if (element.getName().equals(name)) {
        return element;
      }
    }
    if (fIncludes != null) {
      for (int i = 0; i < fIncludes.size(); i++)
      {
        ISchemaInclude include = (ISchemaInclude)fIncludes.get(i);
        ISchema ischema = include.getIncludedSchema();
        if (ischema != null)
        {
          ISchemaElement element = ischema.findElement(name);
          if (element != null) {
            return element;
          }
        }
      }
    }
    return null;
  }
  
  public void fireModelChanged(IModelChangedEvent event)
  {
    if (!fNotificationEnabled) {
      return;
    }
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
      ((IModelChangedListener)listeners[i]).modelChanged(event);
    }
  }
  
  public void fireModelObjectChanged(Object object, String property, Object oldValue, Object newValue)
  {
    fireModelChanged(new ModelChangedEvent(this, object, property, oldValue, newValue));
  }
  
  private String getAttribute(Node node, String name)
  {
    NamedNodeMap map = node.getAttributes();
    Node attNode = map.getNamedItem(name);
    if (attNode != null)
    {
      String value = attNode.getNodeValue();
      if (value.length() > 0) {
        return value;
      }
    }
    return null;
  }
  
  public ISchemaElement[] getCandidateChildren(ISchemaElement element)
  {
    Vector candidates = new Vector();
    ISchemaType type = element.getType();
    if ((type instanceof ISchemaComplexType))
    {
      ISchemaCompositor compositor = ((ISchemaComplexType)type).getCompositor();
      if (compositor != null) {
        collectElements(compositor, candidates);
      }
    }
    ISchemaElement[] result = new ISchemaElement[candidates.size()];
    candidates.copyInto(result);
    return result;
  }
  
  public String getDescription()
  {
    return fDescription;
  }
  
  public boolean isValid()
  {
    return fValid;
  }
  
  public IDocumentSection[] getDocumentSections()
  {
    IDocumentSection[] result = new IDocumentSection[fDocSections.size()];
    fDocSections.copyInto(result);
    return result;
  }
  
  public int getElementCount()
  {
    return fElements.size();
  }
  
  public int getResolvedElementCount()
  {
    int localCount = getElementCount();
    if (fIncludes == null) {
      return localCount;
    }
    int totalCount = localCount;
    for (int i = 0; i < fIncludes.size(); i++)
    {
      ISchemaInclude include = (ISchemaInclude)fIncludes.get(i);
      ISchema schema = include.getIncludedSchema();
      if (schema != null) {
        totalCount += schema.getResolvedElementCount();
      }
    }
    return totalCount;
  }
  
  public ISchemaElement[] getElements()
  {
    if (!isLoaded()) {
      load();
    }
    ISchemaElement[] result = new ISchemaElement[fElements.size()];
    fElements.copyInto(result);
    return result;
  }
  
  public String[] getElementNames()
  {
    ISchemaElement[] elements = getElements();
    String[] names = new String[elements.length];
    for (int i = 0; i < elements.length; i++) {
      names[i] = elements[i].getName();
    }
    return names;
  }
  
  public ISchemaElement[] getResolvedElements()
  {
    if (fIncludes == null) {
      return getElements();
    }
    if (!isLoaded()) {
      load();
    }
    Vector result = (Vector)fElements.clone();
    for (int i = 0; i < fIncludes.size(); i++)
    {
      ISchemaInclude include = (ISchemaInclude)fIncludes.get(i);
      ISchema schema = include.getIncludedSchema();
      if (schema != null)
      {
        ISchemaElement[] ielements = schema.getElements();
        for (int j = 0; j < ielements.length; j++) {
          result.add(ielements[j]);
        }
      }
    }
    return (ISchemaElement[])result.toArray(new ISchemaElement[result.size()]);
  }
  
  public ISchemaInclude[] getIncludes()
  {
    if (fIncludes == null) {
      return new ISchemaInclude[0];
    }
    return (ISchemaInclude[])fIncludes.toArray(new ISchemaInclude[fIncludes.size()]);
  }
  
  public String getName()
  {
    return fName;
  }
  
  private String getNormalizedText(String source)
  {
    if (source == null) {
      return "";
    }
    String result = source.replace('\t', ' ');
    result = result.trim();
    return result;
  }
  
  public ISchemaObject getParent()
  {
    return null;
  }
  
  public void setParent(ISchemaObject obj) {}
  
  public ISchemaElement getElementAt(int index)
  {
    return (ISchemaElement)fElements.get(index);
  }
  
  public String getQualifiedPointId()
  {
    return fPluginID + "." + fPointID;
  }
  
  public String getPluginId()
  {
    return fPluginID;
  }
  
  public String getPointId()
  {
    return fPointID;
  }
  
  public ISchema getSchema()
  {
    return this;
  }
  
  public ISchemaDescriptor getSchemaDescriptor()
  {
    return fSchemaDescriptor;
  }
  
  public URL getURL()
  {
    return fURL;
  }
  
  public int indexOf(Object obj)
  {
    return fElements.indexOf(obj);
  }
  
  public boolean isDisposed()
  {
    return fDisposed;
  }
  
  public boolean isEditable()
  {
    return false;
  }
  
  public boolean isLoaded()
  {
    return fLoaded;
  }
  
  public boolean isNotificationEnabled()
  {
    return fNotificationEnabled;
  }
  
  /* Error */
  public void load()
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aconst_null
    //   3: astore_2
    //   4: aload_0
    //   5: getfield 927	org/eclipse/pde/internal/core/schema/Schema:fURL	Ljava/net/URL;
    //   8: invokestatic 1091	org/eclipse/pde/internal/core/util/SchemaUtil:getURLConnection	(Ljava/net/URL;)Ljava/net/URLConnection;
    //   11: astore_1
    //   12: aload_1
    //   13: invokevirtual 960	java/net/URLConnection:getInputStream	()Ljava/io/InputStream;
    //   16: astore_2
    //   17: aload_0
    //   18: aload_2
    //   19: invokevirtual 1005	org/eclipse/pde/internal/core/schema/Schema:load	(Ljava/io/InputStream;)V
    //   22: goto +112 -> 134
    //   25: pop
    //   26: aload_0
    //   27: iconst_0
    //   28: putfield 919	org/eclipse/pde/internal/core/schema/Schema:fLoaded	Z
    //   31: aload_2
    //   32: ifnull +7 -> 39
    //   35: aload_2
    //   36: invokevirtual 934	java/io/InputStream:close	()V
    //   39: aload_1
    //   40: instanceof 534
    //   43: ifeq +120 -> 163
    //   46: aload_1
    //   47: checkcast 534	java/net/JarURLConnection
    //   50: invokevirtual 959	java/net/JarURLConnection:getJarFile	()Ljava/util/jar/JarFile;
    //   53: invokevirtual 978	java/util/jar/JarFile:close	()V
    //   56: goto +107 -> 163
    //   59: pop
    //   60: goto +103 -> 163
    //   63: astore_3
    //   64: aload_3
    //   65: invokestatic 986	org/eclipse/pde/internal/core/PDECore:logException	(Ljava/lang/Throwable;)V
    //   68: aload_2
    //   69: ifnull +7 -> 76
    //   72: aload_2
    //   73: invokevirtual 934	java/io/InputStream:close	()V
    //   76: aload_1
    //   77: instanceof 534
    //   80: ifeq +83 -> 163
    //   83: aload_1
    //   84: checkcast 534	java/net/JarURLConnection
    //   87: invokevirtual 959	java/net/JarURLConnection:getJarFile	()Ljava/util/jar/JarFile;
    //   90: invokevirtual 978	java/util/jar/JarFile:close	()V
    //   93: goto +70 -> 163
    //   96: pop
    //   97: goto +66 -> 163
    //   100: astore 4
    //   102: aload_2
    //   103: ifnull +7 -> 110
    //   106: aload_2
    //   107: invokevirtual 934	java/io/InputStream:close	()V
    //   110: aload_1
    //   111: instanceof 534
    //   114: ifeq +17 -> 131
    //   117: aload_1
    //   118: checkcast 534	java/net/JarURLConnection
    //   121: invokevirtual 959	java/net/JarURLConnection:getJarFile	()Ljava/util/jar/JarFile;
    //   124: invokevirtual 978	java/util/jar/JarFile:close	()V
    //   127: goto +4 -> 131
    //   130: pop
    //   131: aload 4
    //   133: athrow
    //   134: aload_2
    //   135: ifnull +7 -> 142
    //   138: aload_2
    //   139: invokevirtual 934	java/io/InputStream:close	()V
    //   142: aload_1
    //   143: instanceof 534
    //   146: ifeq +17 -> 163
    //   149: aload_1
    //   150: checkcast 534	java/net/JarURLConnection
    //   153: invokevirtual 959	java/net/JarURLConnection:getJarFile	()Ljava/util/jar/JarFile;
    //   156: invokevirtual 978	java/util/jar/JarFile:close	()V
    //   159: goto +4 -> 163
    //   162: pop
    //   163: return
    // Line number table:
    //   Java source line #346	-> byte code offset #0
    //   Java source line #347	-> byte code offset #2
    //   Java source line #349	-> byte code offset #4
    //   Java source line #350	-> byte code offset #12
    //   Java source line #351	-> byte code offset #17
    //   Java source line #352	-> byte code offset #25
    //   Java source line #353	-> byte code offset #26
    //   Java source line #358	-> byte code offset #31
    //   Java source line
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-2019. Infinite Loop Ltd