01: /* ****************************************************************************
02: * ElementCompiler.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2006 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.compiler;
11:
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: /** Represents a compiler for a specific type of element.
19: *
20: * @author Oliver Steele
21: */
22: abstract class ElementCompiler {
23: /** The name of the ActionScript function that is called to queue
24: * instantiation of a view template. The name of this function
25: * must match the name of the function in the runtime support
26: * library.
27: */
28: protected static final String VIEW_INSTANTIATION_FNAME = "LzInstantiateView";
29: protected final CompilationEnvironment mEnv;
30:
31: ElementCompiler(CompilationEnvironment env) {
32: mEnv = env;
33: }
34:
35: /** Compiles this element within the compilation environment.
36: * @param element
37: */
38: abstract void compile(Element element) throws CompilationError;
39:
40: void updateSchema(Element element, ViewSchema schema, Set visited) {
41: }
42:
43: /** Resolve the src attribute of elt to a file reference.
44: * Relative pathnames are resolved relative to the source location
45: * for elt. */
46: File resolveSrcReference(Element elt) {
47: return mEnv.resolveReference(elt);
48: }
49:
50: /** Returns an element's attribute value, as a String. Same as
51: * Element.getAttributeValue, except guarantees not to return
52: * null and guarantees not to return a non-identifier.
53: *
54: * @param e an Element
55: * @param aname the attribute name
56: * @return a String
57: */
58: public static String requireIdentifierAttributeValue(Element e,
59: String aname) {
60: String value = e.getAttributeValue(aname);
61: if (value == null || !ScriptCompiler.isIdentifier(value)) {
62: throw new MissingAttributeException(e, aname);
63: }
64: return value;
65: }
66:
67: }
|