KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > plugin > DeploymentConfigurationSupport


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
25 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
27 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
28 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
29 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
30
31 import org.apache.xmlbeans.XmlException;
32
33 /**
34  *
35  *
36  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public abstract class DeploymentConfigurationSupport implements DeploymentConfiguration JavaDoc {
39     private final DeployableObject JavaDoc deployable;
40
41     protected DConfigBeanRootSupport dConfigRoot;
42
43     public DeploymentConfigurationSupport(DeployableObject JavaDoc deployable, DConfigBeanRootSupport dConfigRoot) {
44         this.deployable = deployable;
45         this.dConfigRoot = dConfigRoot;
46     }
47
48     public DeployableObject JavaDoc getDeployableObject() {
49         return deployable;
50     }
51
52     public DConfigBeanRoot JavaDoc getDConfigBeanRoot(DDBeanRoot JavaDoc bean) throws ConfigurationException JavaDoc {
53         if (getDeployableObject().getDDBeanRoot().equals(bean)) {
54             return dConfigRoot;
55         }
56         return null;
57     }
58
59     public void removeDConfigBean(DConfigBeanRoot JavaDoc bean) throws BeanNotFoundException JavaDoc {
60     }
61
62     public void save(OutputStream JavaDoc outputArchive) throws ConfigurationException JavaDoc {
63         try {
64             dConfigRoot.toXML(outputArchive);
65             outputArchive.flush();
66         } catch (IOException JavaDoc e) {
67             throw (ConfigurationException JavaDoc) new ConfigurationException JavaDoc("Unable to save configuration").initCause(e);
68         }
69     }
70
71     public void restore(InputStream JavaDoc inputArchive) throws ConfigurationException JavaDoc {
72         try {
73             dConfigRoot.fromXML(inputArchive);
74         } catch (IOException JavaDoc e) {
75             throw (ConfigurationException JavaDoc) new ConfigurationException JavaDoc("Error reading configuration input").initCause(e);
76         } catch (XmlException e) {
77             throw (ConfigurationException JavaDoc) new ConfigurationException JavaDoc("Error parsing configuration input").initCause(e);
78         }
79     }
80
81     public void saveDConfigBean(OutputStream JavaDoc outputArchive, DConfigBeanRoot JavaDoc bean) throws ConfigurationException JavaDoc {
82         try {
83             ((DConfigBeanRootSupport)bean).toXML(outputArchive);
84             outputArchive.flush();
85         } catch (IOException JavaDoc e) {
86             throw (ConfigurationException JavaDoc) new ConfigurationException JavaDoc("Unable to save configuration").initCause(e);
87         }
88     }
89
90     //todo figure out how to implement this.
91
public DConfigBeanRoot JavaDoc restoreDConfigBean(InputStream JavaDoc inputArchive, DDBeanRoot JavaDoc bean) throws ConfigurationException JavaDoc {
92         return null;
93     }
94 }
95
Popular Tags