KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > classycle > dependency > DependencyProcessor


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
29 /**
30  * Processor of {@link Statement Statements} as defined in a
31  * dependency definition file.
32  *
33  * @author Franz-Josef Elmer
34  */

35 public class DependencyProcessor
36 {
37   private final Statement[] _statements;
38   private int _index;
39   
40   /**
41    * Creates a new instance for the specified dependency definition. It also
42    * parses the definition and creates all {@link Statement Statements}.
43    *
44    * @param dependencyDefinition Dependency definition as read from a
45    * .ddf file.
46    * @param properties Contains predefined properties and will also
47    * be populated by definition in <code>dependencyDefinition</code>.
48    * @param renderer Renderer for processing results.
49    * @throws IllegalArgumentException if <tt>dependencyDefinition</tt>
50    * is invalid.
51    */

52   public DependencyProcessor(String JavaDoc dependencyDefinition,
53                              DependencyProperties properties,
54                              ResultRenderer renderer)
55   {
56     _statements = new DependencyDefinitionParser(dependencyDefinition,
57                                                  properties,
58                                                  renderer).getStatements();
59   }
60   
61   /**
62    * Returns <tt>true</tt> if there are still unprocessed statements.
63    * @return
64    */

65   public boolean hasMoreStatements() {
66     return _index < _statements.length;
67   }
68   
69   /**
70    * Executes the next unprocessed statement and returns its result.
71    * @param graph The graph to be checked by the statement.
72    * @return <tt>null</tt> if there is no unprocessed statement.
73    */

74   public Result executeNextStatement(AtomicVertex[] graph) {
75     return hasMoreStatements() ? _statements[_index++].execute(graph) : null;
76   }
77 }
78
Popular Tags