예제 #1
0
  /**
   * Get the set of Java Projects
   *
   * @param project the compapp project
   * @param extensionNamespace
   * @param elementName
   * @param attributeName
   * @return the set of Java Projects
   */
  private static Set<String> collectCasaPortExtensionAttributes(
      JbiProject project, String extensionNamespace, String elementName, String attributeName) {

    Set<String> ret = new HashSet<String>();

    FileObject casaFO = CasaHelper.getCasaFileObject(project, true);
    if (casaFO == null) {
      return ret;
    }

    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      factory.setValidating(false);
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document casaDocument = builder.parse(casaFO.getInputStream());

      NodeList casaPorts = casaDocument.getElementsByTagName(CASA_PORT_ELEM_NAME);

      for (int i = 0; i < casaPorts.getLength(); i++) {
        Element casaPort = (Element) casaPorts.item(i);

        NodeList extElements = casaPort.getElementsByTagNameNS(extensionNamespace, elementName);
        for (int j = 0; j < extElements.getLength(); j++) {
          Element extElement = (Element) extElements.item(j);
          String attributeValue = extElement.getAttribute(attributeName);
          ret.add(attributeValue);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ret;
  }
예제 #2
0
  /**
   * Updates CASA FileObject with service engine service unit info defined in the project
   * properties.
   *
   * @param project a JBI project
   * @param properties project properties (may not been persisted yet)
   */
  public static void updateCasaWithJBIModules(JbiProject project, JbiProjectProperties properties) {

    FileObject casaFO = CasaHelper.getCasaFileObject(project, true);
    if (casaFO == null) {
      return;
    }

    try {
      boolean modified = false; // whether casa is modified

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      factory.setValidating(false);
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document casaDocument = builder.parse(casaFO.getInputStream());

      Element sus =
          (Element)
              casaDocument.getElementsByTagName(CasaConstants.CASA_SERVICE_UNITS_ELEM_NAME).item(0);
      NodeList seSUs =
          sus.getElementsByTagName(CasaConstants.CASA_SERVICE_ENGINE_SERVICE_UNIT_ELEM_NAME);

      @SuppressWarnings("unchecked")
      List<VisualClassPathItem> newContentList =
          (List) properties.get(JbiProjectProperties.JBI_CONTENT_ADDITIONAL);
      @SuppressWarnings("unchecked")
      List<String> newTargetIDs = (List) properties.get(JbiProjectProperties.JBI_CONTENT_COMPONENT);

      List<String> newProjectNameList = new ArrayList<String>();
      for (VisualClassPathItem newContent : newContentList) {
        newProjectNameList.add(newContent.getProjectName());
      }

      List<String> sesuNames = new ArrayList<String>();
      for (int i = 0; i < seSUs.getLength(); i++) {
        Element seSU = (Element) seSUs.item(i);
        String unitName = seSU.getAttribute(CasaConstants.CASA_UNIT_NAME_ATTR_NAME);
        sesuNames.add(unitName);
      }

      // Remove deleted service units from casa
      for (int i = 0; i < seSUs.getLength(); i++) {
        Element seSU = (Element) seSUs.item(i);

        // skip external unknown SUs
        String internal = seSU.getAttribute(CasaConstants.CASA_INTERNAL_ATTR_NAME);
        String unknown = seSU.getAttribute(CasaConstants.CASA_UNKNOWN_ATTR_NAME);
        if ("false".equalsIgnoreCase(internal) && "true".equals(unknown)) { // NOI18N
          continue;
        }

        String projName = seSU.getAttribute(CasaConstants.CASA_UNIT_NAME_ATTR_NAME);
        if (!newProjectNameList.contains(projName)) {
          sus.removeChild(seSU);
          modified = true;
          // System.out.println("removing old su: " + projName);
        }
      }

      // Add new service units to casa
      List<String> externalSuNames = project.getExternalServiceUnitNames();
      for (VisualClassPathItem artifact : newContentList) {
        String projName = artifact.getProjectName();
        String artifactName = artifact.toString();

        if (!sesuNames.contains(projName)) {
          String targetCompID = "unknown"; // NOI18N
          for (int j = 0; j < newContentList.size(); j++) {
            if (newContentList.get(j).toString().equals(artifactName)) {
              targetCompID = newTargetIDs.get(j);
              break;
            }
          }
          Element seSU =
              casaDocument.createElement(CasaConstants.CASA_SERVICE_ENGINE_SERVICE_UNIT_ELEM_NAME);
          seSU.setAttribute(CasaConstants.CASA_X_ATTR_NAME, "-1"); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_Y_ATTR_NAME, "-1"); // NOI18N
          seSU.setAttribute(
              CasaConstants.CASA_INTERNAL_ATTR_NAME,
              externalSuNames.contains(projName) ? "false" : "true"); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_DEFINED_ATTR_NAME, "false"); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_UNKNOWN_ATTR_NAME, "false"); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_NAME_ATTR_NAME, projName); // NOI18N  // FIXME
          seSU.setAttribute(CasaConstants.CASA_UNIT_NAME_ATTR_NAME, projName); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_COMPONENT_NAME_ATTR_NAME, targetCompID); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_DESCRIPTION_ATTR_NAME, "some description"); // NOI18N
          seSU.setAttribute(CasaConstants.CASA_ARTIFACTS_ZIP_ATTR_NAME, artifactName);

          sus.appendChild(seSU);
          modified = true;
          // System.out.println("Adding new su: " + projName);
        }
      }

      if (modified) {
        // System.out.println("CasaHelper: starting writing to CASA (Thread:" +
        // Thread.currentThread().getName() + ")");
        XmlUtil.writeToFileObject(casaFO, casaDocument);
        // System.out.println("CasaHelper: finished writing to CASA (Thread:" +
        // Thread.currentThread().getName() + ")");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }