001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.geronimo;
019:
020: import javax.naming.InitialContext;
021: import javax.naming.NamingException;
022:
023: import org.apache.geronimo.transaction.context.TransactionContextManager;
024: import org.ofbiz.base.container.Container;
025: import org.ofbiz.base.container.ContainerConfig;
026: import org.ofbiz.base.container.ContainerException;
027: import org.ofbiz.base.util.Debug;
028:
029: /**
030: * Geronimo Container
031: */
032: public class GeronimoContainer implements Container {
033:
034: public static final String module = GeronimoContainer.class
035: .getName();
036:
037: protected String configFile = null;
038: protected TransactionContextManager geronimoTcm = null;
039:
040: /**
041: * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)
042: */
043: public void init(String[] args, String configFile)
044: throws ContainerException {
045: this .configFile = configFile;
046: this .startGeronimo();
047: }
048:
049: public boolean start() throws ContainerException {
050: return true;
051: }
052:
053: private void startGeronimo() throws ContainerException {
054: // get the container config
055: ContainerConfig.Container cc = ContainerConfig.getContainer(
056: "geronimo-container", configFile);
057: if (cc == null) {
058: throw new ContainerException(
059: "No geronimo-container configuration found in container config!");
060: }
061:
062: //String carolPropName = ContainerConfig.getPropertyValue(cc, "jndi-config", "iiop.properties");
063:
064: // start Geronimo
065: this .geronimoTcm = new TransactionContextManager();
066:
067: // bind UserTransaction and TransactionManager to JNDI
068: try {
069: InitialContext ic = new InitialContext();
070: // TODO: for some reason this is not working, throwing an error: java.lang.IllegalArgumentException: RegistryContext: object to bind must be Remote, Reference, or Referenceable
071: ic.rebind("java:comp/UserTransaction", this .geronimoTcm
072: .getTransactionManager());
073: } catch (NamingException e) {
074: throw new ContainerException(
075: "Unable to bind UserTransaction/TransactionManager to JNDI",
076: e);
077: }
078:
079: // check JNDI
080: try {
081: InitialContext ic = new InitialContext();
082: Object o = ic.lookup("java:comp/UserTransaction");
083: if (o == null) {
084: throw new NamingException("Object came back null");
085: }
086: } catch (NamingException e) {
087: throw new ContainerException(
088: "Unable to lookup bound objects", e);
089: }
090: Debug
091: .logInfo(
092: "Geronimo is bound to JNDI - java:comp/UserTransaction",
093: module);
094: }
095:
096: public void stop() throws ContainerException {
097: // TODO: how to stop the Geronimo transaction manager? is it even needed?
098: }
099:
100: }
|