1 package org.jicengine.operation; 2 3 4 16 17 public class ArrayConstructionOperation extends InvocationOperation { 18 19 public ArrayConstructionOperation(String signature, Operation componentType, Operation length) 20 { 21 super(signature, componentType, new Operation[]{length}); 22 } 23 24 protected Object execute(Object componentType, Object [] arguments) throws OperationException 25 { 26 try { 27 return constructArray((Class ) componentType, arguments[0]); 28 } catch (RuntimeException e){ 29 throw e; 30 } catch (Exception e){ 31 throw new OperationException(e.toString(), e); 32 } 33 } 34 35 38 private Object constructArray(Class componentType, Object size) throws Exception { 39 int intSize; 40 if( size instanceof Integer ){ 41 intSize = ((Integer )size).intValue(); 42 } 43 else { 44 throw new OperationException("Can't create array, expected the size argument '" + size + "' to be an integer, was '" + size.getClass().getName() + "'"); 45 } 46 47 return java.lang.reflect.Array.newInstance(componentType, intSize); 48 } 49 50 } 51 | Popular Tags |