1 17 package org.apache.geronimo.spring.deployment; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.net.URI ; 22 import java.util.ArrayList ; 23 import java.util.Enumeration ; 24 import java.util.Hashtable ; 25 import java.util.List ; 26 import java.util.jar.JarFile ; 27 import java.util.zip.ZipEntry ; 28 import javax.management.ObjectName ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.apache.geronimo.common.DeploymentException; 33 import org.apache.geronimo.deployment.ConfigurationBuilder; 34 import org.apache.geronimo.gbean.GBeanData; 35 import org.apache.geronimo.gbean.GBeanInfo; 36 import org.apache.geronimo.gbean.GBeanInfoBuilder; 37 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 38 import org.apache.geronimo.kernel.Kernel; 39 import org.apache.geronimo.kernel.config.ConfigurationModuleType; 40 import org.apache.geronimo.kernel.config.ConfigurationData; 41 import org.apache.geronimo.kernel.repository.Repository; 42 import org.apache.geronimo.spring.SpringApplicationImpl; 43 import org.apache.geronimo.spring.SpringGBean; 44 45 48 public class SPRConfigBuilder 49 implements ConfigurationBuilder 50 { 51 protected static final Log _log=LogFactory.getLog(SPRConfigBuilder.class); 52 protected static final String _defaultConfigPath="META-INF/spring.xml"; 53 54 protected final Kernel _kernel; 55 protected final Repository _repository; 56 protected final URI _defaultParentId; 57 58 public 59 SPRConfigBuilder(URI defaultParentId, Repository repository, Kernel kernel) 60 { 61 _kernel =kernel; 62 _repository =repository; 63 _defaultParentId=defaultParentId; 64 } 65 66 69 public static final GBeanInfo GBEAN_INFO; 70 71 static 72 { 73 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(SPRConfigBuilder.class, NameFactory.CONFIG_BUILDER); 74 infoFactory.addAttribute("defaultParentId" , URI .class, true); 75 infoFactory.addReference("Repository" , Repository.class, NameFactory.GERONIMO_SERVICE); 76 infoFactory.addAttribute("kernel" , Kernel.class, false); 77 infoFactory.addInterface(ConfigurationBuilder.class); 78 infoFactory.setConstructor(new String []{"defaultParentId", "Repository", "kernel"}); 79 80 GBEAN_INFO = infoFactory.getBeanInfo(); 81 } 82 83 public static GBeanInfo getGBeanInfo() {return GBEAN_INFO;} 84 85 87 public Object 88 getDeploymentPlan(File planFile, JarFile sprFile) 89 throws DeploymentException 90 { 91 if (sprFile==null || !sprFile.getName().endsWith(".spr")) return null; 92 93 _log.info("Planning: "+sprFile.getName()); 94 95 100 return this; } 102 103 public ConfigurationData 104 buildConfiguration(Object plan, JarFile sprFile, File outfile) 105 throws IOException , DeploymentException 106 { 107 if (!(plan instanceof SPRConfigBuilder)) return null; 109 110 String uid=sprFile.getName(); 112 _log.info("Building: "+uid); 113 114 SPRContext ctx=null; 115 try 116 { 117 URI configId=new URI (sprFile.getName()); URI parentId=_defaultParentId; URI configPath=new URI (_defaultConfigPath); 120 121 ctx=new SPRContext(outfile, configId, ConfigurationModuleType.SPR, parentId, _kernel); 122 123 List classPath=new ArrayList (); 126 classPath.add(new URI (".")); 127 128 for (Enumeration e=sprFile.entries(); e.hasMoreElements();) 129 { 130 ZipEntry entry = (ZipEntry ) e.nextElement(); 131 String name=entry.getName(); 132 ctx.addFile(URI.create(name), sprFile, entry); 133 134 if (name.endsWith(".jar")) 135 classPath.add(new URI (name)); 136 } 137 138 141 { 143 ObjectName name=new ObjectName ("geronimo.config", "name", uid); 144 GBeanData gbeanData=new GBeanData(name, SpringApplicationImpl.GBEAN_INFO); 145 ctx.addGBean(gbeanData); 146 } 147 148 { 150 Hashtable props=new Hashtable (); 151 props.put("J2EEServer" , "geronimo"); 152 props.put("J2EEApplication" , "null"); 153 props.put("j2eeType" , "SpringModule"); 154 props.put("name" , uid); 155 ObjectName on=new ObjectName ("geronimo.server", props); 156 GBeanData gbeanData=new GBeanData(on, SpringGBean.GBEAN_INFO); 157 gbeanData.setAttribute("classPath" , classPath.toArray(new URI [classPath.size()])); 158 gbeanData.setAttribute("configPath" , configPath); 159 ctx.addGBean(gbeanData); 160 } 161 } 162 catch (Exception e) 163 { 164 throw new DeploymentException(e); 165 } 166 finally 167 { 168 if (ctx!=null) ctx.close(); 169 } 170 171 return ctx.getConfigurationData(); 172 } 173 } 174 | Popular Tags |