@Override public Object get(String name, ObjectFactory<?> objectFactory) { Object scopedObject = this.servletContext.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); this.servletContext.setAttribute(name, scopedObject); } return scopedObject; }
private Object getTarget(Method method) { if (target == null) { target = factory.getObject(); } return target; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Map<String, Object> scope = this.threadScope.get(); Object scopedObject = scope.get(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); scope.put(name, scopedObject); } return scopedObject; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { scopeCount++; return objectFactory.getObject(); }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { return objectFactory.getObject(); } @Override
public TestBean getTestBean() { return this.testBeanFactory.getObject(); } }
public TestBean getTestBean() { return this.testBeanFactory.getObject(); } }
public TestBean getTestBean() { return (TestBean) this.testBeanFactory.getObject(); } }
ObjectFactoryConstructorConfig(ObjectFactory<Colour> colourFactory) { this.colour = colourFactory.getObject(); } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Map<String, Object> scope = this.threadScope.get(); Object scopedObject = scope.get(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); scope.put(name, scopedObject); } return scopedObject; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Object scopedObject = this.servletContext.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); this.servletContext.setAttribute(name, scopedObject); } return scopedObject; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("equals")) { // Only consider equal when proxies are identical. return (proxy == args[0]); } else if (methodName.equals("hashCode")) { // Use hashCode of proxy. return System.identityHashCode(proxy); } else if (methodName.equals("toString")) { return this.objectFactory.toString(); } try { return method.invoke(this.objectFactory.getObject(), args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } } }
/** * Resolve the given autowiring value against the given required type, * e.g. an {@link ObjectFactory} value to its actual object result. * @param autowiringValue the value to resolve * @param requiredType the type to assign the result to * @return the resolved value */ public static Object resolveAutowiringValue(Object autowiringValue, Class<?> requiredType) { if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue)) { ObjectFactory<?> factory = (ObjectFactory<?>) autowiringValue; if (autowiringValue instanceof Serializable && requiredType.isInterface()) { autowiringValue = Proxy.newProxyInstance(requiredType.getClassLoader(), new Class<?>[] {requiredType}, new ObjectFactoryDelegatingInvocationHandler(factory)); } else { return factory.getObject(); } } return autowiringValue; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Assert.state(this.active, "Not active"); if (this.instance == null) { this.instance = objectFactory.getObject(); } return this.instance; }
/** * Return the (raw) singleton object registered under the given name. * <p>Checks already instantiated singletons and also allows for an early * reference to a currently created singleton (resolving a circular reference). * @param beanName the name of the bean to look for * @param allowEarlyReference whether early references should be created or not * @return the registered singleton object, or {@code null} if none found */ @Nullable protected Object getSingleton(String beanName, boolean allowEarlyReference) { Object singletonObject = this.singletonObjects.get(beanName); if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) { synchronized (this.singletonObjects) { singletonObject = this.earlySingletonObjects.get(beanName); if (singletonObject == null && allowEarlyReference) { ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName); if (singletonFactory != null) { singletonObject = singletonFactory.getObject(); this.earlySingletonObjects.put(beanName, singletonObject); this.singletonFactories.remove(beanName); } } } } return singletonObject; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { synchronized (this.map) { Object scopedObject = this.map.get(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); this.map.put(name, scopedObject); } return scopedObject; } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("equals")) { // Only consider equal when proxies are identical. return (proxy == args[0]); } else if (methodName.equals("hashCode")) { // Use hashCode of proxy. return System.identityHashCode(proxy); } else if (methodName.equals("toString")) { return this.objectFactory.toString(); } try { return method.invoke(this.objectFactory.getObject(), args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { if (createNewScope) { beans.clear(); // reset the flag back createNewScope = false; } Object bean = beans.get(name); // if a new object is requested or none exists under the current // name, create one if (bean == null) { beans.put(name, objectFactory.getObject()); } return beans.get(name); }
/** * Resolve the given autowiring value against the given required type, * e.g. an {@link ObjectFactory} value to its actual object result. * @param autowiringValue the value to resolve * @param requiredType the type to assign the result to * @return the resolved value */ public static Object resolveAutowiringValue(Object autowiringValue, Class<?> requiredType) { if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue)) { ObjectFactory<?> factory = (ObjectFactory<?>) autowiringValue; if (autowiringValue instanceof Serializable && requiredType.isInterface()) { autowiringValue = Proxy.newProxyInstance(requiredType.getClassLoader(), new Class<?>[] {requiredType}, new ObjectFactoryDelegatingInvocationHandler(factory)); } else { return factory.getObject(); } } return autowiringValue; }
/** * Sets modification and creation date and auditor on the target object in case it implements {@link Auditable} on * persist events. * * @param target */ @PrePersist public void touchForCreate(Object target) { Assert.notNull(target, "Entity must not be null!"); if (handler != null) { AuditingHandler object = handler.getObject(); if (object != null) { object.markCreated(target); } } }