Source Code Cross Referenced for MapperManager.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_ejb » container » jorm » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_ejb.container.jorm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer(s): S.Chassande_________________________.
022:         * Contributor(s): ______________________________________.
023:         *
024:         * --------------------------------------------------------------------------
025:         * $Id: MapperManager.java 6673 2005-04-28 16:53:00Z benoitf $
026:         * --------------------------------------------------------------------------
027:         */package org.objectweb.jonas_ejb.container.jorm;
028:
029:        import java.util.HashMap;
030:        import java.util.Map;
031:        import java.util.Properties;
032:
033:        import org.objectweb.jonas_ejb.container.JContainer;
034:        import org.objectweb.jonas_ejb.container.TraceEjb;
035:
036:        import org.objectweb.jorm.lib.JormConfiguratorImpl;
037:        import org.objectweb.jorm.api.JormConfigurator;
038:        import org.objectweb.jorm.api.PException;
039:        import org.objectweb.jorm.api.PMapper;
040:        import org.objectweb.jorm.lib.Mapper;
041:        import org.objectweb.jorm.util.api.Loggable;
042:
043:        import org.objectweb.medor.eval.prefetch.lib.PrefetchCacheImpl;
044:
045:        import org.objectweb.util.monolog.api.BasicLevel;
046:        import org.objectweb.util.monolog.api.Logger;
047:
048:        /**
049:         * This class manages Jorm mappers. A mapper can be registered for each data
050:         * source (connection factory) used in each EJB container.
051:         * The Mapper manager provides also the JormConfigurator instance used to
052:         * configure Jorm.
053:         *
054:         * @author Sebastien Chassande-Barrioz
055:         */
056:        public class MapperManager {
057:
058:            /**
059:             * The singleton instance of the class
060:             */
061:            private static MapperManager singleton = null;
062:
063:            /**
064:             * It retrieves the unique instance of MapperManager.
065:             */
066:            public static MapperManager getInstance() {
067:                if (singleton == null) {
068:                    singleton = new MapperManager();
069:                }
070:                return singleton;
071:            }
072:
073:            /**
074:             * The Logger used in this class
075:             */
076:            private Logger logger = null;
077:
078:            /**
079:             * This fields contains the association between a mapper ant its name.
080:             * key: JContainer instance
081:             * Value: a map (key = connection factory / value = PMapper instance)
082:             *
083:             */
084:            private HashMap mappers = new HashMap();
085:
086:            /**
087:             * permits to configure Jorm and its mappers
088:             */
089:            private JormConfigurator jormConfigurator;
090:
091:            protected MapperManager() {
092:                logger = TraceEjb.logger;
093:                jormConfigurator = new JormConfiguratorImpl();
094:                Properties prop = new Properties();
095:                prop.put("jorm.generator",
096:                        "org.objectweb.jorm.generator.lib.JormGenerator");
097:                prop.put("jorm.mimanager",
098:                        "org.objectweb.jorm.metainfo.lib.JormManager");
099:                prop.put("jorm.parser",
100:                        "org.objectweb.jorm.xml2mi.lib.BasicDomParser");
101:                prop.put("jorm.verifier",
102:                        "org.objectweb.jorm.verifier.lib.JormVerifier");
103:                prop.put("jorm.writer",
104:                        "org.objectweb.jorm.mi2xml.lib.BasicDomWriter");
105:                prop.put("jorm.mapper.list", "rdb");
106:                prop
107:                        .put("jorm.mapper.mifactory.rdb",
108:                                "org.objectweb.jorm.mapper.rdb.metainfo.RdbMappingFactory");
109:                prop
110:                        .put("jorm.mapper.mopfactory.rdb",
111:                                "org.objectweb.jorm.mapper.rdb.generator.RdbMOPFactory");
112:                prop
113:                        .put("jorm.mapper.gcmapping.rdb",
114:                                "org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassMapping");
115:                prop
116:                        .put("jorm.mapper.schmgr.rdb",
117:                                "org.objectweb.jorm.mapper.rdb.lib.RdbPMappingStructuresManager");
118:                jormConfigurator.configure(prop);
119:                jormConfigurator.setLoggerFactory(TraceEjb.loggerFactory);
120:                if (logger.isLoggable(BasicLevel.DEBUG)) {
121:                    logger.log(BasicLevel.DEBUG, "JormConfigurator created");
122:                }
123:            }
124:
125:            /**
126:             * Lookup a jorm mapper for a given container and a given connection factory
127:             * @param c is the container asking the mapper
128:             * @param cf is the connection factory (datasource for example) represented
129:             * by the expected mapper.
130:             * @return the PMapper instance if it exists, otherwise a null value.
131:             */
132:            public PMapper getMapper(JContainer c, Object cf) {
133:                Map m = (Map) mappers.get(c);
134:                return (m == null ? null : (Mapper) m.get(cf));
135:            }
136:
137:            /**
138:             * Register and start PMapper for a container and a connection factory if
139:             * another mapper is not registered with the same container and the same
140:             * connection factory.
141:             * @param m the mapper to register (never null)
142:             * @param c the container using the mapper (never null)
143:             * @param cf the connection factory represented by the mapper (never null)
144:             * @return the mapper associated to the given container and the given
145:             * connection factory. The returned mapper can be different from the mapper
146:             * instance given in parameter if another similar mapper (same container
147:             * and same connection factory) is already registered.
148:             * @throws PException if it is not possible to start the mapper.
149:             */
150:            public PMapper addMapper(PMapper m, JContainer c, Object cf)
151:                    throws PException {
152:                Map map;
153:                PMapper pm = null;
154:                synchronized (mappers) {
155:                    map = (Map) mappers.get(c);
156:                    if (map == null) {
157:                        map = new HashMap();
158:                        mappers.put(c, map);
159:                    }
160:                }
161:                pm = (PMapper) map.get(cf);
162:                if (pm != null) {
163:                    return pm;
164:                }
165:                synchronized (map) {
166:                    pm = (PMapper) map.get(cf);
167:                    if (pm == null) {
168:                        pm = m;
169:                        //Allocate a new Cache of PreftechBuffer
170:                        m.setPrefetchCache(new PrefetchCacheImpl(logger));
171:                        //Add a logger
172:                        if (TraceEjb.loggerFactory == null) {
173:                            m.setLogger(logger);
174:                        } else {
175:                            m.setLogger(TraceEjb.loggerFactory
176:                                    .getLogger(TraceEjb.prefix + ".mapper."
177:                                            + m.getMapperName()));
178:                            if (m instanceof  Loggable) {
179:                                ((Loggable) m)
180:                                        .setLoggerFactory(TraceEjb.loggerFactory);
181:                            }
182:                        }
183:                        // start the mapper
184:                        m.start();
185:                        //register mapper
186:                        map.put(cf, m);
187:                        if (logger.isLoggable(BasicLevel.DEBUG)) {
188:                            logger.log(BasicLevel.DEBUG, "Mapper ("
189:                                    + m.getMapperName() + ", " + cf
190:                                    + ") initialized");
191:                        }
192:                    }
193:                }
194:                return pm;
195:            }
196:
197:            public Logger getLogger() {
198:                return logger;
199:            }
200:
201:            public JormConfigurator getJormConfigurator() {
202:                return jormConfigurator;
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.