KickJava   Java API By Example, From Geeks To Geeks.

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

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

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