1 4 package org.python.core; 5 6 8 public abstract class PackageManager extends Object { 9 10 public PyJavaPackage topLevelPackage; 11 12 public PackageManager() { 13 topLevelPackage = new PyJavaPackage("",this); 14 } 15 16 abstract public Class findClass(String pkg,String name,String reason); 17 18 public Class findClass(String pkg,String name) { 19 return findClass(pkg,name,"java class"); 20 } 21 22 public void notifyPackageImport(String pkg,String name) {} 23 24 31 public abstract boolean packageExists(String pkg,String name); 32 33 42 public abstract PyList doDir(PyJavaPackage jpkg, boolean instantiate, 43 boolean exclpkgs); 44 45 51 public abstract void addDirectory(java.io.File dir); 52 53 59 public abstract void addJarDir(String dir, boolean cache); 60 61 67 public abstract void addJar(String jarfile, boolean cache); 68 69 73 protected PyList basicDoDir(PyJavaPackage jpkg, boolean instantiate, 74 boolean exclpkgs) 75 { 76 PyStringMap dict = jpkg.__dict__; 77 PyStringMap cls = jpkg.clsSet; 78 79 if(!instantiate) { 80 PyList ret = cls.keys(); 81 82 PyList dictKeys = dict.keys(); 83 84 for(int i=0; i < dictKeys.__len__(); i++) { 85 PyObject name = dictKeys.pyget(i); 86 if (!cls.has_key(name)) { 87 if (exclpkgs && dict.get(name) instanceof PyJavaPackage) 88 continue; 89 ret.append(name); 90 } 91 } 92 93 return ret; 94 } 95 96 PyList clsNames = cls.keys(); 97 98 for(int i=0; i < clsNames.__len__(); i++) { 99 PyObject name = clsNames.pyget(i); 100 if(!dict.has_key(name)) jpkg.addLazyClass(name.toString()); 101 } 102 103 return dict.keys(); 104 } 105 106 108 protected PyList merge(PyList list1,PyList list2) { 109 for(int i=0; i < list2.__len__() ;i++) { 110 PyObject name = list2.pyget(i); 111 list1.append(name); 112 } 113 114 return list1; 115 } 116 117 public PyObject lookupName(String name) { 118 PyObject top = topLevelPackage; 119 do { 120 int dot = name.indexOf('.'); 121 String firstName = name; 122 String lastName = null; 123 if (dot != -1) { 124 firstName = name.substring(0,dot); 125 lastName = name.substring(dot+1, name.length()); 126 } 127 firstName = firstName.intern(); 128 top = top.__findattr__(firstName); 129 if (top == null) return null; 130 name = lastName; 132 } while (name != null); 133 return top; 134 } 135 136 145 public PyJavaPackage makeJavaPackage(String name, String classes, 146 String jarfile) 147 { 148 PyJavaPackage p = topLevelPackage; 149 if(name.length() != 0) p=p.addPackage(name,jarfile); 150 151 if (classes != null) p.addPlaceholders(classes); 152 153 return p; 154 } 155 156 private static final int MAXSKIP = 512; 157 158 161 static protected int checkAccess(java.io.InputStream cstream) 162 throws java.io.IOException 163 { 164 java.io.DataInputStream istream=new java.io.DataInputStream (cstream); 165 166 int magic = istream.readInt(); 167 int minor = istream.readShort(); 168 int major = istream.readShort(); 169 if (magic != 0xcafebabe) return -1; 170 int nconstants = istream.readShort(); 173 for(int i=1; i<nconstants; i++) { 174 int cid = istream.readByte(); 175 switch (cid) { 177 case 7: istream.skipBytes(2); break; 178 case 9: 179 case 10: 180 case 11: istream.skipBytes(4); break; 181 case 8: istream.skipBytes(2); break; 182 case 3: 183 case 4: istream.skipBytes(4); break; 184 case 5: 185 case 6: istream.skipBytes(8); i++; break; 186 case 12: istream.skipBytes(4); break; 187 case 1: 188 int slength = istream.readUnsignedShort(); 190 while (slength > MAXSKIP) { istream.skipBytes(MAXSKIP); 192 slength -= MAXSKIP; 193 } 194 istream.skipBytes(slength); 195 break; 196 default: 197 return -1; 203 } 204 } 205 return istream.readShort(); 206 } 207 208 209 } 210 | Popular Tags |