public LocalProfile getConnectionProfile() { if (connectionProfile == null) { try { connectionProfile = (LocalProfile) ReflectionHelper.create( "org.teiid.jdbc.jboss.ModuleLocalProfile", null, //$NON-NLS-1$ getClass().getClassLoader()); } catch (TeiidException e) { throw new TeiidRuntimeException(e); } } return connectionProfile; }
public <T> void registerClientService(Class<T> iface, T instance, String loggingContext) { this.clientServices.put(iface.getName(), new ClientService(instance, loggingContext, new ReflectionHelper(iface))); }
createMethodMap(); List<Method> methods = methodMap.get(methodName); if (methods != null && methods.size() == 1) { return findBestMethodWithSignature(methodName, Collections.EMPTY_LIST); return findBestMethodWithSignature(methodName,argumentClasses);
@Test public void testFindBestMethodWithSignature_Object() throws Exception { ReflectionHelper helper = new ReflectionHelper(FakeInterface.class); Class[] signatureSought = new Class[] {NullPointerException.class}; try { helper.findBestMethodWithSignature("method", signatureSought ); //$NON-NLS-1$ fail("exception expected"); //$NON-NLS-1$ } catch (NoSuchMethodException e) { assertEquals("method Args: [class java.lang.NullPointerException] has multiple possible signatures.", e.getMessage()); //$NON-NLS-1$ } }
ReflectionHelper helper = new ReflectionHelper(DBCollection.class); Method method = helper.findBestMethodOnTarget(shellOperationName, operations.toArray(new Object[operations.size()])); Object result = method.invoke(collection, operations.toArray(new Object[operations.size()])); if (result instanceof Cursor) {
/** * Find the best method on the target class that matches the signature specified * with the specified name and the list of argument classes. This method first * attempts to find the method with the specified argument classes; if no such * method is found, a NoSuchMethodException is thrown. * @param methodName the name of the method that is to be invoked. * @param argumentsClasses the list of Class instances that correspond * to the classes for each argument passed to the method. * @return the Method object that references the method that satisfies * the requirements, or null if no satisfactory method could be found. * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. */ public Method findBestMethodWithSignature( String methodName, Object[] argumentsClasses ) throws NoSuchMethodException, SecurityException { List argumentClassesList = Arrays.asList(argumentsClasses); return findBestMethodWithSignature(methodName,argumentClassesList); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { this.ctx = ctx; ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)msg; try { Method m = this.clientProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args); try { m.invoke(this, serviceStruct.args); } catch (InvocationTargetException e) { throw e.getCause(); } } catch (Throwable e) { terminate(e); } }
@Test public void testFindBestMethodWithSignature_SerializableAndMethodName() throws Exception { ReflectionHelper helper = new ReflectionHelper(FakeInterface.class); Class[] signatureSought = new Class[] {NullPointerException.class}; Method theMethod = helper.findBestMethodWithSignature("methodSerializable", signatureSought ); //$NON-NLS-1$ assertNotNull("Failed to find method for args: " + signatureSought, theMethod); //$NON-NLS-1$ // make sure we got the method we expected Class[] signatureFound = theMethod.getParameterTypes(); Class[] signatureExpected = new Class[] {Serializable.class}; assertEquals("Wrong class", theMethod.getDeclaringClass().getName(), FakeInterface.class.getName()); //$NON-NLS-1$ helpAssertSameMethodSignature("Found wrong method signature", signatureExpected, signatureFound); //$NON-NLS-1$ }
/** * Find the best method on the target class that matches the signature specified * with the specified name and the list of argument classes. This method first * attempts to find the method with the specified argument classes; if no such * method is found, a NoSuchMethodException is thrown. * @param methodName the name of the method that is to be invoked. * @param argumentsClasses the list of Class instances that correspond * to the classes for each argument passed to the method. * @return the Method object that references the method that satisfies * the requirements, or null if no satisfactory method could be found. * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. */ public Method findBestMethodWithSignature( String methodName, Object[] argumentsClasses ) throws NoSuchMethodException, SecurityException { List argumentClassesList = Arrays.asList(argumentsClasses); return findBestMethodWithSignature(methodName,argumentClassesList); }
private void processMessage(ServiceInvocationStruct serviceStruct) { try { Method m = this.serverProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args); try { // since the postgres protocol can produce more than single response // objects to a request, all the methods are designed to return void. // and relies on client interface to build the responses. m.invoke(this.server, serviceStruct.args); } catch (InvocationTargetException e) { throw e.getCause(); } } catch (Throwable e) { this.server.errorOccurred(e); } }
@Test public void testFindBestMethodWithSignature_long() throws Exception { ReflectionHelper helper = new ReflectionHelper(FakeInterface.class); Class[] signatureSought = new Class[] {Long.TYPE}; Method theMethod = helper.findBestMethodWithSignature("method", signatureSought ); //$NON-NLS-1$ assertNotNull("Failed to find method for args: " + signatureSought, theMethod); //$NON-NLS-1$ // make sure we got the method we expected Class[] signatureFound = theMethod.getParameterTypes(); Class[] signatureExpected = signatureSought; assertEquals("Wrong class", theMethod.getDeclaringClass().getName(), FakeInterface.class.getName()); //$NON-NLS-1$ helpAssertSameMethodSignature("Found wrong method signature", signatureExpected, signatureFound); //$NON-NLS-1$ }
public LocalProfile getConnectionProfile() { if (connectionProfile == null) { try { connectionProfile = (LocalProfile) ReflectionHelper.create( "org.teiid.jdbc.jboss.ModuleLocalProfile", null, //$NON-NLS-1$ getClass().getClassLoader()); } catch (TeiidException e) { throw new TeiidRuntimeException(e); } } return connectionProfile; }
@Test public void testConstructorWithNullTargetClass() { try { new ReflectionHelper(null); fail("Should have caught null target class passed to constructor"); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // expected } }
createMethodMap(); List<Method> methods = methodMap.get(methodName); if (methods != null && methods.size() == 1) { return findBestMethodWithSignature(methodName, Collections.EMPTY_LIST); return findBestMethodWithSignature(methodName,argumentClasses);
final ClientService clientService = this.csr.getClientService(serviceStruct.targetClass.getName()); loggingContext = clientService.getLoggingContext(); Method m = clientService.getReflectionHelper().findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args); Object methodResult; try {
@Test public void testFindBestMethodWithSignature_StringArrayAndMethodName() throws Exception { ReflectionHelper helper = new ReflectionHelper(FakeInterface.class); Class[] signatureSought = new Class[] {String[].class}; Method theMethod = helper.findBestMethodWithSignature("methodStringArray", signatureSought ); //$NON-NLS-1$ assertNotNull("Failed to find method for args: " + signatureSought, theMethod); //$NON-NLS-1$ // make sure we got the method we expected Class[] signatureFound = theMethod.getParameterTypes(); Class[] signatureExpected = signatureSought; assertEquals("Wrong class", theMethod.getDeclaringClass().getName(), FakeInterface.class.getName()); //$NON-NLS-1$ helpAssertSameMethodSignature("Found wrong method signature", signatureExpected, signatureFound); //$NON-NLS-1$ }
public static String getSpanContext() { if (INJECTOR == null) { try { INJECTOR = (Injector) ReflectionHelper.create("org.teiid.jdbc.tracing.GlobalTracerInjector", null, TracingHelper.class.getClassLoader()); //$NON-NLS-1$ } catch (Throwable e) { //must catch both Error and Exception logger.log(Level.FINE, "Unable to load opentracing libraries, propagation will not be used", e); //$NON-NLS-1$ } if (INJECTOR == null) { INJECTOR = new Injector() { @Override public String getSpanContext() { return null; } }; } } return INJECTOR.getSpanContext(); }
@Test public void testConstructorWithValidTargetClass() { final ReflectionHelper helper = new ReflectionHelper(String.class); assertNotNull(helper); }
@Test public void testFindBestMethodWithSignature_SubInterface_2ArgSerializableAndNumber() throws Exception { ReflectionHelper helper = new ReflectionHelper(FakeSubInterface.class); Class[] signatureSought = new Class[] {Serializable.class, Number.class}; Method theMethod = helper.findBestMethodWithSignature("method", signatureSought ); //$NON-NLS-1$ assertNotNull("Failed to find method for args: " + signatureSought, theMethod); //$NON-NLS-1$ // make sure we got the method we expected Class[] signatureFound = theMethod.getParameterTypes(); Class[] signatureExpected = signatureSought; assertEquals("Wrong class", theMethod.getDeclaringClass().getName(), FakeSubInterface.class.getName()); //$NON-NLS-1$ helpAssertSameMethodSignature("Found wrong method signature", signatureExpected, signatureFound); //$NON-NLS-1$ }
public static String getSpanContext() { if (INJECTOR == null) { try { INJECTOR = (Injector) ReflectionHelper.create("org.teiid.jdbc.tracing.GlobalTracerInjector", null, TracingHelper.class.getClassLoader()); //$NON-NLS-1$ } catch (Throwable e) { //must catch both Error and Exception logger.log(Level.FINE, "Unable to load opentracing libraries, propagation will not be used", e); //$NON-NLS-1$ } if (INJECTOR == null) { INJECTOR = new Injector() { @Override public String getSpanContext() { return null; } }; } } return INJECTOR.getSpanContext(); }