KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > config > TypeStrategy


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.config;
31
32 import com.caucho.util.L10N;
33 import com.caucho.xml.QName;
34
35 import org.w3c.dom.Node JavaDoc;
36
37 /**
38  * Strategy for configuring types.
39  */

40 public abstract class TypeStrategy {
41   protected static final L10N L = new L10N(TypeStrategy.class);
42
43   /**
44    * Returns the type name.
45    */

46   public String JavaDoc getTypeName()
47   {
48     return getClass().getName();
49   }
50   
51   /**
52    * Creates a new instance of the type.
53    */

54   public Object JavaDoc create()
55     throws Exception JavaDoc
56   {
57     throw new UnsupportedOperationException JavaDoc(getClass().getName());
58   }
59
60   /**
61    * Sets the object's parent
62    *
63    * @param parent the parent
64    */

65   public void setParent(Object JavaDoc bean, Object JavaDoc parent)
66     throws Exception JavaDoc
67   {
68   }
69
70   /**
71    * Return the attribute strategy for the given name.
72    *
73    * @param attrName the configuration attribute name
74    * @return the attribute strategy or null if no strategy
75    */

76   public AttributeStrategy getAttributeStrategy(QName attrName)
77           throws Exception JavaDoc
78   {
79     throw new ConfigException(L.l("'{0}' is an unknown attribute of {1}.",
80                                   attrName.getName(),
81                   getTypeName()));
82   }
83
84   /**
85    * Returns the type's configured value
86    *
87    * @param builder the context builder
88    * @param node the configuration node
89    * @param parent
90    */

91   abstract public Object JavaDoc configure(NodeBuilder builder, Node JavaDoc node, Object JavaDoc parent)
92     throws Exception JavaDoc;
93
94   /**
95    * Configures the bean
96    *
97    * @param builder the context builder
98    * @param bean the bean to be configured
99    * @param top the configuration node
100    */

101   public void configureBean(NodeBuilder builder, Object JavaDoc bean, Node JavaDoc top)
102     throws Exception JavaDoc
103   {
104     builder.configureBeanImpl(this, bean, top);
105   }
106
107   /**
108    * Configures based on an attribute.
109    */

110   public void configureAttribute(NodeBuilder builder, Object JavaDoc bean, Node JavaDoc attr)
111     throws Exception JavaDoc
112   {
113     builder.configureAttributeImpl(this, bean, attr);
114   }
115
116   /**
117    * Initialize the bean
118    */

119   public void init(Object JavaDoc bean)
120     throws Exception JavaDoc
121   {
122   }
123
124   /**
125    * Factory replacement
126    */

127   public Object JavaDoc replaceObject(Object JavaDoc bean)
128     throws Exception JavaDoc
129   {
130     return bean;
131   }
132 }
133
Popular Tags