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.openejb.core;
017:
018: import org.apache.openejb.Container;
019: import org.apache.openejb.DeploymentInfo;
020: import org.apache.openejb.core.ivm.naming.IvmContext;
021: import org.apache.openejb.loader.SystemInstance;
022:
023: import java.util.Map;
024: import java.util.concurrent.ConcurrentHashMap;
025:
026: /**
027: * @org.apache.xbean.XBean element="containerSystem"
028: */
029: public class CoreContainerSystem implements
030: org.apache.openejb.spi.ContainerSystem {
031: Map<Object, DeploymentInfo> deployments = new ConcurrentHashMap<Object, DeploymentInfo>();
032: Map<Object, Container> containers = new ConcurrentHashMap<Object, Container>();
033: Map<String, WebDeploymentInfo> webDeployments = new ConcurrentHashMap<String, WebDeploymentInfo>();
034: IvmContext jndiRootContext = null;
035:
036: public CoreContainerSystem() {
037:
038: try {
039:
040: jndiRootContext = IvmContext.createRootContext();
041:
042: jndiRootContext.createSubcontext("java:openejb/ejb");
043: jndiRootContext.createSubcontext("java:openejb/client");
044: jndiRootContext.createSubcontext("java:openejb/Deployment");
045: jndiRootContext.bind("openejb/ejb/.", "");
046: jndiRootContext.bind("openejb/client/.", "");
047: jndiRootContext.bind("openejb/Deployment/.", "");
048: } catch (javax.naming.NamingException exception) {
049: throw new RuntimeException();
050: }
051:
052: // todo this should be in a start method because publishing an external reference in the constructor is very dangerous
053: SystemInstance.get().setComponent(
054: org.apache.openejb.spi.ContainerSystem.class, this );
055: }
056:
057: public DeploymentInfo getDeploymentInfo(Object id) {
058: return deployments.get(id);
059: }
060:
061: public DeploymentInfo[] deployments() {
062: return deployments.values().toArray(
063: new DeploymentInfo[deployments.size()]);
064: }
065:
066: public void addDeployment(DeploymentInfo deployment) {
067: this .deployments.put(deployment.getDeploymentID(), deployment);
068: }
069:
070: public void removeDeploymentInfo(DeploymentInfo info) {
071: this .deployments.remove(info.getDeploymentID());
072: }
073:
074: public Container getContainer(Object id) {
075: return containers.get(id);
076: }
077:
078: public Container[] containers() {
079: return containers.values().toArray(
080: new Container[containers.size()]);
081: }
082:
083: public void addContainer(Object id, Container c) {
084: containers.put(id, c);
085: }
086:
087: public void removeContainer(Object id) {
088: containers.remove(id);
089: }
090:
091: public WebDeploymentInfo getWebDeploymentInfo(String id) {
092: return webDeployments.get(id);
093: }
094:
095: public WebDeploymentInfo[] WebDeployments() {
096: return webDeployments.values().toArray(
097: new WebDeploymentInfo[webDeployments.size()]);
098: }
099:
100: public void addWebDeployment(WebDeploymentInfo webDeployment) {
101: this .webDeployments.put(webDeployment.getId(), webDeployment);
102: }
103:
104: public void removeWebDeploymentInfo(WebDeploymentInfo info) {
105: this .webDeployments.remove(info.getId());
106: }
107:
108: public javax.naming.Context getJNDIContext() {
109: return jndiRootContext;
110: }
111: }
|