KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > loaders > SunWS70ResourceDataObject


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 package org.netbeans.modules.j2ee.sun.ws7.serverresources.loaders;
20
21 import java.io.InputStream JavaDoc;
22 import org.xml.sax.InputSource JavaDoc;
23
24 import org.openide.filesystems.*;
25 import org.openide.filesystems.FileObject;
26 import org.openide.loaders.DataObjectExistsException;
27 import org.openide.loaders.XMLDataObject;
28 import org.openide.nodes.Node;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.NbBundle;
31 import org.openide.ErrorManager;
32
33 import org.netbeans.api.xml.cookies.CheckXMLCookie;
34 import org.netbeans.api.xml.cookies.ValidateXMLCookie;
35 import org.netbeans.spi.xml.cookies.CheckXMLSupport;
36 import org.netbeans.spi.xml.cookies.DataObjectAdapters;
37 import org.netbeans.spi.xml.cookies.ValidateXMLSupport;
38
39
40 import org.netbeans.modules.j2ee.sun.ws7.serverresources.dd.*;
41
42
43 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70MailResourceBean;
44 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70MailResourceBeanDataNode;
45 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ExternalResourceBean;
46 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ExternalResourceBeanDataNode;
47 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70CustomResourceBean;
48 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70CustomResourceBeanDataNode;
49 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70JdbcResourceBean;
50 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70JdbcResourceBeanDataNode;
51
52 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants;
53 import org.openide.util.WeakListeners;
54
55 /** Represents a Sun Webserver70 Resource object in the Repository.
56  * Code reused from Appserver common API module
57  *
58  */

59 public class SunWS70ResourceDataObject extends XMLDataObject implements FileChangeListener { // extends MultiDataObject{
60

61
62
63     private ValidateXMLCookie validateCookie = null;
64     private CheckXMLCookie checkCookie = null;
65     
66     private WS70MailResourceBean mailBean = null;
67     private WS70ExternalResourceBean externalJndiBean = null;
68     private WS70CustomResourceBean customBean = null;
69     private WS70JdbcResourceBean jdbcBean = null;
70
71     
72     private String JavaDoc resType;
73     
74     public SunWS70ResourceDataObject(FileObject pf, SunWS70ResourceDataLoader loader) throws DataObjectExistsException {
75         super(pf, loader);
76         pf.addFileChangeListener((FileChangeListener) WeakListeners.create(FileChangeListener.class, this, pf));
77         
78         resType = getResource(pf);
79     }
80     
81     public org.openide.nodes.Node.Cookie getCookie(Class JavaDoc c) {
82         Node.Cookie retValue = null;
83         if (ValidateXMLCookie.class.isAssignableFrom(c)) {
84             if (validateCookie == null) {
85                 InputSource JavaDoc in = DataObjectAdapters.inputSource(this);
86                 validateCookie = new ValidateXMLSupport(in);
87             }
88             return validateCookie;
89         } else if (CheckXMLCookie.class.isAssignableFrom(c)) {
90             if (checkCookie == null) {
91                 InputSource JavaDoc in = DataObjectAdapters.inputSource(this);
92                 checkCookie = new CheckXMLSupport(in);
93             }
94             return checkCookie;
95         }
96         
97         if (retValue == null) {
98             retValue = super.getCookie(c);
99         }
100         return retValue;
101     }
102     
103     
104     public HelpCtx getHelpCtx() {
105         return null; // HelpCtx.DEFAULT_HELP;
106
// If you add context help, change to:
107
// return new HelpCtx(SunWS70ResourceDataObject.class);
108
}
109     
110     protected Node createNodeDelegate() {
111         if(resType != null){
112              if(this.resType.equals(WS70WizardConstants.__MailResource)){
113                     Node node = new WS70MailResourceBeanDataNode(this, getMailBean());
114                     return node;
115              }else if(this.resType.equals(WS70WizardConstants.__JdbcResource)){
116                     Node node = new WS70JdbcResourceBeanDataNode(this, getJdbcBean());
117                     return node;
118              }else if(this.resType.equals(WS70WizardConstants.__CustomResource)){
119                  Node node = new WS70CustomResourceBeanDataNode(this, getCustomBean());
120                  return node;
121              }else if(this.resType.equals(WS70WizardConstants.__ExternalJndiResource)){
122                  Node node = new WS70ExternalResourceBeanDataNode(this, getExternalJndiBean());
123                  return node;
124              }else{
125                     String JavaDoc mess = NbBundle.getMessage(SunWS70ResourceDataObject.class, "Info_notSunWS70Resource"); //NOI18N
126
ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, mess);
127                     return new SunWS70ResourceDataNode(this);
128              }
129         }
130         return new SunWS70ResourceDataNode(this);
131          
132     }
133     
134     private String JavaDoc getResource(FileObject primaryFile) {
135        String JavaDoc type = null;
136        try {
137             if((! primaryFile.isFolder()) && primaryFile.isValid()){
138                 InputStream JavaDoc in = primaryFile.getInputStream();
139                 WS70Resources resources = this.getResourceGraph(in);
140                 // import Mail WS70Resources
141
WS70MailResource[] mailResources = resources.getWS70MailResource();
142                 if(mailResources.length != 0){
143                     WS70MailResourceBean currMailBean = WS70MailResourceBean.createBean(mailResources[0]);
144                     type = WS70WizardConstants.__MailResource;
145                     setMailBean(currMailBean);
146                     return type;
147                 }
148                 
149                 // import WS70ExternalJndiResources
150
WS70ExternalJndiResource[] extResources = resources.getWS70ExternalJndiResource();
151                 if(extResources.length != 0){
152                     WS70ExternalResourceBean currentextBean = WS70ExternalResourceBean.createBean(extResources[0]);
153                     type = WS70WizardConstants.__ExternalJndiResource;
154                     setExternalJndiBean(currentextBean);
155                     return type;
156                 }
157                 // import WS70CustomResources
158
WS70CustomResource[] customResources = resources.getWS70CustomResource();
159                 if(customResources.length != 0){
160                     WS70CustomResourceBean currentCustomBean = WS70CustomResourceBean.createBean(customResources[0]);
161                     type = WS70WizardConstants.__CustomResource;
162                     setCustomBean(currentCustomBean);
163                     return type;
164                 }
165                 // import WS70JdbcResources
166
WS70JdbcResource[] jdbcResources = resources.getWS70JdbcResource();
167                 if(jdbcResources.length != 0){
168                     WS70JdbcResourceBean currentJdbcBean = WS70JdbcResourceBean.createBean(jdbcResources[0]);
169                     type = WS70WizardConstants.__JdbcResource;
170                     setJdbcBean(currentJdbcBean);
171                     return type;
172                 }
173                 return type;
174             }else
175                 return type;
176         }catch(NullPointerException JavaDoc npe){
177             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, npe);
178             return type;
179         }catch(Exception JavaDoc ex){
180             //ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ex.getLocalizedMessage());
181
return type;
182         }
183        
184     }
185     public WS70Resources getResourceGraph(java.io.InputStream JavaDoc in){
186         return org.netbeans.modules.j2ee.sun.ws7.serverresources.dd.impl.WS70Resources.createGraph(in);
187     }
188     
189     private void setMailBean(WS70MailResourceBean in_mailBean){
190         this.mailBean = in_mailBean;
191     }
192     
193     private WS70MailResourceBean getMailBean(){
194         return this.mailBean;
195     }
196    private void setExternalJndiBean(WS70ExternalResourceBean in_extBean){
197         this.externalJndiBean = in_extBean;
198     }
199     
200     private WS70ExternalResourceBean getExternalJndiBean(){
201         return this.externalJndiBean;
202     }
203    private void setCustomBean(WS70CustomResourceBean in_customBean){
204         this.customBean = in_customBean;
205     }
206     
207     private WS70CustomResourceBean getCustomBean(){
208         return this.customBean;
209     }
210    private void setJdbcBean(WS70JdbcResourceBean in_jdbcBean){
211         this.jdbcBean= in_jdbcBean;
212     }
213     
214     private WS70JdbcResourceBean getJdbcBean(){
215         return this.jdbcBean;
216     }
217  
218     
219     public void fileAttributeChanged (FileAttributeEvent fe) {
220         updateDataObject();
221     }
222     
223     public void fileChanged (FileEvent fe) {
224         updateDataObject();
225     }
226     
227     public void fileDataCreated (FileEvent fe) {
228         updateDataObject ();
229     }
230     
231     public void fileDeleted (FileEvent fe) {
232         updateDataObject ();
233     }
234     
235     public void fileFolderCreated (FileEvent fe) {
236         updateDataObject ();
237     }
238     
239     public void fileRenamed (FileRenameEvent fe) {
240         updateDataObject ();
241     }
242     
243     private void updateDataObject(){
244         resType = getResource(this.getPrimaryFile());
245     }
246     
247     public String JavaDoc getResourceType(){
248         return resType;
249     }
250     // If you made an Editor Support you will want to add these methods:
251

252     /*public final void addSaveCookie(SaveCookie save) {
253         getCookieSet().add(save);
254     }
255      
256     public final void removeSaveCookie(SaveCookie save) {
257         getCookieSet().remove(save);
258     }*/

259   
260 }
261
Popular Tags