KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > object > ObjectMarshallerFactory


1 package org.exoplatform.services.xml.querying.impl.xtas.object;
2 import org.exoplatform.services.xml.querying.object.MarshallerCreateException;
3
4 /**
5  * Object Factory for ObjectMarshaller creating
6  * Analyzes <code> xtas.marshaller.internal </code>
7  * or <code> xtas.marshaller.custom </code> system property
8  * depending on type of mapping.
9  * @version $Id: ObjectMarshallerFactory.java 566 2005-01-25 12:50:49Z kravchuk $
10  */

11 public class ObjectMarshallerFactory {
12
13     static {
14         System.setProperty("xtas.marshaller.internal", "org.exoplatform.services.xml.querying.impl.xtas.object.plugins.CastorClassMarshaller");
15         System.setProperty("xtas.marshaller.custom", "org.exoplatform.services.xml.querying.impl.xtas.object.plugins.CastorMappedMarshaller");
16     }
17
18     /** @link dependency
19      * @stereotype instantiate*/

20     /*# ObjectMarshaller lnkObjectMarshaller; */
21
22     /** @link dependency
23      * @stereotype use*/

24     /*# MappingType lnkMappingType; */
25
26     public static ObjectMarshallerFactory getInstance()
27     {
28         return new ObjectMarshallerFactory();
29     }
30
31     /**
32      * ObjectMarshaller instantiator
33      * Returns implementation of ObjectMarshaller
34      * for INTERNAL=0 (for Java Class introspection)
35      * or CUSTOM=1
36      * implementations of XML/Java mapping
37      */

38     public ObjectMarshaller getMarshaller( int mappingType ) throws MarshallerCreateException
39     {
40         String JavaDoc implProperty;
41
42         if( mappingType == MappingType.CUSTOM )
43             implProperty = "xtas.marshaller.custom";
44         else if ( mappingType == MappingType.INTERNAL )
45             implProperty = "xtas.marshaller.internal";
46         else
47             throw new MarshallerCreateException("Mapping Type is invalid! ");
48
49         try {
50
51             ObjectMarshaller impl = (ObjectMarshaller)Class.forName( System.getProperty( implProperty ) ).newInstance();
52             return impl;
53
54         } catch (Exception JavaDoc e) {
55 // e.printStackTrace();
56
throw new MarshallerCreateException(e.getMessage());
57         }
58     }
59
60 }
61
Popular Tags