01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: PropertyValueTemplate.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.ioc;
09:
10: import com.uwyn.rife.ioc.PropertyValue;
11: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
12: import com.uwyn.rife.ioc.exceptions.TemplateFactoryUnknownException;
13: import com.uwyn.rife.template.Template;
14: import com.uwyn.rife.template.TemplateFactory;
15:
16: /**
17: * Retrieves a property value as template instance of a particular type.
18: *
19: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
20: * @version $Revision: 3634 $
21: * @since 1.0
22: */
23: public class PropertyValueTemplate implements PropertyValue {
24: private String mType = null;
25: private String mName = null;
26:
27: /**
28: * The constructor that stores the retrieval parameters.
29: * The template type will be set to "enginehtml"
30: *
31: * @param name the template name
32: * @since 1.4
33: */
34: public PropertyValueTemplate(String name) {
35: this (null, name);
36: }
37:
38: /**
39: * The constructor that stores the retrieval parameters.
40: *
41: * @param type the template factory type; if this argument is <code>null</code>
42: * the template type will be "enginehtml"
43: * @param name the template name
44: * @since 1.0
45: */
46: public PropertyValueTemplate(String type, String name) {
47: if (null == type) {
48: type = "enginehtml";
49: }
50: mType = type;
51: mName = name;
52: }
53:
54: public Template getValue() throws PropertyValueException {
55: TemplateFactory factory = TemplateFactory.getFactory(mType);
56: if (null == factory) {
57: throw new TemplateFactoryUnknownException(mType);
58: }
59: return factory.get(mName);
60: }
61:
62: public String getValueString() throws PropertyValueException {
63: return getValue().getContent();
64: }
65:
66: public String toString() {
67: return getValueString();
68: }
69:
70: public boolean isNeglectable() {
71: return false;
72: }
73:
74: public boolean isStatic() {
75: return false;
76: }
77: }
|