View Javadoc

1   /**
2    * Copyright (C) 2009 Erik Putrycz <erik.putrycz@gmail.com>
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.ep.db4o.javassist;
18  
19  import java.lang.reflect.Array;
20  
21  import com.db4o.reflect.ArrayInfo;
22  import com.db4o.reflect.MultidimensionalArrayInfo;
23  import com.db4o.reflect.ReflectClass;
24  import com.db4o.reflect.Reflector;
25  import com.db4o.reflect.core.AbstractReflectArray;
26  import com.db4o.reflect.jdk.JdkReflector;
27  
28  public class JVSTArray extends AbstractReflectArray {
29  
30  	JVSTArray(Reflector reflector) {
31  		super(reflector);
32  	}
33  
34  	@Override
35  	public Object newInstance(ReflectClass componentType, int length) {
36  		return Array.newInstance(JdkReflector.toNative(componentType), length);
37  	}
38  
39  	@Override
40  	public Object newInstance(ReflectClass componentType, int[] dimensions) {
41  		return Array.newInstance(JdkReflector.toNative(componentType), dimensions);
42  	}
43  
44  	public void analyze(Object obj, ArrayInfo info) {
45      // do nothing
46      // possible further processing here:  
47      // Analyze component type, length, dimensions, primitive ... 
48  	}
49  
50  	public Object newInstance(ReflectClass componentType, ArrayInfo info) {
51      Class clazz = JdkReflector.toNative(componentType);
52      if(info instanceof MultidimensionalArrayInfo){
53          return Array.newInstance(clazz, ((MultidimensionalArrayInfo)info).dimensions());
54      }
55      return Array.newInstance(clazz, info.elementCount());
56  	}
57  
58  }