KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > jmx > AbstractManagementTask


1 package org.apache.tools.ant.taskdefs.optional.jmx;
2
3 /*
4  * ============================================================================
5  * The Apache Software License, Version 1.1
6  * ============================================================================
7  *
8  * Copyright (C) 2000-2002 The Apache Software Foundation. All
9  * rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modifica-
12  * tion, are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any, must
22  * include the following acknowledgment: "This product includes software
23  * developed by the Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself, if
25  * and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Ant" and "Apache Software Foundation" must not be used to
28  * endorse or promote products derived from this software without prior
29  * written permission. For written permission, please contact
30  * apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache", nor may
33  * "Apache" appear in their name, without prior written permission of the
34  * Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
37  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
38  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
39  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
40  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
41  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
42  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
43  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * This software consists of voluntary contributions made by many individuals
48  * on behalf of the Apache Software Foundation. For more information on the
49  * Apache Software Foundation, please see <http://www.apache.org/>.
50  *
51  */

52   
53 import org.apache.tools.ant.BuildException;
54 import org.apache.tools.ant.types.optional.ContextType;
55
56
57 /**
58  * This is the abstract base class for Ant JMX mbean tasks.
59  * Implementations of AbstractMBean inherit its attributes (see below) for connecting to
60  * the JMX MBean server.</br></br>
61  *
62  * Refer to the user documentation for more information and examples on how to use
63  * this task.
64  *
65  * @author <a HREF="mailto:bdueck@yahoo.com">Brian Dueck</a>
66  * @version $Id: AbstractManagementTask.java,v 1.3 2003/05/28 22:28:26 bdueck Exp $
67  *
68  */

69 public abstract class AbstractManagementTask extends org.apache.tools.ant.Task {
70     
71     private boolean failOnError = false;
72
73     private ContextType context = null;
74     
75     public AbstractManagementTask() {
76         context = new ContextType();
77     }
78     
79     protected void setContext(ContextType context) {
80         this.context = context;
81     }
82     
83     protected ContextType getContext() {
84         return context;
85     }
86     
87     /**
88      * Sets the JMX serverType to be used. See <code>JMXConnectorFactory</code>
89      * to understand how this value is used.
90      *
91      * @see org.apache.tools.ant.taskdefs.optional.jmx.connector.JMXConnector
92      */

93     public void setServerType(String JavaDoc serverType) {
94         getContext().setServerType(serverType);
95     }
96     
97     /**
98      * Sets the <code>providerUrl</code> attribute for the JNDI provider.
99      *
100      * @param providerUrl The providerUrl of the JNDI provder.
101      *
102      * e.g. The default value for BEA WebLogic Server is
103      * <code>t3://localhost:7001</code>.
104      *
105      */

106     public void setProviderUrl(String JavaDoc providerUrl) {
107         getContext().setProviderUrl(providerUrl);
108     }
109
110     /**
111      * Sets the <code>jndiName</code> attribute for the JMX MBeanHome.
112      *
113      * @param jndiName The jndi name of the JMX server home.
114      * e.g. The default value for BEA Admin home is
115      * <code>weblogic.management.adminhome</code>.
116      */

117     public void setJndiName(String JavaDoc jndiName) {
118         getContext().setJndiName(jndiName);
119     }
120
121     /**
122      * Sets the <code>user</code> attribute to use for authentication with the JMX server.
123      *
124      * @param user The user-id to use for authentication with the JMX server.
125      */

126     public void setUser(String JavaDoc user) {
127         getContext().setUser(user);
128     }
129
130     /**
131      * Sets the <code>password</code> attribute to use for authentication with the JMX server.
132      *
133      * @param password The password to use
134      */

135     public void setPassword(String JavaDoc password) {
136         getContext().setPassword(password);
137     }
138
139     /**
140      * Sets the <code>failOnError</code> attribute. If false (default),
141      * processing will continue even if an error is detected. Examples of
142      * an error are trying to retrieve a non-existent attribute with getAttribute
143      * or trying to set an attribute value with an incorrect type.
144      *
145      * @param failOnError Behaviour that should happen if an error is detected.
146      */

147     public void setFailOnError(boolean failOnError) {
148         this.failOnError = failOnError;
149     }
150
151     
152     /**
153      * The JNDI entry name of the MBeanServer
154      *
155      * @return The JNDI name of the MBeanServer.
156      */

157     protected String JavaDoc getJndiName() {
158         return getContext().getJndiName();
159     }
160
161
162     /**
163      * The action to take if an error is detected while
164      * processing this task.
165      *
166      * @return true if a task should fail if an error is detected.
167      */

168     protected boolean getFailOnError() {
169         return failOnError;
170     }
171     
172     /**
173      * The url for the JNDI provider.
174      *
175      * @return The current JNDI provider URL.
176      */

177     protected String JavaDoc getProviderUrl() {
178         return getContext().getProviderUrl();
179     }
180     
181     protected String JavaDoc getUser() {
182         return getContext().getUser();
183     }
184     
185     protected String JavaDoc getPassword() {
186         return getContext().getPassword();
187     }
188         
189     public void setContextRef(org.apache.tools.ant.types.Reference ref) {
190         Object JavaDoc obj = ref.getReferencedObject(this.getProject());
191
192         if (!(obj instanceof ContextType)) {
193             String JavaDoc msg = "'" + ref.getRefId() + "' doesn't denote a " + ContextType.DATA_TYPE_NAME + ". " + ref.getRefId() + " is a " + obj.getClass().getName();
194             throw new BuildException(msg);
195         }
196         setContext((ContextType) obj);
197     }
198
199         
200 }
201
202 /*
203  * $Log: AbstractManagementTask.java,v $
204  * Revision 1.3 2003/05/28 22:28:26 bdueck
205  * *** empty log message ***
206  *
207  * Revision 1.2 2003/04/21 15:29:41 bdueck
208  * Various changes in preparation for version 1.2.
209  *
210  * Revision 1.1 2003/04/01 22:04:16 bdueck
211  * Initial check-in.
212  *
213  * Revision 1.1 2003/01/17 12:33:55 bdueck
214  * Initial check-in
215  *
216  *
217  */
Popular Tags