@Test public void testJsonCarRepository() { var initialInstance = new JsonCarRepository("-", "-"); var carRepository = proxyBuilder.buildProxy(ProxyContext .<JsonCarRepository, JsonNode>builder(JsonCarRepository.class) .translator(inputStream2Json()) .initialInstance(initialInstance) .build()); assertThat(carRepository).isNotNull(); assertThat(carRepository).isNotSameAs(initialInstance); assertThat(carRepository.getModel()).isEqualTo("-"); assertThat(carRepository.getManufacturer()).isEqualTo("-"); ressorService(carRepository).reload(load("classpath:proxy/car_repository.json")); assertThat(carRepository.getModel()).isEqualTo("Astra"); assertThat(carRepository.getManufacturer()).isEqualTo("Opel"); }
public synchronized <T, D> T buildProxy(ProxyContext<T, D> context) { var serviceProxy = new RessorServiceImpl<>(context.getType(), getFactory(context), context.getTranslator(), context.getErrorHandler(), context.getInitialInstance(), context.getResource()) .state(StateVariables.SOURCE, context.getSource()); Class<? extends T> loadedClass = null; if (isCachePossible(context)) { var gci = classCache.computeIfAbsent(context.getType(), k -> new GeneratedClassInfo(generateProxyClass(context), context.getProxyDefaultArguments(), context.getClassLoader(), context.isProxyObjectClassMethods())); if (gci.isMatches(context)) { loadedClass = (Class<? extends T>) gci.loadedClass; } } if (loadedClass == null) { loadedClass = generateProxyClass(context); } try { var targetConstructor = loadedClass.getDeclaredConstructor(); targetConstructor.setAccessible(true); var instance = targetConstructor.newInstance(); var mf = instance.getClass().getDeclaredField(RS_VAR); mf.setAccessible(true); mf.set(instance, serviceProxy); return instance; } catch (Throwable t) { throw Exceptions.wrap(t); } }
ServiceProxyBuilder { public synchronized <T, D> T buildProxy(ProxyContext<T, D> context) { var serviceProxy = new RessorServiceImpl<>(context.getType(), getFactory(context), context.getTranslator(), context.getErrorHandler(), context.getInitialInstance(), context.getResource()) .state(StateVariables.SOURCE, context.getSource()); Class<? extends T> loadedClass = null; if (isCachePossible(context)) { var gci = classCache.computeIfAbsent(context.getType(), k -> new GeneratedClassInfo(generateProxyClass(context), context.getProxyDefaultArguments(), context.getClassLoader(), context.isProxyObjectClassMethods())); if (gci.isMatches(context)) { loadedClass = (Class<? extends T>) gci.loadedClass; } } if (loadedClass == null) { loadedClass = generateProxyClass(context); } try { var targetConstructor = loadedClass.getDeclaredConstructor(); targetConstructor.setAccessible(true); var instance = targetConstructor.newInstance(); var mf = instance.getClass().getDeclaredField(RS_VAR); mf.setAccessible(true); mf.set(instance, serviceProxy); return instance; } catch (Throwable t) { throw Exceptions.wrap(t); } } }
ServiceProxyBuilder { public synchronized <T, D> T buildProxy(ProxyContext<T, D> context) { var serviceProxy = new RessorServiceImpl<>(context.getType(), getFactory(context), context.getTranslator(), context.getErrorHandler(), context.getInitialInstance(), context.getResource()) .state(StateVariables.SOURCE, context.getSource()); Class<? extends T> loadedClass = null; if (isCachePossible(context)) { var gci = classCache.computeIfAbsent(context.getType(), k -> new GeneratedClassInfo(generateProxyClass(context), context.getProxyDefaultArguments(), context.getClassLoader(), context.isProxyObjectClassMethods())); if (gci.isMatches(context)) { loadedClass = (Class<? extends T>) gci.loadedClass; } } if (loadedClass == null) { loadedClass = generateProxyClass(context); } try { var targetConstructor = loadedClass.getDeclaredConstructor(); targetConstructor.setAccessible(true); var instance = targetConstructor.newInstance(); var mf = instance.getClass().getDeclaredField(RS_VAR); mf.setAccessible(true); mf.set(instance, serviceProxy); return instance; } catch (Throwable t) { throw Exceptions.wrap(t); } } ServiceProxyBuilder(boolean isCacheClasses); }
ServiceProxyBuilder { public synchronized <T, D> T buildProxy(ProxyContext<T, D> context) { var serviceProxy = new RessorServiceImpl<>(context.getType(), getFactory(context), context.getTranslator(), context.getErrorHandler(), context.getInitialInstance(), context.getResource()) .state(StateVariables.SOURCE, context.getSource()); Class<? extends T> loadedClass = null; if (isCachePossible(context)) { var gci = classCache.computeIfAbsent(context.getType(), k -> new GeneratedClassInfo(generateProxyClass(context), context.getProxyDefaultArguments(), context.getClassLoader(), context.isProxyObjectClassMethods())); if (gci.isMatches(context)) { loadedClass = (Class<? extends T>) gci.loadedClass; } } if (loadedClass == null) { loadedClass = generateProxyClass(context); } try { var targetConstructor = loadedClass.getDeclaredConstructor(); targetConstructor.setAccessible(true); var instance = targetConstructor.newInstance(); var mf = instance.getClass().getDeclaredField(RS_VAR); mf.setAccessible(true); mf.set(instance, serviceProxy); return instance; } catch (Throwable t) { throw Exceptions.wrap(t); } } ServiceProxyBuilder(boolean isCacheClasses); synchronized T buildProxy(ProxyContext<T, D> context); }
ServiceProxyBuilder { public synchronized <T, D> T buildProxy(ProxyContext<T, D> context) { var serviceProxy = new RessorServiceImpl<>(context.getType(), getFactory(context), context.getTranslator(), context.getErrorHandler(), context.getInitialInstance(), context.getResource()) .state(StateVariables.SOURCE, context.getSource()); Class<? extends T> loadedClass = null; if (isCachePossible(context)) { var gci = classCache.computeIfAbsent(context.getType(), k -> new GeneratedClassInfo(generateProxyClass(context), context.getProxyDefaultArguments(), context.getClassLoader(), context.isProxyObjectClassMethods())); if (gci.isMatches(context)) { loadedClass = (Class<? extends T>) gci.loadedClass; } } if (loadedClass == null) { loadedClass = generateProxyClass(context); } try { var targetConstructor = loadedClass.getDeclaredConstructor(); targetConstructor.setAccessible(true); var instance = targetConstructor.newInstance(); var mf = instance.getClass().getDeclaredField(RS_VAR); mf.setAccessible(true); mf.set(instance, serviceProxy); return instance; } catch (Throwable t) { throw Exceptions.wrap(t); } } ServiceProxyBuilder(boolean isCacheClasses); synchronized T buildProxy(ProxyContext<T, D> context);  }