KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > rmi > io > RmiMarshallerFactory


1 /***
2  * Fractal RMI: a binder for remote method calls between Fractal components.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  *
23  * adapted from Jonathan:
24  * org.objectweb.jeremie.libs.presentation.StdMarshallerFactory
25  * (authors: B. Dumant, K. Milsted)
26  * with some comments copied from:
27  * org.objectweb.jonathan.apis.presentation.MarshallerFactory
28  * (author: B. Dumant)
29  */

30
31 package org.objectweb.fractal.rmi.io;
32
33 import org.objectweb.fractal.api.control.BindingController;
34
35 import org.objectweb.jonathan.apis.binding.NamingContext;
36 import org.objectweb.jonathan.apis.kernel.ContextFactory;
37 import org.objectweb.jonathan.apis.presentation.Marshaller;
38 import org.objectweb.jonathan.apis.presentation.MarshallerFactory;
39 import org.objectweb.jonathan.apis.presentation.UnMarshaller;
40 import org.objectweb.jonathan.apis.resources.Chunk;
41 import org.objectweb.jonathan.apis.resources.ChunkFactory;
42 import org.objectweb.jonathan.apis.resources.ChunkProvider;
43
44 /**
45  * Provides a factory for creating marshallers and unmarshallers.
46  */

47
48 public class RmiMarshallerFactory
49   implements MarshallerFactory, BindingController
50 {
51
52   /**
53    * The domain to be used by the (un)marshallers created by this factory.
54    */

55
56   protected NamingContext domain;
57
58   /**
59    * The chunk factory to be used by the (un)marshallers created by this
60    * factory.
61    */

62
63   protected ChunkFactory chunkFactory;
64
65   /**
66    * The context factory to be used by the (un)marshallers created by this
67    * factory.
68    */

69
70   protected ContextFactory contextFactory;
71
72   /**
73    * Constructs a new {@link RmiMarshallerFactory}.
74    */

75
76   public RmiMarshallerFactory () {
77   }
78
79   // --------------------------------------------------------------------------
80
// Implementation of the BindingController interface
81
// --------------------------------------------------------------------------
82

83   public String JavaDoc[] listFc () {
84     return new String JavaDoc[] {
85       "domain",
86       "chunk-factory",
87       "context-factory"
88     };
89   }
90
91   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
92     if (clientItfName.equals("domain")) {
93       return domain;
94     } else if (clientItfName.equals("chunk-factory")) {
95       return chunkFactory;
96     } else if (clientItfName.equals("context-factory")) {
97       return contextFactory;
98     }
99     return null;
100   }
101
102   public void bindFc (final String JavaDoc clientItfName, final Object JavaDoc serverItf) {
103     if (clientItfName.equals("domain")) {
104       domain = (NamingContext)serverItf;
105     } else if (clientItfName.equals("chunk-factory")) {
106       chunkFactory = (ChunkFactory)serverItf;
107     } else if (clientItfName.equals("context-factory")) {
108       contextFactory = (ContextFactory)serverItf;
109     }
110   }
111
112   public void unbindFc (final String JavaDoc clientItfName) {
113     if (clientItfName.equals("domain")) {
114       domain = null;
115     } else if (clientItfName.equals("chunk-factory")) {
116       chunkFactory = null;
117     } else if (clientItfName.equals("context-factory")) {
118       contextFactory = null;
119     }
120   }
121
122   // --------------------------------------------------------------------------
123
// Implementation of the MarshallerFactory interface
124
// --------------------------------------------------------------------------
125

126   /**
127    * Returns a new marshaller.
128    *
129    * @return a new marshaller.
130    */

131
132   public Marshaller newMarshaller() {
133     return new RmiMarshaller(domain, chunkFactory, contextFactory);
134   }
135
136   /**
137    * Returns a new unmarshaller, using the provided chunk provider as a data
138    * source.
139    *
140    * @param message a chunk provider.
141    * @return a new unmarshaller.
142    */

143
144   public UnMarshaller newUnMarshaller (final ChunkProvider message) {
145     return new RmiUnMarshaller(domain, contextFactory, message);
146   }
147
148   /**
149    * Returns a new unmarshaller, using the provided chunk(s) as a data source.
150    * The <tt>read</tt> parameter is used to initialize the number of bytes
151    * read from the message.
152    *
153    * @param chunk a (chain of) chunk(s).
154    * @param read the number of bytes already read from the message.
155    * @return an unmarshaller.
156    */

157
158   public UnMarshaller newUnMarshaller (final Chunk chunk, final int read) {
159     return new RmiUnMarshaller(domain, contextFactory, chunk, read);
160   }
161 }
162
163
Popular Tags