001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.extend;
017:
018: import java.util.Collection;
019: import java.util.Map;
020:
021: /**
022: * A class to manage the converter types and the instantiated class name matches.
023: * @author Joe Walker [joe at getahead dot ltd dot uk]
024: */
025: public interface ConverterManager {
026: /**
027: * Add a new converter type
028: * @param id The name of the converter type
029: * @param className The class to do the conversion
030: */
031: void addConverterType(String id, String className);
032:
033: /**
034: * Add a new converter
035: * @param match The class name(s) to match
036: * @param type The name of the converter type
037: * @param params The extra parameters to allow the creator to configure itself
038: * @throws InstantiationException If reflection based creation fails
039: * @throws IllegalAccessException If reflection based creation fails
040: * @throws IllegalArgumentException If we have a duplicate name
041: */
042: void addConverter(String match, String type,
043: Map<String, String> params)
044: throws IllegalArgumentException, InstantiationException,
045: IllegalAccessException;
046:
047: /**
048: * Add a new converter
049: * @param match The class name(s) to match
050: * @param converter The converter to add
051: * @throws IllegalArgumentException If we have a duplicate name
052: */
053: void addConverter(String match, Converter converter)
054: throws IllegalArgumentException;
055:
056: /**
057: * In order to be able to create stub remote objects we need to know what
058: * they are so you can get a collection of all match strings.
059: * @return A Collection of all the converter match strings
060: * @see #getConverterByMatchString(String)
061: */
062: Collection<String> getConverterMatchStrings();
063:
064: /**
065: * In order to be able to create stub remote objects we need to know what
066: * they are so you can lookup match strings and retrieve the converter.
067: * @param match The match string to lookup
068: * @return The matching converter
069: * @see #getConverterMatchStrings()
070: */
071: Converter getConverterByMatchString(String match);
072:
073: /**
074: * Check if we can coerce the given type
075: * @param paramType The type to check
076: * @return true iff <code>paramType</code> is coercable
077: */
078: boolean isConvertable(Class<?> paramType);
079:
080: /**
081: * Convert an object from being a string into an object of some type.
082: * Designed for use with converters that have a working map passed to them
083: * @param paramType The type that you want the object to be
084: * @param data The string version of the object
085: * @param inctx The map of data that we are working on
086: * @param incc The context of this type conversion
087: * @return The coerced object or null if the object could not be coerced
088: * @throws MarshallException If the conversion failed for some reason
089: */
090: Object convertInbound(Class<?> paramType, InboundVariable data,
091: InboundContext inctx, TypeHintContext incc)
092: throws MarshallException;
093:
094: /**
095: * Convert an object into a Javavscript representation of the same.
096: * This method is for use by converters wishing to recurse into some object.
097: * @param data The object to convert
098: * @param converted The list of converted objects so far
099: * @return A Javascript string version of the object
100: * @throws MarshallException If the conversion failed for some reason
101: */
102: OutboundVariable convertOutbound(Object data,
103: OutboundContext converted) throws MarshallException;
104:
105: /**
106: * We don't know enough from a method signature like setUsers(Set s) to be
107: * able to cast the inbound data to a set of Users. This method enables us
108: * to specify this extra information.
109: * @param thc The context to find any extra type information from
110: * @param type The type of the specified parameter.
111: */
112: void setExtraTypeInfo(TypeHintContext thc, Class<?> type);
113:
114: /**
115: * The extra type information that we have learnt about a method parameter.
116: * This method will return null if there is nothing extra to know
117: * @param thc The context to find any extra type information from
118: * @return A type to use to fill out the generic type
119: */
120: Class<?> getExtraTypeInfo(TypeHintContext thc);
121:
122: /**
123: * Sets the converters for this converter manager.
124: * @param converters the map of match pattern and their converter instances
125: */
126: void setConverters(Map<String, Converter> converters);
127: }
|