KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.tools.ant.taskdefs.optional.jmx.converter;
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
54
55 import java.util.Set JavaDoc;
56 import java.util.StringTokenizer JavaDoc;
57
58 /**
59  * Converts a String to an equivalent java.lang.Set value.
60  *
61  * @author <a HREF="mailto:bdueck@yahoo.com">Brian Dueck</a>
62  * @version $Id: SetValueConverter.java,v 1.2 2003/05/28 22:28:26 bdueck Exp $
63  */

64 public class SetValueConverter implements ValueConverter {
65     
66     private static String JavaDoc[] supportedTypes = {Set JavaDoc.class.getName()};
67     
68     /** Creates a new instance of PropertiesAttributeBuilder
69      *
70      */

71     public SetValueConverter() {
72     }
73     
74     /**
75      * Create an mbean attribute value.
76      *
77      * Value is expected to be in the form of a whitespace separated list of values.
78      * Examples:
79      * red, green, blue</br>
80      */

81     public Object JavaDoc valueOf(String JavaDoc value, String JavaDoc type) throws Exception JavaDoc {
82
83         try {
84             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value," ,[]\t\n\r\f");
85             
86             Set JavaDoc result = new java.util.TreeSet JavaDoc();
87             while (tokenizer.hasMoreTokens()) {
88                 String JavaDoc item = tokenizer.nextToken();
89                 result.add(item);
90             }
91             return result;
92         } catch (Exception JavaDoc x) {
93             throw new org.apache.tools.ant.BuildException("Invalid Set value format. Expected format \"value1, value2, value3\" etc. E.g. [red, green, blue], etc.",x);
94         }
95     }
96     
97     public String JavaDoc[] getSupportedTypes() {
98         return supportedTypes;
99     }
100     
101 }
102
103 /*
104  * $Log: SetValueConverter.java,v $
105  * Revision 1.2 2003/05/28 22:28:26 bdueck
106  * *** empty log message ***
107  *
108  * Revision 1.1 2003/05/26 10:10:56 bdueck
109  * *** empty log message ***
110  *
111  * Revision 1.2 2003/04/21 15:29:42 bdueck
112  * Various changes in preparation for version 1.2.
113  *
114  *
115  */
Popular Tags