001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi;
024:
025: import java.util.Collection;
026: import java.util.LinkedList;
027:
028: import com.pavelvlasov.config.ConfigurationException;
029: import com.pavelvlasov.config.RuntimeConfigurationException;
030:
031: /**
032: * Allows to defer rule instantiation till it is actually needed
033: * @author Pavel Vlasov
034: * @version $Revision: 1.5 $
035: */
036: public class SelfDescribingInspectorProxy implements
037: InspectorDescriptor {
038: private InspectorDescriptor sourceDescriptor;
039:
040: private InspectorDescriptor ruleDescriptor = new InspectorDescriptor() {
041: public String getDescription() {
042: return null;
043: }
044:
045: public Boolean isEnabled() {
046: return null;
047: }
048:
049: public String getName() {
050: return null;
051: }
052:
053: public Integer getSeverity() {
054: return null;
055: }
056:
057: public Integer getOrder() {
058: return null;
059: }
060:
061: public String getRationale() {
062: return null;
063: }
064:
065: public String getViolationSample() {
066: return null;
067: }
068:
069: public String getFixSample() {
070: return null;
071: }
072:
073: public String getResources() {
074: return null;
075: }
076:
077: public String getMessage() {
078: return null;
079: }
080:
081: public Inspector getInspector() {
082: return null;
083: }
084:
085: public Collection getParameters() {
086: return null;
087: }
088:
089: public String getMessage(String key) {
090: return null;
091: }
092:
093: public Boolean isWaivable() {
094: return null;
095: }
096:
097: public Collection getWaiveCases() {
098: return new LinkedList();
099: }
100:
101: public String getWaivedInspectorName(String inspectorKey) {
102: return null;
103: }
104:
105: public String getWaiveReason(String inspectorKey) {
106: return null;
107: }
108:
109: public Collection getWaivedInspectorNames() {
110: return null;
111: }
112:
113: public String getCategory() {
114: return null;
115: }
116:
117: public Collection getFilteredInspectorDesriptors(
118: InspectorSet inspectorSet, Collection chain) {
119: return chain;
120: }
121:
122: public Collection getAfterInspectorNames() {
123: return null;
124: }
125: }; // To avoid if's in every method
126:
127: private boolean ruleInstantiated = false;
128:
129: public SelfDescribingInspectorProxy(InspectorDescriptor descriptor) {
130: super ();
131: sourceDescriptor = descriptor;
132: }
133:
134: private InspectorDescriptor getInspectorDescriptor() {
135: if (!ruleInstantiated) {
136: try {
137: Inspector rule = sourceDescriptor.getInspector();
138: if (rule instanceof InspectorDescriptor) {
139: ruleDescriptor = (InspectorDescriptor) rule;
140: }
141: ruleInstantiated = true;
142: } catch (ConfigurationException e) {
143: throw new RuntimeConfigurationException(
144: "Can't instantiate inspector", e);
145: }
146: }
147: return ruleDescriptor;
148: }
149:
150: public String getCategory() {
151: return getInspectorDescriptor().getCategory();
152: }
153:
154: public String getDescription() {
155: return getInspectorDescriptor().getDescription();
156: }
157:
158: public Boolean isEnabled() {
159: return getInspectorDescriptor().isEnabled();
160: }
161:
162: public String getName() {
163: return getInspectorDescriptor().getName();
164: }
165:
166: public Integer getSeverity() {
167: return getInspectorDescriptor().getSeverity();
168: }
169:
170: public Integer getOrder() {
171: return getInspectorDescriptor().getOrder();
172: }
173:
174: public String getRationale() {
175: return getInspectorDescriptor().getRationale();
176: }
177:
178: public String getViolationSample() {
179: return getInspectorDescriptor().getViolationSample();
180: }
181:
182: public String getFixSample() {
183: return getInspectorDescriptor().getFixSample();
184: }
185:
186: public String getResources() {
187: return getInspectorDescriptor().getResources();
188: }
189:
190: public String getMessage() {
191: return getInspectorDescriptor().getMessage();
192: }
193:
194: public Inspector getInspector() throws ConfigurationException {
195: return getInspectorDescriptor().getInspector();
196: }
197:
198: public Collection getParameters() {
199: return getInspectorDescriptor().getParameters();
200: }
201:
202: public String getMessage(String key) {
203: return getInspectorDescriptor().getMessage(key);
204: }
205:
206: public Boolean isWaivable() {
207: return getInspectorDescriptor().isWaivable();
208: }
209:
210: public Collection getWaiveCases() {
211: return getInspectorDescriptor().getWaiveCases();
212: }
213:
214: public String getWaivedInspectorName(String inspectorKey) {
215: return getInspectorDescriptor().getWaivedInspectorName(
216: inspectorKey);
217: }
218:
219: public String getWaiveReason(String inspectorKey) {
220: return getInspectorDescriptor().getWaiveReason(inspectorKey);
221: }
222:
223: public Collection getWaivedInspectorNames() {
224: return getInspectorDescriptor().getWaivedInspectorNames();
225: }
226:
227: public Collection getFilteredInspectorDesriptors(
228: InspectorSet inspectorSet, Collection chain) {
229: return getInspectorDescriptor().getFilteredInspectorDesriptors(
230: inspectorSet, chain);
231: }
232:
233: public Collection getAfterInspectorNames() {
234: return getInspectorDescriptor().getAfterInspectorNames();
235: }
236: }
|