001: /*
002: * ParFile.java
003: *
004: * Created on October 24, 2001, 4:43 PM
005: */
006:
007: package com.sun.portal.desktop.deployment;
008:
009: import java.util.Vector;
010:
011: import java.util.zip.ZipEntry;
012:
013: import java.util.jar.JarFile;
014:
015: import java.io.InputStream;
016: import java.io.PrintStream;
017:
018: /**
019: * The basic Parfile class. It extends JarFile to handle the specialized manifest
020: * and extraction methods for the portal server.
021: *
022: * @author yabob
023: * @version
024: */
025: public class ParFile extends JarFile {
026:
027: // private constructor, so we can wrap exception thrown by the JarFile constructor.
028:
029: private ParFile(String path) throws Exception {
030: super (path);
031: m_PMan = ParManifest.makeManifest(getManifest());
032: }
033:
034: // static routine which uses the private constructor to create a new ParFile.
035:
036: public static ParFile makeParFile(String path)
037: throws ParFileException {
038:
039: try {
040: return new ParFile(path);
041: } catch (Exception ex) {
042: throw new ParFileException("errorParFileCreation", ex);
043: }
044: }
045:
046: public ParManifest getParManifest() {
047: return m_PMan;
048: }
049:
050: public void describe(PrintStream out) throws ParFileException {
051:
052: // describe logic is handled by the manifest, but it needs a reference to
053: // the par file so it can extract the XML documents to describe them.
054:
055: m_PMan.describe(out, this );
056: }
057:
058: // Perform autoextraction of all of the .par file entries which have autoextraction
059: // defined. Really, we just get the op's out of the manifest and call performExtraction
060: // with them.
061:
062: public void performAutoExtraction(ParExtractionContext pex,
063: String dpnode) throws ParFileException {
064:
065: Vector nl = m_PMan.getDPEntryList();
066: int opcount = 0;
067:
068: for (int i = 0; i < nl.size(); ++i) {
069:
070: String name = (String) nl.elementAt(i);
071: ExtractOp op = m_PMan.getDPEntryAutoExtract(name);
072:
073: if (op != null) {
074: ++opcount;
075: if (dpnode != null) {
076: op.setDPNode(dpnode);
077: }
078: op.setEntryName(name);
079: performExtraction(pex, op);
080: }
081: }
082:
083: if (opcount == 0) {
084: throw new ParFileException("errorNoOperations");
085: }
086: }
087:
088: // Perform autoextraction of all of the .par file entries which have autoextraction
089: // defined. Really, we just get the op's out of the manifest and call performExtraction
090: // with them.
091:
092: public void performAutoExtraction(ParExtractionContext pex,
093: String dpnode, boolean extractDP) throws ParFileException {
094:
095: Vector nl = m_PMan.getDPEntryList();
096: int opcount = 0;
097:
098: for (int i = 0; i < nl.size(); ++i) {
099:
100: String name = (String) nl.elementAt(i);
101: ExtractOp op = m_PMan.getDPEntryAutoExtract(name);
102:
103: if (op != null) {
104: ++opcount;
105: if (dpnode != null) {
106: op.setDPNode(dpnode);
107: }
108: op.setEntryName(name);
109: performExtraction(pex, op, extractDP);
110: }
111: }
112:
113: if (opcount == 0) {
114: throw new ParFileException("errorNoOperations");
115: }
116: }
117:
118: // Perform an extraction operation
119:
120: public void performExtraction(ParExtractionContext pex, ExtractOp op)
121: throws ParFileException {
122:
123: // Just bracket the real work with initialize ... terminate, handling failure appropriately.
124:
125: pex.initializeForOperation(op);
126: try {
127: extractionOperation(pex, op);
128: } catch (ParFileException ex) {
129: pex.terminateOperation(false);
130: throw ex;
131: }
132: pex.terminateOperation(true);
133: }
134:
135: // Perform an extraction operation
136:
137: public void performExtraction(ParExtractionContext pex,
138: ExtractOp op, boolean extractDP) throws ParFileException {
139:
140: // Just bracket the real work with initialize ... terminate, handling failure appropriately.
141:
142: pex.initializeForOperation(op);
143: try {
144: extractionOperation(pex, op, extractDP);
145: } catch (ParFileException ex) {
146: pex.terminateOperation(false);
147: throw ex;
148: }
149: pex.terminateOperation(true);
150: }
151:
152: // Perform file extraction
153: public void performFileExtraction(ParExtractionContext pex,
154: String entryName, int types) throws ParFileException {
155: fileExtractionOperation(pex, entryName, types);
156: }
157:
158: // The real work of an extraction operation.
159: private void extractionOperation(ParExtractionContext pex,
160: ExtractOp op) throws ParFileException {
161:
162: // We HAVE to have a DPEntry file. Extract it, and call putParEntryXMLFile to deploy it.
163:
164: ZipEntry ze = m_PMan.getDPZip(op.getEntryName());
165: InputStream is = getCheckedIS(ze);
166: pex.putParEntryXMLFile(is, op.getTypes());
167: fileExtractionOperation(pex, op.getEntryName(), op.getTypes());
168: }
169:
170: // The real work of an extraction operation.
171: private void extractionOperation(ParExtractionContext pex,
172: ExtractOp op, boolean extractDP) throws ParFileException {
173:
174: // We HAVE to have a DPEntry file. Extract it, and call putParEntryXMLFile to deploy it.
175: ZipEntry ze = m_PMan.getDPZip(op.getEntryName());
176: InputStream is = getCheckedIS(ze);
177: if (extractDP) {
178: pex.putParEntryXMLFile(is, op.getTypes());
179: } else {
180: pex.setChannelPath(is, op.getTypes());
181: }
182: fileExtractionOperation(pex, op.getEntryName(), op.getTypes());
183: }
184:
185: // Gets file list in the par file, and put them back based on type
186: private void fileExtractionOperation(ParExtractionContext pex,
187: String entryName, int types) throws ParFileException {
188: // Get the files associated with our entry
189:
190: Vector files = m_PMan.getDPEntryIncludeList(entryName, types);
191: for (int i = 0; i < files.size(); ++i) {
192:
193: // obtain the ZipEntry and open a stram to it.
194:
195: // technically, we should use the get*Zip() calls to construct ZipEntry's
196: // from our specific types, but we know that all that is going to do is
197: // glue the path back together again, so we can save the trouble, and
198: // just get the normal jar entry.
199:
200: String path = (String) files.elementAt(i);
201: ZipEntry ze = getJarEntry(path);
202: InputStream is = getCheckedIS(ze);
203:
204: // Now, direct the stream according to the type of path.
205:
206: switch (m_PMan.getPathRootType(path)) {
207: case CLASSFILE:
208: String fn = m_PMan.getFullFromClassPath(path);
209: pex.putClassFile(fn, is);
210: break;
211: case PBFILE:
212: String prop = m_PMan.getPropertyFromPBFPath(path);
213: String relp = m_PMan.getPathFromPBFPath(path);
214: pex.putPropLocFile(prop, relp, is);
215: break;
216: case STATFILE:
217: String sp = m_PMan.getPathFromStaticPath(path);
218: pex.putStaticFile(sp, is);
219: break;
220: case WARFILE:
221: String wp = m_PMan.getPathFromWarPath(path);
222: pex.putWarFile(wp, is);
223: break;
224: case CONFFILE:
225: String cp = m_PMan.getPathFromConfPath(path);
226: pex.putConfigFile(cp, is);
227: break;
228: default:
229: throw new ParFileException("errorExportOp");
230: }
231: }
232:
233: }
234:
235: // Wrap stream creation with our own exceptions.
236:
237: private InputStream getCheckedIS(ZipEntry ze)
238: throws ParFileException {
239:
240: try {
241: InputStream is = getInputStream(ze);
242: if (is == null) {
243: throw new ParFileException("errorZipOpen");
244: }
245:
246: return is;
247: } catch (Exception ex) {
248: throw new ParFileException("errorZipOpen", ex);
249: }
250: }
251:
252: private ParManifest m_PMan;
253:
254: private static final int CLASSFILE = ParManifest.CLASSFILE;
255: private static final int PBFILE = ParManifest.PBFILE;
256: private static final int STATFILE = ParManifest.STATFILE;
257: private static final int WARFILE = ParManifest.WARFILE;
258: private static final int CONFFILE = ParManifest.CONFFILE;
259: }
|