KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > ejb > EjbJarDDUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ddloaders.ejb;
21
22 import org.netbeans.modules.schema2beans.BaseBean;
23 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
24 import org.netbeans.modules.j2ee.dd.impl.ejb.EjbJarProxy;
25
26
27 /**
28  *
29  * @author mkuchtiak
30  */

31 public class EjbJarDDUtils {
32      private EjbJarDDUtils() {}
33
34     /** Finds a name similar to requested that uniquely identifies
35      * element between the other elements of the same name.
36      *
37      * @param elements checked elements
38      * @param identifier name of tag that contains identification value
39      * @return a free element name
40      */

41     public static String JavaDoc findFreeName (CommonDDBean[] elements, String JavaDoc identifier, String JavaDoc name) {
42         if (checkFreeName (elements, identifier, name)) {
43             return name;
44         }
45         for (int i = 1;;i++) {
46             String JavaDoc destName = name + "_"+i; // NOI18N
47
if (checkFreeName (elements, identifier, destName)) {
48                 return destName;
49             }
50         }
51     }
52     
53     /** Test if given name is free in given context.
54      * @param elements checked elements
55      * @param identifier name of tag that contains identification value
56      * @param o object to be checked
57      * @return true, if such name does not exists
58      */

59     private static boolean checkFreeName (CommonDDBean [] elements, String JavaDoc identifier, Object JavaDoc o) {
60         for (int i=0; i<elements.length; i++) {
61             Object JavaDoc val = elements[i].getValue (identifier);
62             if (val != null && val.equals (o)) {
63                 return false;
64             }
65         }
66         return true;
67     }
68
69     /** Convenient method for getting the BaseBean object from CommonDDBean object
70     */

71     public static BaseBean getBaseBean(CommonDDBean bean) {
72         if (bean instanceof BaseBean) return (BaseBean)bean;
73         else if (bean instanceof EjbJarProxy) return (BaseBean) ((EjbJarProxy)bean).getOriginal();
74         return null;
75     }
76 }
77
Popular Tags