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.db4ounit.common.reflect.custom;
022:
023: import com.db4o.foundation.*;
024: import com.db4o.reflect.*;
025:
026: public class CustomClass implements ReflectClass {
027:
028: // fields must be public so test works on less capable runtimes
029: public CustomClassRepository _repository;
030: public String _name;
031: public ReflectField[] _fields;
032:
033: public CustomClass() {
034: }
035:
036: public CustomClass(CustomClassRepository repository, String name,
037: String[] fieldNames, Class[] fieldTypes) {
038: _repository = repository;
039: _name = name;
040: _fields = createFields(fieldNames, fieldTypes);
041: }
042:
043: private ReflectField[] createFields(String[] fieldNames,
044: Class[] fieldTypes) {
045: ReflectField[] fields = new ReflectField[fieldNames.length + 1];
046: for (int i = 0; i < fieldNames.length; ++i) {
047: fields[i] = new CustomField(_repository, i, fieldNames[i],
048: fieldTypes[i]);
049: }
050: fields[fields.length - 1] = new CustomUidField(_repository);
051: return fields;
052: }
053:
054: public ReflectClass getComponentType() {
055: throw new NotImplementedException();
056: }
057:
058: public ReflectConstructor[] getDeclaredConstructors() {
059: throw new NotImplementedException();
060: }
061:
062: public CustomField customField(String name) {
063: return (CustomField) getDeclaredField(name);
064: }
065:
066: public ReflectField getDeclaredField(String name) {
067: for (int i = 0; i < _fields.length; ++i) {
068: ReflectField field = _fields[i];
069: if (field.getName().equals(name)) {
070: return field;
071: }
072: }
073: return null;
074: }
075:
076: public ReflectField[] getDeclaredFields() {
077: return _fields;
078: }
079:
080: public ReflectClass getDelegate() {
081: return this ;
082: }
083:
084: public ReflectMethod getMethod(String methodName,
085: ReflectClass[] paramClasses) {
086: return null;
087: }
088:
089: public String getName() {
090: return _name;
091: }
092:
093: public ReflectClass getSuperclass() {
094: return null;
095: // return _repository.reflectClass(java.lang.Object.class);
096: }
097:
098: public boolean isAbstract() {
099: return false;
100: }
101:
102: public boolean isArray() {
103: return false;
104: }
105:
106: public boolean isAssignableFrom(ReflectClass type) {
107: return equals(type);
108: }
109:
110: public boolean isCollection() {
111: return false;
112: }
113:
114: public boolean isInstance(Object obj) {
115: throw new NotImplementedException();
116: }
117:
118: public boolean isInterface() {
119: return false;
120: }
121:
122: public boolean isPrimitive() {
123: return false;
124: }
125:
126: public boolean isSecondClass() {
127: return false;
128: }
129:
130: public Object newInstance() {
131: return new PersistentEntry(
132: _name,
133: null,
134: new Object[_fields.length - 1 /* uid field is kept explicitly */]);
135: }
136:
137: public Reflector reflector() {
138: throw new NotImplementedException();
139: }
140:
141: public boolean skipConstructor(boolean flag, boolean testConstructor) {
142: return false;
143: }
144:
145: public Object[] toArray(Object obj) {
146: throw new NotImplementedException();
147: }
148:
149: public void useConstructor(ReflectConstructor constructor,
150: Object[] params) {
151: throw new NotImplementedException();
152: }
153:
154: public Iterator4 customFields() {
155: return Iterators.filter(_fields, new Predicate4() {
156: public boolean match(Object candidate) {
157: return candidate instanceof CustomField;
158: }
159: });
160: }
161: }
|