KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > SelfDescribingInspectorProxy


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi;
24
25 import java.util.Collection JavaDoc;
26 import java.util.LinkedList JavaDoc;
27
28 import com.pavelvlasov.config.ConfigurationException;
29 import com.pavelvlasov.config.RuntimeConfigurationException;
30
31 /**
32  * Allows to defer rule instantiation till it is actually needed
33  * @author Pavel Vlasov
34  * @version $Revision: 1.5 $
35  */

36 public class SelfDescribingInspectorProxy implements InspectorDescriptor {
37     private InspectorDescriptor sourceDescriptor;
38     
39     private InspectorDescriptor ruleDescriptor=new InspectorDescriptor() {
40         public String JavaDoc getDescription() { return null; }
41         public Boolean JavaDoc isEnabled() { return null; }
42         public String JavaDoc getName() { return null; }
43         public Integer JavaDoc getSeverity() { return null; }
44         public Integer JavaDoc getOrder() { return null; }
45         public String JavaDoc getRationale() { return null; }
46         public String JavaDoc getViolationSample() { return null; }
47         public String JavaDoc getFixSample() { return null; }
48         public String JavaDoc getResources() { return null; }
49         public String JavaDoc getMessage() { return null; }
50         public Inspector getInspector() { return null; }
51         public Collection JavaDoc getParameters() { return null; }
52         public String JavaDoc getMessage(String JavaDoc key) { return null; }
53         public Boolean JavaDoc isWaivable() { return null; }
54         public Collection JavaDoc getWaiveCases() { return new LinkedList JavaDoc(); }
55         public String JavaDoc getWaivedInspectorName(String JavaDoc inspectorKey) { return null; }
56         public String JavaDoc getWaiveReason(String JavaDoc inspectorKey) { return null; }
57         public Collection JavaDoc getWaivedInspectorNames() { return null; }
58         public String JavaDoc getCategory() { return null; }
59         public Collection JavaDoc getFilteredInspectorDesriptors(InspectorSet inspectorSet, Collection JavaDoc chain) {
60             return chain;
61         }
62         public Collection JavaDoc getAfterInspectorNames() { return null; }
63     }; // To avoid if's in every method
64

65     private boolean ruleInstantiated=false;
66     
67     public SelfDescribingInspectorProxy(InspectorDescriptor descriptor) {
68         super();
69         sourceDescriptor=descriptor;
70     }
71     
72     private InspectorDescriptor getInspectorDescriptor() {
73         if (!ruleInstantiated) {
74             try {
75                 Inspector rule=sourceDescriptor.getInspector();
76                 if (rule instanceof InspectorDescriptor) {
77                     ruleDescriptor=(InspectorDescriptor) rule;
78                 }
79                 ruleInstantiated=true;
80             } catch (ConfigurationException e) {
81                 throw new RuntimeConfigurationException("Can't instantiate inspector", e);
82             }
83         }
84         return ruleDescriptor;
85     }
86
87     public String JavaDoc getCategory() {
88         return getInspectorDescriptor().getCategory();
89     }
90
91     public String JavaDoc getDescription() {
92         return getInspectorDescriptor().getDescription();
93     }
94
95     public Boolean JavaDoc isEnabled() {
96         return getInspectorDescriptor().isEnabled();
97     }
98
99     public String JavaDoc getName() {
100         return getInspectorDescriptor().getName();
101     }
102
103     public Integer JavaDoc getSeverity() {
104         return getInspectorDescriptor().getSeverity();
105     }
106
107     public Integer JavaDoc getOrder() {
108         return getInspectorDescriptor().getOrder();
109     }
110
111     public String JavaDoc getRationale() {
112         return getInspectorDescriptor().getRationale();
113     }
114
115     public String JavaDoc getViolationSample() {
116         return getInspectorDescriptor().getViolationSample();
117     }
118
119     public String JavaDoc getFixSample() {
120         return getInspectorDescriptor().getFixSample();
121     }
122
123     public String JavaDoc getResources() {
124         return getInspectorDescriptor().getResources();
125     }
126
127     public String JavaDoc getMessage() {
128         return getInspectorDescriptor().getMessage();
129     }
130
131     public Inspector getInspector() throws ConfigurationException {
132         return getInspectorDescriptor().getInspector();
133     }
134
135     public Collection JavaDoc getParameters() {
136         return getInspectorDescriptor().getParameters();
137     }
138
139     public String JavaDoc getMessage(String JavaDoc key) {
140         return getInspectorDescriptor().getMessage(key);
141     }
142
143     public Boolean JavaDoc isWaivable() {
144         return getInspectorDescriptor().isWaivable();
145     }
146
147     public Collection JavaDoc getWaiveCases() {
148         return getInspectorDescriptor().getWaiveCases();
149     }
150
151     public String JavaDoc getWaivedInspectorName(String JavaDoc inspectorKey) {
152         return getInspectorDescriptor().getWaivedInspectorName(inspectorKey);
153     }
154
155     public String JavaDoc getWaiveReason(String JavaDoc inspectorKey) {
156         return getInspectorDescriptor().getWaiveReason(inspectorKey);
157     }
158
159     public Collection JavaDoc getWaivedInspectorNames() {
160         return getInspectorDescriptor().getWaivedInspectorNames();
161     }
162
163     public Collection JavaDoc getFilteredInspectorDesriptors(InspectorSet inspectorSet, Collection JavaDoc chain) {
164         return getInspectorDescriptor().getFilteredInspectorDesriptors(inspectorSet, chain);
165     }
166
167     public Collection JavaDoc getAfterInspectorNames() {
168         return getInspectorDescriptor().getAfterInspectorNames();
169     }
170 }
171
Popular Tags