KickJava   Java API By Example, From Geeks To Geeks.

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


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.UnableToCompleteException;
19
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Abstract base class for reflection-based push-parsing of XML.
26  */

27 public abstract class Schema {
28
29   private final Map JavaDoc convertersByType = new HashMap JavaDoc();
30
31   private Schema parent;
32
33   private int lineNumber;
34
35   /**
36    * Finds the most recent converter in the schema chain that can convert the
37    * specified type.
38    */

39   public AttributeConverter getAttributeConverter(Class JavaDoc type) {
40     AttributeConverter converter = (AttributeConverter) convertersByType.get(type);
41     if (converter != null) {
42       return converter;
43     } else if (parent != null) {
44       return parent.getAttributeConverter(type);
45     }
46
47     throw new IllegalStateException JavaDoc(
48         "Unable to find an attribute converter for type " + type.getName());
49   }
50
51   public int getLineNumber() {
52     return lineNumber;
53   }
54
55   public void onBadAttributeValue(int line, String JavaDoc elem, String JavaDoc attr,
56       String JavaDoc value, Class JavaDoc paramType) throws UnableToCompleteException {
57     if (parent != null) {
58       parent.onBadAttributeValue(line, elem, attr, value, paramType);
59     }
60   }
61
62   public void onHandlerException(int line, String JavaDoc elem, Method JavaDoc method,
63       Throwable JavaDoc e) throws UnableToCompleteException {
64     if (parent != null) {
65       parent.onHandlerException(line, elem, method, e);
66     }
67   }
68
69   public void onMissingAttribute(int line, String JavaDoc elem, String JavaDoc attr)
70       throws UnableToCompleteException {
71     if (parent != null) {
72       parent.onMissingAttribute(line, elem, attr);
73     }
74   }
75
76   public void onUnexpectedAttribute(int line, String JavaDoc elem, String JavaDoc attr,
77       String JavaDoc value) throws UnableToCompleteException {
78     if (parent != null) {
79       parent.onUnexpectedAttribute(line, elem, attr, value);
80     }
81   }
82
83   public void onUnexpectedChild(int line, String JavaDoc elem)
84       throws UnableToCompleteException {
85     if (parent != null) {
86       parent.onUnexpectedChild(line, elem);
87     }
88   }
89
90   public void onUnexpectedElement(int line, String JavaDoc elem)
91       throws UnableToCompleteException {
92     if (parent != null) {
93       parent.onUnexpectedElement(line, elem);
94     }
95   }
96
97   public void registerAttributeConverter(Class JavaDoc type,
98       AttributeConverter converter) {
99     convertersByType.put(type, converter);
100   }
101
102   public void setLineNumber(int lineNumber) {
103     this.lineNumber = lineNumber;
104   }
105
106   public void setParent(Schema parent) {
107     this.parent = parent;
108   }
109 }
110
Popular Tags