KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > JCAResourceImpl


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
36  */

37 public class JCAResourceImpl implements JCAResource {
38     private final String JavaDoc objectName;
39
40     private final Collection JavaDoc connectionFactories;
41     private final Collection JavaDoc resourceAdapters;
42     private final Collection JavaDoc adminObjects;
43
44     public JCAResourceImpl(String JavaDoc objectName, Collection JavaDoc connectionFactories, Collection JavaDoc resourceAdapters, Collection JavaDoc adminObjects) {
45         this.objectName = objectName;
46         this.connectionFactories = connectionFactories;
47         this.resourceAdapters = resourceAdapters;
48         this.adminObjects = adminObjects;
49     }
50
51     public String JavaDoc[] getConnectionFactories() {
52         return Util.getObjectNames(getConnectionFactoryInstances());
53     }
54
55     public String JavaDoc[] getResourceAdapterInstanceNames() {
56         ArrayList JavaDoc temp = new ArrayList JavaDoc();
57         for (Iterator JavaDoc iterator = resourceAdapters.iterator(); iterator.hasNext();) {
58             JCAResourceAdapter resourceAdapter = (JCAResourceAdapter) iterator.next();
59             temp.add(resourceAdapter.getObjectName());
60         }
61         return (String JavaDoc[])temp.toArray(new String JavaDoc[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 JavaDoc[]) null);
74     }
75
76     public JCAManagedConnectionFactory[] getOutboundFactories(String JavaDoc connectionFactoryInterface) {
77         return getOutboundFactories(new String JavaDoc[]{connectionFactoryInterface});
78     }
79
80     public JCAManagedConnectionFactory[] getOutboundFactories(String JavaDoc[] connectionFactoryInterfaces) {
81         Set JavaDoc interfaceFilter = null;
82         if (connectionFactoryInterfaces != null) {
83             interfaceFilter = new HashSet JavaDoc(Arrays.asList(connectionFactoryInterfaces));
84         }
85
86         List JavaDoc list = new ArrayList JavaDoc();
87         for (Iterator JavaDoc 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 JavaDoc 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 JavaDoc[] 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 JavaDoc adminObjectInterface) {
114         return getAdminObjectInstances(new String JavaDoc[] {adminObjectInterface});
115     }
116
117     public JCAAdminObject[] getAdminObjectInstances(String JavaDoc[] adminObjectInterfaces) {
118         Set JavaDoc interfaceFilter = null;
119         if (adminObjectInterfaces != null) {
120             interfaceFilter = new HashSet JavaDoc(Arrays.asList(adminObjectInterfaces));
121         }
122
123         List JavaDoc list = new ArrayList JavaDoc();
124
125         for (Iterator JavaDoc 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 JavaDoc 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