KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > reflect > generic > GenericArrayReflector


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.reflect.generic;
22
23 import com.db4o.reflect.*;
24
25 /**
26  * @exclude
27  */

28 public class GenericArrayReflector implements ReflectArray{
29     
30     private final ReflectArray _delegate;
31     
32     public GenericArrayReflector(GenericReflector reflector){
33         _delegate = reflector.getDelegate().array();
34     }
35
36     public int[] dimensions(Object JavaDoc arr) {
37         return _delegate.dimensions(arr);
38     }
39
40     public int flatten(Object JavaDoc a_shaped, int[] a_dimensions, int a_currentDimension, Object JavaDoc[] a_flat, int a_flatElement) {
41         return _delegate.flatten(a_shaped, a_dimensions, a_currentDimension, a_flat, a_flatElement);
42     }
43
44     public Object JavaDoc get(Object JavaDoc onArray, int index) {
45         if(onArray instanceof GenericArray){
46             return ((GenericArray)onArray)._data[index];
47         }
48         return _delegate.get(onArray, index);
49     }
50
51     public ReflectClass getComponentType(ReflectClass claxx) {
52         claxx = claxx.getDelegate();
53         if(claxx instanceof GenericClass){
54             return claxx;
55         }
56         return _delegate.getComponentType(claxx);
57     }
58
59     public int getLength(Object JavaDoc array) {
60         if(array instanceof GenericArray){
61             return ((GenericArray)array).getLength();
62         }
63         return _delegate.getLength(array);
64     }
65     
66     public boolean isNDimensional(ReflectClass a_class) {
67         if(a_class instanceof GenericArrayClass){
68             return false;
69         }
70         return _delegate.isNDimensional(a_class.getDelegate());
71     }
72
73     public Object JavaDoc newInstance(ReflectClass componentType, int length) {
74         componentType = componentType.getDelegate();
75         if(componentType instanceof GenericClass){
76             return new GenericArray(((GenericClass)componentType).arrayClass(), length);
77         }
78         return _delegate.newInstance(componentType, length);
79     }
80
81     public Object JavaDoc newInstance(ReflectClass componentType, int[] dimensions) {
82         return _delegate.newInstance(componentType.getDelegate(), dimensions);
83     }
84
85     public void set(Object JavaDoc onArray, int index, Object JavaDoc element) {
86         if(onArray instanceof GenericArray){
87             ((GenericArray)onArray)._data[index] = element;
88             return;
89         }
90         _delegate.set(onArray, index, element);
91     }
92
93     public int shape(Object JavaDoc[] a_flat, int a_flatElement, Object JavaDoc a_shaped, int[] a_dimensions, int a_currentDimension) {
94         return _delegate.shape(a_flat, a_flatElement, a_shaped, a_dimensions, a_currentDimension);
95     }
96
97 }
98
Popular Tags