/** * Use this constructor in subclasses to provide a custom * {@link ExceptionHandler}. * * @param exceptionHandler an {@link ExceptionHandler} instance * @param serviceDecorators an array of ServiceLayerDecorators that change how * the RequestFactory request processor interact with the domain * objects */ public RequestFactoryServlet(ExceptionHandler exceptionHandler, ServiceLayerDecorator... serviceDecorators) { processor = new SimpleRequestProcessor(ServiceLayer.create(serviceDecorators)); processor.setExceptionHandler(exceptionHandler); }
@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); }
Class<?> domainClass = service.resolveDomainClass(id.getProxyClass()); if (beans.containsKey(id)) { Object domain = service.createDomainObject(domainClass); if (domain == null) { throw new UnexpectedException("Could not create instance of " Class<?> param = service.getIdType(domainClass); Object domainParam; if (ValueCodex.canDecode(param)) { domainClasses.add(service.resolveDomainClass(id.getProxyClass())); domainIds.add(domainParam); idsToLoad.add(id); List<Object> loaded = service.loadDomainObjects(domainClasses, domainIds); if (idsToLoad.size() != loaded.size()) { throw new UnexpectedException("Expected " + idsToLoad.size()
@SuppressWarnings("unchecked") private <T, I> Locator<T, I> getLocator(Class<T> domainType) { Class<? extends Locator<?, ?>> locatorType = getTop().resolveLocator(domainType); if (locatorType == null) { return null; } return (Locator<T, I>) getTop().createLocator(locatorType); }
Method contextMethod = service.resolveRequestContextMethod(operation); if (contextMethod == null) { throw new UnexpectedException("Cannot resolve operation " + invocation.getOperation(), Method domainMethod = service.resolveDomainMethod(operation); if (domainMethod == null) { throw new UnexpectedException( if (service.requiresServiceLocator(contextMethod, domainMethod)) { Class<? extends RequestContext> requestContext = service.resolveRequestContext(operation); Object serviceInstance = service.createServiceInstance(requestContext); args.add(0, serviceInstance); domainReturnValue = service.invoke(domainMethod, args.toArray()); if (invocation.getPropertyRefs() != null) { SortedSet<String> paths = allPropertyRefs.get(domainReturnValue); if (successes.next()) { Type requestReturnType = service.getRequestReturnType(contextMethod); returnValue = state.getResolver().resolveClientValue(returnValue, requestReturnType,
} else if (!service.isLive(domainObject)) { writeOperation = WriteOperation.DELETE; } else if (id.wasEphemeral()) { Object domainVersion = service.getVersion(domainObject); if (domainVersion == null) { throw new UnexpectedException("The persisted entity with id " + service.getId(domainObject) + " has a null version", null); op.setTypeToken(service.resolveTypeToken(id.getProxyClass())); if (version != null) { op.setVersion(toBase64(version.getPayload()));
@Override public Method resolveDomainMethod(String operation) { /* * The validator has already determined the mapping from the RequsetContext * method to a domain method signature. We'll reuse this calculation instead * of iterating over all methods. */ String domainDescriptor = deobfuscator.getDomainMethodDescriptor(operation); if (domainDescriptor == null) { return die(null, "No domain method descriptor is mapped to operation %s", operation); } Class<?>[] domainArgs = getArgumentTypes(domainDescriptor); Class<? extends RequestContext> requestContext = getTop().resolveRequestContext(operation); Class<?> serviceImplementation = getTop().resolveServiceClass(requestContext); // Request<FooProxy> someMethod(int a, double b, FooProxy c); Method requestContextMethod = getTop().resolveRequestContextMethod(operation); Throwable ex; try { return serviceImplementation.getMethod(requestContextMethod.getName(), domainArgs); } catch (SecurityException e) { ex = e; } catch (NoSuchMethodException e) { ex = e; } return die(ex, "Could not find method in implementation %s matching descriptor %s for operation %s", serviceImplementation.getCanonicalName(), domainDescriptor, operation); }
@Override public ClassLoader getDomainClassLoader() { return getNext().getDomainClassLoader(); }
@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) {
if (isEntityProxy) { domainId = service.getId(domainEntity); domainVersion = service.getVersion(domainEntity); } else { domainId = null; domainVersion = service.getVersion(domainEntity); } else {
@Override public Method getGetter(Class<?> domainType, String property) { return getNext().getGetter(domainType, property); }
@Override public Class<?> resolveServiceClass(Class<? extends RequestContext> requestContextClass) { return getNext().resolveServiceClass(requestContextClass); }
@Override public Object getId(Object domainObject) { return getNext().getId(domainObject); }
@Override public <T extends ServiceLocator> T createServiceLocator(Class<T> clazz) { return getNext().createServiceLocator(clazz); }
@Override public Object createServiceInstance(Class<? extends RequestContext> requestContext) { return getNext().createServiceInstance(requestContext); }
@Override public <T> T createDomainObject(Class<T> clazz) { return getNext().createDomainObject(clazz); }
@Override public Class<?> getIdType(Class<?> domainType) { return getNext().getIdType(domainType); }
@Override public <T extends Locator<?, ?>> T createLocator(Class<T> clazz) { return getNext().createLocator(clazz); }
Method contextMethod = service.resolveRequestContextMethod(operation); if (contextMethod == null) { throw new UnexpectedException("Cannot resolve operation " + invocation.getOperation(), Method domainMethod = service.resolveDomainMethod(operation); if (domainMethod == null) { throw new UnexpectedException( if (service.requiresServiceLocator(contextMethod, domainMethod)) { Class<? extends RequestContext> requestContext = service.resolveRequestContext(operation); Object serviceInstance = service.createServiceInstance(requestContext); args.add(0, serviceInstance); domainReturnValue = service.invoke(domainMethod, args.toArray()); if (invocation.getPropertyRefs() != null) { SortedSet<String> paths = allPropertyRefs.get(domainReturnValue); if (successes.next()) { Type requestReturnType = service.getRequestReturnType(contextMethod); returnValue = state.getResolver().resolveClientValue(returnValue, requestReturnType,