001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.deployment.plugin;
017:
018: import java.io.OutputStream;
019: import java.io.InputStream;
020: import java.io.IOException;
021:
022: import javax.enterprise.deploy.spi.DeploymentConfiguration;
023: import javax.enterprise.deploy.spi.DConfigBeanRoot;
024: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
025: import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
026: import javax.enterprise.deploy.model.DeployableObject;
027: import javax.enterprise.deploy.model.DDBeanRoot;
028:
029: import org.apache.xmlbeans.XmlException;
030:
031: /**
032: *
033: *
034: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
035: */
036: public abstract class DeploymentConfigurationSupport implements
037: DeploymentConfiguration {
038: private final DeployableObject deployable;
039:
040: protected DConfigBeanRootSupport dConfigRoot;
041:
042: public DeploymentConfigurationSupport(DeployableObject deployable,
043: DConfigBeanRootSupport dConfigRoot) {
044: this .deployable = deployable;
045: this .dConfigRoot = dConfigRoot;
046: }
047:
048: public DeployableObject getDeployableObject() {
049: return deployable;
050: }
051:
052: public DConfigBeanRoot getDConfigBeanRoot(DDBeanRoot bean)
053: throws ConfigurationException {
054: if (getDeployableObject().getDDBeanRoot().equals(bean)) {
055: return dConfigRoot;
056: }
057: return null;
058: }
059:
060: public void removeDConfigBean(DConfigBeanRoot bean)
061: throws BeanNotFoundException {
062: }
063:
064: public void save(OutputStream outputArchive)
065: throws ConfigurationException {
066: try {
067: dConfigRoot.toXML(outputArchive);
068: outputArchive.flush();
069: } catch (IOException e) {
070: throw (ConfigurationException) new ConfigurationException(
071: "Unable to save configuration").initCause(e);
072: }
073: }
074:
075: public void restore(InputStream inputArchive)
076: throws ConfigurationException {
077: try {
078: dConfigRoot.fromXML(inputArchive);
079: } catch (IOException e) {
080: throw (ConfigurationException) new ConfigurationException(
081: "Error reading configuration input").initCause(e);
082: } catch (XmlException e) {
083: throw (ConfigurationException) new ConfigurationException(
084: "Error parsing configuration input").initCause(e);
085: }
086: }
087:
088: public void saveDConfigBean(OutputStream outputArchive,
089: DConfigBeanRoot bean) throws ConfigurationException {
090: try {
091: ((DConfigBeanRootSupport) bean).toXML(outputArchive);
092: outputArchive.flush();
093: } catch (IOException e) {
094: throw (ConfigurationException) new ConfigurationException(
095: "Unable to save configuration").initCause(e);
096: }
097: }
098:
099: //todo figure out how to implement this.
100: public DConfigBeanRoot restoreDConfigBean(InputStream inputArchive,
101: DDBeanRoot bean) throws ConfigurationException {
102: return null;
103: }
104: }
|