1 15 package org.apache.hivemind.annotations.internal; 16 17 import java.lang.reflect.Method ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Location; 21 import org.apache.hivemind.definition.Contribution; 22 import org.apache.hivemind.definition.ContributionContext; 23 24 30 public class MethodCallContributionConstructor implements 31 Contribution 32 { 33 private Method _templateMethod; 34 35 private ModuleInstanceProvider _moduleInstanceProvider; 36 37 private Location _location; 38 39 public MethodCallContributionConstructor(Location location, Method factoryMethod, 40 ModuleInstanceProvider moduleInstanceProvider) 41 { 42 _location = location; 43 _templateMethod = factoryMethod; 44 _moduleInstanceProvider = moduleInstanceProvider; 45 } 46 47 public Location getLocation() 48 { 49 return _location; 50 } 51 52 public void contribute(ContributionContext context) 53 { 54 try 55 { 56 if (_templateMethod.getParameterTypes().length == 0) { 57 Object result = _templateMethod.invoke(_moduleInstanceProvider.getModuleInstance()); 58 if (result != null) { 61 context.mergeContribution(result); 62 } 63 } else if (_templateMethod.getParameterTypes().length == 1) { 64 Object [] params = new Object [] {context.getConfigurationData()}; 65 _templateMethod.invoke(_moduleInstanceProvider.getModuleInstance(), params); 66 } else { 67 } 69 } 70 catch (Exception ex) 71 { 72 throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex); 73 } 74 75 } 76 77 } 78 | Popular Tags |