KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > DDUtils


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.web;
21
22 import javax.xml.parsers.ParserConfigurationException JavaDoc;
23 import javax.xml.parsers.SAXParser JavaDoc;
24 import javax.xml.parsers.SAXParserFactory JavaDoc;
25 import org.openide.filesystems.FileObject;
26
27 import org.netbeans.modules.schema2beans.BaseBean;
28 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
29 import org.netbeans.modules.j2ee.dd.impl.web.WebAppProxy;
30 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
31 import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
32 import java.io.*;
33 import org.xml.sax.*;
34 //import java.util.*;
35

36
37 /**
38  *
39  * @author mkuchtiak
40  */

41 public class DDUtils {
42
43     private static final String JavaDoc EXCEPTION_PREFIX="version:"; //NOI18N
44

45     /** Finds a name similar to requested that uniquely identifies
46      * element between the other elements of the same name.
47      *
48      * @param elements checked elements
49      * @param identifier name of tag that contains identification value
50      * @param o object to be checked
51      * @return a free element name
52      */

53     public static String JavaDoc findFreeName (CommonDDBean[] elements, String JavaDoc identifier, String JavaDoc name) {
54         if (checkFreeName (elements, identifier, name)) {
55             return name;
56         }
57         for (int i = 1;;i++) {
58             String JavaDoc destName = name + "_"+i; // NOI18N
59
if (checkFreeName (elements, identifier, destName)) {
60                 return destName;
61             }
62         }
63     }
64     
65     /** Test if given name is free in given context.
66      * @param elements checked elements
67      * @param identifier name of tag that contains identification value
68      * @param o object to be checked
69      * @return true, if such name does not exists
70      */

71     private static boolean checkFreeName (CommonDDBean [] elements, String JavaDoc identifier, Object JavaDoc o) {
72         for (int i=0; i<elements.length; i++) {
73             Object JavaDoc val = elements[i].getValue (identifier);
74             if (val != null && val.equals (o)) {
75                 return false;
76             }
77         }
78         return true;
79     }
80
81     /** Convenient method for getting the BaseBean object from CommonDDBean object
82     */

83     public static BaseBean getBaseBean(CommonDDBean bean) {
84         if (bean instanceof BaseBean) return (BaseBean)bean;
85         else if (bean instanceof WebAppProxy) return (BaseBean) ((WebAppProxy)bean).getOriginal();
86         return null;
87     }
88   
89 }
Popular Tags