001: /*
002: * @(#) TSHandlerFactory
003: *
004: * JOTM: Java Open Transaction Manager
005: *
006: * This module was originally developed by
007: * - INRIA inside the ObjectWeb Consortium(http://www.objectweb.org)
008: *
009: * The original code and portions created by INRIA are
010: * Copyright (C) 2002 - INRIA (www.inria.fr)
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * -Redistributions of source code must retain the above copyright notice, this
017: * list of conditions and the following disclaimer.
018: *
019: * -Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
024: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
025: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
026: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
027: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
028: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
030: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
031: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
032: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
033: * POSSIBILITY OF SUCH DAMAGE.
034: *
035: * --------------------------------------------------------------------------
036: * $Id: TSHandlerFactory.java,v 1.2 2004/05/14 17:49:36 tonyortiz Exp $
037: * --------------------------------------------------------------------------
038: */
039: package org.objectweb.jotm.jta.jeremie;
040:
041: import org.objectweb.jonathan.apis.kernel.Context;
042: import org.objectweb.jonathan.apis.kernel.InternalException;
043: import org.objectweb.jonathan.apis.kernel.JonathanException;
044: import org.objectweb.jonathan.presentation.api.MarshallerFactory;
045: import org.objectweb.jonathan.libs.kernel.GenericFactory;
046:
047: /**
048: * {@link TSHandler TSHandler}
049: */
050: public class TSHandlerFactory extends GenericFactory {
051:
052: /**
053: * Name used to designate the context containing the TSHandler components.
054: */
055: static public final String ts_context_name = "/jotm/transaction/TSHandler";
056:
057: /**
058: * Returns the components required to create a new
059: * {@link TSHandler TSHandler} instance.
060: * <p>
061: * <code>_c</code> must contain a (non null) component of name
062: * "MarshallerFactory" of type {@link MarshallerFactory MarshallerFactory}.
063: * <p>
064: * It may contain a component of name "id", of type Integer; this id
065: * should then represent the service id to use for the created service.
066: * <p>
067: * It may contain a component of name "sender", of type Sender,
068: * and a component of name "receiver", of type Receiver.
069: *
070: * @param c a {@link Context Context} instance;
071: * @return the components needed to create an TSHandler instance.
072: */
073: protected Object[] getUsedComponents(Context c) {
074:
075: Object[] used_components = { Context.NO_VALUE,
076: Context.NO_VALUE, Context.NO_VALUE, Context.NO_VALUE };
077:
078: if (c != null) {
079: used_components[0] = c.getValue("id", (char) 0);
080: used_components[1] = c.getValue("sender", (char) 0);
081: used_components[2] = c.getValue("receiver", (char) 0);
082: used_components[3] = c.getValue("MarshallerFactory",
083: (char) 0);
084: }
085: if (!(used_components[0] instanceof Integer)) {
086: used_components[0] = new Integer(Integer.MAX_VALUE);
087: }
088: if (!(used_components[1] instanceof JotmTransactionSender)) {
089: used_components[1] = null;
090: }
091: if (!(used_components[2] instanceof JotmTransactionReceiver)) {
092: used_components[2] = null;
093: }
094: if (!(used_components[3] instanceof MarshallerFactory)) {
095: throw new InternalException(
096: "Component MarshallerFactory of type MarshallerFactory is required by TSHandler.");
097: }
098:
099: return used_components;
100: }
101:
102: /**
103: * Returns a new TSHandler instance created using the provided
104: * components.
105: *
106: * @param c a context;
107: * @param components components to be used to create a new TSHandler instance;
108: * @return a new TSHandler instance;
109: * @exception JonathanException if something goes wrong.
110: */
111: protected Object newInstance(Context c, Object[] components)
112: throws JonathanException {
113: return new TSHandler(c, components);
114: }
115: }
|