KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > naming > api > NamingManager


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.naming.api;
19
20 import org.objectweb.perseus.cache.api.CacheManager;
21 import org.objectweb.speedo.metadata.SpeedoClass;
22 import org.objectweb.speedo.generation.jorm.JormMIMappingBuilder;
23 import org.objectweb.speedo.api.SpeedoException;
24 import org.objectweb.speedo.mapper.api.JormFactory;
25 import org.objectweb.speedo.pm.api.ProxyManagerFactory;
26 import org.objectweb.jorm.metainfo.api.NameDef;
27 import org.objectweb.jorm.metainfo.api.MetaObject;
28 import org.objectweb.jorm.metainfo.api.Reference;
29 import org.objectweb.jorm.metainfo.api.CommonClassMapping;
30 import org.objectweb.jorm.metainfo.api.Manager;
31 import org.objectweb.jorm.api.PClassMapping;
32 import org.objectweb.jorm.api.PException;
33 import org.objectweb.jorm.api.PMapper;
34 import org.objectweb.jorm.naming.api.PBinder;
35 import org.objectweb.jorm.naming.api.PName;
36 import org.objectweb.jorm.naming.api.PNameCoder;
37 import org.objectweb.jorm.naming.api.PNamingContext;
38 import org.objectweb.jorm.type.api.PType;
39 import org.objectweb.util.monolog.api.Logger;
40
41 import java.util.Collection JavaDoc;
42 import java.util.Map JavaDoc;
43 import java.util.Properties JavaDoc;
44
45 /**
46  * It defines a manager of a type of naming. This interface covers needs at
47  * compile time and at run time. In particular a naming manager is able to
48  * fill the Speedo meta information with the particularity of the a naming.
49  *
50  * @author S.Chassande-Barrioz
51  */

52 public interface NamingManager {
53
54     String JavaDoc SEP = "/";
55
56     /**
57      * Indicates if the naming manager is able to manage the identifier of a
58      * persistent class.
59      * @param sc The speedo meta object representing the persistent class
60      */

61     boolean canManage(SpeedoClass sc);
62
63     /**
64      * indicates if the naming manager is able to build a PBinder instance for
65      * this hints parameter specified
66      * @param hints is the helper of the PBinder building
67      * @param classLoader is the classloader to use for instanciate the PBinder
68      */

69     boolean canProvidePBinder(Object JavaDoc hints, ClassLoader JavaDoc classLoader);
70
71     /**
72      * indicates if the naming manager is able to build a PNC instance for
73      * this hints parameter specified
74      * @param hints is the helper of the PNC building
75      * @param classLoader is the classloader to use for instanciate the PNC
76      */

77     boolean canProvidePNamingContext(Object JavaDoc hints, ClassLoader JavaDoc classLoader);
78
79     /**
80      * Build a PBinder instance for this hints parameter specified
81      * @param hints is the helper of the PBinder building. This hints must be
82      * the result of the getJormConfig call.
83      * @param classLoader is the classloader to use for instanciate the PBinder
84      * @param mappingStructureRule indicates the rule to apply concerning the
85      * data strucuture. Indeed a PBinder building can require to read the data
86      * support.
87      * @param cn2binder is the map of the existing PBinder instance
88      * (key = class name, value = PBinder instance)
89      * @param cn2pnc is the map of the existing PNC instance
90      * (key = class name, value = PNC instance)
91      */

92     PBinder getPBinder(String JavaDoc className,
93                        String JavaDoc hints,
94                        ClassLoader JavaDoc classLoader,
95                        byte mappingStructureRule,
96                        Map JavaDoc cn2binder,
97                        Map JavaDoc cn2pnc) throws PException;
98
99     /**
100      * Build a PNamingContext instance for this hints parameter specified
101      * @param hints is the helper of the PBinder building. This hints must be
102      * the result of the getJormConfig call.
103      * @param classLoader is the classloader to use for instanciate the PBinder
104      * @param mappingStructureRule indicates the rule to apply concerning the
105      * data strucuture. Indeed a PBinder building can require to read the data
106      * support.
107      * @param cn2binder is the map of the existing PBinder instance
108      * (key = class name, value = PBinder instance)
109      * @param cn2pnc is the map of the existing PNC instance
110      * (key = class name, value = PNC instance)
111      */

112     PNamingContext getPNamingContext(String JavaDoc className,
113                                      String JavaDoc hints,
114                                      ClassLoader JavaDoc classLoader,
115                                      byte mappingStructureRule, Map JavaDoc cn2binder,
116                                      Map JavaDoc cn2pnc, Manager miManager,
117                                      PClassMapping pcm) throws PException;
118
119     /**
120      * Decodes an object identifier into a PName.
121      * @param pnc is the PNameCoder instance to use for the decoding the object
122      * identifier. The pnc parameter can be null. In this case the oid must
123      * @param oid is the object identifier
124      * @param clazz is the java.lang.Class of the persistent class identified by
125      * the oid
126      * @param jf is the JormFactory instance. It permits to
127      * @return the object identifier decode as PName
128      * @throws PException
129      */

130     PName decode(PNameCoder pnc,
131                  Object JavaDoc oid,
132                  Class JavaDoc clazz,
133                  JormFactory jf) throws PException;
134
135     /**
136      * Encode a PName into an object
137      * @param pn is the pname to encode
138      */

139     Object JavaDoc encode(PName pn) throws PException;
140
141     /**
142      * indicates if the use of PNamingContext is support by this mapping. If
143      * true then getPNamingContext method can be use, otherwise the getPBinder
144      * must be use instead. The case of PNamingContext are not supported, means
145      * the PBinder are used as PNameCoder by PBinding as reference coder.
146      */

147     boolean supportPNamingcontext();
148
149     /**
150      * Fill the name def of an identifier or a reference
151      * @param nd is the name def to fill
152      * @param isIdentifier indicates if the name represents an identifier (true)
153      * or a reference (false).
154      * @param isInGenClass indicates if the name is defined in a generic class
155      * (true) of in a class (false).
156      * @param ref meta object which the name def must be
157      * defined. This value is used only in the case of isIdentifier == false and
158      * isInGenClass == false.
159      * @param tsc is the speedo meta object representing the referenced class.
160      * This value is used only in the case of isIdentifier == false.
161      * @param mo is the jorm meta object hosting the name def and on which the
162      * eventual hidden field will be created.
163      * @param hcm if the mapping structure hosting the mapping of the reference.
164      * This value must be ClassMapping or GenClassMapping instance.
165      * @param mb is the mapping builder permitting the creation of the mapping
166      * part.
167      * @param createdMOs is a result paramter. This collection must be fill with
168      * the created Jorm Meta objects representing a class or a composite name.
169      * Here only the new used composite name will be added.
170      * @throws SpeedoException if the speedo meta information is not completly
171      * defined.
172      */

173     void fillNameDef(MIBuilderHelper mibh,
174                      Manager manager,
175                      NameDef nd,
176                      SpeedoClass tsc,
177                      SpeedoClass ssc,
178                      MetaObject mo,
179                      Reference ref,
180                      CommonClassMapping hcm,
181                      JormMIMappingBuilder mb,
182                      boolean isIdentifier,
183                      boolean isInGenClass,
184                      boolean createField,
185                      Collection JavaDoc createdMOs) throws SpeedoException, PException;
186
187     /**
188      * computes the naming configuration information for a class or a reference.
189      * This information is store as a String. The string value will be passed
190      * to the getPBinder and getPNamingContext methods as hints. This method is
191      * used at generation time.
192      * <table>
193      * <tr><td>naming of a/td><td>MOClass/td></tr>
194      * <tr><td>class/td><td>Class/td></tr>
195      * <tr><td>reference to a Class/td><td>ClassRef/td></tr>
196      * <tr><td>reference to a GenClass/td><td>GenClassRef/td></tr>
197      * <tr><td>a GenClass identifier/td><td>GenClassRef/td></tr>
198      * </table>
199      *
200      * @param targetClass is the Speedo meta object representing the class which
201      * is designates by the
202      * @param result is the Properties which must be filled
203      */

204     void getJormNamingConfig(NameDef nd,
205                          SpeedoClass targetClass,
206                          MetaObject sourceMO,
207                          String JavaDoc key,
208                          Properties JavaDoc result) throws SpeedoException;
209
210     /**
211      * compute a string value which permit to help the building of the class
212      * PName (export)
213      * @param sc is the Speedo class which the hints must be specified
214      * @param nd is the name def of the class
215      */

216     String JavaDoc getPNameHints(SpeedoClass sc, NameDef nd);
217
218     /**
219      * compute a string value which permit to help the building of the genclass
220      * PName (export)
221      * @param sc is the Speedo class which the hints must be specified
222      * @param nd is the name def of the gen class
223      */

224     String JavaDoc getGCPNameHints(SpeedoClass sc, NameDef nd);
225
226     void setPMapper(PMapper mapper) throws PException;
227
228     void setLogger(Logger logger);
229     
230     void setCache(CacheManager cache);
231     
232     void setPmf(ProxyManagerFactory pmf);
233
234     /**
235      * Retrieves the array of field used in the identifier of a persistent class
236      * and which values are not calculated by the application. The application
237      * field must be set at makePersistent time.
238      *
239      * @param sc is the speedo meta object of the persistent class
240      */

241     NamingField[] getNamingfields(SpeedoClass sc) throws PException;
242
243     /**
244      * Defines the field used in an identifier and which must be set at
245      * makePersistent time.
246      */

247     class NamingField {
248         private String JavaDoc userFieldName = null;
249         private Class JavaDoc userFieldType = null;
250         private String JavaDoc namingFieldName = null;
251         private PType namingFieldType = null;
252
253         /**
254          * @param userFieldName is the field name in the persistent class
255          * @param userFieldType is the field type (java type) in the persistent
256          * class
257          * @param namingFieldName is the field name in the identifier
258          * @param namingFieldType is the field type (Jorm type) in the identifier
259          */

260         public NamingField(String JavaDoc userFieldName,
261                            Class JavaDoc userFieldType,
262                            String JavaDoc namingFieldName,
263                            PType namingFieldType) {
264             this.userFieldName = userFieldName;
265             this.userFieldType = userFieldType;
266             this.namingFieldName = namingFieldName;
267             this.namingFieldType = namingFieldType;
268         }
269         /**
270          * @return the field name in the persistent class
271          */

272         public String JavaDoc getUserFieldName() { return userFieldName; }
273         /**
274          * @return the field type (java type) in the persistent
275          */

276         public Class JavaDoc getUserFieldType() { return userFieldType; }
277         /**
278          * @return the field name in the identifier
279          */

280         public String JavaDoc getNamingFieldName() { return namingFieldName; }
281         /**
282          * @return the field type (Jorm type) in the identifier
283          */

284         public PType getNamingFieldType() { return namingFieldType; }
285     }
286 }
Popular Tags