1 17 18 package org.apache.geronimo.deployment.plugin; 19 20 import java.io.OutputStream ; 21 import java.io.InputStream ; 22 import java.io.IOException ; 23 24 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 25 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 28 import javax.enterprise.deploy.model.DeployableObject ; 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 31 import org.apache.xmlbeans.XmlException; 32 33 38 public abstract class DeploymentConfigurationSupport implements DeploymentConfiguration { 39 private final DeployableObject deployable; 40 41 protected DConfigBeanRootSupport dConfigRoot; 42 43 public DeploymentConfigurationSupport(DeployableObject deployable, DConfigBeanRootSupport dConfigRoot) { 44 this.deployable = deployable; 45 this.dConfigRoot = dConfigRoot; 46 } 47 48 public DeployableObject getDeployableObject() { 49 return deployable; 50 } 51 52 public DConfigBeanRoot getDConfigBeanRoot(DDBeanRoot bean) throws ConfigurationException { 53 if (getDeployableObject().getDDBeanRoot().equals(bean)) { 54 return dConfigRoot; 55 } 56 return null; 57 } 58 59 public void removeDConfigBean(DConfigBeanRoot bean) throws BeanNotFoundException { 60 } 61 62 public void save(OutputStream outputArchive) throws ConfigurationException { 63 try { 64 dConfigRoot.toXML(outputArchive); 65 outputArchive.flush(); 66 } catch (IOException e) { 67 throw (ConfigurationException ) new ConfigurationException ("Unable to save configuration").initCause(e); 68 } 69 } 70 71 public void restore(InputStream inputArchive) throws ConfigurationException { 72 try { 73 dConfigRoot.fromXML(inputArchive); 74 } catch (IOException e) { 75 throw (ConfigurationException ) new ConfigurationException ("Error reading configuration input").initCause(e); 76 } catch (XmlException e) { 77 throw (ConfigurationException ) new ConfigurationException ("Error parsing configuration input").initCause(e); 78 } 79 } 80 81 public void saveDConfigBean(OutputStream outputArchive, DConfigBeanRoot bean) throws ConfigurationException { 82 try { 83 ((DConfigBeanRootSupport)bean).toXML(outputArchive); 84 outputArchive.flush(); 85 } catch (IOException e) { 86 throw (ConfigurationException ) new ConfigurationException ("Unable to save configuration").initCause(e); 87 } 88 } 89 90 public DConfigBeanRoot restoreDConfigBean(InputStream inputArchive, DDBeanRoot bean) throws ConfigurationException { 92 return null; 93 } 94 } 95 | Popular Tags |