Exemplo n.º 1
0
  /**
   * Determine what nodes are affected (i.e. contain references to the items being deleted), if
   * these nodes are deleted.
   *
   * @param affectedNodes
   * @param edNode
   */
  public Map<EditableObjectNode, List<EditableObjectNode>> findAffectedNodes(
      List<EditableObjectNode> nodesToRemove) {
    Map<EditableObjectNode, List<EditableObjectNode>> referenceLinks =
        new HashMap<EditableObjectNode, List<EditableObjectNode>>();

    for (TreeNode node : nodesToRemove) {
      // find references to this node and its children
      for (Enumeration<?> en = ((DefaultMutableTreeNode) node).preorderEnumeration();
          en != null && en.hasMoreElements(); ) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) en.nextElement();
        if (child instanceof EditableObjectNode) {
          List<EditableObjectNode> references = findReferences((EditableObjectNode) child);
          for (EditableObjectNode referencedNode : references) {
            // add reference node to map
            List<EditableObjectNode> refersToList = referenceLinks.get(referencedNode);
            if (refersToList == null) {
              refersToList = new ArrayList<EditableObjectNode>();
              referenceLinks.put(referencedNode, refersToList);
            }
            // add child to the "refersTo" list
            if (!refersToList.contains(child)) {
              refersToList.add((EditableObjectNode) child);
            }
          }
        }
      }
    }

    // ignore references within the nodes we're removing
    for (EditableObjectNode node : nodesToRemove) {
      for (Enumeration<?> en = ((DefaultMutableTreeNode) node).preorderEnumeration();
          en != null && en.hasMoreElements(); ) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) en.nextElement();
        referenceLinks.remove(child);
      }

      // special case - don't include MessageSyntaxModelNode if we're removing the root
      if (node.getParent() instanceof MessageSyntaxModelNode) {
        MessageSyntaxModelNode syntaxModelNode = (MessageSyntaxModelNode) node.getParent();
        MessageSyntaxModel syntaxModel = (MessageSyntaxModel) syntaxModelNode.getUserObject();
        if (syntaxModel.getRoot() == node.getUserObject()) {
          referenceLinks.remove(syntaxModelNode);
        }
      }
    }

    return referenceLinks;
  }
Exemplo n.º 2
0
  /**
   * toXMI - takes a root MDMI node object and writes it out into a blank MDMI map.
   *
   * @param path The path of the output MDMI map.
   * @param root The root MDMI node object that will be attached to the resulting Message Model.
   */
  public static void toXMI(String path, Node root) {
    List<MessageGroup> messageGroups = new ArrayList<MessageGroup>();
    MessageGroup messageGroup = new MessageGroup();
    MessageModel messageModel = new MessageModel();
    MessageSyntaxModel syntaxModel = new MessageSyntaxModel();

    syntaxModel.setRoot(root);
    messageModel.setSyntaxModel(syntaxModel);
    messageGroup.addModel(messageModel);
    messageGroups.add(messageGroup);

    try {
      XMIWriterDirect.write(path, messageGroups);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }