KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > dd > BaseBeanUtils


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.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.common.dd;
24
25 import org.netbeans.modules.schema2beans.BaseBean;
26 import org.netbeans.modules.schema2beans.GraphManager;
27 import org.netbeans.modules.schema2beans.BaseProperty;
28 /** Utilities that apply to all the various generated schema2beans objects in the
29  * system
30  * @author vkraemer
31  */

32 public class BaseBeanUtils {
33     
34     /** Creates a new instance of BaseBeanUtils */
35     protected BaseBeanUtils() {
36     }
37     
38     /** A utility for finding beans in a graph of BaseBean objects.
39      *
40      * Search the bean graph, starting at a given root, for beans where the named
41      * property has the given value. The returned list is filtered by assignment
42      * compatibility.
43      * @return The assignment compatible BaseBeans that were found.
44      * @param root The root of a search
45      * @param propName The name of the element
46      * @param propVal the value of the element
47      * @param type The expected type of the value to be returned.
48      * @throws IllegalArgumentException If the bean is not part of a complete bean graph.
49      */

50     protected static java.util.List JavaDoc findCompatibleBeansWithValue(BaseBean root, String JavaDoc propName, String JavaDoc propVal, Class JavaDoc type) throws IllegalArgumentException JavaDoc {
51         java.util.List JavaDoc retVal = null;
52         GraphManager gm = root.graphManager();
53         if (null == gm)
54             throw new IllegalArgumentException JavaDoc("Disconnected beans not supported");
55         String JavaDoc[] props = root.findPropertyValue(propName, propVal);
56         int len = 0;
57         if (null != props)
58             len = props.length;
59         if (len > 0)
60             retVal = new java.util.ArrayList JavaDoc();
61         for (int i = 0; i < len; i++) {
62             // get the bean that is the property's parent.
63
BaseBean candidate = gm.getPropertyParent(props[i]);
64             if (type.isInstance(candidate))
65                 retVal.add(candidate);
66         }
67         return retVal;
68     }
69 }
70
Popular Tags