1 19 package org.netbeans.modules.j2ee.sun.ws7.serverresources.loaders; 20 21 import java.io.InputStream ; 22 import org.xml.sax.InputSource ; 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 59 public class SunWS70ResourceDataObject extends XMLDataObject implements FileChangeListener { 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 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 c) { 82 Node.Cookie retValue = null; 83 if (ValidateXMLCookie.class.isAssignableFrom(c)) { 84 if (validateCookie == null) { 85 InputSource 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 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; } 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 mess = NbBundle.getMessage(SunWS70ResourceDataObject.class, "Info_notSunWS70Resource"); ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, mess); 127 return new SunWS70ResourceDataNode(this); 128 } 129 } 130 return new SunWS70ResourceDataNode(this); 131 132 } 133 134 private String getResource(FileObject primaryFile) { 135 String type = null; 136 try { 137 if((! primaryFile.isFolder()) && primaryFile.isValid()){ 138 InputStream in = primaryFile.getInputStream(); 139 WS70Resources resources = this.getResourceGraph(in); 140 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 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 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 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 npe){ 177 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, npe); 178 return type; 179 }catch(Exception ex){ 180 return type; 182 } 183 184 } 185 public WS70Resources getResourceGraph(java.io.InputStream 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 getResourceType(){ 248 return resType; 249 } 250 252 259 260 } 261 | Popular Tags |