001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
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: */
017: package edu.iu.uis.eden.plugin;
018:
019: import javax.xml.namespace.QName;
020:
021: import org.kuali.rice.core.Core;
022: import org.kuali.rice.definition.ObjectDefinition;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
026:
027: public class TestPluginRegistry extends BasePluginRegistry implements
028: PluginRegistry {
029:
030: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
031: .getLogger(TestPluginRegistry.class);
032:
033: private boolean embeddedInitialized = false;
034: private String currentClientProtocol;
035: private PluginRegistry embeddedPluginRegistry = new NullPluginRegistry();
036: private PluginRegistry actualPluginRegistry;
037:
038: public Plugin getInstitutionalPlugin() {
039: updatePluginRegistry();
040: return actualPluginRegistry.getInstitutionalPlugin();
041: }
042:
043: public Object getObject(ObjectDefinition definition) {
044: updatePluginRegistry();
045: return super .getObject(definition);
046: }
047:
048: public PluginEnvironment getPluginEnvironment(QName pluginName) {
049: updatePluginRegistry();
050: return actualPluginRegistry.getPluginEnvironment(pluginName);
051: }
052:
053: public Object getService(QName serviceName) {
054: updatePluginRegistry();
055: return super .getService(serviceName);
056: }
057:
058: public void start() throws Exception {
059: updatePluginRegistry();
060: // we don't want to call super.start() because the updatePluginRegistry is going to start our resource loaders
061: //super.start();
062: }
063:
064: public void stop() throws Exception {
065: if (actualPluginRegistry != null) {
066: actualPluginRegistry.stop();
067: }
068: if (embeddedPluginRegistry != null) {
069: embeddedPluginRegistry.stop();
070: }
071: super .stop();
072: }
073:
074: protected synchronized void updatePluginRegistry() {
075: try {
076: // it's important to always check the root config for this since our config system utilizes a ghetto hierarchy. This means
077: // that when I manually change the client protocol it only happens on the root config and doesn't get propogated to
078: // it's "children" which still contain the original client protocol. This could cause some other subtle issues to
079: // crop up in the test harness...let's hope not ;)
080: String clientProtocol = Core.getRootConfig()
081: .getClientProtocol();
082: if (EdenConstants.EMBEDDED_CLIENT_PROTOCOL
083: .equals(clientProtocol)
084: && !embeddedInitialized) {
085: LOG
086: .info("The bootstrap EMBEDDED plugin registry has not yet been started, starting...");
087: actualPluginRegistry = new NullPluginRegistry();
088: removeAllResourceLoaders();
089: addResourceLoader(actualPluginRegistry);
090: embeddedInitialized = true;
091: currentClientProtocol = EdenConstants.EMBEDDED_CLIENT_PROTOCOL;
092: embeddedPluginRegistry = new EmbeddedPluginRegistry();
093: addResourceLoader(embeddedPluginRegistry);
094: embeddedPluginRegistry.start();
095: LOG
096: .info("... started the bootstrap EMBEDDED plugin registry.");
097: } else if (currentClientProtocol != null
098: && !currentClientProtocol.equals(clientProtocol)) {
099: LOG.info("Client protocol changed from '"
100: + currentClientProtocol + "' to '"
101: + clientProtocol
102: + "', stopping current plugin registry.");
103: actualPluginRegistry.stop();
104: LOG.info("Current plugin registry was stopped.");
105: currentClientProtocol = clientProtocol;
106: if (currentClientProtocol
107: .equals(EdenConstants.LOCAL_CLIENT_PROTOCOL)
108: || currentClientProtocol
109: .equals(EdenConstants.EMBEDDED_CLIENT_PROTOCOL)) {
110: actualPluginRegistry = new NullPluginRegistry();
111: } else {
112: actualPluginRegistry = new PluginRegistryFactory()
113: .createPluginRegistry();
114: }
115: LOG
116: .info("Initialized new plugin registry for client protocol '"
117: + currentClientProtocol
118: + "', starting...");
119: removeAllResourceLoaders();
120: addResourceLoader(actualPluginRegistry);
121: addResourceLoader(embeddedPluginRegistry);
122: actualPluginRegistry.start();
123: LOG.info("...new plugin registry started.");
124: }
125: } catch (Exception e) {
126: throw new WorkflowRuntimeException(
127: "Failed to start plugin registry for client protocol: "
128: + currentClientProtocol, e);
129: }
130: }
131:
132: private class NullPluginRegistry extends BasePluginRegistry {
133: }
134:
135: }
|