1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 abstract public class ArchiveServantBase 38 extends org.omg.CORBA.LocalObject 39 { 40 static private String _class_name = "ArchiveServantBase"; 42 private String _uuid; 43 private String _archive_location; 44 private String _archive_cache; 45 private java.util.Hashtable _entry2loc; 46 47 protected 48 ArchiveServantBase(String uuid, 49 String loc) 50 { 51 _uuid = uuid; 53 _archive_location = loc; 54 _archive_cache = null; 55 _entry2loc = new java.util.Hashtable (); 56 } 57 58 62 abstract protected ORBService 63 getORBService(); 64 65 69 final protected java.util.zip.ZipFile 70 openZip() 71 { 72 if (_archive_cache==null) { 73 int idx = _archive_location.lastIndexOf("."); 75 _archive_cache = _archive_location.substring(0, idx); 76 77 new java.io.File (_archive_cache).mkdirs(); 79 } 80 81 try { 82 return new java.util.zip.ZipFile (_archive_location); 83 } catch(java.lang.Exception ex) { 84 final String opname = "openZip"; 86 TheLogger.error(_class_name, opname, "FAILED", ex); 87 return null; 88 } 89 } 90 91 final protected String 92 extractFile(java.util.zip.ZipFile zip, 93 java.util.zip.ZipEntry entry) 94 { 95 final String opname = "extractFile"; 96 java.io.InputStream in = null; 97 java.io.FileOutputStream out = null; 98 99 try { 100 in = zip.getInputStream(entry); 101 java.io.File fout = new java.io.File (_archive_cache+"/"+entry.getName()); 102 fout.getParentFile().mkdirs(); 103 out = new java.io.FileOutputStream (fout); 104 } catch (java.io.IOException ex) { 105 TheLogger.error(_class_name, opname, "FAILED", ex); 107 return null; 108 } 109 110 int nread = 0; 111 byte[] buffer = new byte[2048]; 112 try { 113 while (nread!=-1) { 114 nread = in.read(buffer, 0, 2048); 115 if (nread!=-1) out.write(buffer, 0, nread); 116 } 117 118 in.close(); 119 out.close(); 120 } catch (java.io.IOException ex) { 121 final String msg = "FAILED (entry: "+entry.getName()+")"; 123 TheLogger.error(_class_name, opname, "FAILED", ex); 124 return null; 125 } 126 127 return _archive_cache+"/"+entry.getName(); 128 } 129 130 134 final public String 135 get_fileinarchive_location(String name) 136 { 137 final String opname = "get_fileinarchive_location"; 138 139 String location = (String )_entry2loc.get(name); 141 if (location!=null) { 142 return location; 143 } 144 145 java.util.zip.ZipFile zip = openZip(); 147 148 java.util.Enumeration entries = zip.entries(); 150 java.util.zip.ZipEntry entry = null; 151 java.util.zip.ZipEntry fentry = null; 152 while (entries.hasMoreElements()) { 153 entry = (java.util.zip.ZipEntry )entries.nextElement(); 154 if (entry.getName().equals(name)) { 155 fentry = entry; 156 break; 157 } 158 } 159 160 if (fentry==null) { 162 final String msg = "FAILED (entry not found: "+name+")"; 163 TheLogger.error(_class_name, opname, msg); 164 } 165 166 location = extractFile(zip, fentry); 168 169 _entry2loc.put(name, location); 171 172 return location; 173 } 174 175 final public String 176 get_href_location(String href) 177 { 178 final String opname = "get_href_location"; 179 final String msg = "FAILED (not implemented, rethrown)"; 180 TheLogger.debug(_class_name, opname, msg); 181 182 throw new org.omg.CORBA.NO_IMPLEMENT (); 183 } 184 185 final public String 186 get_link_location(String link) 187 { 188 final String opname = "get_link_location"; 189 final String msg = "FAILED (not implemented, rethrown)"; 190 TheLogger.debug(_class_name, opname, msg); 191 192 throw new org.omg.CORBA.NO_IMPLEMENT (); 193 } 194 195 final public String 196 get_ins_as_objref(String ins) 197 { 198 RegistrationService regs = org.objectweb.corba.runtime.Runtime.getRegistrationService(); 199 INSRegistrationScheme scheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID); 200 201 org.omg.CORBA.Object ref = scheme.lookup(ins, getORBService()); 202 return getORBService().object_to_string(ref); 203 } 204 205 final public String 206 uuid() 207 { 208 return _uuid; 209 } 210 } 211 | Popular Tags |