KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > e_app > EarDeployGenerator


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.e_app;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.server.deploy.DeployContainer;
34 import com.caucho.server.deploy.ExpandDeployGenerator;
35 import com.caucho.server.webapp.WebAppContainer;
36 import com.caucho.vfs.Path;
37
38 import java.util.ArrayList JavaDoc;
39
40 /**
41  * The generator for the ear-deploy
42  */

43 public class EarDeployGenerator
44   extends ExpandDeployGenerator<EarDeployController>
45 {
46   private final EarDeployGeneratorAdmin _admin = new EarDeployGeneratorAdmin(this);
47
48   private String JavaDoc _urlPrefix = "";
49
50   private WebAppContainer _parentContainer;
51   
52   private EarConfig _earDefault;
53
54   private ArrayList JavaDoc<EarConfig> _earDefaultList
55     = new ArrayList JavaDoc<EarConfig>();
56
57   public EarDeployGenerator(DeployContainer<EarDeployController> deployContainer,
58                 WebAppContainer parentContainer)
59   {
60     super(deployContainer, parentContainer.getRootDirectory());
61
62     try {
63       setExpandPrefix("_ear_");
64       setExtension(".ear");
65     } catch (Exception JavaDoc e) {
66       throw new RuntimeException JavaDoc(e);
67     }
68
69     _parentContainer = parentContainer;
70
71     _earDefaultList.addAll(parentContainer.getEarDefaultList());
72   }
73
74   /**
75    * Returns the parent container;
76    */

77   WebAppContainer getContainer()
78   {
79     return _parentContainer;
80   }
81
82   /**
83    * Gets the URL prefix.
84    */

85   public String JavaDoc getURLPrefix()
86   {
87     return _urlPrefix;
88   }
89
90   /**
91    * Sets the URL prefix.
92    */

93   public void setURLPrefix(String JavaDoc prefix)
94   {
95     _urlPrefix = prefix;
96   }
97
98   /**
99    * Sets the ear default.
100    */

101   public void addEarDefault(EarConfig config)
102   {
103     _earDefaultList.add(config);
104   }
105
106   @Override JavaDoc
107   protected void initImpl()
108     throws ConfigException
109   {
110     super.initImpl();
111   }
112
113   @Override JavaDoc
114   protected void startImpl()
115     throws ConfigException
116   {
117     super.startImpl();
118
119     _admin.register();
120   }
121
122   /**
123    * Converts the archive name to the entry name, returns null if
124    * the path name is not a valid entry name.
125    */

126   protected String JavaDoc archiveNameToEntryName(String JavaDoc archiveName)
127   {
128     if (! archiveName.endsWith(".ear"))
129       return null;
130     else
131       return archiveName.substring(0, archiveName.length() - 4);
132   }
133   
134   /**
135    * Returns the current array of application entries.
136    */

137   public EarDeployController createController(String JavaDoc name)
138   {
139     String JavaDoc archiveName = name + getExtension();
140     Path archivePath = getArchiveDirectory().lookup(archiveName);
141
142     Path rootDirectory;
143
144     if (archivePath.isDirectory()) {
145       rootDirectory = getExpandDirectory().lookup(archiveName);
146       archivePath = null;
147     }
148     else {
149       rootDirectory = getExpandDirectory().lookup(getExpandName(name));
150
151       if (! archivePath.canRead() && ! rootDirectory.canRead())
152     return null;
153     }
154
155     EarDeployController controller
156       = new EarDeployController(name, rootDirectory, _parentContainer);
157
158     controller.setArchivePath(archivePath);
159
160     for (EarConfig config : _earDefaultList)
161       controller.addConfigDefault(config);
162
163     return controller;
164   }
165
166   @Override JavaDoc
167   protected void destroyImpl()
168   {
169     _admin.unregister();
170
171     super.destroyImpl();
172   }
173 }
174
Popular Tags