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.connector.deployment.dconfigbean;
017:
018: import java.io.IOException;
019: import java.io.InputStream;
020:
021: import javax.enterprise.deploy.model.DDBean;
022: import javax.enterprise.deploy.model.DDBeanRoot;
023: import javax.enterprise.deploy.spi.DConfigBean;
024: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
025:
026: import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport;
027: import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
028: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
029: import org.apache.xmlbeans.SchemaTypeLoader;
030: import org.apache.xmlbeans.XmlBeans;
031: import org.apache.xmlbeans.XmlException;
032: import org.apache.xmlbeans.XmlObject;
033:
034: /**
035: *
036: *
037: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
038: *
039: * */
040: public class ResourceAdapterDConfigRoot extends DConfigBeanRootSupport {
041: static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans
042: .typeLoaderUnion(new SchemaTypeLoader[] {
043: XmlBeans
044: .typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class
045: .getClassLoader()),
046: XmlBeans
047: .typeLoaderForClassLoader(GerConnectorDocument.class
048: .getClassLoader()) });
049:
050: private static String[][] XPATHS = { { "connector",
051: "resourceadapter" } };
052:
053: private ResourceAdapterDConfigBean resourceAdapterDConfigBean;
054:
055: public ResourceAdapterDConfigRoot(DDBeanRoot ddBean) {
056: super (ddBean, loadDefaultData(ddBean));
057: replaceResourceAdapterDConfigBean(getConnectorDocument()
058: .getConnector().getResourceadapterArray()[0]);
059: }
060:
061: private static XmlObject loadDefaultData(DDBeanRoot root) {
062: InputStream in = root.getDeployableObject().getEntry(
063: "META-INF/geronimo-ra.xml");
064: if (in == null) {
065: GerConnectorDocument doc = GerConnectorDocument.Factory
066: .newInstance();
067: doc.addNewConnector().addNewResourceadapter();
068: return doc;
069: } else {
070: try {
071: XmlObject result = GerConnectorDocument.Factory
072: .parse(in);
073: in.close();
074: return result;
075: } catch (XmlException e) {
076: throw new RuntimeException(
077: "Unable to load default Geronimo RA data", e);
078: } catch (IOException e) {
079: throw new RuntimeException(
080: "Unable to load default Geronimo RA data", e);
081: }
082: }
083: }
084:
085: private void replaceResourceAdapterDConfigBean(
086: GerResourceadapterType resourceAdapter) {
087: DDBean ddBean = getDDBean();
088: String path = getXpaths()[0];
089: System.out.println("********** Searching XPath " + path
090: + " -- " + ddBean.getChildBean(path));
091: DDBean childDDBean = ddBean.getChildBean(path)[0];
092: resourceAdapterDConfigBean = new ResourceAdapterDConfigBean(
093: childDDBean, resourceAdapter);
094: }
095:
096: GerConnectorDocument getConnectorDocument() {
097: return (GerConnectorDocument) getXmlObject();
098: }
099:
100: public String[] getXpaths() {
101: return getXPathsForJ2ee_1_4(XPATHS);
102: }
103:
104: public DConfigBean getDConfigBean(DDBean bean)
105: throws ConfigurationException {
106: if (getXpaths()[0].equals(bean.getXpath())) {
107: return resourceAdapterDConfigBean;
108: }
109: return null;
110: }
111:
112: public void fromXML(InputStream inputStream) throws XmlException,
113: IOException {
114: super .fromXML(inputStream);
115: //TODO this is so totally wrong...
116: replaceResourceAdapterDConfigBean(getConnectorDocument()
117: .getConnector().getResourceadapterArray()[0]);
118: }
119:
120: protected SchemaTypeLoader getSchemaTypeLoader() {
121: return SCHEMA_TYPE_LOADER;
122: }
123: }
|