KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > functions > ReturnType


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util.functions;
11
12 import java.util.*;
13
14 /**
15  * Description of the return type of certain function. This wraps a Class object but it has some
16  * extra members. Can be used as a constructor argument of {@link Function} objects or as an
17  * argument of {@link Function#setReturnType}.
18  *
19  * @author Daniel Ockeloen
20  * @author Michiel Meeuwissen
21
22  * @version $Id: ReturnType.java,v 1.14 2005/07/28 17:07:55 michiel Exp $
23  * @since MMBase-1.7
24  */

25 public class ReturnType extends Parameter implements java.io.Serializable JavaDoc {
26
27     /**
28      * The return type of a function that does not return a thing.
29      */

30     public static final ReturnType VOID = new ReturnType(void.class, "Does not return anything");
31
32     /**
33      * The return type of a function that returns a String.
34      */

35     public static final ReturnType STRING = new ReturnType(String JavaDoc.class, "String");
36
37     public static final ReturnType CHARSEQUENCE = new ReturnType(CharSequence JavaDoc.class, "CharSequence");
38
39     /**
40      * The return type of a function that returns a Integer.
41      */

42     public static final ReturnType INTEGER = new ReturnType(Integer JavaDoc.class, "Integer");
43
44     /**
45      * The return type of a function that returns a Long.
46      */

47     public static final ReturnType LONG = new ReturnType(Long JavaDoc.class, "Long");
48
49     /**
50      * The return type of a function that returns a Double.
51      */

52     public static final ReturnType DOUBLE = new ReturnType(Double JavaDoc.class, "Double");
53
54     /**
55      * The return type of a function that returns a Boolean.
56      */

57     public static final ReturnType BOOLEAN = new ReturnType(Boolean JavaDoc.class, "Boolean");
58
59     /**
60      * The return type of a function that returns a List.
61      */

62     public static final ReturnType LIST = new ReturnType(List.class, "List");
63
64
65     /**
66      * The return type of a function that returns a NodeList.
67      */

68     public static final ReturnType NODELIST = new ReturnType(org.mmbase.bridge.NodeList.class, "NodeList");
69
70     /**
71      * The return type of a function that returns a Node.
72      */

73     public static final ReturnType NODE = new ReturnType(org.mmbase.bridge.Node.class, "Node");
74
75     /**
76      * The return type of a function that returns a Set.
77      */

78     public static final ReturnType SET = new ReturnType(Set.class, "Set");
79     /**
80      * The return type of a function that returns a Set.
81      */

82     public static final ReturnType COLLECTION = new ReturnType(Collection.class, "Collection");
83
84     /**
85      * The return type of a function that returns a Map.
86      */

87     public static final ReturnType MAP = new ReturnType(Map.class, "Map");
88
89     /**
90      * The return type of a function is unknown.
91      */

92     public static final ReturnType UNKNOWN = new ReturnType(Object JavaDoc.class, "unknown");
93
94     /**
95      * The return type of a function is None
96      */

97     public static final ReturnType NONE = new ReturnType(Object JavaDoc.class, "none");
98
99     /**
100      * Can be return by functions that don't want to return anything. (The function framework
101      * requires you to return <em>something</em>).
102      */

103     public static final Object JavaDoc VOID_VALUE = new Object JavaDoc();
104
105     private Map typeStruct = new HashMap(); // key -> ReturnType
106

107     public ReturnType(Class JavaDoc type, String JavaDoc description) {
108         super("RETURN_VALUE", type);
109         setDescription(description, null);
110     }
111
112     public boolean isRequired() {
113         return false;
114     }
115
116     /**
117      * If the return type is like a map or struct (key-values pairs), then you might want to describe the
118      * types of the values seperately too.
119      */

120     public ReturnType addSubType(String JavaDoc name, ReturnType type) {
121         return (ReturnType) typeStruct.put(name, type);
122     }
123
124     /**
125      * @return Unmodifiable Map containing the 'subtypes' in case the type is Map. An empty Map otherwise.
126      */

127     public Map getSubTypes() {
128         return Collections.unmodifiableMap(typeStruct);
129     }
130
131
132     public String JavaDoc toString() {
133         return getDataType().getTypeAsClass().getName();
134     }
135
136 }
137
Popular Tags