KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
33  * A saved program for configuring an object.
34  */

35 public abstract class BuilderProgram {
36   //private NodeBuilder _nodeBuilder;
37
private NodeBuilder _nodeBuilder;
38   private ClassLoader JavaDoc _loader;
39
40   protected BuilderProgram()
41   {
42     this(NodeBuilder.getCurrentBuilder());
43   }
44
45   protected BuilderProgram(NodeBuilder builder)
46   {
47     // server/13co
48
/*
49     _nodeBuilder = builder;
50
51     if (builder == null)
52       _nodeBuilder = new NodeBuilder(); // XXX:
53     */

54
55     _loader = Thread.currentThread().getContextClassLoader();
56   }
57
58   /**
59    * Configures the object.
60    */

61   public void configure(Object JavaDoc bean)
62     throws ConfigException
63   {
64     // server/23e7
65
if (NodeBuilder.getCurrentBuilder() != null)
66       configureImpl(NodeBuilder.getCurrentBuilder(), bean);
67     else
68       configureImpl(NodeBuilder.createForProgram(), bean);
69   }
70
71   public Object JavaDoc configure(Class JavaDoc type)
72     throws ConfigException
73   {
74     if (NodeBuilder.getCurrentBuilder() != null)
75       return configureImpl(NodeBuilder.getCurrentBuilder(), type);
76     else
77       return configureImpl(NodeBuilder.createForProgram(), type);
78   }
79
80   /**
81    * Configures the object.
82    */

83   public void configureImpl(NodeBuilder builder, Object JavaDoc bean)
84     throws ConfigException
85   {
86     throw new UnsupportedOperationException JavaDoc(getClass().getName());
87   }
88
89   /**
90    * Configures a bean given a class to instantiate.
91    */

92   protected Object JavaDoc configureImpl(NodeBuilder builder, Class JavaDoc type)
93     throws ConfigException
94   {
95     try {
96       Object JavaDoc bean = type.newInstance();
97
98       configureImpl(builder, bean);
99
100       return bean;
101     } catch (RuntimeException JavaDoc e) {
102       throw e;
103     } catch (Exception JavaDoc e) {
104       throw new ConfigException(e);
105     }
106   }
107
108   public void init(Object JavaDoc bean)
109     throws ConfigException
110   {
111     Config.init(bean);
112   }
113 }
114
Popular Tags