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 javax.enterprise.deploy.model.DDBean;
019:
020: import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
021: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
022: import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
023: import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
024: import org.apache.xmlbeans.SchemaTypeLoader;
025:
026: /**
027: *
028: *
029: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
030: *
031: **/
032: public class ConnectionDefinitionDConfigBean extends DConfigBeanSupport {
033:
034: private ConnectionDefinitionInstance[] instances = new ConnectionDefinitionInstance[0];
035:
036: public ConnectionDefinitionDConfigBean(DDBean ddBean,
037: GerConnectionDefinitionType connectionDefinition) {
038: super (ddBean, connectionDefinition);
039: String connectionfactoryInterface = ddBean
040: .getText("connectionfactory-interface")[0];
041: if (connectionDefinition.getConnectionfactoryInterface() == null) {
042: connectionDefinition
043: .setConnectionfactoryInterface(connectionfactoryInterface);
044: } else {
045: assert connectionfactoryInterface
046: .equals(connectionDefinition
047: .getConnectionfactoryInterface());
048: }
049: // Get initial list of instances
050: instances = new ConnectionDefinitionInstance[getConnectionDefinition()
051: .getConnectiondefinitionInstanceArray().length];
052: for (int i = 0; i < instances.length; i++) {
053: instances[i] = new ConnectionDefinitionInstance();
054: instances[i].initialize(getConnectionDefinition()
055: .getConnectiondefinitionInstanceArray(i), this );
056: }
057: }
058:
059: GerConnectionDefinitionType getConnectionDefinition() {
060: return (GerConnectionDefinitionType) getXmlObject();
061: }
062:
063: public ConnectionDefinitionInstance[] getConnectionDefinitionInstance() {
064: return instances;
065: }
066:
067: public void setConnectionDefinitionInstance(
068: ConnectionDefinitionInstance[] instances) {
069: ConnectionDefinitionInstance[] old = getConnectionDefinitionInstance();
070: this .instances = instances;
071: for (int i = 0; i < instances.length; i++) { // catch additions
072: ConnectionDefinitionInstance instance = instances[i];
073: if (!instance.hasParent()) {
074: GerConnectiondefinitionInstanceType xmlObject = getConnectionDefinition()
075: .addNewConnectiondefinitionInstance();
076: xmlObject
077: .setConnectionmanager(GerConnectionmanagerType.Factory
078: .newInstance());
079: instance.initialize(xmlObject, this );
080: }
081: }
082: for (int i = 0; i < old.length; i++) { // catch removals
083: ConnectionDefinitionInstance instance = old[i];
084: boolean found = false;
085: for (int j = 0; j < instances.length; j++) {
086: if (instances[j] == instance) {
087: found = true;
088: break;
089: }
090: }
091: if (!found) {
092: // remove the XmlBean
093: for (int j = 0; j < getConnectionDefinition()
094: .getConnectiondefinitionInstanceArray().length; j++) {
095: GerConnectiondefinitionInstanceType test = getConnectionDefinition()
096: .getConnectiondefinitionInstanceArray(j);
097: if (test == instance
098: .getConnectiondefinitionInstance()) {
099: getConnectionDefinition()
100: .removeConnectiondefinitionInstance(j);
101: break;
102: }
103: }
104: // clean up the removed JavaBean
105: instance.dispose();
106: }
107: }
108: pcs.firePropertyChange("connectionDefinitionInstance", old,
109: instances);
110: }
111:
112: protected SchemaTypeLoader getSchemaTypeLoader() {
113: return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
114: }
115:
116: }
|