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.HashMap;
20  import java.util.Map;
21  
22  import net.sf.ezmorph.bean.MorphDynaBean;
23  import net.sf.ezmorph.bean.MorphDynaClass;
24  
25  /**
26   * @author Andres Almiray <aalmiray@users.sourceforge.net>
27   */
28  public class TestJSONObjectStaticBuilders_DynaBean extends AbstractJSONObjectStaticBuildersTestCase {
29     public static void main( String[] args ) {
30        junit.textui.TestRunner.run( TestJSONObjectStaticBuilders_DynaBean.class );
31     }
32  
33     public TestJSONObjectStaticBuilders_DynaBean( String name ) {
34        super( name );
35     }
36  
37     protected Object getSource() {
38        Map map = new HashMap();
39        String[] props = getProperties();
40        for( int i = 0; i < props.length; i++ ){
41           map.put( props[i], PropertyConstants.getPropertyClass( props[i] ) );
42        }
43        map.put( "class", Class.class );
44        map.put( "pexcluded", String.class );
45        MorphDynaClass dynaClass = new MorphDynaClass( map );
46        MorphDynaBean dynaBean = null;
47        try{
48           dynaBean = (MorphDynaBean) dynaClass.newInstance();
49           for( int i = 0; i < props.length; i++ ){
50              dynaBean.set( props[i], PropertyConstants.getPropertyValue( props[i] ) );
51           }
52           dynaBean.set( "class", Object.class );
53           dynaBean.set( "pexcluded", "" );
54        }catch( Exception e ){
55           throw new RuntimeException( e );
56        }
57  
58        return dynaBean;
59     }
60  }