01: package org.jicengine.operation;
02:
03: /**
04: *
05: *
06: *
07: * <p>
08: * Copyright (C) 2004 Timo Laitinen
09: * </p>
10: * @author Timo Laitinen
11: * @created 2004-09-20
12: * @since JICE-0.10
13: *
14: */
15:
16: public class ArrayConstructionOperation extends InvocationOperation {
17:
18: public ArrayConstructionOperation(String signature,
19: Operation componentType, Operation length) {
20: super (signature, componentType, new Operation[] { length });
21: }
22:
23: protected Object execute(Object componentType, Object[] arguments)
24: throws OperationException {
25: try {
26: return constructArray((Class) componentType, arguments[0]);
27: } catch (RuntimeException e) {
28: throw e;
29: } catch (Exception e) {
30: throw new OperationException(e.toString(), e);
31: }
32: }
33:
34: /**
35: * instantiates a class.
36: */
37: private Object constructArray(Class componentType, Object size)
38: throws Exception {
39: int intSize;
40: if (size instanceof Integer) {
41: intSize = ((Integer) size).intValue();
42: } else {
43: throw new OperationException(
44: "Can't create array, expected the size argument '"
45: + size + "' to be an integer, was '"
46: + size.getClass().getName() + "'");
47: }
48:
49: return java.lang.reflect.Array.newInstance(componentType,
50: intSize);
51: }
52:
53: }
|