KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > ResourceUtilities


1 /*
2 * The contents of this file are subject to the terms
3 * of the Common Development and Distribution License
4 * (the License). You may not use this file except in
5 * compliance with the License.
6 *
7 * You can obtain a copy of the license at
8 * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9 * glassfish/bootstrap/legal/CDDLv1.0.txt.
10 * See the License for the specific language governing
11 * permissions and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL
14 * Header Notice in each file and include the License file
15 * at glassfish/bootstrap/legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header,
16 * with the fields enclosed by brackets [] replaced by
17 * you own identifying information:
18 * "Portions Copyrighted [year] [name of copyright owner]"
19 *
20 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
21 */

22
23 package com.sun.enterprise.resource;
24
25 import com.sun.enterprise.config.ConfigBean;
26 import com.sun.enterprise.config.ConfigContext;
27 import com.sun.enterprise.config.ConfigException;
28 import com.sun.enterprise.config.serverbeans.ResourceHelper;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31 import javax.management.Attribute JavaDoc;
32 import javax.management.AttributeList JavaDoc;
33 import static com.sun.enterprise.resource.ResourceConstants.*;
34
35 /** A class that holds utility/helper routines. Expected to contain static
36 * methods to perform utility operations.
37 *
38 * @since Appserver 9.0
39 */

40 public class ResourceUtilities {
41      private ResourceUtilities()/*disallowed*/ {
42    }
43
44    /** Checks if any of the Resource in the given set has a conflict with
45     * resource definitions in the domain.xml. A <b> conflict </b> is defined
46     * based on the type of the resource. For example, a JDBC Resource has "jndi-name"
47     * that is the identifying key where as for a JDBC Connection Pool, it is
48     * the "name" that must be unique.
49     * @param resSet a Set of Resource elements.
50     * @param cc instance of ConfigContext that you want to confirm this against. May not be null.
51     * @return a Set of Resource elements that contains conflicting elements from the given Set. This
52     * method does not create any Resource elements. It just references an element in conflict
53     * from a Set that is returned. If there are no conflicts, an empty Set is returned. This method
54     * never returns a null. If the given Set is null, an empty Set is returned.
55     * @throws ConfigException if there is any error with accessing the configuration
56     * hierarchy.
57     */

58    public static Set JavaDoc<Resource> getResourceConfigConflicts(final Set JavaDoc<Resource> resSet,
59        final ConfigContext cc) throws ConfigException {
60              final Set JavaDoc<Resource> conflicts = new HashSet JavaDoc<Resource>();
61        if (resSet != null) {
62            for (final Resource res : resSet) {
63                final String JavaDoc id = getIdToCompare(res);
64                final ConfigBean sb = ResourceHelper.findResource(cc, id);
65                if (sb != null) {
66                    conflicts.add(res);
67                }
68            }
69        }
70        return ( conflicts );
71    }
72      private static String JavaDoc getIdToCompare(final Resource res) {
73        final AttributeList JavaDoc attrs = res.getAttributes();
74        final String JavaDoc type = res.getType();
75        String JavaDoc id;
76        if (Resource.JDBC_CONNECTION_POOL.equals(type) ||
77            Resource.CONNECTOR_CONNECTION_POOL.equals(type) ||
78            Resource.RESOURCE_ADAPTER_CONFIG.equals(type) ||
79            Resource.CONNECTOR_SECURITY_MAP.equals(type)) {
80           id = getNamedAttributeValue(attrs, CONNECTION_POOL_NAME); // this should come from refactored stuff TBD
81
}
82        else if (Resource.RESOURCE_ADAPTER_CONFIG.equals(type)) {
83            id = getNamedAttributeValue(attrs, RESOURCE_ADAPTER_CONFIG_NAME); // this should come from refactored stuff TBD
84
}
85        else {
86            //it is OK to assume that this Resource will one of the *RESOURCEs?
87
id = getNamedAttributeValue(attrs, JNDI_NAME); // this should come from refactored stuff TBD
88
}
89        return ( id );
90    }
91      private static String JavaDoc getNamedAttributeValue(final AttributeList JavaDoc attrs, final String JavaDoc aName) {
92        String JavaDoc value = null;
93        for (final Object JavaDoc obj : attrs) {
94            if (obj instanceof Attribute JavaDoc) {
95                final Attribute JavaDoc a = (Attribute JavaDoc) obj;
96                if (aName.equals(a.getName())) {
97                    value = a.getValue().toString();
98                }
99            }
100        }
101        return ( value );
102    }
103 }
104
Popular Tags