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;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Collection;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Set;
025:
026: import org.apache.geronimo.j2ee.management.impl.Util;
027: import org.apache.geronimo.management.geronimo.JCAAdminObject;
028: import org.apache.geronimo.management.geronimo.JCAConnectionFactory;
029: import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
030: import org.apache.geronimo.management.geronimo.JCAResource;
031: import org.apache.geronimo.management.geronimo.JCAResourceAdapter;
032:
033: /**
034: * @version $Rev: 550546 $ $Date: 2007-06-25 09:52:11 -0700 (Mon, 25 Jun 2007) $
035: */
036: public class JCAResourceImpl implements JCAResource {
037: private final String objectName;
038:
039: private final Collection connectionFactories;
040: private final Collection resourceAdapters;
041: private final Collection adminObjects;
042:
043: public JCAResourceImpl(String objectName,
044: Collection connectionFactories,
045: Collection resourceAdapters, Collection adminObjects) {
046: this .objectName = objectName;
047: this .connectionFactories = connectionFactories;
048: this .resourceAdapters = resourceAdapters;
049: this .adminObjects = adminObjects;
050: }
051:
052: public String[] getConnectionFactories() {
053: return Util.getObjectNames(getConnectionFactoryInstances());
054: }
055:
056: public String[] getResourceAdapterInstanceNames() {
057: ArrayList temp = new ArrayList();
058: for (Iterator iterator = resourceAdapters.iterator(); iterator
059: .hasNext();) {
060: JCAResourceAdapter resourceAdapter = (JCAResourceAdapter) iterator
061: .next();
062: temp.add(resourceAdapter.getObjectName());
063: }
064: return (String[]) temp.toArray(new String[temp.size()]);
065: }
066:
067: public JCAResourceAdapter[] getResourceAdapterInstances() {
068: return (JCAResourceAdapter[]) resourceAdapters
069: .toArray(new JCAResourceAdapter[resourceAdapters.size()]);
070: }
071:
072: public JCAConnectionFactory[] getConnectionFactoryInstances() {
073: return (JCAConnectionFactory[]) connectionFactories
074: .toArray(new JCAConnectionFactory[connectionFactories
075: .size()]);
076: }
077:
078: public JCAManagedConnectionFactory[] getOutboundFactories() {
079: return getOutboundFactories((String[]) null);
080: }
081:
082: public JCAManagedConnectionFactory[] getOutboundFactories(
083: String connectionFactoryInterface) {
084: return getOutboundFactories(new String[] { connectionFactoryInterface });
085: }
086:
087: public JCAManagedConnectionFactory[] getOutboundFactories(
088: String[] connectionFactoryInterfaces) {
089: Set interfaceFilter = null;
090: if (connectionFactoryInterfaces != null) {
091: interfaceFilter = new HashSet(Arrays
092: .asList(connectionFactoryInterfaces));
093: }
094:
095: List list = new ArrayList();
096: for (Iterator iterator = connectionFactories.iterator(); iterator
097: .hasNext();) {
098: JCAConnectionFactory jcaConnectionFactory = (JCAConnectionFactory) iterator
099: .next();
100: JCAManagedConnectionFactory mcf = jcaConnectionFactory
101: .getManagedConnectionFactoryInstance();
102: if (interfaceFilter == null
103: || interfaceFilter.contains(mcf
104: .getConnectionFactoryInterface())) {
105: list.add(mcf);
106: continue;
107: }
108: for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) {
109: String iface = mcf.getImplementedInterfaces()[m];
110: if (interfaceFilter == null
111: || interfaceFilter.contains(iface)) {
112: list.add(mcf);
113: break;
114: }
115: }
116: }
117: return (JCAManagedConnectionFactory[]) list
118: .toArray(new JCAManagedConnectionFactory[list.size()]);
119: }
120:
121: public String[] getAdminObjects() {
122: return Util.getObjectNames(getAdminObjectInstances());
123: }
124:
125: public JCAAdminObject[] getAdminObjectInstances() {
126: return (JCAAdminObject[]) adminObjects
127: .toArray(new JCAAdminObject[adminObjects.size()]);
128: }
129:
130: public JCAAdminObject[] getAdminObjectInstances(
131: String adminObjectInterface) {
132: return getAdminObjectInstances(new String[] { adminObjectInterface });
133: }
134:
135: public JCAAdminObject[] getAdminObjectInstances(
136: String[] adminObjectInterfaces) {
137: Set interfaceFilter = null;
138: if (adminObjectInterfaces != null) {
139: interfaceFilter = new HashSet(Arrays
140: .asList(adminObjectInterfaces));
141: }
142:
143: List list = new ArrayList();
144:
145: for (Iterator iterator = adminObjects.iterator(); iterator
146: .hasNext();) {
147: JCAAdminObject adminObject = (JCAAdminObject) iterator
148: .next();
149: if (interfaceFilter == null
150: || interfaceFilter.contains(adminObject
151: .getAdminObjectInterface())) {
152: list.add(adminObject);
153: }
154: }
155:
156: return (JCAAdminObject[]) list.toArray(new JCAAdminObject[list
157: .size()]);
158: }
159:
160: public String getObjectName() {
161: return objectName;
162: }
163:
164: public boolean isStateManageable() {
165: return false;
166: }
167:
168: public boolean isStatisticsProvider() {
169: return false;
170: }
171:
172: public boolean isEventProvider() {
173: return false;
174: }
175: }
|