KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ServerTarget


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
21 package org.netbeans.modules.j2ee.deployment.impl;
22
23 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
24 import org.openide.nodes.Node;
25 import javax.enterprise.deploy.spi.Target JavaDoc;
26 import org.openide.util.NbBundle;
27 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
28
29 // PENDING use environment providers, not Cookies
30
// PENDING issue -- Target <==> J2EEDomain relationship 1 to many, many to 1, 1 to 1, or many to many
31
public class ServerTarget implements Node.Cookie {
32
33     ServerInstance instance;
34     Target JavaDoc target;
35     //PENDING: caching state, sync, display through icon and action list.
36

37     public ServerTarget(ServerInstance instance, Target JavaDoc target) {
38         this.instance = instance;
39         this.target = target;
40     }
41     
42     public ServerInstance getInstance() {
43         return instance;
44     }
45     
46     public String JavaDoc getName() {
47         return target.getName();
48     }
49     
50     public boolean hasWebContainerOnly() {
51         Server server = instance.getServer();
52         return (server.canDeployWars() && ! server.canDeployEars() && ! server.canDeployEjbJars());
53     }
54     
55     public Target JavaDoc getTarget() {
56         return target;
57     }
58     
59     public boolean isAlsoServerInstance() {
60         return instance.getStartServer().isAlsoTargetServer(target);
61     }
62     
63     public boolean isRunning() {
64         if (isAlsoServerInstance())
65             return instance.isRunning();
66         
67         StartServer ss = instance.getStartServer();
68         if (ss != null) {
69             return ss.isRunning(target);
70         }
71         return false;
72     }
73     
74     public ProgressObject JavaDoc start() {
75         StartServer ss = instance.getStartServer();
76         if (ss != null && ss.supportsStartTarget(target)) {
77             ProgressObject JavaDoc po = ss.startTarget(target);
78             if (po != null) {
79                 return po;
80             }
81         }
82         String JavaDoc name = target == null ? "null" : target.getName(); //NOI18N
83
String JavaDoc msg = NbBundle.getMessage(ServerTarget.class, "MSG_StartStopTargetNotSupported", name);
84         throw new UnsupportedOperationException JavaDoc(msg);
85     }
86     
87     public ProgressObject JavaDoc stop() {
88         StartServer ss = instance.getStartServer();
89         if (ss != null && ss.supportsStartTarget(target)) {
90             ProgressObject JavaDoc po = ss.stopTarget(target);
91             if (po != null) {
92                 return po;
93             }
94         }
95         String JavaDoc name = target == null ? "null" : target.getName(); //NOI18N
96
String JavaDoc msg = NbBundle.getMessage(ServerTarget.class, "MSG_StartStopTargetNotSupported", name);
97         throw new UnsupportedOperationException JavaDoc(msg);
98     }
99 }
100
Popular Tags