1 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 ; 39 40 43 public class EarDeployGenerator 44 extends ExpandDeployGenerator<EarDeployController> 45 { 46 private final EarDeployGeneratorAdmin _admin = new EarDeployGeneratorAdmin(this); 47 48 private String _urlPrefix = ""; 49 50 private WebAppContainer _parentContainer; 51 52 private EarConfig _earDefault; 53 54 private ArrayList <EarConfig> _earDefaultList 55 = new ArrayList <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 e) { 66 throw new RuntimeException (e); 67 } 68 69 _parentContainer = parentContainer; 70 71 _earDefaultList.addAll(parentContainer.getEarDefaultList()); 72 } 73 74 77 WebAppContainer getContainer() 78 { 79 return _parentContainer; 80 } 81 82 85 public String getURLPrefix() 86 { 87 return _urlPrefix; 88 } 89 90 93 public void setURLPrefix(String prefix) 94 { 95 _urlPrefix = prefix; 96 } 97 98 101 public void addEarDefault(EarConfig config) 102 { 103 _earDefaultList.add(config); 104 } 105 106 @Override 107 protected void initImpl() 108 throws ConfigException 109 { 110 super.initImpl(); 111 } 112 113 @Override 114 protected void startImpl() 115 throws ConfigException 116 { 117 super.startImpl(); 118 119 _admin.register(); 120 } 121 122 126 protected String archiveNameToEntryName(String archiveName) 127 { 128 if (! archiveName.endsWith(".ear")) 129 return null; 130 else 131 return archiveName.substring(0, archiveName.length() - 4); 132 } 133 134 137 public EarDeployController createController(String name) 138 { 139 String 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 167 protected void destroyImpl() 168 { 169 _admin.unregister(); 170 171 super.destroyImpl(); 172 } 173 } 174 | Popular Tags |