org.eclipse.pde.core_3.7.1.v20120103_r372

   ProcessingInstruction instruction = doc.createProcessingInstruction("pde", "version=\"3.6\"");
    doc.appendChild(instruction);
    
    Element rootElement = doc.createElement("target");
    if (definition.getName() != null) {
      rootElement.setAttribute("name", definition.getName());
    }
    if (((TargetDefinition)definition).getUIMode() == 1) {
      rootElement.setAttribute("includeMode", "feature");
    }
    rootElement.setAttribute("sequenceNumber", Integer.toString(((TargetDefinition)definition).getSequenceNumber()));
    
    IBundleContainer[] containers = definition.getBundleContainers();
    if ((containers != null) && (containers.length > 0))
    {
      Element containersElement = doc.createElement("locations");
      for (int i = 0; i < containers.length; i++)
      {
        Element containerElement = serializeBundleContainer(doc, (AbstractBundleContainer)containers[i]);
        containersElement.appendChild(containerElement);
      }
      rootElement.appendChild(containersElement);
    }
    NameVersionDescriptor[] included = definition.getIncluded();
    if (included != null)
    {
      Element includedElement = doc.createElement("includeBundles");
      serializeBundles(doc, includedElement, included);
      rootElement.appendChild(includedElement);
    }
    NameVersionDescriptor[] optional = definition.getOptional();
    if (optional != null)
    {
      Element optionalElement = doc.createElement("optionalBundles");
      serializeBundles(doc, optionalElement, optional);
      rootElement.appendChild(optionalElement);
    }
    if ((definition.getOS() != null) || (definition.getWS() != null) || (definition.getArch() != null) || (definition.getNL() != null))
    {
      Element envElement = doc.createElement("environment");
      if (definition.getOS() != null)
      {
        Element element = doc.createElement("os");
        setTextContent(element, definition.getOS());
        envElement.appendChild(element);
      }
      if (definition.getWS() != null)
      {
        Element element = doc.createElement("ws");
        setTextContent(element, definition.getWS());
        envElement.appendChild(element);
      }
      if (definition.getArch() != null)
      {
        Element element = doc.createElement("arch");
        setTextContent(element, definition.getArch());
        envElement.appendChild(element);
      }
      if (definition.getNL() != null)
      {
        Element element = doc.createElement("nl");
        setTextContent(element, definition.getNL());
        envElement.appendChild(element);
      }
      rootElement.appendChild(envElement);
    }
    if (definition.getJREContainer() != null)
    {
      Element jreElement = doc.createElement("targetJRE");
      IPath path = definition.getJREContainer();
      jreElement.setAttribute("path", path.toPortableString());
      rootElement.appendChild(jreElement);
    }
    if ((definition.getVMArguments() != null) || (definition.getProgramArguments() != null))
    {
      Element argElement = doc.createElement("launcherArgs");
      if (definition.getVMArguments() != null)
      {
        Element element = doc.createElement("vmArgs");
        setTextContent(element, definition.getVMArguments());
        argElement.appendChild(element);
      }
      if (definition.getProgramArguments() != null)
      {
        Element element = doc.createElement("programArgs");
        setTextContent(element, definition.getProgramArguments());
        argElement.appendChild(element);
      }
      rootElement.appendChild(argElement);
    }
    NameVersionDescriptor[] implicitDependencies = definition.getImplicitDependencies();
    if ((implicitDependencies != null) && (implicitDependencies.length > 0))
    {
      Element implicit = doc.createElement("implicitDependencies");
      for (int i = 0; i < implicitDependencies.length; i++)
      {
        Element plugin = doc.createElement("plugin");
        plugin.setAttribute("id", implicitDependencies[i].getId());
        if (implicitDependencies[i].getVersion() != null) {
          plugin.setAttribute("version", implicitDependencies[i].getVersion());
        }
        implicit.appendChild(plugin);
      }
      rootElement.appendChild(implicit);
    }
    doc.appendChild(rootElement);
    DOMSource source = new DOMSource(doc);
    
    StreamResult outputTarget = new StreamResult(output);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty("method", "xml");
    transformer.setOutputProperty("indent", "yes");
    transformer.transform(source, outputTarget);
  }
  
  public static void initFromXML(ITargetDefinition definition, InputStream input)
    throws CoreException, ParserConfigurationException, SAXException, IOException
  {
    DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    parser.setErrorHandler(new DefaultHandler());
    Document doc = parser.parse(new InputSource(input));
    
    Element root = doc.getDocumentElement();
    if (!root.getNodeName().equalsIgnoreCase("target")) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.TargetDefinitionPersistenceHelper_0));
    }
    String version = null;
    NodeList list = doc.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 7)
      {
        ProcessingInstruction instruction = (ProcessingInstruction)node;
        if (instruction.getTarget() == "pde")
        {
          String data = instruction.getData();
          Pattern pattern = Pattern.compile("version=\"(.*)\"");
          Matcher matcher = pattern.matcher(data);
          if (matcher.matches())
          {
            version = matcher.group(1);
            break;
          }
        }
      }
    }
    if ((version == null) || (version.length() == 0)) {
      TargetPersistence36Helper.initFromDoc(definition, root);
    } else if (version.equals("3.6")) {
      TargetPersistence36Helper.initFromDoc(definition, root);
    } else if (version.equals("3.5")) {
      TargetPersistence35Helper.initFromDoc(definition, root);
    } else if (version.compareTo("3.4") <= 0) {
      TargetPersistence34Helper.initFromDoc(definition, root);
    }
  }
  
  static ITargetPlatformService getTargetPlatformService()
    throws CoreException
  {
    if (fTargetService == null)
    {
      fTargetService = (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
      if (fTargetService == null) {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.TargetDefinitionPersistenceHelper_1));
      }
    }
    return fTargetService;
  }
  
  static String getTextContent(Element element)
    throws DOMException
  {
    NodeList children = element.getChildNodes();
    StringBuffer result = new StringBuffer();
    for (int i = 0; i < children.getLength(); i++)
    {
      Node currentNode = children.item(i);
      if (currentNode.getNodeType() == 3) {
        result.append(currentNode.getNodeValue());
      }
    }
    return result.toString();
  }
  
  private static Element serializeBundleContainer(Document doc, AbstractBundleContainer container)
    throws CoreException
  {
    Element containerElement = doc.createElement("location");
    if (!(container instanceof IUBundleContainer)) {
      containerElement.setAttribute("path", container.getLocation(false));
    }
    containerElement.setAttribute("type", container.getType());
    if ((container instanceof FeatureBundleContainer))
    {
      containerElement.setAttribute("id", ((FeatureBundleContainer)container).getFeatureId());
      String version = ((FeatureBundleContainer)container).getFeatureVersion();
      if (version != null) {
        containerElement.setAttribute("version", version);
      }
    }
    else if ((container instanceof ProfileBundleContainer))
    {
      String configurationArea = ((ProfileBundleContainer)container).getConfigurationLocation();
      if (configurationArea != null) {
        containerElement.setAttribute("configuration", configurationArea);
      }
    }
    else if ((container instanceof IUBundleContainer))
    {
      IUBundleContainer iubc = (IUBundleContainer)container;
      containerElement.setAttribute("includeMode", iubc.getIncludeAllRequired() ? "planner" : "slicer");
      containerElement.setAttribute("includeAllPlatforms", Boolean.toString(iubc.getIncludeAllEnvironments()));
      containerElement.setAttribute("includeSource", Boolean.toString(iubc.getIncludeSource()));
      String[] ids = iubc.getIds();
      Version[] versions = iubc.getVersions();
      for (int i = 0; i < ids.length; i++)
      {
        Element unit = doc.createElement("unit");
        unit.setAttribute("id", ids[i]);
        unit.setAttribute("version", versions[i].toString());
        containerElement.appendChild(unit);
      }
      URI[] repositories = iubc.getRepositories();
      if (repositories != null) {
        for (int i = 0; i < repositories.length; i++)
        {
          Element repo = doc.createElement("repository");
          repo.setAttribute("location", repositories[i].toASCIIString());
          containerElement.appendChild(repo);
        }
      }
    }
    return containerElement;
  }
  
  private static void serializeBundles(Document doc, Element parent, NameVersionDescriptor[] bundles)
  {
    for (int j = 0; j < bundles.length; j++) {
      if (bundles[j].getType() == "feature")
      {
        Element includedBundle = doc.createElement("feature");
        includedBundle.setAttribute("id", bundles[j].getId());
        String version = bundles[j].getVersion();
        if (version != null) {
          includedBundle.setAttribute("version", version);
        }
        parent.appendChild(includedBundle);
      }
      else
      {
        Element includedBundle = doc.createElement("plugin");
        includedBundle.setAttribute("id", bundles[j].getId());
        String version = bundles[j].getVersion();
        if (version != null) {
          includedBundle.setAttribute("version", version);
        }
        parent.appendChild(includedBundle);
      }
    }
  }
  
  private static void setTextContent(Element element, String text)
    throws DOMException
  {
    Node child;
    while ((child = element.getFirstChild()) != null)
    {
      Node child;
      element.removeChild(child);
    }
    if ((text != null) && (text.length() > 0))
    {
      Text textNode = element.getOwnerDocument().createTextNode(text);
      element.appendChild(textNode);
    }
  }
}

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

import java.io.File;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetHandle;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;

public class TargetMetadataCollector
{
  public static URI[] getMetadataRepositories(ITargetDefinition definition)
    throws CoreException
  {
    if (definition == null)
    {
      ITargetPlatformService service = (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
      if (service == null) {
        return null;
      }
      ITargetHandle handle = service.getWorkspaceTargetHandle();
      definition = handle.getTargetDefinition();
    }
    Set repos = new HashSet();
    
    IBundleContainer[] containers = definition.getBundleContainers();
    if (containers != null) {
      for (int i = 0; i < containers.length; i++)
      {
        IBundleContainer currentContainer = containers[i];
        if ((currentContainer instanceof ProfileBundleContainer))
        {
          File profileLocation = ((ProfileBundleContainer)currentContainer).getProfileFileLocation();
          if (profileLocation != null) {
            repos.add(profileLocation.toURI());
          }
        }
        else if ((currentContainer instanceof IUBundleContainer))
        {
          URI[] locations = ((IUBundleContainer)currentContainer).getRepositories();
          if (locations != null) {
            for (int j = 0; j < locations.length; j++) {
              if (URIUtil.isFileURI(locations[j])) {
                repos.add(locations[j]);
              }
            }
          }
        }
      }
    }
    return (URI[])repos.toArray(new URI[repos.size()]);
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.NameVersionDescriptor;
import org.eclipse.pde.internal.core.util.VMUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TargetPersistence34Helper
{
  public static void initFromDoc(ITargetDefinition definition, Element root)
    throws CoreException
  {
    String name = root.getAttribute("name");
    if (name.length() > 0) {
      definition.setName(name);
    }
    AbstractBundleContainer oldStylePrimaryContainer = null;
    List bundleContainers = new ArrayList();
    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 1)
      {
        Element element = (Element)node;
        String nodeName = element.getNodeName();
        if (nodeName.equalsIgnoreCase("location"))
        {
          oldStylePrimaryContainer = (AbstractBundleContainer)deserializeBundleContainer(element);
        }
        else if (nodeName.equalsIgnoreCase("content"))
        {
          boolean useAll = Boolean.TRUE.toString().equalsIgnoreCase(element.getAttribute("useAllPlugins"));
          if (useAll) {
            bundleContainers.add(oldStylePrimaryContainer);
          }
          bundleContainers.addAll(deserializeBundleContainersFromOldStyleElement(element, definition, oldStylePrimaryContainer, useAll));
          if (bundleContainers.isEmpty()) {
            bundleContainers.add(oldStylePrimaryContainer);
          }
        }
        else if (nodeName.equalsIgnoreCase("environment"))
        {
          NodeList envEntries = element.getChildNodes();
          for (int j = 0; j < envEntries.getLength(); j++)
          {
            Node entry = envEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("os")) {
                definition.setOS(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("ws")) {
                definition.setWS(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("arch")) {
                definition.setArch(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("nl")) {
                definition.setNL(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("targetJRE"))
        {
          String text = element.getAttribute("path");
          if (text.length() == 0)
          {
            NodeList argEntries = element.getChildNodes();
            for (int j = 0; j < argEntries.getLength(); j++)
            {
              Node entry = argEntries.item(j);
              if (entry.getNodeType() == 1)
              {
                Element currentElement = (Element)entry;
                IPath path = null;
                if (currentElement.getNodeName().equalsIgnoreCase("execEnv"))
                {
                  IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
                  if (env != null) {
                    path = JavaRuntime.newJREContainerPath(env);
                  }
                }
                else if (currentElement.getNodeName().equalsIgnoreCase("jreName"))
                {
                  String vmName = TargetDefinitionPersistenceHelper.getTextContent(currentElement);
                  IVMInstall vmInstall = VMUtil.getVMInstall(vmName);
                  if (vmInstall != null) {
                    path = JavaRuntime.newJREContainerPath(vmInstall);
                  }
                }
                definition.setJREContainer(path);
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("launcherArgs"))
        {
          NodeList argEntries = element.getChildNodes();
          for (int j = 0; j < argEntries.getLength(); j++)
          {
            Node entry = argEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("programArgs")) {
                definition.setProgramArguments(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("vmArgs")) {
                definition.setVMArguments(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("implicitDependencies"))
        {
          NodeList implicitEntries = element.getChildNodes();
          List implicit = new ArrayList(implicitEntries.getLength());
          for (int j = 0; j < implicitEntries.getLength(); j++)
          {
            Node entry = implicitEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("plugin"))
              {
                String version = currentElement.getAttribute("version");
                NameVersionDescriptor bundle = new NameVersionDescriptor(currentElement.getAttribute("id"), version.length() > 0 ? version : null);
                implicit.add(bundle);
              }
            }
          }
          definition.setImplicitDependencies((NameVersionDescriptor[])implicit.toArray(new NameVersionDescriptor[implicit.size()]));
        }
      }
    }
    definition.setBundleContainers((IBundleContainer[])bundleContainers.toArray(new IBundleContainer[bundleContainers.size()]));
  }
  
  private static IBundleContainer deserializeBundleContainer(Element location)
    throws CoreException
  {
    String def = location.getAttribute("useDefault");
    String path = null;
    String type = null;
    if ((def.length() > 0) && (Boolean.valueOf(def).booleanValue()))
    {
      path = "${eclipse_home}";
      type = "Profile";
    }
    else
    {
      path = location.getAttribute("path");
    }
    if (type == null) {
      if (path.endsWith("plugins")) {
        type = "Directory";
      } else {
        type = "Profile";
      }
    }
    IBundleContainer container = null;
    if ("Directory".equals(type))
    {
      container = TargetDefinitionPersistenceHelper.getTargetPlatformService().newDirectoryContainer(path);
    }
    else if ("Profile".equals(type))
    {
      String configArea = location.getAttribute("configuration");
      container = TargetDefinitionPersistenceHelper.getTargetPlatformService().newProfileContainer(path, configArea.length() > 0 ? configArea : null);
    }
    return container;
  }
  
  private static List deserializeBundleContainersFromOldStyleElement(Element content, ITargetDefinition definition, AbstractBundleContainer primaryContainer, boolean useAll)
    throws CoreException
  {
    List containers = new ArrayList();
    NodeList list = content.getChildNodes();
    List included = new ArrayList(list.getLength());
    List optional = new ArrayList();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 1)
      {
        Element element = (Element)node;
        if ((!useAll) && (element.getNodeName().equalsIgnoreCase("plugins")))
        {
          NodeList plugins = element.getChildNodes();
          for (int j = 0; j < plugins.getLength(); j++)
          {
            Node lNode = plugins.item(j);
            if (lNode.getNodeType() == 1)
            {
              Element plugin = (Element)lNode;
              String id = plugin.getAttribute("id");
              boolean isOptional = plugin.getAttribute("optional").equalsIgnoreCase(Boolean.toString(true));
              if (id.length() > 0)
              {
                NameVersionDescriptor info = new NameVersionDescriptor(id, null);
                if (isOptional) {
                  optional.add(info);
                } else {
                  included.add(info);
                }
              }
            }
          }
          if ((included.size() > 0) || (optional.size() > 0)) {
            containers.add(primaryContainer);
          }
        }
        else if (element.getNodeName().equalsIgnoreCase("extraLocations"))
        {
          NodeList locations = element.getChildNodes();
          for (int j = 0; j < locations.getLength(); j++)
          {
            Node lNode = locations.item(j);
            if (lNode.getNodeType() == 1)
            {
              Element location = (Element)lNode;
              String path = location.getAttribute("path");
              if (path.length() > 0) {
                containers.add(TargetDefinitionPersistenceHelper.getTargetPlatformService().newDirectoryContainer(path));
              }
            }
          }
        }
        else if ((!useAll) && (element.getNodeName().equalsIgnoreCase("features")))
        {
          NodeList features = element.getChildNodes();
          for (int j = 0; j < features.getLength(); j++)
          {
            Node lNode = features.item(j);
            if (lNode.getNodeType() == 1)
            {
              Element feature = (Element)lNode;
              String id = feature.getAttribute("id");
              if ((id.length() > 0) && 
                (primaryContainer != null)) {
                containers.add(TargetDefinitionPersistenceHelper.getTargetPlatformService().newFeatureContainer(primaryContainer.getLocation(false), id, null));
              }
            }
          }
        }
      }
    }
    if ((!useAll) && ((included.size() > 0) || (optional.size() > 0)))
    {
      if (included.size() > 0) {
        definition.setIncluded((NameVersionDescriptor[])included.toArray(new NameVersionDescriptor[included.size()]));
      }
      if (optional.size() > 0) {
        definition.setOptional((NameVersionDescriptor[])optional.toArray(new NameVersionDescriptor[optional.size()]));
      }
    }
    return containers;
  }
}

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

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.NameVersionDescriptor;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TargetPersistence35Helper
{
  public static void initFromDoc(ITargetDefinition definition, Element root)
    throws CoreException
  {
    String name = root.getAttribute("name");
    if (name.length() > 0) {
      definition.setName(name);
    }
    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 1)
      {
        Element element = (Element)node;
        String nodeName = element.getNodeName();
        if (nodeName.equalsIgnoreCase("locations"))
        {
          NodeList locations = element.getChildNodes();
          for (int j = 0; j < locations.getLength(); j++)
          {
            Node locationNode = locations.item(j);
            if (locationNode.getNodeType() == 1)
            {
              Element locationElement = (Element)locationNode;
              if (locationElement.getNodeName().equalsIgnoreCase("location")) {
                deserializeBundleContainer(definition, locationElement);
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("environment"))
        {
          NodeList envEntries = element.getChildNodes();
          for (int j = 0; j < envEntries.getLength(); j++)
          {
            Node entry = envEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("os")) {
                definition.setOS(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("ws")) {
                definition.setWS(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("arch")) {
                definition.setArch(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("nl")) {
                definition.setNL(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("targetJRE"))
        {
          String text = element.getAttribute("path");
          if (text.length() != 0)
          {
            IPath path = Path.fromPortableString(text);
            definition.setJREContainer(path);
          }
        }
        else if (nodeName.equalsIgnoreCase("launcherArgs"))
        {
          NodeList argEntries = element.getChildNodes();
          for (int j = 0; j < argEntries.getLength(); j++)
          {
            Node entry = argEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("programArgs")) {
                definition.setProgramArguments(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              } else if (currentElement.getNodeName().equalsIgnoreCase("vmArgs")) {
                definition.setVMArguments(TargetDefinitionPersistenceHelper.getTextContent(currentElement));
              }
            }
          }
        }
        else if (nodeName.equalsIgnoreCase("implicitDependencies"))
        {
          NodeList implicitEntries = element.getChildNodes();
          List implicit = new ArrayList(implicitEntries.getLength());
          for (int j = 0; j < implicitEntries.getLength(); j++)
          {
            Node entry = implicitEntries.item(j);
            if (entry.getNodeType() == 1)
            {
              Element currentElement = (Element)entry;
              if (currentElement.getNodeName().equalsIgnoreCase("plugin"))
              {
                String version = currentElement.getAttribute("version");
                NameVersionDescriptor bundle = new NameVersionDescriptor(currentElement.getAttribute("id"), version.length() > 0 ? version : null);
                implicit.add(bundle);
              }
            }
          }
          definition.setImplicitDependencies((NameVersionDescriptor[])implicit.toArray(new NameVersionDescriptor[implicit.size()]));
        }
      }
    }
  }
  
  private static void deserializeBundleContainer(ITargetDefinition definition, Element location)
    throws CoreException
  {
    String path = location.getAttribute("path");
    String type = location.getAttribute("type");
    if (type.length() == 0) {
      if (path.endsWith("plugins")) {
        type = "Directory";
      } else {
        type = "Profile";
      }
    }
    IBundleContainer container = null;
    if ("Directory".equals(type))
    {
      container = TargetDefinitionPersistenceHelper.getTargetPlatformService().newDirectoryContainer(path);
    }
    else if ("Profile".equals(type))
    {
      String configArea = location.getAttribute("configuration");
      container = TargetDefinitionPersistenceHelper.getTargetPlatformService().newProfileContainer(path, configArea.length() > 0 ? configArea : null);
    }
    else if ("Feature".equals(type))
    {
      String version = location.getAttribute("version");
      container = TargetDefinitionPersistenceHelper.getTargetPlatformService().newFeatureContainer(path, location.getAttribute("id"), version.length() > 0 ? version : null);
    }
    else if ("InstallableUnit".equals(type))
    {
      String includeMode = location.getAttribute("includeMode");
      String includeAllPlatforms = location.getAttribute("includeAllPlatforms");
      NodeList list = location.getChildNodes();
      List ids = new ArrayList();
      List versions = new ArrayList();
      List repos = new ArrayList();
      for (int i = 0; i < list.getLength(); i++)
      {
        Node node = list.item(i);
        if (node.getNodeType() == 1)
        {
          Element element = (Element)node;
          if (element.getNodeName().equalsIgnoreCase("unit"))
          {
            String id = element.getAttribute("id");
            if (id.length() > 0)
            {
              String version = element.getAttribute("version");
              if (version.length() > 0)
              {
                ids.add(id);
                versions.add(version);
              }
            }
          }
          else if (element.getNodeName().equalsIgnoreCase("repository"))
          {
            String loc = element.getAttribute("location");
            if (loc.length() > 0) {
              try
              {
                repos.add(new URI(loc));
              }
              catch (URISyntaxException localURISyntaxException) {}
            }
          }
        }
      }
      String[] iuIDs = (String[])ids.toArray(new String[ids.size()]);
      String[] iuVer = (String[])versions.toArray(new String[versions.size()]);
      URI[] uris = (URI[])repos.toArray(new URI[repos.size()]);
      int flags = 1;
      if ((includeMode != null) && (includeMode.trim().length() > 0) && 
        (includeMode.equals("slicer"))) {
        flags = 0;
      }
      flags |= (Boolean.valueOf(includeAllPlatforms).booleanValue() ? 2 : 0);
      container = new IUBundleContainer(iuIDs, iuVer, uris, flags);
    }
    NodeList list = location.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 1)
      {
        Element element = (Element)node;
        if (element.getNodeName().equalsIgnoreCase("includeBundles"))
        {
          NameVersionDescriptor[] included = deserializeBundles(element);
          NameVersionDescriptor[] currentIncluded = definition.getIncluded();
          if ((currentIncluded == null) || (currentIncluded.length == 0))
          {
            definition.setIncluded(included);
          }
          else
          {
            NameVersionDescriptor[] newIncluded = new NameVersionDescriptor[currentIncluded.length + included.length];
            System.arraycopy(currentIncluded, 0, newIncluded, 0, currentIncluded.length);
            System.arraycopy(included, 0, newIncluded, currentIncluded.length, included.length);
            definition.setIncluded(newIncluded);
          }
        }
        else if (element.getNodeName().equalsIgnoreCase("optionalBundles"))
        {
          NameVersionDescriptor[] optional = deserializeBundles(element);
          NameVersionDescriptor[] currentOptional = definition.getIncluded();
          if ((currentOptional == null) || (currentOptional.length == 0))
          {
            definition.setIncluded(optional);
          }
          else
          {
            NameVersionDescriptor[] newOptional = new NameVersionDescriptor[currentOptional.length + optional.length];
            System.arraycopy(currentOptional, 0, newOptional, 0, currentOptional.length);
            System.arraycopy(optional, 0, newOptional, currentOptional.length, optional.length);
            definition.setIncluded(newOptional);
          }
        }
      }
    }
    IBundleContainer[] currentContainers = definition.getBundleContainers();
    if ((currentContainers == null) || (currentContainers.length == 0))
    {
      definition.setBundleContainers(new IBundleContainer[] { container });
    }
    else
    {
      IBundleContainer[] newContainers = new IBundleContainer[currentContainers.length + 1];
      System.arraycopy(currentContainers, 0, newContainers, 0, currentContainers.length);
      newContainers[currentContainers.length] = container;
      definition.setBundleContainers(newContainers);
    }
  }
  
  private static NameVersionDescriptor[] deserializeBundles(Element bundleContainer)
  {
    NodeList nodes = bundleContainer.getChildNodes();
    List bundles = new ArrayList(nodes.getLength());
    for (int j = 0; j < nodes.getLength(); j++)
    {
      Node include = nodes.item(j);
      if (include.getNodeType() == 1)
      {
        Element includeElement = (Element)include;
        if (includeElement.getNodeName().equalsIgnoreCase("plugin"))
        {
          String id = includeElement.getAttribute("id");
          String version = includeElement.getAttribute("version");
          bundles.add(new NameVersionDescriptor(id, version.length() > 0 ? version : null));
        }
      }
    }
    return (NameVersionDescriptor[])bundles.toArray(new NameVersionDescriptor[bundles.size()]);
  }
}

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

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.NameVersionDescriptor;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TargetPersistence36Helper
{
  public static void initFromDoc(ITargetDefinition definition, Element root)
    throws CoreException
  {
    String name = root.getAttribute("name");
    if (name.length() > 0) {
      definition.setName(name);
    }
    String mode = root.getAttribute("includeMode");
    if (mode.equalsIgnoreCase("feature")) {
      ((TargetDefinition)definition).setUIMode(1);
    }
    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
    {
      Node node = list.item(i);
      if (node.getNodeType() == 1)
      {
        Element element = (Element)node;
        String nodeName = element.getNodeName();
        if (nodeName.equalsIgnoreCase("locations"))
        {
          NodeList locations = element.getChildNodes();
          List bundleContainers = new ArrayList();
          for (int j = 0; j < locations.getLength(); j++)
          {
            Node locationNode = locations.item(j);
            if (locationNode.getNodeType() == 1)
            {
              Element locationElement = (Element)locationNode;
              if (locationElement.getNodeName().equalsIgnoreCase("location")) {
                bundleContainers.add(deserializeBundleContainer(locationElement));
              }
            }
          }
          definition.setBundleContainers((IBundleContainer[])bundleContainers.toArray(new IBundleContainer[bundleContainers.size()]));
        }
        else if (nodeName.equalsIgnoreCase("includeBundles"))
        {
          NodeList children = element.getChildNodes();
          List included = new ArrayList();
          for (int j = 0; j < children.getLength(); j++)
          {
            Node child = children.item(j);
            if (child.getNodeType() == 1)
            {
              Element includeElement = (Element)child;
              if (includeElement.getNodeName().equalsIgnoreCase("plugin"))
              {
                String id = includeElement.getAttribute("id");
                String version = includeElement.getAttribute("version");
                included.add(new NameVersionDescriptor(id, version.length() > 0 ? version : null));
              }
              else if (includeElement.getNodeName().equalsIgnoreCase("feature"))
              {
                String id = includeElement.getAttribute("id");
                String version = includeElement.getAttribute("version");
                included.add(new NameVersionDescriptor(id, version.length() > 0 ? version : null, "feature"));
              }
            }
          }
          definition.setIncluded((NameVersionDescriptor[])included.toArray(new NameVersionDescriptor[included.size()]));
        }
        else if (nodeName.equalsIgnoreCase("optionalBundles"))
        {
          NodeList children = element.getChildNodes();
          List optional = new ArrayList();
          for (int j = 0; j < children.getLength(); j++)
          {
            Node child = children.item(j);
            if (child.getNodeType() == 1)
            {
              Element optionalElement = (Element)child;
              if (optionalElement.getNodeName().equalsIgnoreCase("plugin"))
              {
                String id = optionalElement.getAttribute("id");
                String version = optionalElement.getAttribute("version");
                optional.add(new NameVersionDescriptor(id, version.length() > 0 ? version : null));
              }
            }
          }
          definition.setOptional((NameVersionDescriptor[])optional.toArray(new NameVersionDescriptor[optional.size()]));
        }
        else if (nodeName.equalsIgnoreCase("environment"))
        {
          NodeList envEntries = element.getChildNodes();
          for (int j = 0; j < envE
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