Revision 25791 branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/dynobject/impl/DefaultDynObject.java
DefaultDynObject.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.dynobject.impl; |
2 | 2 |
|
3 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
3 | 4 |
import org.gvsig.tools.dynobject.DynClass; |
4 |
import org.gvsig.tools.dynobject.DynFieldNotFoundException;
|
|
5 |
import org.gvsig.tools.dynobject.DynMethod;
|
|
5 | 6 |
import org.gvsig.tools.dynobject.DynObject; |
7 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
8 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
|
9 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
|
6 | 10 |
import org.gvsig.tools.dynobject.impl.DefaultDynClass.FieldAndIndex; |
7 | 11 |
|
8 |
public class DefaultDynObject implements DynObject { |
|
12 |
public class DefaultDynObject implements DelegatedDynObject {
|
|
9 | 13 |
|
10 | 14 |
private DefaultDynClass dynClass; |
11 | 15 |
private Object[] values; |
... | ... | |
49 | 53 |
// if( this.values == null ) { |
50 | 54 |
// this.values = this.dynClass.createValues(null); |
51 | 55 |
// } |
52 |
values[dynClass.getFieldIndex(name)] = value; |
|
56 |
int pos = dynClass.getFieldIndex(name); |
|
57 |
if (pos < 0 || pos >= values.length) { |
|
58 |
throw new DynFieldNotFoundException(name,this.getDynClass().getName()); |
|
59 |
} |
|
60 |
values[pos] = value; |
|
53 | 61 |
} |
54 | 62 |
|
55 | 63 |
public boolean instanceOf(DynClass dynClass) { |
... | ... | |
71 | 79 |
return true; |
72 | 80 |
} |
73 | 81 |
|
74 |
public void delegate(DynObject[] dynObjects) {
|
|
82 |
public void delegate(DynObject dynObjects) { |
|
75 | 83 |
if( delegateds == null ) { |
76 |
this.delegateds = new DynObject[ dynObjects.length];
|
|
77 |
System.arraycopy(dynObjects, 0, this.delegateds, 0, dynObjects.length);
|
|
84 |
this.delegateds = new DynObject[1];
|
|
85 |
this.delegateds[0] = dynObjects;
|
|
78 | 86 |
return ; |
79 | 87 |
} |
80 |
DynObject[] newValues = new DynObject[ this.delegateds.length+dynObjects.length];
|
|
88 |
DynObject[] newValues = new DynObject[this.delegateds.length + 1];
|
|
81 | 89 |
System.arraycopy(delegateds, 0, newValues, 0, delegateds.length); |
82 |
System.arraycopy(dynObjects, delegateds.length, newValues, delegateds.length, dynObjects.length);
|
|
83 |
// TODO, seguro que me he ido en algun +-1 en algun lado del arraycopy.
|
|
90 |
newValues[delegateds.length] = dynObjects;
|
|
91 |
this.delegateds = newValues;
|
|
84 | 92 |
} |
85 | 93 |
|
94 |
public Object invokeDynMethod(String name, DynObject context) throws DynMethodException { |
|
95 |
throw new IllegalArgumentException("self required"); |
|
96 |
} |
|
97 |
|
|
98 |
public Object invokeDynMethod(int code, DynObject context) throws DynMethodException { |
|
99 |
throw new IllegalArgumentException("self required"); |
|
100 |
} |
|
101 |
|
|
102 |
public Object invokeDynMethod(Object self, String methodName, |
|
103 |
DynObject context)throws DynMethodException { |
|
104 |
DynMethod method = this.dynClass.getDynMethod(methodName); |
|
105 |
if (method == null) { |
|
106 |
// FIXME |
|
107 |
// throw new DynMethodNotSupportedException(getDynClass().getName(), |
|
108 |
// methodName); |
|
109 |
throw new DynMethodNotSupportedException( |
|
110 |
0); |
|
111 |
|
|
112 |
} |
|
113 |
return method.invoke(self, context); |
|
114 |
} |
|
115 |
|
|
116 |
public Object invokeDynMethod(Object self, int methodCode, DynObject context) throws DynMethodException { |
|
117 |
return this.dynClass.manager.invokeDynMethod(self, methodCode, context); |
|
118 |
} |
|
86 | 119 |
} |
Also available in: Unified diff