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 */
017
018 package org.apache.geronimo.connector.deployment.dconfigbean;
019
020 import java.io.IOException;
021 import java.io.InputStream;
022 import javax.enterprise.deploy.model.DDBean;
023 import javax.enterprise.deploy.model.DDBeanRoot;
024 import javax.enterprise.deploy.spi.DConfigBean;
025 import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
026
027 import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport;
028 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
029 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
030 import org.apache.xmlbeans.SchemaTypeLoader;
031 import org.apache.xmlbeans.XmlException;
032
033 /**
034 *
035 *
036 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
037 *
038 * */
039 public class ResourceAdapter_1_0DConfigRoot extends DConfigBeanRootSupport {
040
041 private static String[] XPATHS = {
042 "connector/resourceadapter"
043 };
044
045 private ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean;
046
047 public ResourceAdapter_1_0DConfigRoot(DDBeanRoot ddBean) {
048 super(ddBean, GerConnectorDocument.Factory.newInstance());
049 GerConnectionDefinitionType connectionDefinition = getConnectorDocument().addNewConnector().addNewResourceadapter().addNewOutboundResourceadapter().addNewConnectionDefinition();
050 replaceConnectionDefinitionDConfigBean(connectionDefinition);
051 }
052
053 private void replaceConnectionDefinitionDConfigBean(GerConnectionDefinitionType connectionDefinition) {
054 DDBean ddBean = getDDBean();
055 DDBean childDDBean = ddBean.getChildBean(getXpaths()[0])[0];
056 connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(childDDBean, connectionDefinition);
057 }
058
059 GerConnectorDocument getConnectorDocument() {
060 return (GerConnectorDocument) getXmlObject();
061 }
062
063 public String[] getXpaths() {
064 return XPATHS;
065 }
066
067 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException {
068 if (getXpaths()[0].equals(bean.getXpath())) {
069 return connectionDefinitionDConfigBean;
070 }
071 return null;
072 }
073
074 public void fromXML(InputStream inputStream) throws XmlException, IOException {
075 super.fromXML(inputStream);
076 //TODO this is so totally wrong...
077 replaceConnectionDefinitionDConfigBean(getConnectorDocument().getConnector().getResourceadapterArray()[0].getOutboundResourceadapter().getConnectionDefinitionArray(0));
078 }
079
080 protected SchemaTypeLoader getSchemaTypeLoader() {
081 return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
082 }
083 }