1 19 20 23 24 package org.netbeans.modules.j2ee.sun.ws7.nodes; 25 26 import javax.enterprise.deploy.spi.DeploymentManager ; 27 import javax.enterprise.deploy.spi.Target ; 28 29 import org.openide.nodes.AbstractNode; 30 import org.openide.nodes.Node; 31 import org.openide.nodes.Children; 32 import org.openide.util.Lookup; 33 34 import java.io.File ; 35 import org.openide.windows.InputOutput; 36 import java.util.List ; 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.Collections ; 40 import java.lang.reflect.Method ; 41 import javax.swing.Action ; 42 import java.awt.Image ; 43 import org.openide.util.Utilities; 44 import org.openide.util.NbBundle; 45 import org.openide.ErrorManager; 46 47 import org.netbeans.modules.j2ee.sun.ws7.j2ee.ResourceType; 48 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 49 import org.openide.util.actions.SystemAction; 50 import org.openide.actions.PropertiesAction; 51 import org.netbeans.modules.j2ee.sun.ws7.nodes.actions.StartStopServerAction; 52 import org.netbeans.modules.j2ee.sun.ws7.nodes.actions.ViewTargetServerLogAction; 53 import org.netbeans.modules.j2ee.sun.ws7.nodes.actions.EditServerXmlAction; 54 import org.netbeans.modules.j2ee.sun.ws7.j2ee.WS70LogViewer; 55 56 import org.openide.filesystems.FileObject; 57 import org.openide.filesystems.FileUtil; 58 import org.openide.filesystems.FileChangeAdapter; 59 import org.openide.filesystems.FileChangeListener; 60 import org.openide.filesystems.FileEvent; 61 import org.openide.loaders.DataObject; 62 import org.openide.loaders.DataObjectNotFoundException; 63 import org.openide.cookies.EditorCookie; 64 65 import org.openide.windows.IOProvider; 66 import org.openide.windows.OutputWriter; 67 68 72 public class WS70TargetNode extends AbstractNode implements Node.Cookie{ 73 private WS70SunDeploymentManager manager; 74 private Target target; 75 private Lookup looup; 76 private String configName; 77 private boolean isConfigChanged = false; 78 private static Map serverXmlListeners = 79 Collections.synchronizedMap((Map )new HashMap (2,1)); 80 81 82 public WS70TargetNode(Lookup lookup){ 83 super(new Children.Array()); 84 this.looup = lookup; 85 target = (Target )lookup.lookup(Target .class); 86 setName(target.getName()); 87 try{ 88 Method getConfigName = target.getClass().getDeclaredMethod("getConfigName", new Class []{}); 89 configName = (String )getConfigName.invoke(target, new Object []{}); 90 91 }catch(Exception ex){ 92 ex.printStackTrace(); 93 } 94 this.manager = (WS70SunDeploymentManager)lookup.lookup(DeploymentManager .class); 95 96 List jvmOptions = ((WS70SunDeploymentManager)manager).getJVMOptions(configName, Boolean.valueOf(false), null); 97 Map jvmProps = ((WS70SunDeploymentManager)manager).getJVMProps(configName); 98 99 WS70JVMManagedObject jvm = new WS70JVMManagedObject(this.manager, configName, 100 (HashMap )jvmProps, jvmOptions); 101 102 103 setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/ws7/resources/ConfigIcon.gif"); 104 getCookieSet().add(this); 105 getChildren().add(new Node[] {new WS70WebModulesRootNode(lookup), 106 new WS70ResourcesRootNode(lookup, ResourceType.JDBC), 107 new WS70ResourcesRootNode(lookup, ResourceType.JNDI), 108 new WS70ResourcesRootNode(lookup, ResourceType.CUSTOM), 109 new WS70ResourcesRootNode(lookup, ResourceType.MAIL), 110 new WS70JVMNode(jvm)}); 111 setMyDisplayName(); 112 113 } 114 public Action getPreferredAction() { 115 return SystemAction.get(PropertiesAction.class); 116 } 117 public Action [] getActions(boolean context) { 118 return new SystemAction[] { 119 SystemAction.get(StartStopServerAction.class), 120 null, 121 SystemAction.get(EditServerXmlAction.class), 122 SystemAction.get(ViewTargetServerLogAction.class), 123 }; 124 } 125 126 public boolean isRunning(){ 127 return manager.isRunning(configName); 128 } 129 public boolean isLocalServer(){ 130 return manager.isLocalServer(); 131 } 132 public void startTarget(){ 133 try{ 134 manager.startServer(configName); 135 }catch(Exception ex){ 136 } 137 if(manager.isLocalServer()){ 140 invokeLogViewer(); 141 } 142 } 143 public void stopTarget(){ 144 try{ 145 manager.stopServer(configName); 146 }catch(Exception ex){ 147 } 148 } 149 public void invokeLogViewer(){ 150 String location = manager.getServerLocation(); 151 location = location+File.separator+"https-"+configName+ 152 File.separator+"logs"+File.separator+"errors"; 153 String logName = NbBundle.getMessage(WS70TargetNode.class, "LBL_WS70_MANAGER_NODE_NAME")+ 154 "--"+configName; 155 WS70LogViewer logViewer = new WS70LogViewer(new File (location)); 156 InputOutput io = IOProvider.getDefault().getIO(logName, false); 157 try{ 158 logViewer.showLogViewer(io); 159 }catch(Exception ex){ 160 ErrorManager.getDefault().notify(ErrorManager.WARNING, ex); 161 } 162 163 } 164 public void showServerXml(){ 165 String location = manager.getServerLocation()+File.separator+ 166 "admin-server"+File.separator+"config-store"+ File.separator+configName+ File.separator+ "config"; File serverXmlFile = new File (location, "server.xml"); FileObject fileObject = FileUtil.toFileObject(serverXmlFile); 171 if (fileObject == null) { 172 OutputWriter writer = IOProvider.getDefault().getStdOut(); 173 writer.println(NbBundle.getMessage(WS70TargetNode.class, 174 "ERR_Server_XML_not_found", configName)); 175 return; 176 } 177 DataObject dataObject = null; 178 try { 179 dataObject = DataObject.find(fileObject); 180 } catch(DataObjectNotFoundException ex) { 181 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 182 } 183 if (dataObject != null) { 184 EditorCookie editorCookie = (EditorCookie)dataObject.getCookie(EditorCookie.class); 185 if (editorCookie != null) { 186 editorCookie.open(); 187 if(serverXmlListeners.get(location)==null){ 188 ServerFileChangeListener listener = new ServerFileChangeListener(editorCookie); 189 fileObject.addFileChangeListener(listener); 190 serverXmlListeners.put(location, listener); 191 } 192 } else { 193 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Cannot find EditorCookie."); } 195 } 196 } 197 private void setMyDisplayName(){ 198 this.setDisplayName(target.getName()); 199 } 200 public void fireChangeIcon(){ 201 isConfigChanged = true; 202 this.fireIconChange(); 203 } 204 205 public Image getIcon(int type){ 206 Image img1 = this.getOpenedIcon(type); 207 if(!isConfigChanged){ 208 return img1; 209 }else{ 210 Image img2 = Utilities.loadImage("org/netbeans/modules/j2ee/sun/ws7/resources/ConfigChanged.gif"); 211 Image img3 = Utilities.mergeImages(img1, img2, 15, 8); 212 return img3; 213 } 214 215 } 216 private class ServerFileChangeListener extends FileChangeAdapter{ 217 private EditorCookie cookie; 218 public ServerFileChangeListener(EditorCookie e){ 219 cookie = e; 220 } 221 public void fileChanged(FileEvent fe){ 222 if(!cookie.isModified()){ 223 return; } 225 OutputWriter writer = IOProvider.getDefault().getStdOut(); 226 227 try { 228 FileObject obj = fe.getFile(); 229 writer.println(NbBundle.getMessage(WS70TargetNode.class, 230 "MSG_Deploying_Config", configName)); 231 manager.deployAndReconfig(configName); 232 writer.println(NbBundle.getMessage(WS70TargetNode.class, 233 "MSG_Config_Deployed", configName)); 234 } catch(Exception ex){ 235 writer.println(NbBundle.getMessage(WS70TargetNode.class, 236 "ERR_Config_deployed_failed", ex.getMessage())); 237 } 238 } 239 } 240 } 241 | Popular Tags |