KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > dd > impl > common > EnclosingBean


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 /**
21  * Superclass for most s2b beans that provides useful methods for creating and finding beans
22  * in bean graph.
23  *
24  * @author Milan Kuchtiak
25  */

26
27 package org.netbeans.modules.web.dd.impl.common;
28
29 import org.netbeans.modules.schema2beans.Version;
30 import org.netbeans.modules.schema2beans.BaseBean;
31 import org.netbeans.api.web.dd.common.*;
32 import org.netbeans.api.web.dd.WebApp;
33
34 public abstract class EnclosingBean extends BaseBean implements CommonDDBean, CreateCapability, FindCapability {
35
36     /** Creates a new instance of EnclosingBean */
37     public EnclosingBean(java.util.Vector JavaDoc comps, Version version) {
38     super(comps, version);
39     }
40     
41     /**
42     * Method is looking for the nested bean according to the specified property and value
43     *
44     * @param beanName e.g. "Servlet" or "ResourceRef"
45     * @param propertyName e.g. "ServletName" or ResourceRefName"
46     * @param value specific propertyName value e.g. "ControllerServlet" or "jdbc/EmployeeAppDb"
47     * @return Bean satisfying the parameter values or null if not found
48     */

49     public CommonDDBean findBeanByName(String JavaDoc beanName, String JavaDoc propertyName, String JavaDoc value) {
50         return (CommonDDBean)CommonDDAccess.findBeanByName(this, beanName, propertyName, value);
51     }
52     
53     /**
54     * An empty (not bound to schema2beans graph) bean is created corresponding to beanName
55     * regardless the Servlet Spec. version
56     * @param beanName bean name e.g. Servlet
57     * @return CommonDDBean corresponding to beanName value
58     */

59     public CommonDDBean createBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
60         return (CommonDDBean)CommonDDAccess.newBean(this, beanName, getPackagePostfix ());
61     }
62     
63     private String JavaDoc getPackagePostfix () {
64         String JavaDoc pack = getClass().getPackage().getName();
65         if (pack.endsWith(CommonDDAccess.SERVLET_2_4)) return CommonDDAccess.SERVLET_2_4;
66         else return CommonDDAccess.SERVLET_2_3;
67     }
68     
69     public void write (org.openide.filesystems.FileObject fo) throws java.io.IOException JavaDoc {
70         // PENDING
71
// need to be implemented with Dialog opened when the file object is locked
72
}
73     
74     public CommonDDBean addBean(String JavaDoc beanName, String JavaDoc[] propertyNames, Object JavaDoc[] propertyValues, String JavaDoc keyProperty) throws ClassNotFoundException JavaDoc, NameAlreadyUsedException {
75         if (keyProperty!=null) {
76             Object JavaDoc keyValue = null;
77             if (propertyNames!=null)
78                 for (int i=0;i<propertyNames.length;i++) {
79                     if (keyProperty.equals(propertyNames[i])) {
80                         keyValue=propertyValues[i];
81                         break;
82                     }
83                 }
84             if (keyValue!=null && keyValue instanceof String JavaDoc) {
85                 if (findBeanByName(beanName, keyProperty,(String JavaDoc)keyValue)!=null) {
86                     throw new NameAlreadyUsedException(beanName, keyProperty, (String JavaDoc)keyValue);
87                 }
88             }
89         }
90         CommonDDBean newBean = createBean(beanName);
91         if (propertyNames!=null)
92             for (int i=0;i<propertyNames.length;i++) {
93                 try {
94                     ((BaseBean)newBean).setValue(propertyNames[i],propertyValues[i]);
95                 } catch (IndexOutOfBoundsException JavaDoc ex) {
96                     ((BaseBean)newBean).setValue(propertyNames[i],new Object JavaDoc[]{propertyValues[i]});
97                 }
98             }
99         CommonDDAccess.addBean(this, newBean, beanName, getPackagePostfix ());
100         return newBean;
101     }
102     
103     public CommonDDBean addBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
104         try {
105             return addBean(beanName,null,null,null);
106         } catch (NameAlreadyUsedException ex){}
107         return null;
108     }
109     
110     public void merge(RootInterface root, int mode) {
111         this.merge((BaseBean)root,mode);
112     }
113     
114 }
115
Popular Tags