001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.geronimo.connector; 019 020 import org.apache.geronimo.management.geronimo.JCAResource; 021 import org.apache.geronimo.management.geronimo.JCAResourceAdapter; 022 import org.apache.geronimo.management.geronimo.JCAConnectionFactory; 023 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory; 024 import org.apache.geronimo.management.geronimo.JCAAdminObject; 025 import org.apache.geronimo.j2ee.management.impl.Util; 026 027 import java.util.Collection; 028 import java.util.ArrayList; 029 import java.util.Iterator; 030 import java.util.Set; 031 import java.util.HashSet; 032 import java.util.Arrays; 033 import java.util.List; 034 035 /** 036 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 037 */ 038 public class JCAResourceImpl implements JCAResource { 039 private final String objectName; 040 041 private final Collection connectionFactories; 042 private final Collection resourceAdapters; 043 private final Collection adminObjects; 044 045 public JCAResourceImpl(String objectName, Collection connectionFactories, 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.hasNext();) { 059 JCAResourceAdapter resourceAdapter = (JCAResourceAdapter) iterator.next(); 060 temp.add(resourceAdapter.getObjectName()); 061 } 062 return (String[])temp.toArray(new String[temp.size()]); 063 } 064 065 public JCAResourceAdapter[] getResourceAdapterInstances() { 066 return (JCAResourceAdapter[])resourceAdapters.toArray(new JCAResourceAdapter[resourceAdapters.size()]); 067 } 068 069 public JCAConnectionFactory[] getConnectionFactoryInstances() { 070 return (JCAConnectionFactory[])connectionFactories.toArray(new JCAConnectionFactory[connectionFactories.size()]); 071 } 072 073 public JCAManagedConnectionFactory[] getOutboundFactories() { 074 return getOutboundFactories((String[]) null); 075 } 076 077 public JCAManagedConnectionFactory[] getOutboundFactories(String connectionFactoryInterface) { 078 return getOutboundFactories(new String[]{connectionFactoryInterface}); 079 } 080 081 public JCAManagedConnectionFactory[] getOutboundFactories(String[] connectionFactoryInterfaces) { 082 Set interfaceFilter = null; 083 if (connectionFactoryInterfaces != null) { 084 interfaceFilter = new HashSet(Arrays.asList(connectionFactoryInterfaces)); 085 } 086 087 List list = new ArrayList(); 088 for (Iterator iterator = connectionFactories.iterator(); iterator.hasNext();) { 089 JCAConnectionFactory jcaConnectionFactory = (JCAConnectionFactory) iterator.next(); 090 JCAManagedConnectionFactory mcf = jcaConnectionFactory.getManagedConnectionFactoryInstance(); 091 if (interfaceFilter == null || interfaceFilter.contains(mcf.getConnectionFactoryInterface())) { 092 list.add(mcf); 093 continue; 094 } 095 for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) { 096 String iface = mcf.getImplementedInterfaces()[m]; 097 if (interfaceFilter == null || interfaceFilter.contains(iface)) { 098 list.add(mcf); 099 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 }