KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > values > types > SingleType


1 /*
2  * Copyright (c) 2005, Rob Gordon.
3  */

4 package org.oddjob.values.types;
5
6 import org.oddjob.arooa.ArooaContext;
7 import org.oddjob.arooa.ArooaHandler;
8 import org.oddjob.arooa.handlers.ValueHandler;
9 import org.oddjob.arooa.reflect.IntrospectionHelper;
10
11 /**
12  * Wrapper for any one thing which forces the thing to be created using the
13  * factory. OutputStream for instance which can be text, buffer, file etc.
14  *
15  * @author Rob Gordon.
16  */

17 public class SingleType {
18     
19     private Object JavaDoc wrapper;
20             
21     public void addValue(Object JavaDoc type) {
22         wrapper = type;
23     }
24     
25     /**
26      * Return the value for this type. Defers to the nested value type.
27      * @param required The required class.
28      * @return The value.
29      */

30     public Object JavaDoc valueFor(Class JavaDoc required) {
31         return IntrospectionHelper.valueFor(wrapper, required);
32     }
33     
34     /**
35      * Provide our own handler for the values.
36      *
37      * @param context Not required.
38      * @return Our handler.
39      */

40     public ArooaHandler handlerFor(ArooaContext context) {
41         // a handler that will call the addValue method.
42
return new ValueHandler("");
43     }
44  
45     public String JavaDoc toString() {
46         if (wrapper == null) {
47             return null;
48         }
49         return wrapper.toString();
50     }
51
52 }
53
Popular Tags