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.jsr88;
017:
018: import java.util.Set;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import javax.enterprise.deploy.model.DDBean;
022: import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
023: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
024: import org.apache.geronimo.xbeans.geronimo.GerOutboundResourceadapterType;
025: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
026: import org.apache.xmlbeans.SchemaTypeLoader;
027:
028: /**
029: * Represents /connector/resourceadapter in the Geronimo Connector deployment plan.
030: * Note: is not a DConfigBean, because there may be more than one ResourceAdapter
031: * in the Geronimo plan per ResourceAdapter in the J2EE deployment descriptor.
032: *
033: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
034: */
035: public class ResourceAdapter extends XmlBeanSupport {
036: private DDBean resourceAdapter;
037: private ConnectionDefinition[] instances = new ConnectionDefinition[0];
038: private ResourceAdapterInstance resourceAdapterInstance;
039:
040: public ResourceAdapter() {
041: super (null);
042: }
043:
044: public ResourceAdapter(DDBean resourceAdapter,
045: GerResourceadapterType ra) {
046: super (null);
047: configure(resourceAdapter, ra);
048: }
049:
050: protected GerResourceadapterType getResourceAdapter() {
051: return (GerResourceadapterType) getXmlObject();
052: }
053:
054: void configure(DDBean resourceAdapter, GerResourceadapterType ra) {
055: this .resourceAdapter = resourceAdapter;
056: setXmlObject(ra);
057: if (ra.isSetResourceadapterInstance()) {
058: resourceAdapterInstance = new ResourceAdapterInstance(
059: resourceAdapter, ra.getResourceadapterInstance());
060: } else {
061: resourceAdapterInstance = null;
062: }
063: if (ra.isSetOutboundResourceadapter()) {
064: DDBean[] test = resourceAdapter
065: .getChildBean("outbound-resourceadapter");
066: if (test != null && test.length > 0) {
067: GerOutboundResourceadapterType outbound = ra
068: .getOutboundResourceadapter();
069: GerConnectionDefinitionType[] defs = outbound
070: .getConnectionDefinitionArray();
071: if (defs != null) {
072: instances = new ConnectionDefinition[defs.length];
073: for (int i = 0; i < defs.length; i++) {
074: GerConnectionDefinitionType def = defs[i];
075: instances[i] = new ConnectionDefinition(
076: resourceAdapter, def);
077: }
078: }
079: } else {
080: //todo: clean up the Geronimo deployment info since there's no J2EE outbound RA
081: }
082: }
083: }
084:
085: // ----------------------- JavaBean Properties for /connector/resourceadapter ----------------------
086:
087: public ConnectionDefinition[] getConnectionDefinition() {
088: return instances;
089: }
090:
091: public ConnectionDefinition getConnectionDefinition(int index) {
092: return instances[index];
093: }
094:
095: public void setConnectionDefinition(
096: ConnectionDefinition[] definitions) {
097: ConnectionDefinition[] old = getConnectionDefinition();
098:
099: if (definitions != null && definitions.length > 0) {
100: if (!getResourceAdapter().isSetOutboundResourceadapter()) {
101: getResourceAdapter().addNewOutboundResourceadapter();
102: }
103: } else {
104: if (getResourceAdapter().isSetOutboundResourceadapter()) {
105: getResourceAdapter().unsetOutboundResourceadapter();
106: }
107: }
108: Set before = new HashSet();
109: for (int i = 0; i < old.length; i++) {
110: before.add(old[i]);
111: }
112: instances = definitions;
113: // Handle current or new definitions
114: for (int i = 0; i < definitions.length; i++) {
115: ConnectionDefinition definition = definitions[i];
116: if (definition.getConnectionDefinition() == null) {
117: definition.configure(resourceAdapter,
118: getResourceAdapter()
119: .getOutboundResourceadapter()
120: .addNewConnectionDefinition());
121: } else {
122: before.remove(definition);
123: }
124: }
125: // Handle removed definitions
126: for (Iterator it = before.iterator(); it.hasNext();) {
127: ConnectionDefinition definition = (ConnectionDefinition) it
128: .next();
129: GerConnectionDefinitionType all[] = getResourceAdapter()
130: .isSetOutboundResourceadapter() ? getResourceAdapter()
131: .getOutboundResourceadapter()
132: .getConnectionDefinitionArray()
133: : new GerConnectionDefinitionType[0];
134: for (int i = 0; i < all.length; i++) {
135: if (all[i] == definition) {
136: getResourceAdapter().getOutboundResourceadapter()
137: .removeConnectionDefinition(i);
138: break;
139: }
140: }
141: }
142: pcs.firePropertyChange("connectionDefinition", old, instances);
143: }
144:
145: public void setConnectionDefinition(int index,
146: ConnectionDefinition definition) {
147: ConnectionDefinition[] old = instances;
148: instances[index] = definition;
149: if (definition.getConnectionDefinition() == null) {
150: definition.configure(resourceAdapter, getResourceAdapter()
151: .getOutboundResourceadapter()
152: .addNewConnectionDefinition());
153: }
154: pcs.firePropertyChange("connectionDefinition", old, instances);
155: }
156:
157: public ResourceAdapterInstance getResourceAdapterInstance() {
158: return resourceAdapterInstance;
159: }
160:
161: public void setResourceAdapterInstance(
162: ResourceAdapterInstance resourceAdapterInstance) {
163: ResourceAdapterInstance old = this .resourceAdapterInstance;
164: this .resourceAdapterInstance = resourceAdapterInstance;
165: if (resourceAdapterInstance.getResourceAdapterInstance() == null) {
166: if (getResourceAdapter().isSetResourceadapterInstance()) {
167: resourceAdapterInstance.configure(resourceAdapter,
168: getResourceAdapter()
169: .getResourceadapterInstance());
170: } else {
171: resourceAdapterInstance.configure(resourceAdapter,
172: getResourceAdapter()
173: .addNewResourceadapterInstance());
174: }
175: }
176: pcs.firePropertyChange("resourceAdapterInstance", old,
177: instances);
178: }
179:
180: // ----------------------- End of JavaBean Properties ----------------------
181:
182: protected SchemaTypeLoader getSchemaTypeLoader() {
183: return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
184: }
185: }
|