View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
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  /**
34   *
35   *
36   * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
37   */
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      //todo figure out how to implement this.
91      public DConfigBeanRoot restoreDConfigBean(InputStream inputArchive, DDBeanRoot bean) throws ConfigurationException {
92          return null;
93      }
94  }