KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > actions > RegisterWS70ResourceAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * RegisterWS70ResourceAction.java
21  *
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.serverresources.actions;
25
26 import java.text.MessageFormat JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28
29 import org.openide.nodes.Node;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32 import org.openide.ErrorManager;
33 import org.openide.DialogDisplayer;
34 import org.openide.NotifyDescriptor;
35 import org.openide.util.actions.NodeAction;
36
37 import org.openide.loaders.DataObject;
38 import org.openide.filesystems.FileObject;
39 import org.netbeans.api.project.FileOwnerQuery;
40 import org.netbeans.api.project.Project;
41 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
42 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
43
44 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants;
45 import org.netbeans.modules.j2ee.sun.ws7.serverresources.loaders.SunWS70ResourceDataObject;
46 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70BaseResourceNode;
47 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ResourceUtils;
48 import org.netbeans.modules.j2ee.sun.ws7.serverresources.dd.*;
49 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
50 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager;
51 import org.netbeans.modules.j2ee.sun.ws7.ui.Util;
52
53 import java.util.HashMap JavaDoc;
54         
55 /**
56  * Code reused from Appserver common API module
57  * @author Nitya Doraisamy
58  */

59 public class RegisterWS70ResourceAction extends NodeAction implements WS70WizardConstants{
60
61     protected void performAction(Node[] nodes) {
62         InstanceProperties target = getTargetServer(nodes[0]);
63         WS70SunDeploymentManager manager = null;
64         String JavaDoc configName = null;
65         if(target!=null){
66             DeploymentManager JavaDoc dm = target.getDeploymentManager();
67             if(! (dm instanceof WS70SunDeploymentManager)){
68                 Util.showWarning(NbBundle.getMessage(RegisterWS70ResourceAction.class, "Msg_invalid_server"),
69                         NbBundle.getMessage(RegisterWS70ResourceAction.class, "Title_invalid_server")
70                         );
71                 return;
72                 
73             }
74             //
75
manager= (WS70SunDeploymentManager)dm;
76             configName = target.getProperty("configName");
77         }else{
78             Util.showWarning(NbBundle.getMessage(RegisterWS70ResourceAction.class, "Msg_invalid_server"),
79                         NbBundle.getMessage(RegisterWS70ResourceAction.class, "Title_invalid_server")
80                         );
81             return;
82         }
83         try{
84             SunWS70ResourceDataObject dobj = (SunWS70ResourceDataObject)nodes[0].getCookie(SunWS70ResourceDataObject.class);
85             WS70BaseResourceNode resNode = (WS70BaseResourceNode)dobj.getNodeDelegate();
86             WS70Resources resources = resNode.getBeanGraph();
87             String JavaDoc resourceType = dobj.getResourceType();
88             if(resourceType == null){
89                 String JavaDoc message = MessageFormat.format(NbBundle.getMessage(RegisterWS70ResourceAction.class, "Err_InvalidXML"), new Object JavaDoc[]{nodes[0].getName()}); //NOI18N
90
Util.showError(message);
91                 return;
92             }
93
94             WS70ResourceUtils.registerResource(resources, resourceType, configName, manager);
95         }catch(Exception JavaDoc ex){
96             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
97             Util.showError(ex.getLocalizedMessage());
98         }
99     }
100     
101     protected boolean enable(Node[] nodes) {
102        if( (nodes != null) && (nodes.length == 1) )
103             return true;
104         else
105             return false;
106     }
107     
108     protected boolean asynchronous() {
109         return false;
110     }
111     
112     public String JavaDoc getName() {
113         return NbBundle.getMessage(RegisterWS70ResourceAction.class, "LBL_RegisterAction"); //NOI18N
114
}
115     
116     protected String JavaDoc iconResource() {
117         return "org/netbeans/modules/j2ee/sun/ws7/resources/ConfigIcon.gif"; //NOI18N
118
}
119     
120     public HelpCtx getHelpCtx() {
121         return null; // HelpCtx.DEFAULT_HELP;
122
// If you will provide context help then use:
123
// return new HelpCtx(RegisterWS70ResourceAction.class);
124
}
125     
126     private InstanceProperties getTargetServer(Node node){
127         InstanceProperties server = null;
128         DataObject dob = (DataObject) node.getCookie(DataObject.class);
129         if(dob!=null){
130             
131             FileObject fo = dob.getPrimaryFile();
132             Project holdingProj = FileOwnerQuery.getOwner(fo);
133             if (holdingProj != null){
134                 J2eeModuleProvider modProvider = (J2eeModuleProvider) holdingProj.getLookup().lookup(J2eeModuleProvider.class);
135                 server = modProvider.getInstanceProperties();
136             }
137         }
138         
139         return server;
140     }
141     
142
143     /** Perform extra initialization of this action's singleton.
144      * PLEASE do not use constructors for this purpose!
145      * protected void initialize() {
146      * super.initialize();
147      * putProperty(Action.SHORT_DESCRIPTION, NbBundle.getMessage(RegisterAction.class, "HINT_Action"));
148      * }
149      */

150     
151 }
152
Popular Tags