private void inspectExtension(ISchema schema, IPluginParent parent, IFile file) {
    IPluginObject[] children = parent.getChildren();

    if (parent instanceof PluginElementNode && parent.getParent() instanceof PluginElementNode) {
      // check if this node corresponds to a Java type attribute which would have been defined has
      // an element
      PluginElementNode node = (PluginElementNode) parent;
      PluginElementNode parentNode = (PluginElementNode) parent.getParent();
      ISchemaElement schemaElement = schema.findElement(parentNode.getName());
      if (schemaElement != null) {
        ISchemaAttribute attInfo = schemaElement.getAttribute(node.getName());
        if (attInfo != null && attInfo.getKind() == IMetaAttribute.JAVA)
          checkMatch(node.getAttribute("class"), file); // $NON-NLS-1$
      }
    }

    for (int i = 0; i < children.length; i++) {
      IPluginElement child = (IPluginElement) children[i];
      ISchemaElement schemaElement = schema.findElement(child.getName());
      if (schemaElement != null) {
        IPluginAttribute[] attributes = child.getAttributes();
        for (int j = 0; j < attributes.length; j++) {
          IPluginAttribute attr = attributes[j];
          ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName());
          if (attInfo != null
              && attInfo.getKind() == IMetaAttribute.JAVA
              && attr instanceof IDocumentAttributeNode) checkMatch(attr, file);
        }
      }
      inspectExtension(schema, child, file);
    }
  }
Exemple #2
0
  protected void createChange(IPluginModelBase model) {
    Object node = findNode(model);
    if (!(node instanceof IPluginObject)) return;
    try {
      IPluginObject pluginObject = (IPluginObject) node;
      IPluginObject parent = pluginObject.getParent();
      if (parent instanceof IPluginParent) ((IPluginParent) parent).remove(pluginObject);
      else if (parent instanceof PluginBaseNode) ((PluginBaseNode) parent).remove(pluginObject);
      else if (pluginObject instanceof PluginAttribute) {
        PluginAttribute attr = (PluginAttribute) pluginObject;
        attr.getEnclosingElement().setXMLAttribute(attr.getName(), null);
      }

    } catch (CoreException e) {
    }
  }
  private void executeAdd(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.add((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.add((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.add((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.add((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).addContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).add(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.add(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel pluginModel = (BundlePluginModel) aggModel;
              RequireBundleObject requireBundle = (RequireBundleObject) element;
              pluginBase = pluginModel.getPluginBase();
              String elementValue = requireBundle.getValue();
              IPluginImport importNode = null;
              if (pluginModel.getPluginFactory() instanceof BundlePluginModelBase)
                importNode =
                    ((BundlePluginModelBase) pluginModel.getPluginFactory())
                        .createImport(elementValue);
              String version =
                  ((RequireBundleObject) element).getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
              IManifestHeader header =
                  bundleModel.getBundle().getManifestHeader(Constants.REQUIRE_BUNDLE);
              int bundleManifestVersion =
                  BundlePluginBase.getBundleManifestVersion(
                      ((RequireBundleHeader) header).getBundle());
              boolean option =
                  (bundleManifestVersion > 1)
                      ? Constants.RESOLUTION_OPTIONAL.equals(
                          requireBundle.getDirective(Constants.RESOLUTION_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.OPTIONAL_ATTRIBUTE)); // $NON-NLS-1$;
              boolean exported =
                  (bundleManifestVersion > 1)
                      ? Constants.VISIBILITY_REEXPORT.equals(
                          requireBundle.getDirective(Constants.VISIBILITY_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.REPROVIDE_ATTRIBUTE)); // $NON-NLS-1$;
              if (importNode != null) {
                importNode.setVersion(version);
                importNode.setOptional(option);
                importNode.setReexported(exported);
              }
              if (pluginBase instanceof BundlePluginBase && importNode != null)
                ((BundlePluginBase) pluginBase).add(importNode);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }
  private void executeRemove(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.remove((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.remove((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.remove((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.remove((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).removeContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).remove(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.remove(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel mod = (BundlePluginModel) aggModel;
              pluginBase = mod.getPluginBase();
              IPluginImport[] imports = pluginBase.getImports();
              IPluginImport currentImport = null;
              for (IPluginImport pluginImport : imports) {
                String elementValue = ((RequireBundleObject) element).getValue();
                if (pluginImport.getId().equals(elementValue)) {
                  currentImport = pluginImport;
                  break;
                }
              }
              IPluginImport[] plugins = {currentImport};
              if (pluginBase instanceof BundlePluginBase && currentImport != null)
                ((BundlePluginBase) pluginBase).remove(plugins);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }