001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg;
031:
032: import java.util.*;
033: import java.util.logging.*;
034:
035: import com.caucho.config.*;
036: import com.caucho.ejb.manager.EjbContainer;
037: import com.caucho.loader.*;
038: import com.caucho.util.*;
039: import com.caucho.vfs.*;
040:
041: /**
042: * Manages the EJB configuration files.
043: */
044: public class EjbConfigManager extends EjbConfig {
045: private static final L10N L = new L10N(EjbConfigManager.class);
046: private static final Logger log = Logger
047: .getLogger(EjbConfigManager.class.getName());
048:
049: private HashMap<Path, EjbRootConfig> _rootConfigMap = new HashMap<Path, EjbRootConfig>();
050:
051: private ArrayList<EjbRootConfig> _rootPendingList = new ArrayList<EjbRootConfig>();
052:
053: private ArrayList<Path> _pathPendingList = new ArrayList<Path>();
054:
055: public EjbConfigManager(EjbContainer ejbContainer) {
056: super (ejbContainer);
057: }
058:
059: /**
060: * Returns an EjbRootConfig for a class-loader root.
061: */
062: public EjbRootConfig createRootConfig(Path root) {
063: EjbRootConfig rootConfig = _rootConfigMap.get(root);
064:
065: if (rootConfig == null) {
066: rootConfig = new EjbRootConfig(root);
067: _rootConfigMap.put(root, rootConfig);
068: _rootPendingList.add(rootConfig);
069:
070: Path ejbJar = root.lookup("META-INF/ejb-jar.xml");
071: if (ejbJar.canRead())
072: addEjbPath(ejbJar);
073: }
074:
075: return rootConfig;
076: }
077:
078: public void start() {
079: ArrayList<EjbRootConfig> pendingList = new ArrayList<EjbRootConfig>(
080: _rootPendingList);
081: _rootPendingList.clear();
082:
083: for (EjbRootConfig rootConfig : pendingList) {
084: for (String className : rootConfig.getClassNameList()) {
085: addIntrospectableClass(className);
086: }
087: }
088:
089: configurePaths();
090:
091: configure();
092:
093: deploy();
094: }
095:
096: /**
097: * Adds a path for an EJB config file to the config list.
098: */
099: @Override
100: public void addEjbPath(Path path) {
101: if (_pathPendingList.contains(path))
102: return;
103:
104: _pathPendingList.add(path);
105: }
106:
107: private void configurePaths() {
108: ArrayList<Path> pathList = new ArrayList<Path>(_pathPendingList);
109: _pathPendingList.clear();
110:
111: for (Path path : pathList) {
112: if (path.getScheme().equals("jar"))
113: path.setUserPath(path.getURL());
114:
115: Environment.addDependency(path);
116:
117: String ejbModuleName;
118:
119: if (path instanceof JarPath) {
120: ejbModuleName = ((JarPath) path).getContainer()
121: .getPath();
122: } else {
123: ejbModuleName = path.getPath();
124: }
125:
126: EjbJar ejbJar = new EjbJar(this , ejbModuleName);
127:
128: try {
129: new Config().configure(ejbJar, path, getSchema());
130: } catch (ConfigException e) {
131: throw e;
132: } catch (Exception e) {
133: throw ConfigException.create(e);
134: }
135: }
136: }
137: }
|