list.add(new LocatorServiceLayer());
@Override public Class<? extends ServiceLocator> resolveServiceLocator( Class<? extends RequestContext> requestContext) { Class<? extends ServiceLocator> locatorType; Service l = requestContext.getAnnotation(Service.class); ServiceName ln = requestContext.getAnnotation(ServiceName.class); if (l != null && !ServiceLocator.class.equals(l.locator())) { locatorType = l.locator(); } else if (ln != null && ln.locator().length() > 0) { try { locatorType = Class.forName(ln.locator(), false, getTop().getDomainClassLoader()).asSubclass( ServiceLocator.class); } catch (ClassNotFoundException e) { return die(e, "Could not find the locator type specified in the @%s annotation %s", ServiceName.class.getCanonicalName(), ln.value()); } } else { locatorType = null; } return locatorType; }
@Override public Object getId(Object domainObject) { return doGetId(domainObject); }
private <T> Object doGetVersion(T domainObject) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) domainObject.getClass(); Locator<T, ?> l = getLocator(clazz); if (l == null) { return super.getVersion(domainObject); } return l.getVersion(domainObject); }
@Override public <T extends Locator<?, ?>> T createLocator(Class<T> clazz) { return newInstance(clazz, Locator.class); }
@Override public <T> T loadDomainObject(Class<T> clazz, Object domainId) { return doLoadDomainObject(clazz, domainId); }
@Override public boolean isLive(Object domainObject) { return doIsLive(domainObject); }
private <T> T newInstance(Class<T> clazz, Class<? super T> base) { Throwable ex; try { return clazz.newInstance(); } catch (InstantiationException e) { ex = e; } catch (IllegalAccessException e) { ex = e; } return this.<T> die(ex, "Could not instantiate %s %s. Is it default-instantiable?", base .getSimpleName(), clazz.getCanonicalName()); } }
@Override public Object getVersion(Object domainObject) { return doGetVersion(domainObject); }
private <T> Object doGetId(T domainObject) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) domainObject.getClass(); Locator<T, ?> l = getLocator(clazz); if (l == null) { return super.getId(domainObject); } return l.getId(domainObject); }
@Override public Object createServiceInstance(Class<? extends RequestContext> requestContext) { Class<? extends ServiceLocator> locatorType = getTop().resolveServiceLocator(requestContext); ServiceLocator locator = getTop().createServiceLocator(locatorType); Class<?> serviceClass = getTop().resolveServiceClass(requestContext); return locator.getInstance(serviceClass); }
@Override public <T extends ServiceLocator> T createServiceLocator(Class<T> serviceLocatorType) { return newInstance(serviceLocatorType, ServiceLocator.class); }
@Override public <T> T loadDomainObject(Class<T> clazz, Object domainId) { return doLoadDomainObject(clazz, domainId); }
@Override public boolean isLive(Object domainObject) { return doIsLive(domainObject); }
private <T> T newInstance(Class<T> clazz, Class<? super T> base) { Throwable ex; try { return clazz.newInstance(); } catch (InstantiationException e) { ex = e; } catch (IllegalAccessException e) { ex = e; } return this.<T> die(ex, "Could not instantiate %s %s. Is it default-instantiable?", base .getSimpleName(), clazz.getCanonicalName()); } }
@Override public Object getVersion(Object domainObject) { return doGetVersion(domainObject); }
@Override public Class<? extends Locator<?, ?>> resolveLocator(Class<?> domainType) { Class<?> proxyType = getTop().resolveClientType(domainType, BaseProxy.class, false); if (proxyType == null) { return null; Class<? extends Locator<?, ?>> found = (Class<? extends Locator<?, ?>>) Class.forName(ln.locator(), false, getTop().getDomainClassLoader()).asSubclass(Locator.class); locatorType = found; } catch (ClassNotFoundException e) { return die(e, "Could not find the locator type specified in the @%s annotation %s", ProxyForName.class.getCanonicalName(), ln.value());
private <T> boolean doIsLive(T domainObject) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) domainObject.getClass(); Locator<T, ?> l = getLocator(clazz); if (l == null) { return super.isLive(domainObject); } return l.isLive(domainObject); }