1 4 5 9 10 package org.openlaszlo.compiler; 11 import java.io.*; 12 import java.util.*; 13 import org.jdom.Document; 14 import org.jdom.Element; 15 import org.openlaszlo.utils.ChainedException; 16 import org.apache.log4j.*; 17 18 22 class LibraryCompiler extends ToplevelCompiler { 23 final static String HREF_ANAME = "href"; 24 25 27 private static Logger mLogger = Logger.getLogger(Compiler .class); 28 29 30 31 LibraryCompiler(CompilationEnvironment env) { 32 super(env); 33 } 34 35 static boolean isElement(Element element) { 36 return element.getName().equals("library"); 37 } 38 39 static File resolveLibraryName(File file) 41 { 42 if (file.isDirectory()) { 43 file = new File(file, "library.lzx"); 44 } 45 return file; 46 } 47 48 51 static Element resolveLibraryElement(File file, 52 CompilationEnvironment env, 53 Set visited, 54 boolean validate) 55 { 56 try { 57 file = resolveLibraryName(file); 58 File key = file.getCanonicalFile(); 59 if (!visited.contains(key)) { 60 visited.add(key); 61 62 if (env.isImportLib()) { 67 68 if (env.isImportLib() && env.getLoadableImportedLibraryFiles().containsKey(key)) { 72 env.warn("The library file \""+file+"\" included by loadable library \"" 73 + env.getApplicationFile() 74 + "\" was also included by another loadable library \"" 75 + env.getLoadableImportedLibraryFiles().get(key) +"\". " 76 + "This may lead to unexpected behavior, especially if the library defines new classes."); 77 } 78 79 env.getLoadableImportedLibraryFiles().put(key, env.getApplicationFile()); 80 } 81 82 Document doc = env.getParser().parse(file); 83 if (validate) 84 Parser.validate(doc, file.getPath(), env); 85 Element root = doc.getRootElement(); 86 return root; 87 } else { 88 return null; 89 } 90 } catch (IOException e) { 91 throw new CompilationError(e); 92 } 93 } 94 95 98 static Element resolveLibraryElement(Element element, 99 CompilationEnvironment env, 100 Set visited, 101 boolean validate) 102 { 103 String href = element.getAttributeValue(HREF_ANAME); 104 if (href == null) { 105 return element; 106 } 107 File file = env.resolveReference(element, HREF_ANAME); 108 return resolveLibraryElement(file, env, visited, validate); 109 } 110 111 public void compile(Element element) throws CompilationError 112 { 113 element = resolveLibraryElement( 114 element, mEnv, mEnv.getImportedLibraryFiles(), 115 mEnv.getBooleanProperty(mEnv.VALIDATE_PROPERTY)); 116 if (element != null) { 117 super.compile(element); 118 } 119 } 120 121 void updateSchema(Element element, ViewSchema schema, Set visited) { 122 element = resolveLibraryElement(element, mEnv, visited, false); 123 if (element != null) { 124 super.updateSchema(element, schema, visited); 125 } 128 } 129 } 130 | Popular Tags |