コード例 #1
0
  /**
   * Returns the CSPEC base that contains the top element attribute overrides and all pure additions
   *
   * @return A Cspec that acts as the base for the extension
   */
  public void alterTopElement(CSpecBuilder bld) throws CoreException {
    Version extVersion = base.getVersion();
    if (extVersion != null) bld.setVersion(extVersion);

    String ctype = base.getComponentTypeID();
    if (ctype != null) bld.setComponentTypeID(ctype);
  }
コード例 #2
0
  public void alterCSpec(CSpecBuilder cspecBuilder) throws CoreException {
    for (String removedDep : removedDependencies) {
      cspecBuilder.getRequiredDependency(new ComponentRequest(removedDep, null, null));
      cspecBuilder.removeDependency(removedDep);
    }

    for (AlterDependency alterDep : alteredDependencies.values())
      alterDep.alterDependency(cspecBuilder.getRequiredDependency(alterDep));

    Collection<? extends IComponentRequest> addedDeps = base.getDependencies();
    for (IComponentRequest addedDep : addedDeps) cspecBuilder.addDependency(addedDep);

    for (IGenerator addedGenerator : base.getGeneratorList()) {
      GeneratorBuilder bld = cspecBuilder.createGeneratorBuilder();
      bld.initFrom(addedGenerator);
      cspecBuilder.addGenerator(bld);
    }

    for (String removedAttr : removedAttributes) {
      cspecBuilder.getRequiredAttribute(removedAttr);
      cspecBuilder.removeAttribute(removedAttr);
    }

    for (Map.Entry<String, String> renamedAttribute : renamedAttributes.entrySet()) {
      String oldName = renamedAttribute.getKey();
      AttributeBuilder bld = cspecBuilder.getRequiredAttribute(oldName);
      bld.setName(renamedAttribute.getValue());
      cspecBuilder.removeAttribute(oldName);
      cspecBuilder.addAttribute(bld);
    }

    for (AlterAttribute<?> alterAttr : alteredAttributes.values())
      alterAttr.alterAttribute(
          (TopLevelAttributeBuilder) cspecBuilder.getRequiredAttribute(alterAttr.getName()));

    Map<String, ? extends IAttribute> addedAttrs = base.getAttributes();
    for (IAttribute addedAttr : addedAttrs.values()) {
      AttributeBuilder attrBld;
      if (addedAttr instanceof IActionArtifact)
        attrBld = cspecBuilder.createActionArtifactBuilder();
      else if (addedAttr instanceof IAction) attrBld = cspecBuilder.createActionBuilder();
      else if (addedAttr instanceof IArtifact) attrBld = cspecBuilder.createArtifactBuilder();
      else attrBld = cspecBuilder.createGroupBuilder();
      attrBld.initFrom(addedAttr);
      cspecBuilder.addAttribute(attrBld);
    }

    // On the top element, we never override a value with NULL unless it is
    // explicitly set to the string "null"
    //
    cspecBuilder.setComponentTypeID(
        overrideCheckNull(cspecBuilder.getComponentTypeID(), base.getComponentTypeID()));
    cspecBuilder.setVersion(overrideCheckNull(cspecBuilder.getVersion(), base.getVersion()));

    Documentation origDoc = cspecBuilder.getDocumentation();
    Documentation baseDoc = base.getDocumentation();
    cspecBuilder.setDocumentation(origDoc == null ? baseDoc : origDoc.merge(baseDoc));
  }
コード例 #3
0
  /**
   * We will initialize file contents with a sample text.
   *
   * @throws SAXException
   */
  @Override
  protected InputStream openContentStream(String containerName, String fileName) {
    String name = containerName;
    int lastSlash = name.lastIndexOf('/');
    if (lastSlash >= 0) name = name.substring(lastSlash + 1);

    CSpecBuilder builder = new CSpecBuilder();
    builder.setName(name);
    builder.setComponentTypeID(INIT_COMPONENT_TYPE);
    builder.setVersion(Version.parseVersion(INIT_VERSION_STRING));

    CSpec cspec = new CSpec(builder);

    AccessibleByteArrayOutputStream bld = new AccessibleByteArrayOutputStream();
    try {
      Utils.serialize(cspec, bld);
    } catch (SAXException e) {
      throw new RuntimeException(
          Messages.cannot_create_a_new_buckminster_component_specification_file, e);
    }

    return bld.getInputStream();
  }