@Override public T build() { return (T) transformation.createInstantiator().newInstance(); } }
@Override public T build() { return (T) transformation.createInstantiator().newInstance(); } }
/** * Creates a class and an instance of that class. Updates the cache and returns the instance. */ private <S> S createInstance(final Class<S> serviceInterface) { ClassInstantiator instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer() { @Override public void transform(PlasticClass plasticClass) { plasticClass.addToString(String.format("<NoOp %s>", serviceInterface.getName())); } }); return serviceInterface.cast(instantiator.newInstance()); } }
/** * Creates a class and an instance of that class. Updates the cache and returns the instance. */ private <S> S createInstance(final Class<S> serviceInterface) { ClassInstantiator instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer() { @Override public void transform(PlasticClass plasticClass) { plasticClass.addToString(String.format("<NoOp %s>", serviceInterface.getName())); } }); return serviceInterface.cast(instantiator.newInstance()); } }
@Override @SuppressWarnings("unchecked") public <T> T build(final Class<T> commandInterface, List<T> commands) { // Jump through some hoops to convert the list into an array of the proper type Object[] array = (Object[]) Array.newInstance(commandInterface, commands.size()); final Object[] commandsArray = commands.toArray(array); ClassInstantiator<T> instantiator = proxyFactory.createProxy(commandInterface, new PlasticClassTransformer() { @Override public void transform(PlasticClass plasticClass) { PlasticField commandsField = plasticClass.introduceField(commandsArray.getClass(), "commands").inject( commandsArray); for (Method method : commandInterface.getMethods()) { implementMethod(plasticClass, method, commandsField); } plasticClass.addToString(String.format("<Command chain of %s>", commandInterface.getName())); } }); return instantiator.newInstance(); }
public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); } }
@Override @SuppressWarnings("unchecked") public <T> T build(final Class<T> commandInterface, List<T> commands) { // Jump through some hoops to convert the list into an array of the proper type Object[] array = (Object[]) Array.newInstance(commandInterface, commands.size()); final Object[] commandsArray = commands.toArray(array); ClassInstantiator<T> instantiator = proxyFactory.createProxy(commandInterface, new PlasticClassTransformer() { @Override public void transform(PlasticClass plasticClass) { PlasticField commandsField = plasticClass.introduceField(commandsArray.getClass(), "commands").inject( commandsArray); for (Method method : commandInterface.getMethods()) { implementMethod(plasticClass, method, commandsField); } plasticClass.addToString(String.format("<Command chain of %s>", commandInterface.getName())); } }); return instantiator.newInstance(); }
return instantiator.newInstance();
return instantiator.newInstance();
return interfaceType.cast(instantiator.newInstance());
return interfaceType.cast(instantiator.newInstance());
@Override public <T> T createThunk(Class<T> proxyType, ObjectCreator objectCreator, String description) { assert proxyType != null; assert objectCreator != null; assert InternalUtils.isNonBlank(description); if (!proxyType.isInterface()) throw new IllegalArgumentException(String.format( "Thunks may only be created for interfaces; %s is a class.", PlasticUtils.toTypeName(proxyType))); return getInstantiator(proxyType).with(ObjectCreator.class, objectCreator).with(String.class, description) .newInstance(); }
@Override public <T> T createThunk(Class<T> proxyType, ObjectCreator objectCreator, String description) { assert proxyType != null; assert objectCreator != null; assert InternalUtils.isNonBlank(description); if (!proxyType.isInterface()) throw new IllegalArgumentException(String.format( "Thunks may only be created for interfaces; %s is a class.", PlasticUtils.toTypeName(proxyType))); return getInstantiator(proxyType).with(ObjectCreator.class, objectCreator).with(String.class, description) .newInstance(); }
return interfaceType.cast(instantiator.newInstance());
/** * Instantiates a bridge object. * * @param nextBridge * the next Bridge object in the pipeline, or the terminator service * @param filter * the filter object for this step of the pipeline */ public S instantiateBridge(S nextBridge, F filter) { if (instantiator == null) createInstantiator(); return instantiator.with(filterInterface, filter).with(serviceInterface, nextBridge).newInstance(); }
return instantiator.newInstance();
/** * Instantiates a bridge object. * * @param nextBridge * the next Bridge object in the pipeline, or the terminator service * @param filter * the filter object for this step of the pipeline */ public S instantiateBridge(S nextBridge, F filter) { if (instantiator == null) createInstantiator(); return instantiator.with(filterInterface, filter).with(serviceInterface, nextBridge).newInstance(); }
return propertyType.cast(instantiator.newInstance());
return propertyType.cast(instantiator.newInstance());
new PropertyConduitBuilder(rootClass, expression, tree)).newInstance(); } catch (Exception ex)