KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jotm > jta > jeremie > TSHandlerFactory


1 /*
2  * @(#) TSHandlerFactory
3  *
4  * JOTM: Java Open Transaction Manager
5  *
6  * This module was originally developed by
7  * - INRIA inside the ObjectWeb Consortium(http://www.objectweb.org)
8  *
9  * The original code and portions created by INRIA are
10  * Copyright (C) 2002 - INRIA (www.inria.fr)
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * -Redistributions of source code must retain the above copyright notice, this
17  * list of conditions and the following disclaimer.
18  *
19  * -Redistributions in binary form must reproduce the above copyright notice,
20  * this list of conditions and the following disclaimer in the documentation
21  * and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * --------------------------------------------------------------------------
36  * $Id: TSHandlerFactory.java,v 1.2 2004/05/14 17:49:36 tonyortiz Exp $
37  * --------------------------------------------------------------------------
38  */

39 package org.objectweb.jotm.jta.jeremie;
40
41 import org.objectweb.jonathan.apis.kernel.Context;
42 import org.objectweb.jonathan.apis.kernel.InternalException;
43 import org.objectweb.jonathan.apis.kernel.JonathanException;
44 import org.objectweb.jonathan.presentation.api.MarshallerFactory;
45 import org.objectweb.jonathan.libs.kernel.GenericFactory;
46
47
48 /**
49  * {@link TSHandler TSHandler}
50  */

51 public class TSHandlerFactory extends GenericFactory {
52
53    /**
54     * Name used to designate the context containing the TSHandler components.
55     */

56    static public final String JavaDoc ts_context_name = "/jotm/transaction/TSHandler";
57
58    /**
59     * Returns the components required to create a new
60     * {@link TSHandler TSHandler} instance.
61     * <p>
62     * <code>_c</code> must contain a (non null) component of name
63     * "MarshallerFactory" of type {@link MarshallerFactory MarshallerFactory}.
64     * <p>
65     * It may contain a component of name "id", of type Integer; this id
66     * should then represent the service id to use for the created service.
67     * <p>
68     * It may contain a component of name "sender", of type Sender,
69     * and a component of name "receiver", of type Receiver.
70     *
71     * @param c a {@link Context Context} instance;
72     * @return the components needed to create an TSHandler instance.
73     */

74    protected Object JavaDoc[] getUsedComponents(Context c) {
75       
76       Object JavaDoc[] used_components = {
77       Context.NO_VALUE, Context.NO_VALUE, Context.NO_VALUE, Context.NO_VALUE
78       };
79
80       if (c != null) {
81          used_components[0] = c.getValue("id", (char) 0);
82          used_components[1] = c.getValue("sender", (char) 0);
83          used_components[2] = c.getValue("receiver", (char) 0);
84          used_components[3] = c.getValue("MarshallerFactory", (char) 0);
85       }
86       if (! (used_components[0] instanceof Integer JavaDoc)) {
87          used_components[0] = new Integer JavaDoc(Integer.MAX_VALUE);
88       }
89       if (! (used_components[1] instanceof JotmTransactionSender)) {
90          used_components[1] = null;
91       }
92       if (! (used_components[2] instanceof JotmTransactionReceiver)) {
93          used_components[2] = null;
94       }
95       if (! (used_components[3] instanceof MarshallerFactory)) {
96          throw new InternalException("Component MarshallerFactory of type MarshallerFactory is required by TSHandler.");
97       }
98       
99       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 JavaDoc newInstance(Context c, Object JavaDoc[] components) throws JonathanException {
112       return new TSHandler(c, components);
113    }
114 }
115
116
Popular Tags