1 17 package org.apache.geronimo.connector; 18 19 import org.apache.geronimo.management.geronimo.JCAResource; 20 import org.apache.geronimo.management.geronimo.JCAResourceAdapter; 21 import org.apache.geronimo.management.geronimo.JCAConnectionFactory; 22 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory; 23 import org.apache.geronimo.management.geronimo.JCAAdminObject; 24 import org.apache.geronimo.j2ee.management.impl.Util; 25 26 import java.util.Collection ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 import java.util.HashSet ; 31 import java.util.Arrays ; 32 import java.util.List ; 33 34 37 public class JCAResourceImpl implements JCAResource { 38 private final String objectName; 39 40 private final Collection connectionFactories; 41 private final Collection resourceAdapters; 42 private final Collection adminObjects; 43 44 public JCAResourceImpl(String objectName, Collection connectionFactories, Collection resourceAdapters, Collection adminObjects) { 45 this.objectName = objectName; 46 this.connectionFactories = connectionFactories; 47 this.resourceAdapters = resourceAdapters; 48 this.adminObjects = adminObjects; 49 } 50 51 public String [] getConnectionFactories() { 52 return Util.getObjectNames(getConnectionFactoryInstances()); 53 } 54 55 public String [] getResourceAdapterInstanceNames() { 56 ArrayList temp = new ArrayList (); 57 for (Iterator iterator = resourceAdapters.iterator(); iterator.hasNext();) { 58 JCAResourceAdapter resourceAdapter = (JCAResourceAdapter) iterator.next(); 59 temp.add(resourceAdapter.getObjectName()); 60 } 61 return (String [])temp.toArray(new String [temp.size()]); 62 } 63 64 public JCAResourceAdapter[] getResourceAdapterInstances() { 65 return (JCAResourceAdapter[])resourceAdapters.toArray(new JCAResourceAdapter[resourceAdapters.size()]); 66 } 67 68 public JCAConnectionFactory[] getConnectionFactoryInstances() { 69 return (JCAConnectionFactory[])connectionFactories.toArray(new JCAConnectionFactory[connectionFactories.size()]); 70 } 71 72 public JCAManagedConnectionFactory[] getOutboundFactories() { 73 return getOutboundFactories((String []) null); 74 } 75 76 public JCAManagedConnectionFactory[] getOutboundFactories(String connectionFactoryInterface) { 77 return getOutboundFactories(new String []{connectionFactoryInterface}); 78 } 79 80 public JCAManagedConnectionFactory[] getOutboundFactories(String [] connectionFactoryInterfaces) { 81 Set interfaceFilter = null; 82 if (connectionFactoryInterfaces != null) { 83 interfaceFilter = new HashSet (Arrays.asList(connectionFactoryInterfaces)); 84 } 85 86 List list = new ArrayList (); 87 for (Iterator iterator = connectionFactories.iterator(); iterator.hasNext();) { 88 JCAConnectionFactory jcaConnectionFactory = (JCAConnectionFactory) iterator.next(); 89 JCAManagedConnectionFactory mcf = jcaConnectionFactory.getManagedConnectionFactoryInstance(); 90 if (interfaceFilter == null || interfaceFilter.contains(mcf.getConnectionFactoryInterface())) { 91 list.add(mcf); 92 continue; 93 } 94 for (int m = 0; m < mcf.getImplementedInterfaces().length; m++) { 95 String iface = mcf.getImplementedInterfaces()[m]; 96 if (interfaceFilter == null || interfaceFilter.contains(iface)) { 97 list.add(mcf); 98 break; 99 } 100 } 101 } 102 return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]); 103 } 104 105 public String [] getAdminObjects() { 106 return Util.getObjectNames(getAdminObjectInstances()); 107 } 108 109 public JCAAdminObject[] getAdminObjectInstances() { 110 return (JCAAdminObject[]) adminObjects.toArray(new JCAAdminObject[adminObjects.size()]); 111 } 112 113 public JCAAdminObject[] getAdminObjectInstances(String adminObjectInterface) { 114 return getAdminObjectInstances(new String [] {adminObjectInterface}); 115 } 116 117 public JCAAdminObject[] getAdminObjectInstances(String [] adminObjectInterfaces) { 118 Set interfaceFilter = null; 119 if (adminObjectInterfaces != null) { 120 interfaceFilter = new HashSet (Arrays.asList(adminObjectInterfaces)); 121 } 122 123 List list = new ArrayList (); 124 125 for (Iterator iterator = adminObjects.iterator(); iterator.hasNext();) { 126 JCAAdminObject adminObject = (JCAAdminObject) iterator.next(); 127 if (interfaceFilter == null || interfaceFilter.contains(adminObject.getAdminObjectInterface())) { 128 list.add(adminObject); 129 } 130 } 131 132 return (JCAAdminObject[]) list.toArray(new JCAAdminObject[list.size()]); 133 } 134 135 136 public String getObjectName() { 137 return objectName; 138 } 139 140 public boolean isStateManageable() { 141 return false; 142 } 143 144 public boolean isStatisticsProvider() { 145 return false; 146 } 147 148 public boolean isEventProvider() { 149 return false; 150 } 151 } 152 | Popular Tags |