List of usage examples for org.apache.wicket.proxy IProxyTargetLocator locateProxyTarget
Object locateProxyTarget();
From source file:org.jabylon.rest.ui.wicket.injector.OSGiFieldValueFactory.java
License:Open Source License
@Override public Object getFieldValue(Field field, Object fieldOwner) { Object target = null;/*w ww .j av a 2 s . c om*/ Inject injectAnnotation = field.getAnnotation(Inject.class); if (!Modifier.isStatic(field.getModifiers()) && injectAnnotation != null) { try { Class<?> type = field.getType(); if (!type.isInterface()) throw new IllegalArgumentException( "Can only inject interfaces, not classes: " + field + " type: " + type); boolean isList = isCollection(field); if (isList) type = extractType(field); final IProxyTargetLocator locator = new OSGiProxyTargetLocator(type, isList); if (wrapInProxies) { target = OSGiProxy.wrap(locator, field.getType()); } else { target = locator.locateProxyTarget(); } if (!field.isAccessible()) { field.setAccessible(true); } field.set(fieldOwner, target); return target; } catch (IllegalAccessException e) { throw new WicketRuntimeException( "Error OSGi-injecting field " + field.getName() + " in " + fieldOwner, e); } } return null; }
From source file:org.jabylon.rest.ui.wicket.injector.OSGiProxy.java
License:Open Source License
@Override public Object apply(IProxyTargetLocator input) { return input.locateProxyTarget(); }
From source file:org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory.java
License:Apache License
/** * Gets the corresponding object (or its proxy) for the field from the cache, or if it's not * cached, then returns a newly created proxy or the object itself. * /*from w ww. ja va 2s. com*/ * @param field * The field, in which we're trying to inject * @param locator * The locator, which will locate the corresponding object for the field * @return The injectable value */ private Object getCachedProxy(Field field, IProxyTargetLocator locator) { Class<?> type = field.getType(); if (locator == null) { return null; } // if the field contains the "stateful" description, or the field itself // is a no-interfaceview Stateful bean if ((field.isAnnotationPresent(EJB.class) && field.getAnnotation(EJB.class).description().equals("stateful") || field.getType().isAnnotationPresent(Stateful.class))) { // creates a session if there wasn't already HttpServletRequest httpServletRequest = (HttpServletRequest) RequestCycle.get().getRequest() .getContainerRequest(); HttpSession session = httpServletRequest.getSession(); // check if it's already cached Object retValue = session.getAttribute(type.getName()); if (retValue == null) { if (!Modifier.isFinal(type.getModifiers())) { retValue = LazyInitProxyFactory.createProxy(type, locator); } else { retValue = locator.locateProxyTarget(); } session.setAttribute(type.getName(), retValue); } return retValue; } else { if (cache.containsKey(locator)) { return cache.get(locator); } if (!Modifier.isFinal(type.getModifiers())) { Object proxy = LazyInitProxyFactory.createProxy(type, locator); cache.put(locator, proxy); return proxy; } else { Object value = locator.locateProxyTarget(); cache.put(locator, value); return value; } } }
From source file:org.xaloon.wicket.component.inject.j2ee.JavaWeldProxyFieldValueFactory.java
License:Apache License
private Object getCachedProxy(Field field, IProxyTargetLocator locator) { Class<?> type = field.getType(); if (locator == null) { return null; }//from ww w.j a v a 2s . c o m if (cache.containsKey(locator)) { return cache.get(locator); } if (!Modifier.isFinal(type.getModifiers())) { Object proxy = LazyInitProxyFactory.createProxy(type, locator); cache.put(locator, proxy); return proxy; } else { Object value = locator.locateProxyTarget(); cache.put(locator, value); return value; } }