1 19 20 package org.netbeans.modules.j2ee.sun.share.config; 21 22 import java.util.Collections ; 23 import java.util.Set ; 24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 25 import org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport; 26 27 import org.openide.cookies.EditCookie; 28 import org.openide.cookies.OpenCookie; 29 import org.openide.cookies.SaveCookie; 30 import org.openide.filesystems.FileObject; 31 import org.openide.loaders.DataObject; 32 import org.openide.loaders.DataObjectExistsException; 33 import org.openide.loaders.DataObjectNotFoundException; 34 import org.openide.loaders.MultiFileLoader; 35 36 import org.netbeans.modules.j2ee.sun.share.config.ui.ConfigBeanTopComponent; 37 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration; 38 import org.openide.filesystems.FileUtil; 39 40 41 44 public class SecondaryConfigDataObject extends ConfigDataObject { 45 46 private ConfigDataObject primary; 47 48 49 public SecondaryConfigDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException { 50 super(pf, loader); 51 } 52 53 public boolean isSecondaryOf(ConfigDataObject primary) { 54 return getPrimaryDataObject() == primary; 55 } 56 57 public SunONEDeploymentConfiguration getDeploymentConfiguration() throws ConfigurationException { 58 ConfigDataObject p = getPrimaryDataObject(); 60 FileObject fo = p.getPrimaryFile(); 61 String serverId = getProvider().getServerID(); 62 ConfigurationSupport.requestCreateConfiguration(fo, serverId); 63 return SunONEDeploymentConfiguration.getConfiguration(FileUtil.toFile(fo)); 64 } 65 66 private ConfigDataObject getPrimaryDataObject() { 67 if (primary == null || !primary.isValid()) { 68 FileObject folder = getPrimaryFile().getParent(); 73 FileObject sejFO = folder.getFileObject("sun-ejb-jar", "xml"); 74 if(sejFO != null) { 75 try { 76 DataObject dObj = DataObject.find(sejFO); 77 primary = (ConfigDataObject) dObj.getCookie(ConfigDataObject.class); 78 if(primary != null) { 79 primary.addSecondary(this); 80 } 81 } catch(DataObjectNotFoundException ex) { 82 } 83 } 84 } 85 86 return primary; 87 } 88 89 private EditCookie _getEditCookie() { 90 ConfigDataObject cdo = getPrimaryDataObject(); 91 EditCookie primaryEdit = cdo == null ? null : cdo.getEditCookie(); 92 EditCookie myEdit = super.getEditCookie(); 93 if (primaryEdit != null) { 94 return myEdit; 95 } else { 96 return null; 97 } 98 } 99 100 private OpenCookie _getOpenCookie() { 101 ConfigDataObject cdo = getPrimaryDataObject(); 102 return cdo == null ? null : (OpenCookie) cdo.getCookie(OpenCookie.class); 103 } 104 105 public org.openide.nodes.Node.Cookie getCookie(Class c) { 106 if (OpenCookie.class.isAssignableFrom(c)) { 107 return _getOpenCookie(); 108 } else if (EditCookie.class.isAssignableFrom(c)) { 109 return _getEditCookie(); 110 } 111 return super.getCookie(c); 112 } 113 114 protected Set getSecondaries() { 115 return Collections.EMPTY_SET; 116 } 117 118 protected ConfigurationStorage getStorage() { 119 ConfigDataObject cdo = getPrimaryDataObject(); 120 return cdo == null ? null : cdo.getStorage(); 121 } 122 123 protected void openConfigEditor() { 124 ConfigDataObject cdo = getPrimaryDataObject(); 125 if (cdo != null) { 126 getPrimaryDataObject().openConfigEditor(); 127 firePropertyChange(PROP_COOKIE, null, null); 128 } 129 } 130 131 protected ConfigBeanTopComponent findOpenedConfigEditor() { 132 ConfigDataObject cdo = getPrimaryDataObject(); 133 return cdo == null ? null : cdo.findOpenedConfigEditor(); 134 } 135 136 public boolean closeConfigEditors() { 137 ConfigDataObject cdo = getPrimaryDataObject(); 138 return cdo == null ? false : cdo.closeConfigEditors(); 139 } 140 141 public void fileDeleted(org.openide.filesystems.FileEvent fe) { 142 if (fe.getFile().equals(this.getPrimaryFile()) && getPrimaryDataObject() != null) { 143 primary.removeSecondary(this); 144 } 145 } 146 147 protected void fireCookieChange() { 148 fireLimitedCookieChange(); 149 ConfigDataObject cdo = getPrimaryDataObject(); 150 if (cdo != null) { 151 cdo.fireLimitedCookieChange(); 152 } 153 } 154 155 public void setChanged() { 157 addSaveCookie(new S0()); 158 } 159 160 private class S0 implements SaveCookie { 162 public void save() throws java.io.IOException { 163 ConfigDataObject cdo = getPrimaryDataObject(); 164 if (cdo != null) { 165 cdo.resetAllChanged(); 166 } 167 } 168 } 169 } 170 | Popular Tags |