KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > util > xml > DefaultSchema


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, 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 JavaDoc;
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, new AttributeConverterForInteger());
37     registerAttributeConverter(Integer JavaDoc.class,
38         new AttributeConverterForInteger());
39     registerAttributeConverter(String JavaDoc.class, new AttributeConverterForString());
40     registerAttributeConverter(boolean.class,
41         new AttributeConverterForBoolean());
42     registerAttributeConverter(Boolean JavaDoc.class,
43         new AttributeConverterForBoolean());
44   }
45
46   public void onBadAttributeValue(int line, String JavaDoc elem, String JavaDoc attr,
47       String JavaDoc value, Class JavaDoc paramType) throws UnableToCompleteException {
48     Messages.XML_ATTRIBUTE_CONVERSION_ERROR.log(logger, line, attr, paramType,
49         null);
50     throw new UnableToCompleteException();
51   }
52
53   public void onHandlerException(int line, String JavaDoc elem, Method JavaDoc method,
54       Throwable JavaDoc e) throws UnableToCompleteException {
55     Messages.XML_ELEMENT_HANDLER_EXCEPTION.log(logger, line, elem, e);
56     throw new UnableToCompleteException();
57   }
58
59   public void onMissingAttribute(int line, String JavaDoc elem, String JavaDoc attr)
60       throws UnableToCompleteException {
61     Messages.XML_REQUIRED_ATTRIBUTE_MISSING.log(logger, elem, line, attr, null);
62     throw new UnableToCompleteException();
63   }
64
65   public void onUnexpectedAttribute(int line, String JavaDoc elem, String JavaDoc attr,
66       String JavaDoc value) throws UnableToCompleteException {
67     Messages.XML_ATTRIBUTE_UNEXPECTED.log(logger, elem, line, attr, null);
68     throw new UnableToCompleteException();
69   }
70
71   public void onUnexpectedChild(int line, String JavaDoc childElem)
72       throws UnableToCompleteException {
73     Messages.XML_CHILDREN_NOT_ALLOWED.log(logger, childElem, line, null);
74     throw new UnableToCompleteException();
75   }
76
77   public void onUnexpectedElement(int line, String JavaDoc elem)
78       throws UnableToCompleteException {
79     Messages.XML_ELEMENT_UNEXPECTED.log(logger, line, elem, null);
80     throw new UnableToCompleteException();
81   }
82 }
83
Popular Tags