1   /*
2    * Copyright 2002-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.json;
18  
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import net.sf.json.sample.ObjectBean;
25  
26  /**
27   * @author Andres Almiray <aalmiray@users.sourceforge.net>
28   */
29  public final class PropertyConstants {
30     private static final String ARRAY = "parray";
31     private static final String BEAN = "pbean";
32     private static final String BOOLEAN = "pboolean";
33     private static final String BYTE = "pbyte";
34     private static final String CHAR = "pchar";
35     private static final String CLASS = "pclass";
36     private static Map classes = new HashMap();
37     private static final String DOUBLE = "pdouble";
38     private static final String FLOAT = "pfloat";
39     private static final String FUNCTION = "pfunction";
40     private static final String INT = "pint";
41     private static final String LIST = "plist";
42     private static final String LONG = "plong";
43     private static final String SHORT = "pshort";
44     private static final String STRING = "pstring";
45     private static Map values = new HashMap();
46  
47     static{
48        values.put( BYTE, new Byte( Byte.MAX_VALUE ) );
49        values.put( SHORT, new Short( Short.MAX_VALUE ) );
50        values.put( INT, new Integer( Integer.MAX_VALUE ) );
51        values.put( LONG, new Long( Long.MAX_VALUE ) );
52        values.put( FLOAT, new Float( Float.MAX_VALUE ) );
53        values.put( DOUBLE, new Double( Double.MAX_VALUE ) );
54        values.put( BOOLEAN, Boolean.TRUE );
55        values.put( CHAR, new Character( 'J' ) );
56        values.put( STRING, "json" );
57        values.put( FUNCTION, new JSONFunction( "this;" ) );
58        values.put( ARRAY, new int[] { 1, 2 } );
59        List list = new ArrayList();
60        list.add( "a" );
61        list.add( "b" );
62        values.put( LIST, list );
63        values.put( CLASS, Object.class );
64        values.put( BEAN, new ObjectBean() );
65  
66        classes.put( BYTE, Byte.class );
67        classes.put( SHORT, Short.class );
68        classes.put( INT, Integer.class );
69        classes.put( LONG, Long.class );
70        classes.put( FLOAT, Float.class );
71        classes.put( DOUBLE, Double.class );
72        classes.put( BOOLEAN, Boolean.class );
73        classes.put( CHAR, Character.class );
74        classes.put( STRING, String.class );
75        classes.put( FUNCTION, JSONFunction.class );
76        classes.put( ARRAY, int[].class );
77        classes.put( LIST, List.class );
78        classes.put( CLASS, Class.class );
79        classes.put( BEAN, ObjectBean.class );
80     }
81  
82     public static String[] getProperties() {
83        return new String[] { BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR, BOOLEAN, STRING, FUNCTION,
84              ARRAY, LIST, CLASS, BEAN };
85     }
86  
87     public static Class getPropertyClass( String key ) {
88        return (Class) classes.get( key );
89     }
90  
91     public static Object getPropertyValue( String key ) {
92        return values.get( key );
93     }
94  }