001 /** 002 * Copyright (C) 2009 Erik Putrycz <erik.putrycz@gmail.com> 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package net.ep.db4o.javassist; 018 019 import java.lang.reflect.Array; 020 021 import com.db4o.reflect.ArrayInfo; 022 import com.db4o.reflect.MultidimensionalArrayInfo; 023 import com.db4o.reflect.ReflectClass; 024 import com.db4o.reflect.Reflector; 025 import com.db4o.reflect.core.AbstractReflectArray; 026 import com.db4o.reflect.jdk.JdkReflector; 027 028 public class JVSTArray extends AbstractReflectArray { 029 030 JVSTArray(Reflector reflector) { 031 super(reflector); 032 } 033 034 @Override 035 public Object newInstance(ReflectClass componentType, int length) { 036 return Array.newInstance(JdkReflector.toNative(componentType), length); 037 } 038 039 @Override 040 public Object newInstance(ReflectClass componentType, int[] dimensions) { 041 return Array.newInstance(JdkReflector.toNative(componentType), dimensions); 042 } 043 044 public void analyze(Object obj, ArrayInfo info) { 045 // do nothing 046 // possible further processing here: 047 // Analyze component type, length, dimensions, primitive ... 048 } 049 050 public Object newInstance(ReflectClass componentType, ArrayInfo info) { 051 Class clazz = JdkReflector.toNative(componentType); 052 if(info instanceof MultidimensionalArrayInfo){ 053 return Array.newInstance(clazz, ((MultidimensionalArrayInfo)info).dimensions()); 054 } 055 return Array.newInstance(clazz, info.elementCount()); 056 } 057 058 }