001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022:
023: package org.jboss.test.classloader.leak.clstore;
024:
025: import java.util.ArrayList;
026: import java.util.Collections;
027: import java.util.List;
028:
029: /**
030: * A node (i.e. line item) in a {@link LeakAnalyzer} report.
031: *
032: * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
033: * @version $Revision: 1.1 $
034: */
035: public class ReferenceReportNode {
036: private String message;
037: private List<ReferenceReportNode> children = new ArrayList<ReferenceReportNode>();;
038: private ReferenceReportNode parent;
039: private Boolean critical = Boolean.TRUE;
040: private int nonCriticalChildren = 0;
041:
042: public ReferenceReportNode() {
043: }
044:
045: public ReferenceReportNode(String msg) {
046: this .message = msg;
047: }
048:
049: public void addChild(ReferenceReportNode child) {
050: children.add(child);
051: child.setParent(this );
052: critical = null;
053: }
054:
055: public void removeBranch() {
056: if (parent != null)
057: parent.removeChild(this );
058: }
059:
060: private void removeChild(ReferenceReportNode child) {
061: children.remove(child);
062: if (children.size() == 0)
063: removeBranch();
064: }
065:
066: public boolean isLeaf() {
067: return children.size() == 0;
068: }
069:
070: public boolean isCritical() {
071: if (critical != null) {
072: return critical.booleanValue();
073: }
074: return (children.size() - nonCriticalChildren > 0);
075: }
076:
077: public void markNonCritical() {
078: critical = Boolean.FALSE;
079: if (parent != null)
080: parent.markChildNonCritical();
081: }
082:
083: private void markChildNonCritical() {
084: nonCriticalChildren++;
085: if (!isCritical() && parent != null)
086: parent.markChildNonCritical();
087: }
088:
089: public List<ReferenceReportNode> getChildren() {
090: return Collections.unmodifiableList(children);
091: }
092:
093: public ReferenceReportNode getParent() {
094: return parent;
095: }
096:
097: private void setParent(ReferenceReportNode parent) {
098: this .parent = parent;
099: }
100:
101: public String getMessage() {
102: return message;
103: }
104:
105: public void setMessage(String msg) {
106: this.message = msg;
107: }
108: }
|