KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > classycle > dependency > LayeringStatement


1 /*
2  * Copyright (c) 2003-2006, Franz-Josef Elmer, All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */

25 package classycle.dependency;
26
27 import classycle.graph.AtomicVertex;
28 import classycle.util.StringPattern;
29
30 /**
31  * @author Franz-Josef Elmer
32  */

33 public class LayeringStatement implements Statement
34 {
35   private final StringPattern[][] _layers;
36   private final boolean _strictLayering;
37   private final SetDefinitionRepository _repository;
38   private final LayerDefinitionRepository _layerRepository;
39   private final ResultRenderer _renderer;
40   
41   public LayeringStatement(StringPattern[][] layers, boolean strictLayering,
42                            SetDefinitionRepository repository,
43                            LayerDefinitionRepository layerRepository,
44                            ResultRenderer renderer)
45   {
46     _layers = layers;
47     _repository = repository;
48     _layerRepository = layerRepository;
49     _strictLayering = strictLayering;
50     _renderer = renderer;
51   }
52
53   public Result execute(AtomicVertex[] graph)
54   {
55     ResultContainer result = new ResultContainer();
56     for (int i = 0; i < _layers.length; i++)
57     {
58       checkIntraLayerDependencies(result, _layers[i], graph);
59       for (int j = i + 1; j < _layers.length; j++)
60       {
61         DependencyStatement s = new DependencyStatement(_layers[i], _layers[j],
62                                                  true, _repository, _renderer);
63         result.add(s.execute(graph));
64       }
65       if (_strictLayering)
66       {
67         for (int j = i - 2; j >= 0; j--)
68         {
69           DependencyStatement s = new DependencyStatement(_layers[i],
70                                      _layers[j], true, _repository, _renderer);
71           result.add(s.execute(graph));
72         }
73       }
74     }
75     return result;
76   }
77   
78   private void checkIntraLayerDependencies(ResultContainer result,
79                                            StringPattern[] patterns,
80                                            AtomicVertex[] graph)
81   {
82     StringPattern[] startSets = new StringPattern[1];
83     StringPattern[] endSets = new StringPattern[patterns.length - 1];
84     for (int i = 0; i < patterns.length; i++)
85     {
86       startSets[0] = patterns[i];
87       System.arraycopy(patterns, 0, endSets, 0, i);
88       System.arraycopy(patterns, i + 1, endSets, i, patterns.length - i - 1);
89       DependencyStatement s = new DependencyStatement(startSets, endSets,
90                                               true, _repository, _renderer);
91       result.add(s.execute(graph));
92     }
93   }
94   
95   public String JavaDoc toString()
96   {
97     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("check ");
98     buffer.append(_strictLayering ? "strictLayeringOf" : "layeringOf");
99     for (int i = 0; i < _layers.length; i++)
100     {
101       buffer.append(' ').append(_layerRepository.getName(_layers[i]));
102     }
103     return new String JavaDoc(buffer);
104   }
105 }
106
Popular Tags