001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.reflect.generic;
022:
023: import com.db4o.reflect.*;
024:
025: /**
026: * @exclude
027: */
028: public class GenericArrayReflector implements ReflectArray {
029:
030: private final ReflectArray _delegate;
031:
032: public GenericArrayReflector(GenericReflector reflector) {
033: _delegate = reflector.getDelegate().array();
034: }
035:
036: public int[] dimensions(Object arr) {
037: return _delegate.dimensions(arr);
038: }
039:
040: public int flatten(Object a_shaped, int[] a_dimensions,
041: int a_currentDimension, Object[] a_flat, int a_flatElement) {
042: return _delegate.flatten(a_shaped, a_dimensions,
043: a_currentDimension, a_flat, a_flatElement);
044: }
045:
046: public Object get(Object onArray, int index) {
047: if (onArray instanceof GenericArray) {
048: return ((GenericArray) onArray)._data[index];
049: }
050: return _delegate.get(onArray, index);
051: }
052:
053: public ReflectClass getComponentType(ReflectClass claxx) {
054: claxx = claxx.getDelegate();
055: if (claxx instanceof GenericClass) {
056: return claxx;
057: }
058: return _delegate.getComponentType(claxx);
059: }
060:
061: public int getLength(Object array) {
062: if (array instanceof GenericArray) {
063: return ((GenericArray) array).getLength();
064: }
065: return _delegate.getLength(array);
066: }
067:
068: public boolean isNDimensional(ReflectClass a_class) {
069: if (a_class instanceof GenericArrayClass) {
070: return false;
071: }
072: return _delegate.isNDimensional(a_class.getDelegate());
073: }
074:
075: public Object newInstance(ReflectClass componentType, int length) {
076: componentType = componentType.getDelegate();
077: if (componentType instanceof GenericClass) {
078: return new GenericArray(((GenericClass) componentType)
079: .arrayClass(), length);
080: }
081: return _delegate.newInstance(componentType, length);
082: }
083:
084: public Object newInstance(ReflectClass componentType,
085: int[] dimensions) {
086: return _delegate.newInstance(componentType.getDelegate(),
087: dimensions);
088: }
089:
090: public void set(Object onArray, int index, Object element) {
091: if (onArray instanceof GenericArray) {
092: ((GenericArray) onArray)._data[index] = element;
093: return;
094: }
095: _delegate.set(onArray, index, element);
096: }
097:
098: public int shape(Object[] a_flat, int a_flatElement,
099: Object a_shaped, int[] a_dimensions, int a_currentDimension) {
100: return _delegate.shape(a_flat, a_flatElement, a_shaped,
101: a_dimensions, a_currentDimension);
102: }
103:
104: }
|