View Javadoc

1   /*
2    * Copyright 2004-2005 The Apache Software Foundation or its licensors,
3    *                     as applicable.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
18  
19  import java.io.InputStream;
20  import java.sql.Timestamp;
21  import java.util.Calendar;
22  import java.util.Date;
23  import java.util.GregorianCalendar;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  
28  /***
29   * An <code>AtomicTypeConverterProvider</code> that registers by default the
30   * convertes available in Graffito.
31   * 
32   * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
33   */
34  public class DefaultAtomicTypeConverterProvider extends AtomicTypeConverterProviderImpl {
35      /***
36       * No-arg constructor.
37       */
38      public DefaultAtomicTypeConverterProvider() {
39          m_converters= registerDefaultAtomicTypeConverters();
40      }
41      
42      /***
43       * Full constructor.
44       * 
45       * @param converters a map of classes and their associated <code>AtomicTypeConverter</code>
46       * classes.
47       */
48      public DefaultAtomicTypeConverterProvider(Map converters) {
49          this();
50          m_converters.putAll(converters);
51      }
52      
53      /***
54       * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.AtomicTypeConverterProviderImpl#setAtomicTypeConvertors(java.util.Map)
55       */
56      public void setAtomicTypeConvertors(Map converters) {
57          m_converters.putAll(converters);
58      }
59      
60      protected Map registerDefaultAtomicTypeConverters() {
61          Map converters= new HashMap();
62          
63          converters.put(String.class, StringTypeConverterImpl.class);
64          converters.put(InputStream.class, BinaryTypeConverterImpl.class);
65          converters.put(long.class, LongTypeConverterImpl.class);
66          converters.put(Long.class, LongTypeConverterImpl.class);
67          converters.put(int.class, IntTypeConverterImpl.class);
68          converters.put(Integer.class, IntTypeConverterImpl.class);
69          converters.put(double.class, DoubleTypeConverterImpl.class);
70          converters.put(Double.class, DoubleTypeConverterImpl.class);
71          converters.put(boolean.class, BooleanTypeConverterImpl.class);
72          converters.put(Boolean.class, BooleanTypeConverterImpl.class);
73          converters.put(Calendar.class, CalendarTypeConverterImpl.class);
74          converters.put(GregorianCalendar.class, CalendarTypeConverterImpl.class);
75          converters.put(Date.class, UtilDateTypeConverterImpl.class);
76          converters.put(byte[].class, ByteArrayTypeConverterImpl.class);
77          converters.put(Timestamp.class, TimestampTypeConverterImpl.class);
78          
79          return converters;
80      }
81  }