KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > configuration > OnErrorEl


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
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 package scriptella.configuration;
17
18 import scriptella.spi.DialectIdentifier;
19 import scriptella.spi.Resource;
20
21 import java.util.Arrays JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.LinkedHashSet JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.regex.Pattern JavaDoc;
26
27 /**
28  * Represents <onerror> xml element.
29  *
30  * @author Fyodor Kupolov
31  * @version 1.0
32  */

33 public class OnErrorEl extends XmlConfigurableBase {
34     private static final Pattern JavaDoc CODES_SEPARATOR = Pattern.compile("\\s*\\,\\s*");
35     private Pattern JavaDoc type;
36     private Pattern JavaDoc message;
37     private Set JavaDoc<String JavaDoc> codes;
38     private boolean retry;
39     protected DialectBasedContentEl content;
40
41     public OnErrorEl() {
42     }
43
44     public OnErrorEl(final XmlElement element) {
45         configure(element);
46     }
47
48     public void configure(final XmlElement element) {
49         setPatternProperty(element, "type");
50         setPatternProperty(element, "message");
51         String JavaDoc codestr = element.getAttribute("codes");
52         if (codestr == null) {
53             codes = Collections.emptySet();
54         } else {
55             codes = new LinkedHashSet JavaDoc<String JavaDoc>(Arrays.asList(CODES_SEPARATOR.split(codestr)));
56         }
57         retry = element.getBooleanAttribute("retry", false);
58         content = new DialectBasedContentEl(element);
59     }
60
61     /**
62      * @return Regular expression pattern to match exception type.
63      */

64     public Pattern JavaDoc getType() {
65         return type;
66     }
67
68     public void setType(Pattern JavaDoc type) {
69         this.type = type;
70     }
71
72     /**
73      * @return Regular expression pattern to match exception message
74      */

75     public Pattern JavaDoc getMessage() {
76         return message;
77     }
78
79     public void setMessage(Pattern JavaDoc message) {
80         this.message = message;
81     }
82
83     /**
84      * @return set of vendor codes/sql states.
85      */

86     public Set JavaDoc<String JavaDoc> getCodes() {
87         return codes;
88     }
89
90     public void setCodes(Set JavaDoc<String JavaDoc> codes) {
91         this.codes = codes;
92     }
93
94     /**
95      * @return true if statement which caused a problem should be retried after onerror handler. Default value if false.
96      */

97     public boolean isRetry() {
98         return retry;
99     }
100
101     public void setRetry(boolean retry) {
102         this.retry = retry;
103     }
104
105     public Resource getContent(DialectIdentifier id) {
106         Resource r = content.getContent(id);
107         if (r==null) {
108             return ContentEl.NULL_CONTENT;
109         } else {
110             return r;
111         }
112     }
113
114
115     public String JavaDoc toString() {
116         StringBuilder JavaDoc res = new StringBuilder JavaDoc("OnError{");
117         if (type!=null) {
118             res.append("type=").append(type).append(", ");
119         }
120         if (message!=null) {
121             res.append("message=").append(message).append(", ");
122         }
123         if (codes!=null) {
124             res.append("codes=").append(codes).append(", ");
125         }
126
127         res.append("retry=").append(retry).append('}');
128         return res.toString();
129     }
130 }
131
Popular Tags