1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.geronimo.connector; 19 20 import org.apache.geronimo.management.geronimo.JCAResource; 21 import org.apache.geronimo.management.geronimo.JCAResourceAdapter; 22 import org.apache.geronimo.management.geronimo.JCAConnectionFactory; 23 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory; 24 import org.apache.geronimo.management.geronimo.JCAAdminObject; 25 import org.apache.geronimo.j2ee.management.impl.Util; 26 27 import java.util.Collection; 28 import java.util.ArrayList; 29 import java.util.Iterator; 30 import java.util.Set; 31 import java.util.HashSet; 32 import java.util.Arrays; 33 import java.util.List; 34 35 /** 36 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 37 */ 38 public class JCAResourceImpl implements JCAResource { 39 private final String objectName; 40 41 private final Collection connectionFactories; 42 private final Collection resourceAdapters; 43 private final Collection adminObjects; 44 45 public JCAResourceImpl(String objectName, Collection connectionFactories, Collection resourceAdapters, Collection adminObjects) { 46 this.objectName = objectName; 47 this.connectionFactories = connectionFactories; 48 this.resourceAdapters = resourceAdapters; 49 this.adminObjects = adminObjects; 50 } 51 52 public String[] getConnectionFactories() { 53 return Util.getObjectNames(getConnectionFactoryInstances()); 54 } 55 56 public String[] getResourceAdapterInstanceNames() { 57 ArrayList temp = new ArrayList(); 58 for (Iterator iterator = resourceAdapters.iterator(); iterator.hasNext();) { 59 JCAResourceAdapter resourceAdapter = (JCAResourceAdapter) iterator.next(); 60 temp.add(resourceAdapter.getObjectName()); 61 } 62 return (String[])temp.toArray(new String[temp.size()]); 63 } 64 65 public JCAResourceAdapter[] getResourceAdapterInstances() { 66 return (JCAResourceAdapter[])resourceAdapters.toArray(new JCAResourceAdapter[resourceAdapters.size()]); 67 } 68 69 public JCAConnectionFactory[] getConnectionFactoryInstances() { 70 return (JCAConnectionFactory[])connectionFactories.toArray(new JCAConnectionFactory[connectionFactories.size()]); 71 } 72 73 public JCAManagedConnectionFactory[] getOutboundFactories() { 74 return getOutboundFactories((String[]) null); 75 } 76 77 public JCAManagedConnectionFactory[] getOutboundFactories(String connectionFactoryInterface) { 78 return getOutboundFactories(new String[]{connectionFactoryInterface}); 79 } 80 81 public JCAManagedConnectionFactory[] getOutboundFactories(String[] connectionFactoryInterfaces) { 82 Set interfaceFilter = null; 83 if (connectionFactoryInterfaces != null) { 84 interfaceFilter = new HashSet(Arrays.asList(connectionFactoryInterfaces)); 85 } 86 87 List list = new ArrayList(); 88 for (Iterator iterator = connectionFactories.iterator(); iterator.hasNext();) { 89 JCAConnectionFactory jcaConnectionFactory = (JCAConnectionFactory) iterator.next(); 90 JCAManagedConnectionFactory mcf = jcaConnectionFactory.getManagedConnectionFactoryInstance(); 91 if (interfaceFilter == null || interfaceFilter.contains(mcf.getConnectionFactoryInterface())) { 92 list.add(mcf); 93 continue; 94 } 95 for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) { 96 String iface = mcf.getImplementedInterfaces()[m]; 97 if (interfaceFilter == null || interfaceFilter.contains(iface)) { 98 list.add(mcf); 99 break; 100 } 101 } 102 } 103 return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]); 104 } 105 106 public String[] getAdminObjects() { 107 return Util.getObjectNames(getAdminObjectInstances()); 108 } 109 110 public JCAAdminObject[] getAdminObjectInstances() { 111 return (JCAAdminObject[]) adminObjects.toArray(new JCAAdminObject[adminObjects.size()]); 112 } 113 114 public JCAAdminObject[] getAdminObjectInstances(String adminObjectInterface) { 115 return getAdminObjectInstances(new String[] {adminObjectInterface}); 116 } 117 118 public JCAAdminObject[] getAdminObjectInstances(String[] adminObjectInterfaces) { 119 Set interfaceFilter = null; 120 if (adminObjectInterfaces != null) { 121 interfaceFilter = new HashSet(Arrays.asList(adminObjectInterfaces)); 122 } 123 124 List list = new ArrayList(); 125 126 for (Iterator iterator = adminObjects.iterator(); iterator.hasNext();) { 127 JCAAdminObject adminObject = (JCAAdminObject) iterator.next(); 128 if (interfaceFilter == null || interfaceFilter.contains(adminObject.getAdminObjectInterface())) { 129 list.add(adminObject); 130 } 131 } 132 133 return (JCAAdminObject[]) list.toArray(new JCAAdminObject[list.size()]); 134 } 135 136 137 public String getObjectName() { 138 return objectName; 139 } 140 141 public boolean isStateManageable() { 142 return false; 143 } 144 145 public boolean isStatisticsProvider() { 146 return false; 147 } 148 149 public boolean isEventProvider() { 150 return false; 151 } 152 }