KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > extend > ConverterManager


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.directwebremoting.extend;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Map JavaDoc;
20
21 /**
22  * A class to manage the converter types and the instantiated class name matches.
23  * @author Joe Walker [joe at getahead dot ltd dot uk]
24  */

25 public interface ConverterManager
26 {
27     /**
28      * Add a new converter type
29      * @param id The name of the converter type
30      * @param className The class to do the conversion
31      */

32     void addConverterType(String JavaDoc id, String JavaDoc className);
33
34     /**
35      * Add a new converter
36      * @param match The class name(s) to match
37      * @param type The name of the converter type
38      * @param params The extra parameters to allow the creator to configure itself
39      * @throws InstantiationException If reflection based creation fails
40      * @throws IllegalAccessException If reflection based creation fails
41      * @throws IllegalArgumentException If we have a duplicate name
42      */

43     void addConverter(String JavaDoc match, String JavaDoc type, Map JavaDoc params) throws IllegalArgumentException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc;
44
45     /**
46      * Add a new converter
47      * @param match The class name(s) to match
48      * @param converter The converter to add
49      * @throws IllegalArgumentException If we have a duplicate name
50      */

51     void addConverter(String JavaDoc match, Converter converter) throws IllegalArgumentException JavaDoc;
52
53     /**
54      * In order to be able to create stub remote objects we need to know what
55      * they are so you can get a collection of all match strings.
56      * @return A Collection of all the converter match strings
57      * @see #getConverterByMatchString(String)
58      */

59     Collection JavaDoc getConverterMatchStrings();
60
61     /**
62      * In order to be able to create stub remote objects we need to know what
63      * they are so you can lookup match strings and retrieve the converter.
64      * @param match The match string to lookup
65      * @return The matching converter
66      * @see #getConverterMatchStrings()
67      */

68     Converter getConverterByMatchString(String JavaDoc match);
69
70     /**
71      * Check if we can coerce the given type
72      * @param paramType The type to check
73      * @return true iff <code>paramType</code> is coercable
74      */

75     boolean isConvertable(Class JavaDoc paramType);
76
77     /**
78      * Convert an object from being a string into an object of some type.
79      * Designed for use with converters that have a working map passed to them
80      * @param paramType The type that you want the object to be
81      * @param iv The string version of the object
82      * @param inctx The map of data that we are working on
83      * @param incc The context of this type conversion
84      * @return The coerced object or null if the object could not be coerced
85      * @throws MarshallException If the conversion failed for some reason
86      */

87     Object JavaDoc convertInbound(Class JavaDoc paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc) throws MarshallException;
88
89     /**
90      * Convert an object into a Javavscript representation of the same.
91      * This method is for use by converters wishing to recurse into some object.
92      * @param object The object to convert
93      * @param converted The list of converted objects so far
94      * @return A Javascript string version of the object
95      * @throws MarshallException If the conversion failed for some reason
96      */

97     OutboundVariable convertOutbound(Object JavaDoc object, OutboundContext converted) throws MarshallException;
98
99     /**
100      * We don't know enough from a method signature like setUsers(Set s) to be
101      * able to cast the inbound data to a set of Users. This method enables us
102      * to specify this extra information.
103      * @param thc The context to find any extra type information from
104      * @param type The type of the specified parameter.
105      */

106     void setExtraTypeInfo(TypeHintContext thc, Class JavaDoc type);
107
108     /**
109      * The extra type information that we have learnt about a method parameter.
110      * This method will return null if there is nothing extra to know
111      * @param thc The context to find any extra type information from
112      * @return A type to use to fill out the generic type
113      */

114     Class JavaDoc getExtraTypeInfo(TypeHintContext thc);
115
116     /**
117      * Sets the converters for this converter manager.
118      * @param converters the map of match pattern and their converter instances
119      */

120     void setConverters(Map JavaDoc converters);
121 }
122
Popular Tags