Source Code Cross Referenced for EditableKernelConfigurationManager.java in  » EJB-Server-geronimo » kernel » org » apache » geronimo » kernel » config » 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 » EJB Server geronimo » kernel » org.apache.geronimo.kernel.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.kernel.config;
017:
018:        import java.util.ArrayList;
019:        import java.util.Collection;
020:        import java.util.Collections;
021:        import java.util.Iterator;
022:        import java.util.List;
023:
024:        import org.apache.geronimo.gbean.AbstractName;
025:        import org.apache.geronimo.gbean.AbstractNameQuery;
026:        import org.apache.geronimo.gbean.GBeanData;
027:        import org.apache.geronimo.gbean.GBeanInfo;
028:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
029:        import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
030:        import org.apache.geronimo.kernel.GBeanNotFoundException;
031:        import org.apache.geronimo.kernel.Kernel;
032:        import org.apache.geronimo.kernel.management.State;
033:        import org.apache.geronimo.kernel.repository.Artifact;
034:        import org.apache.geronimo.kernel.repository.ArtifactManager;
035:        import org.apache.geronimo.kernel.repository.ArtifactResolver;
036:
037:        /**
038:         * Standard implementation of an editable ConfigurationManager.
039:         *
040:         * @version $Rev:386276 $ $Date: 2007-11-21 00:39:04 -0800 (Wed, 21 Nov 2007) $
041:         */
042:        public class EditableKernelConfigurationManager extends
043:                KernelConfigurationManager implements 
044:                EditableConfigurationManager {
045:            private final AbstractNameQuery defaultStoreNameQuery;
046:
047:            public EditableKernelConfigurationManager(Kernel kernel,
048:                    AbstractNameQuery defaultStoreNameQuery, Collection stores,
049:                    ManageableAttributeStore attributeStore,
050:                    PersistentConfigurationList configurationList,
051:                    ArtifactManager artifactManager,
052:                    ArtifactResolver artifactResolver, Collection repositories,
053:                    Collection watchers, ClassLoader classLoader) {
054:                super (kernel, stores, attributeStore, configurationList,
055:                        artifactManager, artifactResolver, repositories,
056:                        watchers, classLoader);
057:                this .defaultStoreNameQuery = defaultStoreNameQuery;
058:            }
059:
060:            @Override
061:            protected List getStoreList() {
062:                if (null == defaultStoreNameQuery) {
063:                    return super .getStoreList();
064:                }
065:
066:                List<ConfigurationStore> storeList = new ArrayList<ConfigurationStore>();
067:                for (Iterator iterator = stores.iterator(); iterator.hasNext();) {
068:                    ConfigurationStore configurationStore = (ConfigurationStore) iterator
069:                            .next();
070:                    if (defaultStoreNameQuery.matches(configurationStore
071:                            .getAbstractName(), Collections.EMPTY_SET)) {
072:                        storeList.add(0, configurationStore);
073:                    } else {
074:                        storeList.add(configurationStore);
075:                    }
076:                }
077:                return storeList;
078:            }
079:
080:            public void addGBeanToConfiguration(Artifact configurationId,
081:                    GBeanData gbean, boolean start)
082:                    throws InvalidConfigException {
083:                Configuration configuration = getConfiguration(configurationId);
084:
085:                try {
086:                    // add the gbean to the configuration
087:                    configuration.addGBean(gbean);
088:                } catch (GBeanAlreadyExistsException e) {
089:                    throw new InvalidConfigException("Cound not add GBean "
090:                            + gbean.getAbstractName() + " to configuration "
091:                            + configurationId, e);
092:                }
093:
094:                addGBeanToConfiguration(configuration, gbean, start);
095:            }
096:
097:            public void addGBeanToConfiguration(Artifact configurationId,
098:                    String name, GBeanData gbean, boolean start)
099:                    throws InvalidConfigException {
100:                Configuration configuration = getConfiguration(configurationId);
101:
102:                try {
103:                    // add the gbean to the configuration
104:                    configuration.addGBean(name, gbean);
105:                } catch (GBeanAlreadyExistsException e) {
106:                    throw new InvalidConfigException("Cound not add GBean "
107:                            + gbean.getAbstractName() + " to configuration "
108:                            + configurationId, e);
109:                }
110:
111:                addGBeanToConfiguration(configuration, gbean, start);
112:            }
113:
114:            private void addGBeanToConfiguration(Configuration configuration,
115:                    GBeanData gbean, boolean start)
116:                    throws InvalidConfigException {
117:                ClassLoader configurationClassLoader = configuration
118:                        .getConfigurationClassLoader();
119:                ClassLoader oldCl = Thread.currentThread()
120:                        .getContextClassLoader();
121:                try {
122:                    Thread.currentThread().setContextClassLoader(
123:                            configurationClassLoader);
124:
125:                    log.trace("Registering GBean " + gbean.getAbstractName());
126:
127:                    // preprocess the gbean data before loading it into the kernel
128:                    ConfigurationUtil.preprocessGBeanData(configuration
129:                            .getAbstractName(), configuration, gbean);
130:
131:                    // register the bean with the kernel
132:                    kernel.loadGBean(gbean, configurationClassLoader);
133:
134:                    // start the configuration
135:                    if (start) {
136:                        try {
137:                            kernel.startRecursiveGBean(gbean.getAbstractName());
138:                        } catch (GBeanNotFoundException e) {
139:                            throw new InvalidConfigException(
140:                                    "How could we not find a GBean that we just loaded ('"
141:                                            + gbean.getAbstractName() + "')?",
142:                                    e);
143:                        }
144:                    }
145:
146:                } catch (Exception e) {
147:                    // clean up failed gbean
148:                    try {
149:                        configuration.removeGBean(gbean.getAbstractName());
150:                    } catch (GBeanNotFoundException e1) {
151:                        // this is good
152:                    }
153:                    try {
154:                        kernel.stopGBean(gbean.getAbstractName());
155:                    } catch (GBeanNotFoundException e1) {
156:                        // this is good
157:                    }
158:                    try {
159:                        kernel.unloadGBean(gbean.getAbstractName());
160:                    } catch (GBeanNotFoundException e1) {
161:                        // this is good
162:                    }
163:
164:                    if (e instanceof  InvalidConfigException) {
165:                        throw (InvalidConfigException) e;
166:                    }
167:                    throw new InvalidConfigException("Cound not add GBean "
168:                            + gbean.getAbstractName() + " to configuration "
169:                            + configuration.getId(), e);
170:                } finally {
171:                    Thread.currentThread().setContextClassLoader(oldCl);
172:                }
173:
174:                if (attributeStore != null) {
175:                    attributeStore.addGBean(configuration.getId(), gbean,
176:                            configurationClassLoader);
177:                }
178:            }
179:
180:            public void removeGBeanFromConfiguration(Artifact configurationId,
181:                    AbstractName gbeanName) throws GBeanNotFoundException,
182:                    InvalidConfigException {
183:                Configuration configuration = getConfiguration(configurationId);
184:                if (!configuration.containsGBean(gbeanName)) {
185:                    throw new GBeanNotFoundException(gbeanName);
186:                }
187:                configuration.removeGBean(gbeanName);
188:
189:                try {
190:                    if (kernel.getGBeanState(gbeanName) == State.RUNNING_INDEX) {
191:                        kernel.stopGBean(gbeanName);
192:                    }
193:                    kernel.unloadGBean(gbeanName);
194:                } catch (GBeanNotFoundException e) {
195:                    // Bean is no longer loaded
196:                }
197:
198:                // Make sure it's not loaded next time the configuration is loaded
199:                if (attributeStore != null) {
200:                    attributeStore.setShouldLoad(configurationId, gbeanName,
201:                            false);
202:                }
203:            }
204:
205:            public static final GBeanInfo GBEAN_INFO;
206:
207:            public static final String GBEAN_ATTR_DEFAULT_STORE_NAME_QUERY = "defaultStoreNameQuery";
208:
209:            static {
210:                GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
211:                        EditableKernelConfigurationManager.class,
212:                        KernelConfigurationManager.GBEAN_INFO,
213:                        "ConfigurationManager");
214:
215:                infoFactory.addAttribute(GBEAN_ATTR_DEFAULT_STORE_NAME_QUERY,
216:                        AbstractNameQuery.class, true);
217:
218:                infoFactory.addInterface(EditableConfigurationManager.class);
219:
220:                infoFactory.setConstructor(new String[] { "kernel",
221:                        GBEAN_ATTR_DEFAULT_STORE_NAME_QUERY, "Stores",
222:                        "AttributeStore", "PersistentConfigurationList",
223:                        "ArtifactManager", "ArtifactResolver", "Repositories",
224:                        "Watchers", "classLoader" });
225:
226:                GBEAN_INFO = infoFactory.getBeanInfo();
227:            }
228:
229:            public static GBeanInfo getGBeanInfo() {
230:                return GBEAN_INFO;
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.