1 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 ; 33 import java.io.StringWriter ; 34 import java.io.Writer ; 35 import org.xml.sax.*; 36 37 38 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 DD_MULTIVIEW_POSTFIX = "_multiview_design"; 49 public static final String MULTIVIEW_WEBBND = "webbnd"; 50 public static final String MULTIVIEW_WEBEXT = "webext"; 51 public static final String MULTIVIEW_APPBND = "appbnd"; 52 public static final String MULTIVIEW_APPEXT = "appext"; 53 public static final String MULTIVIEW_EJBBND = "ejbbnd"; 54 public static final String MULTIVIEW_EJBEXT = "ejbext"; 55 58 public WSMultiViewDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { 59 super(pf, loader); 60 modelSynchronizer = new ModelSynchronizer(this); 61 org.xml.sax.InputSource 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 ex) { 69 System.out.println("ex="+ex); 70 } 71 } 72 protected String getPrefixMark() { 73 return null; 74 } 75 76 80 protected java.io.InputStream getInputStream() { 81 return getDataCache().createInputStream(); 82 } 83 84 85 86 87 protected void parseDocument() throws IOException { 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 getIcon(); 129 public abstract String preferredID() ; 130 131 } 132 public abstract DDXmi getDD() throws java.io.IOException ; 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 e) { 150 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 151 } 152 } 153 154 155 protected void updateDataFromModel(Object model, org.openide.filesystems.FileLock lock, boolean modify) { 156 if (model == null) { 157 return; 158 } 159 try { 160 Writer out = new StringWriter (); 161 ((DDXmi) model).write(out); 162 out.close(); 163 getDataCache().setData(lock, out.toString(), modify); 164 } catch (IOException 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 getModel() { 172 try { 173 return getDD(); 174 } catch (IOException 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 e) { 184 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 185 } 186 } 187 188 } 191 public XmlMultiViewDataSynchronizer getModelSynchronizer() { 192 return modelSynchronizer; 193 } 194 195 197 198 public ToolBarMultiViewElement getActiveMultiViewElement0() { 199 return (ToolBarMultiViewElement)super.getActiveMultiViewElement(); 200 } 201 202 203 } 204 | Popular Tags |