KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > ElementCompiler


1 /* ****************************************************************************
2  * ElementCompiler.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
11 package org.openlaszlo.compiler;
12 import java.io.*;
13 import java.util.*;
14 import org.jdom.Element;
15 import org.openlaszlo.sc.ScriptCompiler;
16 import org.openlaszlo.xml.internal.MissingAttributeException;
17
18
19 /** Represents a compiler for a specific type of element.
20  *
21  * @author Oliver Steele
22  */

23 abstract class ElementCompiler {
24     /** The name of the ActionScript function that is called to queue
25      * instantiation of a view template. The name of this function
26      * must match the name of the function in the runtime support
27      * library.
28      */

29     protected static final String JavaDoc VIEW_INSTANTIATION_FNAME = "LzInstantiateView";
30     protected final CompilationEnvironment mEnv;
31
32     ElementCompiler(CompilationEnvironment env) {
33         mEnv = env;
34     }
35
36     /** Compiles this element within the compilation environment.
37      * @param env a compilation environment
38      */

39     abstract void compile(Element element) throws CompilationError;
40
41     void updateSchema(Element element, ViewSchema schema, Set visited) {
42     }
43
44     /** Resolve the src attribute of elt to a file reference.
45      * Relative pathnames are resolved relative to the source location
46      * for elt. */

47     File resolveSrcReference(Element elt) {
48         return mEnv.resolveReference(elt);
49     }
50
51     /** Returns an element's attribute value, as a String. Same as
52      * Element.getAttributeValue, except guarantees not to return
53      * null and guarantees not to return a non-identifier.
54      *
55      * @param e an Element
56      * @param aname the attribute name
57      * @return a String
58      */

59     public static String JavaDoc requireIdentifierAttributeValue(Element e, String JavaDoc aname) {
60         String JavaDoc value = e.getAttributeValue(aname);
61         if (value == null || !ScriptCompiler.isIdentifier(value)) {
62             throw new MissingAttributeException(e, aname);
63         }
64         return value;
65     }
66     
67
68
69 }
70
Popular Tags