|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.j2ee.deployment.impl.ui; import org.openide.nodes.*; import org.openide.util.actions.CookieAction; import org.openide.util.actions.SystemAction; import org.openide.util.HelpCtx; import org.netbeans.modules.j2ee.deployment.impl.*; import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*; import org.openide.util.NbBundle; import org.openide.ErrorManager; import java.util.*; import javax.enterprise.deploy.spi.Target; import javax.management.ObjectName; import javax.management.j2ee.Management; import javax.swing.Action; import java.awt.event.ActionEvent; import javax.management.*; import javax.management.NotificationListener; import javax.swing.*; /** * @author George FinKlang */ public class TargetNode extends TargetBaseNode { public TargetNode(ServerTarget target) { super(new TargetChildren(target), target); setDisplayName(target.getName()); setIconBase(target.getInstance().getServer().getIconBase()); getCookieSet().add(target); Management mgmt = target.getManagement(); if (mgmt == null) return; ObjectName j2eeServer = target.getJ2eeServer(); if (j2eeServer != null) { ManagedObject mo = new ManagedObject(mgmt, j2eeServer); getCookieSet().add(mo); Refresher refresher = new Refresher(); getCookieSet().add(refresher); mo.registerListener(refresher, null); } } public Action[] getActions(boolean b) { ArrayList actions = new ArrayList(); actions.addAll(java.util.Arrays.asList(super.getActions(b))); ServerTarget target = getServerTarget(); ManagedObject mo = getManagedObject(); if (mo != null && target != null && target.isRunning()) { actions.addAll(0, Arrays.asList(mo.getStandardActions())); if (mo.isEventProvider()) { actions.add(SystemAction.get(ShowEventWindowsAction.class)); } actions.add(null); actions.add(mo.getExpertOperationsAction()); } return (Action[]) actions.toArray(new Action[actions.size()]); } private class Refresher implements NotificationListener, RefreshAction.RefreshCookie { //Force refresh need to remove all reference to the listener public void refresh() { refreshSubtree(); getManagedObject().updateSheet(getSheet()); } public boolean isRefreshable() { ServerTarget target = (ServerTarget) getCookie(ServerTarget.class); return target.getInstance().isRunning(); } void refreshSubtree() { ServerTarget target = (ServerTarget) getCookie(ServerTarget.class); Children old = getChildren(); Children replacing = new TargetChildren(target); //PENDING: traverse old subtree to remove listener. } public void handleNotification(javax.management.Notification notification, Object obj) { if ("j2ee.object.created".equals(notification.getType())) { //PENDIN: to refine with more surgical action if possible refreshSubtree(); } else if ("j2ee.object.deleted".equals(notification.getType())) { //PENDIN: to refine with more surgical action if possible refreshSubtree(); } else if ("j2ee.attribute.changed".equals(notification.getType())) //PENDIN: to refine with more surgical action if possible getManagedObject().updateSheet(getSheet()); } } public Sheet createSheet() { Sheet sheet = Sheet.createDefault(); ManagedObject mo = getManagedObject(); ServerTarget target = getServerTarget(); if (mo != null && target.getInstance().isRunning()) mo.updateSheet(sheet); return sheet; } ManagedObject getManagedObject() { return (ManagedObject) getCookie(ManagedObject.class); } public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } private static J2eeTypeQueries[] j2eeTypeQueries = null; private static J2eeTypeQueries[] webTypeQueries = null; private static void initJ2eeTypesMap() { if (j2eeTypeQueries != null) return; String[] queriesForJvms = new String[] {"j2eeType=JVM"}; //NOI18N String[] queriesForApplications = new String[] {"j2eeType=J2EEApplication"}; //NOI18N String[] queriesForEjbModules = new String[] { "j2eeType=EJBModule,J2EEApplication=null"}; //NOI18N String[] queriesForWebModules = new String[] { "j2eeType=WebModule,J2EEApplication=null", //NOI18N "j2eeType=WebModule,J2EEApplication=none"// trick to get Tomcat's web modules NOI18N }; String[] queriesForRars = new String[] {"j2eeType=ResourceAdapterModule,J2EEApplication=null"}; //NOI18N String[] queriesForClients = new String[] {"j2eeType=AppClientModule,J2EEApplication=null"}; //NOI18N String[] queriesForOtherResources = new String[] { "type=Logger", //NOI18N "type=Resource" , //NOI18N others include Environment, ResourceLink, Valve }; String[] queriesForJDBCResources = new String[] { "j2eeType=JDBCResource" }; //NOI18N String[] queriesForJavaMailResources = new String[] { "j2eeType=JavaMailResource" }; //NOI18N String[] queriesForJMSResources = new String[] { "j2eeType=JMSResource" }; //NOI18N String[] queriesForJCAResources = new String[] { "j2eeType=JCAResource", //NOI18N "j2eeType=JCAConnectionFactory", //NOI18N "j2eeType=JCAManagedConnectionFactory" //NOI18N }; String[] queriesForJTAResources = new String[] { "j2eeType=JTAResource" }; //NOI18N String[] queriesForJNDIResources = new String[] {"j2eeType=JNDIResource"}; //NOI18N java.util.List queries = new java.util.ArrayList(); queries.add(new J2eeTypeQueries(getLocString("LBL_Applications"), queriesForApplications)); queries.add(new J2eeTypeQueries(getLocString("LBL_EjbModules"), queriesForEjbModules)); queries.add(new J2eeTypeQueries(getLocString("LBL_WebModules"), queriesForWebModules)); queries.add(new J2eeTypeQueries(getLocString("LBL_ResourceAdaptors"), queriesForRars)); queries.add(new J2eeTypeQueries(getLocString("LBL_AppClients"), queriesForClients)); queries.add(new J2eeTypeQueries(getLocString("LBL_JNDIResources"), queriesForJNDIResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JDBCResources"), queriesForJDBCResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JMSResources"), queriesForJMSResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JavaMailResources"), queriesForJavaMailResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JCAResources"), queriesForJCAResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JTAResources"), queriesForJTAResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_OtherResources"), queriesForOtherResources)); queries.add(new J2eeTypeQueries(getLocString("LBL_JVMs"), queriesForJvms)); j2eeTypeQueries = (J2eeTypeQueries[]) queries.toArray(new J2eeTypeQueries[queries.size()]); java.util.List wqueries = new java.util.ArrayList(); wqueries.add(new J2eeTypeQueries(getLocString("LBL_WebModules"), queriesForWebModules)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_JNDIResources"), queriesForJNDIResources)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_JDBCResources"), queriesForJDBCResources)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_JMSResources"), queriesForJMSResources)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_JavaMailResources"), queriesForJavaMailResources)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_OtherResources"), queriesForOtherResources)); wqueries.add(new J2eeTypeQueries(getLocString("LBL_JVMs"), queriesForJvms)); webTypeQueries = (J2eeTypeQueries[]) wqueries.toArray(new J2eeTypeQueries[wqueries.size()]); } private static class J2eeTypeQueries { String j2eeType; String[] queries; J2eeTypeQueries(String j2eeType, String[] queries) { this.j2eeType = j2eeType; this.queries = queries; } } private static String getLocString(String key) { return NbBundle.getMessage(TargetNode.class, key); } private static J2eeTypeQueries[] getJ2eeTypeQueries() { initJ2eeTypesMap(); return j2eeTypeQueries; } private static J2eeTypeQueries[] getWebTypeQueries() { initJ2eeTypesMap(); return webTypeQueries; } public static class MQueries { public String name; public ObjectName[] queries; public MQueries(String name, ObjectName[] queries) { this.name = name; this.queries = queries; } } static public MQueries[] getMQueries(ServerTarget target) { try { Management mgmt = target.getManagement(); ObjectName j2eeServer = target.getJ2eeServer(); if (mgmt == null || j2eeServer == null) return new MQueries[0]; String serverName = j2eeServer.getKeyProperty("name"); String domainName = j2eeServer.getDomain(); String j2eeType = j2eeServer.getKeyProperty("j2eeType"); if (! "J2EEServer".equals(j2eeType) || serverName == null) return new MQueries[0]; J2eeTypeQueries[] typeQueries; if (target.hasWebContainerOnly()) typeQueries = getWebTypeQueries(); else typeQueries = getJ2eeTypeQueries(); MQueries[] ret = new MQueries[typeQueries.length]; for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.