1 28 29 package com.caucho.java.gen; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.server.util.CauchoSystem; 33 import com.caucho.util.L10N; 34 import com.caucho.vfs.Depend; 35 import com.caucho.vfs.Path; 36 import com.caucho.vfs.PersistentDependency; 37 38 import java.io.IOException ; 39 import java.util.ArrayList ; 40 41 44 public class DependencyComponent extends ClassComponent { 45 private static final L10N L = new L10N(DependencyComponent.class); 46 47 private String _initMethod = "_caucho_init"; 48 private String _isModifiedMethod = "_caucho_is_modified"; 49 50 private Path _searchPath; 51 52 private ArrayList <PersistentDependency> _dependList = 53 new ArrayList <PersistentDependency>(); 54 55 58 public void setSearchPath(Path searchPath) 59 { 60 _searchPath = searchPath; 61 } 62 63 66 public void addDependencyList(ArrayList <PersistentDependency> dependList) 67 { 68 for (int i = 0; i < dependList.size(); i++) 69 addDependency(dependList.get(i)); 70 } 71 72 75 public void addDependency(PersistentDependency depend) 76 { 77 if (! _dependList.contains(depend)) 78 _dependList.add(depend); 79 } 80 81 86 public void generate(JavaWriter out) 87 throws IOException 88 { 89 out.println("private static com.caucho.vfs.Dependency []_caucho_depend;"); 90 91 out.println(); 92 out.println("public static void " + _initMethod + "(com.caucho.vfs.Path path)"); 93 out.println("{"); 94 out.pushDepth(); 95 96 out.println("_caucho_depend = new com.caucho.vfs.Dependency[" + 97 _dependList.size() + "];"); 98 99 Path searchPath = _searchPath; 100 101 if (searchPath == null) 102 searchPath = JavaClassGenerator.getDefaultSearchPath(); 103 104 for (int i = 0; i < _dependList.size(); i++) { 105 PersistentDependency dependency = _dependList.get(i); 106 107 if (dependency instanceof Depend) { 108 Depend depend = (Depend) _dependList.get(i); 109 Path path = depend.getPath(); 110 111 out.print("_caucho_depend[" + i + "] = new com.caucho.vfs.Depend("); 112 113 String relativePath; 114 relativePath = searchPath.lookup(path.getRelativePath()).getRelativePath(); 115 out.print("path.lookup(\"" + relativePath + "\"), "); 116 117 out.println(depend.getDigest() + "L, " + 118 depend.getRequireSource() + ");"); 119 } 120 else { 121 out.print("_caucho_depend[" + i + "] = "); 122 out.print(dependency.getJavaCreateString()); 123 out.println(";"); 124 } 125 } 126 127 out.popDepth(); 128 out.println("}"); 129 130 out.println(); 131 out.println("public static boolean " + _isModifiedMethod + "()"); 132 out.println("{"); 133 out.pushDepth(); 134 135 printVersionChange(out); 136 137 out.println("for (int i = _caucho_depend.length - 1; i >= 0; i--) {"); 138 out.println(" if (_caucho_depend[i].isModified())"); 139 out.println(" return true;"); 140 out.println("}"); 141 142 out.println(); 143 out.println("return false;"); 144 145 out.popDepth(); 146 out.println("}"); 147 } 148 149 152 protected void printVersionChange(JavaWriter out) 153 throws IOException 154 { 155 out.println("if (com.caucho.server.util.CauchoSystem.getVersionId() != " + 156 "0x" + Long.toHexString(CauchoSystem.getVersionId()) + "L)"); 157 out.println(" return true;"); 158 } 159 } 160 | Popular Tags |