View Javadoc

1   /*
2    Copyright 2006 Ernest Micklei @ PhilemonWorks.com
3   
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7   
8    http://www.apache.org/licenses/LICENSE-2.0
9   
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15   
16   */
17  package com.philemonworks.selfdiagnose.check;
18  
19  import org.xml.sax.Attributes;
20  
21  import com.philemonworks.selfdiagnose.DiagnoseException;
22  import com.philemonworks.selfdiagnose.DiagnoseUtil;
23  import com.philemonworks.selfdiagnose.ExecutionContext;
24  import com.philemonworks.selfdiagnose.PatternMatchingTask;
25  /**
26   * CheckProperty is an abstract class for tasks that verifies properties against a regular expression pattern.
27   * 
28   * @author Ernest Micklei
29   */
30  public abstract class CheckProperty extends PatternMatchingTask {
31  	private static final long serialVersionUID = -1701980048760932884L;
32  
33  	protected static final String PARAMETER_PROPERTY = "property";
34  
35  	// parameters
36  	protected String property;
37  
38  	/*
39  	 * (non-Javadoc)
40  	 * 
41  	 * @see com.philemonworks.selfdiagnose.DiagnosticTask#initializeFromAttributes(Attributes)
42  	 */
43  	public void initializeFromAttributes(Attributes attributes) {
44  		// store variable if specified
45  		super.initializeFromAttributes(attributes);
46  		this.setProperty(attributes.getValue(PARAMETER_PROPERTY));
47  	}
48  
49  	public void setUp(ExecutionContext ctx) throws DiagnoseException {
50  		super.setUp(ctx);
51  		this.checkPropertyAccess();
52  	}
53  
54  	protected void checkPropertyAccess() throws DiagnoseException {
55  		DiagnoseUtil.verifyNonEmptyString(PARAMETER_PROPERTY, property,this.getClass());
56  	}
57  
58  	/**
59  	 * @return
60  	 */
61  	public String getProperty() {
62  		return property;
63  	}
64  
65  	/**
66  	 * @param string
67  	 */
68  	public void setProperty(String string) {
69  		property = string;
70  	}
71  	/**
72  	 * Answer whether the object itself is checked rather than one of its properties (field,operation).
73  	 */
74  	public boolean isThisRequested(){
75  		return "this".equals(property);
76  	}
77  }