View Javadoc
1 /*** 2 * Perspective.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 20.01.2003 pko creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.graph; 31 32 33 import att.grappa.Graph; 34 import java.io.StringWriter; 35 import java.util.ArrayList; 36 import java.util.Iterator; 37 import org.apache.log4j.Logger; 38 39 /*** 40 * A graph representing dependencies in an analyzed project can be 41 * vieved using different perspectives. A perspective may simplyfy the 42 * graph in a complex project. A perspective has one LayerOrder which 43 * defines layers, multiple filters that filter packages which are not 44 * interesting for the user and multiple aggregators which aggregate 45 * several packages into one component. 46 * 47 * @author Pawel Kowalski 48 * @version 1.0-beta 49 */ 50 public class Perspective extends AbstractGraphProcessor { 51 52 /*** 53 * Log4j Logger. 54 */ 55 private static final Logger LOG = Logger.getLogger(Perspective.class); 56 57 /*** 58 * A default Perspective. 59 */ 60 public static final Perspective DEFAULT_PERSPECTIVE = new Perspective("Default", new Filter("java_excl", "java.*")); 61 // public static final Perspective DEFAULT_PERSPECTIVE = new Perspective("Default", new Filter("", "")); 62 63 /*** 64 * A LayerOrder defining Layers within a graph. 65 */ 66 private LayerOrder m_layerOrder = null; 67 68 /*** 69 * A list of aggregators used by this perspective. 70 */ 71 private ArrayList m_aggregators = new ArrayList(); 72 73 /*** 74 * A list of filters used by this perspective. 75 */ 76 private ArrayList m_filters = new ArrayList(); 77 78 /*** 79 * Creates a new <code>Perspective</code> instance. 80 */ 81 public Perspective() { 82 LOG.debug("Create perspective"); 83 } 84 85 /*** 86 * Creates a new <code>Perspective</code> instance. 87 * 88 * @param name a <code>String</code> value 89 * @param basicFilter a <code>Filter</code> value 90 */ 91 public Perspective(String name, Filter basicFilter) { 92 setName(name); 93 addFilter(basicFilter); 94 } 95 96 /*** 97 * Set the LayerOrder associated with this perspective. 98 * 99 * @param layerOrder a <code>LayerOrder</code> value 100 */ 101 public void setLayerOrder(LayerOrder layerOrder) { 102 m_layerOrder = layerOrder; 103 LOG.debug("Set LayerOrder: " + layerOrder.toString()); 104 } 105 106 /*** 107 * Get the LayerOrder associated with this perspective. 108 * 109 * @return a <code>LayerOrder</code> value 110 */ 111 public LayerOrder getLayerOrder() { 112 return m_layerOrder; 113 } 114 115 /*** 116 * Add an <code>Aggregator</code> to the list of aggregators used 117 * by this perspective. 118 * 119 * @param aggregator an <code>Aggregator</code> value 120 */ 121 public void addAggregator(Aggregator aggregator) { 122 m_aggregators.add(aggregator); 123 LOG.debug("Added Aggregator: " + aggregator.toString()); 124 } 125 126 /*** 127 * Get all Aggregators used within this perspective. 128 * 129 * @return an <code>ArrayList</code> value 130 */ 131 public ArrayList getAggregators() { 132 return m_aggregators; 133 } 134 135 /*** 136 * Find an Aggregator for a certain name. 137 * 138 * @param name a <code>String</code> value 139 * @return an <code>Aggregator</code> value 140 */ 141 public Aggregator findAggregatorForName(String name) { 142 for (Iterator iter = m_aggregators.iterator(); iter.hasNext();) { 143 Aggregator aggregator = (Aggregator)iter.next(); 144 if (aggregator.getName().equals(name)) { 145 return aggregator; 146 } 147 } 148 return null; 149 } 150 151 /*** 152 * Add an <code>Filter</code> to the list of filters used by this 153 * perspective. 154 * 155 * @param filter a <code>Filter</code> value 156 */ 157 public void addFilter(Filter filter) { 158 LOG.debug("Added Filter: " + filter.toString()); 159 m_filters.add(filter); 160 } 161 162 /*** 163 * Process a graph to display it "from" this perspective. 164 * 165 * @param inputGraph a <code>Graph</code> value 166 * @return a <code>Graph</code> value 167 */ 168 public Graph process(Graph inputGraph) { 169 170 LOG.debug("Processing Graph: " + inputGraph.getName()); 171 172 Graph graph = GraphUtils.copy(inputGraph); 173 174 for (Iterator iter = m_filters.iterator(); iter.hasNext(); ) { 175 ((Filter)iter.next()).process(graph); 176 } 177 178 for (Iterator iter = m_aggregators.iterator(); iter.hasNext(); ) { 179 ((Aggregator)iter.next()).process(graph); 180 } 181 182 if (m_layerOrder != null) { 183 m_layerOrder.process(graph); 184 } 185 186 if (false) { 187 StringWriter writer = new StringWriter(); 188 graph.printGraph(writer); 189 LOG.debug("Processed Graph is:" + writer.toString()); 190 } 191 192 return graph; 193 } 194 }

This page was automatically generated by Maven