KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > xml > internal > Schema


1 /* ****************************************************************************
2  * Schema.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.xml.internal;
11 import org.jdom.Element;
12 import java.util.*;
13
14 /**
15  * Describes the content model of an XML document.
16  *
17  * @author Oliver Steele
18  * @version 1.0
19  */

20 public abstract class Schema {
21     
22     /** Hold mapping from Javascript type names to Types */
23     static Map typeNames = new HashMap();
24
25     /** Represents the type of an attribute whose type isn't known. */
26     public static final Type UNKNOWN_TYPE = newType("unknown");
27     /** Represents a String. */
28     public static final Type STRING_TYPE = newType("string");
29     /** Represents a number. */
30     public static final Type NUMBER_TYPE = newType("number");
31     /** Represents an XML ID. */
32     public static final Type ID_TYPE = newType("ID");
33
34     /** The type of an attribute. */
35     public static class Type {
36         private String JavaDoc mName;
37
38         public Type(String JavaDoc name) {
39             mName = name;
40         }
41         
42         public String JavaDoc toString() {
43             return mName;
44         }
45     }
46     
47     /** Returns a unique type.
48      * @return a unique type
49      */

50     public static Type newType(String JavaDoc typeName) {
51         Type newtype = new Type(typeName);
52         typeNames.put(typeName, newtype);
53         return newtype;
54     }
55     
56     /** Look up the Type object from a Javascript type name */
57     public Type getTypeForName (String JavaDoc typeName) {
58         return (Type) typeNames.get(typeName);
59     }
60
61     /** An empty Schema, all of whose attribute types are unknown. */
62     public static final Schema DEFAULT_SCHEMA =
63         new Schema() {
64             /** @see Schema */
65             public Type getAttributeType(Element element, String JavaDoc name) {
66                 return UNKNOWN_TYPE;
67             }
68         };
69     
70     /**
71      * Returns a value representing the type of an attribute within an
72      * XML element.
73      *
74      * @param element an Element
75      * @param attributeName an attribute name
76      * @return a value represting the type of the attribute's
77      */

78     public abstract Type getAttributeType(Element element,
79                                          String JavaDoc attributeName);
80 }
81
Popular Tags