KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > WSMultiViewDataObject


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.websphere6.dd.loaders;
20
21 import org.netbeans.api.xml.cookies.CheckXMLCookie;
22 import org.netbeans.api.xml.cookies.ValidateXMLCookie;
23 import org.netbeans.modules.xml.multiview.*;
24 import org.netbeans.modules.schema2beans.*;
25 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmi;
26 import org.netbeans.core.spi.multiview.MultiViewElement;
27 import org.netbeans.spi.xml.cookies.*;
28 import org.openide.filesystems.FileObject;
29 import org.openide.ErrorManager;
30 import org.openide.loaders.DataObjectExistsException;
31 import org.openide.loaders.MultiFileLoader;
32 import java.io.IOException JavaDoc;
33 import java.io.StringWriter JavaDoc;
34 import java.io.Writer JavaDoc;
35 import org.xml.sax.*;
36
37
38 /**
39  *
40  * @author dlm198383
41  */

42 public abstract class WSMultiViewDataObject extends XmlMultiViewDataObject{
43     protected WSDesignView designView;
44     protected ModelSynchronizer modelSynchronizer;
45     protected boolean changedFromUI;
46     protected DDXmi ddBaseBean;
47     private static final long serialVersionUID = 76675745399723L;
48     public static final String JavaDoc DD_MULTIVIEW_POSTFIX = "_multiview_design";
49     public static final String JavaDoc MULTIVIEW_WEBBND = "webbnd";
50     public static final String JavaDoc MULTIVIEW_WEBEXT = "webext";
51     public static final String JavaDoc MULTIVIEW_APPBND = "appbnd";
52     public static final String JavaDoc MULTIVIEW_APPEXT = "appext";
53     public static final String JavaDoc MULTIVIEW_EJBBND = "ejbbnd";
54     public static final String JavaDoc MULTIVIEW_EJBEXT = "ejbext";
55     /**
56      * Creates a new instance of WSMultiViewDataObject
57      */

58     public WSMultiViewDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException JavaDoc {
59         super(pf, loader);
60         modelSynchronizer = new ModelSynchronizer(this);
61         org.xml.sax.InputSource JavaDoc in = DataObjectAdapters.inputSource(this);
62         CheckXMLCookie checkCookie = new CheckXMLSupport(in);
63         getCookieSet().add(checkCookie);
64         ValidateXMLCookie validateCookie = new ValidateXMLSupport(in);
65         getCookieSet().add(validateCookie);
66         try {
67             parseDocument();
68         } catch (IOException JavaDoc ex) {
69             System.out.println("ex="+ex);
70         }
71     }
72     protected String JavaDoc getPrefixMark() {
73         return null;
74     }
75     
76     /**
77      *
78      * @throws IOException
79      */

80     protected java.io.InputStream JavaDoc getInputStream() {
81         return getDataCache().createInputStream();
82     }
83     
84     
85     
86     
87     protected void parseDocument() throws IOException JavaDoc {
88         if(ddBaseBean==null) {
89             ddBaseBean=getDD();
90         } else {
91             try {
92                 SAXParseException error = DDUtils.parse(new InputSource(getDataCache().createReader()));
93                 setSaxError(error);
94                 
95                 DDXmi bb = createDDXmiFromDataCache();
96                 
97                 if (bb!=null) {
98                     ddBaseBean.merge(bb, org.netbeans.modules.schema2beans.BaseBean.MERGE_UPDATE);
99                 }
100             } catch (SAXException ex) {
101                 setSaxError(ex);
102             }
103         }
104     }
105     
106     protected abstract DesignMultiViewDesc[] getMultiViewDesc();
107     
108     public WSDesignView getDesignView() {
109         return designView;
110     }
111     
112     public void modelUpdatedFromUI() {
113         modelSynchronizer.requestUpdateData();
114     }
115     public boolean isChangedFromUI() {
116         return changedFromUI;
117     }
118     
119     public void setChangedFromUI(boolean changedFromUI) {
120         this.changedFromUI=changedFromUI;
121     }
122     protected abstract class WSDesignView extends DesignMultiViewDesc {
123         private static final long serialVersionUID = 71111745399723L;
124         protected WSDesignView(WSMultiViewDataObject dObj) {
125             super(dObj, "Design");
126         }
127         public abstract MultiViewElement createElement();
128         public abstract java.awt.Image JavaDoc getIcon();
129         public abstract String JavaDoc preferredID() ;
130         
131     }
132     public abstract DDXmi getDD() throws java.io.IOException JavaDoc;
133     
134     protected abstract DDXmi createDDXmiFromDataCache() ;
135     
136     protected class ModelSynchronizer extends XmlMultiViewDataSynchronizer {
137         
138         public ModelSynchronizer(XmlMultiViewDataObject dataObject) {
139             super(dataObject, 500);
140         }
141         
142         protected boolean mayUpdateData(boolean allowDialog) {
143             return true;
144         }
145         public void updateData(org.openide.filesystems.FileLock dataLock, boolean modify) {
146             super.updateData(dataLock, modify);
147             try {
148                 parseDocument();
149             } catch (IOException JavaDoc e) {
150                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
151             }
152         }
153         
154         
155         protected void updateDataFromModel(Object JavaDoc model, org.openide.filesystems.FileLock lock, boolean modify) {
156             if (model == null) {
157                 return;
158             }
159             try {
160                 Writer JavaDoc out = new StringWriter JavaDoc();
161                 ((DDXmi) model).write(out);
162                 out.close();
163                 getDataCache().setData(lock, out.toString(), modify);
164             } catch (IOException JavaDoc e) {
165                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
166             } catch (Schema2BeansException e) {
167                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
168             }
169         }
170         
171         protected Object JavaDoc getModel() {
172             try {
173                 return getDD();
174             } catch (IOException JavaDoc e) {
175                 ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, e);
176                 return null;
177             }
178         }
179         
180         protected void reloadModelFromData() {
181             try {
182                 parseDocument();
183             } catch (IOException JavaDoc e) {
184                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
185             }
186         }
187         
188         //protected void updateDataFromModel(Object object, org.openide.filesystems.FileLock fileLock, boolean b) {
189
//}
190
}
191     public XmlMultiViewDataSynchronizer getModelSynchronizer() {
192         return modelSynchronizer;
193     }
194     
195     /** Enable to get active MultiViewElement object
196      */

197     
198     public ToolBarMultiViewElement getActiveMultiViewElement0() {
199         return (ToolBarMultiViewElement)super.getActiveMultiViewElement();
200     }
201     
202     
203 }
204
Popular Tags