KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > cfg > EjbBeanConfigProxy


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.cfg;
30
31 import com.caucho.config.BuilderProgram;
32 import com.caucho.config.BuilderProgramContainer;
33 import com.caucho.config.ConfigException;
34 import com.caucho.config.DependencyBean;
35 import com.caucho.util.L10N;
36 import com.caucho.vfs.PersistentDependency;
37
38 import javax.annotation.PostConstruct;
39 import java.util.ArrayList JavaDoc;
40
41 /**
42  * Proxy for an ejb bean configuration. This proxy is needed to handle
43  * the merging of ejb definitions.
44  */

45 public class EjbBeanConfigProxy implements DependencyBean {
46   private static final L10N L = new L10N(EjbBeanConfigProxy.class);
47
48   private final EjbConfig _config;
49   private final String JavaDoc _ejbModuleName;
50
51   private String JavaDoc _ejbName;
52
53   private String JavaDoc _filename = "";
54   private String JavaDoc _location = "";
55   
56   // The configuration program
57
private BuilderProgramContainer _program = new BuilderProgramContainer();
58
59   private EjbBean _bean;
60   
61   ArrayList JavaDoc<PersistentDependency> _dependList =
62     new ArrayList JavaDoc<PersistentDependency>();
63   
64   /**
65    * Creates a new entity bean configuration.
66    */

67   public EjbBeanConfigProxy(EjbConfig config, String JavaDoc ejbModuleName)
68   {
69     _config = config;
70     _ejbModuleName = ejbModuleName;
71   }
72
73   /**
74    * Returns the configuration.
75    */

76   public EjbConfig getConfig()
77   {
78     return _config;
79   }
80
81    public String JavaDoc getEJBModuleName()
82   {
83     return _ejbModuleName;
84   }
85
86   /**
87    * Sets the location
88    */

89   public void setConfigLocation(String JavaDoc filename, int line)
90   {
91     _filename = filename;
92     _location = filename + ":" + line + ": ";
93   }
94
95   /**
96    * Gets the location
97    */

98   public String JavaDoc getLocation()
99   {
100     return _location;
101   }
102
103   /**
104    * Gets the filename
105    */

106   public String JavaDoc getFilename()
107   {
108     return _filename;
109   }
110     
111   /**
112    * Sets the ejbName
113    */

114   public void setEJBName(String JavaDoc ejbName)
115   {
116     _ejbName = ejbName;
117   }
118
119   /**
120    * Gets the ejbName
121    */

122   public String JavaDoc getEJBName()
123   {
124     return _ejbName;
125   }
126
127   /**
128    * Add a dependency.
129    */

130   public void addDependency(PersistentDependency depend)
131   {
132     if (! _dependList.contains(depend))
133       _dependList.add(depend);
134   }
135
136   /**
137    * Gets the depend list.
138    */

139   public ArrayList JavaDoc<PersistentDependency> getDependencyList()
140   {
141     return _dependList;
142   }
143
144   /**
145    * Adds to the builder program.
146    */

147   public void addBuilderProgram(BuilderProgram program)
148   {
149     _program.addProgram(program);
150   }
151
152   /**
153    * Returns the program.
154    */

155   public BuilderProgram getBuilderProgram()
156   {
157     return _program;
158   }
159
160   /**
161    * Initializes and configures the entity bean.
162    */

163   @PostConstruct
164   public void init()
165     throws Throwable JavaDoc
166   {
167     _bean = getConfig().getBeanConfig(getEJBName());
168
169     if (_bean == null) {
170       throw new ConfigException(L.l("bean '{0}' has no primary definition.",
171                     getEJBName()));
172     }
173
174     // _entity.addDependencyList(getDependencyList());
175

176     getBuilderProgram().configure(_bean);
177   }
178
179   /**
180    * Returns the entity config.
181    */

182   public EjbBean getBean()
183   {
184     return _bean;
185   }
186 }
187
Popular Tags