KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > WarFilePanel


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24
25 package org.enhydra.tool.archive.wizard;
26
27 // ToolBox
28
import org.enhydra.tool.archive.ArchiveException;
29 import org.enhydra.tool.archive.Descriptor;
30 import org.enhydra.tool.archive.JarPlan;
31 import org.enhydra.tool.archive.WarPlan;
32
33 // JDK
34
import java.awt.*;
35 import java.beans.Beans JavaDoc;
36 import java.io.File JavaDoc;
37 import java.lang.ref.WeakReference JavaDoc;
38 import javax.swing.*;
39
40 //
41
public class WarFilePanel extends ArchivePanel {
42     private BorderLayout layoutMain = null;
43     private FilePanel filePanel = null;
44
45     public WarFilePanel() {
46         try {
47             jbInit();
48             pmInit();
49         } catch (Exception JavaDoc ex) {
50             ex.printStackTrace();
51         }
52     }
53
54     public void readPlan(JarPlan plan) throws ArchiveException {
55         filePanel.setArchivePath(plan.getArchivePath());
56         if (plan instanceof WarPlan) {
57             WarPlan wp = (WarPlan) plan;
58             Descriptor[] rows = plan.getDescriptors();
59
60             filePanel.getDDTableModel().clear();
61             for (int i = 0 ; i < rows.length ; i++ ) {
62               filePanel.getDDTableModel().addDescriptor(rows[i]);
63             }
64             filePanel.getDDTable().setRowSelectionInterval(0, 0);
65         } else {
66             throw new ArchiveException("Unable to read plan: expecting type WarPlan");
67         }
68     }
69
70     public void writePlan(JarPlan plan) throws ArchiveException {
71         validatePlan();
72         plan.setArchivePath(filePanel.getArchivePath());
73         plan.setDescriptors(filePanel.getDDTableModel().getDescriptors());
74     }
75
76     public void validatePlan() throws ArchiveException {
77         filePanel.validatePlan();
78     }
79
80     public String JavaDoc getPageTitle() {
81         return "Web Archive";
82     }
83
84     public String JavaDoc getInstructions() {
85         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
86
87         buf.append("Enter details for the web archive file.");
88         return buf.toString();
89     }
90
91     // override ArchivePanel
92
protected void setWizard(ArchiveWizard wizard) {
93       super.setWizard(wizard);
94       filePanel.setWizard(wizard);
95     }
96
97     protected void preparePanel() {
98        String JavaDoc[] defaultDD = new String JavaDoc[1];
99        StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
100        buf.append("src");
101        buf.append(File.separator);
102        buf.append("WEB-INF");
103        buf.append(File.separator);
104        buf.append("web.xml");
105        defaultDD[0] = buf.toString();
106        filePanel.setDefaultDD(defaultDD);
107        filePanel.preparePanel();
108     }
109
110     private void pmInit() {
111       filePanel.setExtension("war");
112     }
113
114     private void jbInit() throws Exception JavaDoc {
115         layoutMain =
116             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
117                                              BorderLayout.class.getName());
118         filePanel = (FilePanel) Beans.instantiate(getClass().getClassLoader(),
119                                                   FilePanel.class.getName());
120         this.setLayout(layoutMain);
121         this.add(filePanel, BorderLayout.CENTER);
122     }
123
124 }
125
Popular Tags