01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.util.xml;
17:
18: import com.google.gwt.core.ext.TreeLogger;
19: import com.google.gwt.core.ext.UnableToCompleteException;
20:
21: import java.lang.reflect.Method;
22:
23: /**
24: * A base class for parsing XML that registers standard converters and throws
25: * exceptions.
26: */
27: public class DefaultSchema extends Schema {
28:
29: private final TreeLogger logger;
30:
31: public DefaultSchema(TreeLogger logger) {
32: this .logger = logger;
33:
34: // Registers converters for the typical primitive types.
35: //
36: registerAttributeConverter(int.class,
37: new AttributeConverterForInteger());
38: registerAttributeConverter(Integer.class,
39: new AttributeConverterForInteger());
40: registerAttributeConverter(String.class,
41: new AttributeConverterForString());
42: registerAttributeConverter(boolean.class,
43: new AttributeConverterForBoolean());
44: registerAttributeConverter(Boolean.class,
45: new AttributeConverterForBoolean());
46: }
47:
48: public void onBadAttributeValue(int line, String elem, String attr,
49: String value, Class paramType)
50: throws UnableToCompleteException {
51: Messages.XML_ATTRIBUTE_CONVERSION_ERROR.log(logger, line, attr,
52: paramType, null);
53: throw new UnableToCompleteException();
54: }
55:
56: public void onHandlerException(int line, String elem,
57: Method method, Throwable e)
58: throws UnableToCompleteException {
59: Messages.XML_ELEMENT_HANDLER_EXCEPTION.log(logger, line, elem,
60: e);
61: throw new UnableToCompleteException();
62: }
63:
64: public void onMissingAttribute(int line, String elem, String attr)
65: throws UnableToCompleteException {
66: Messages.XML_REQUIRED_ATTRIBUTE_MISSING.log(logger, elem, line,
67: attr, null);
68: throw new UnableToCompleteException();
69: }
70:
71: public void onUnexpectedAttribute(int line, String elem,
72: String attr, String value) throws UnableToCompleteException {
73: Messages.XML_ATTRIBUTE_UNEXPECTED.log(logger, elem, line, attr,
74: null);
75: throw new UnableToCompleteException();
76: }
77:
78: public void onUnexpectedChild(int line, String childElem)
79: throws UnableToCompleteException {
80: Messages.XML_CHILDREN_NOT_ALLOWED.log(logger, childElem, line,
81: null);
82: throw new UnableToCompleteException();
83: }
84:
85: public void onUnexpectedElement(int line, String elem)
86: throws UnableToCompleteException {
87: Messages.XML_ELEMENT_UNEXPECTED.log(logger, line, elem, null);
88: throw new UnableToCompleteException();
89: }
90: }
|