/** * Asserts that an object is null. If it is not, an {@link AssertionError} * is thrown with the given message. * * @param message * the identifying message for the {@link AssertionError} ( * <code>null</code> okay) * @param object * Object to check or <code>null</code> */ public static void assertNull(String message, Object object) { assertTrue(message, object == null); } }
/** * Asserts that an object isn't null. If it is an {@link AssertionError} is * thrown with the given message. * * @param message * the identifying message for the {@link AssertionError} ( * <code>null</code> okay) * @param object * Object to check or <code>null</code> */ public static void assertNotNull(String message, Object object) { assertTrue(message, object != null); }
/** * Asserts that a condition is false. If it isn't it throws an * {@link AssertionError} with the given message. * * @param message * the identifying message for the {@link AssertionError} ( * <code>null</code> okay) * @param condition * condition to be checked */ public static void assertFalse(String message, boolean condition) { assertTrue(message, !condition); }
@SuppressWarnings("unchecked") private void handleTarget(MultivaluedMap<I, D> bulkResult, D result, Set<I> sourceIdSet, String oppositeName, ResourceInformation sourceInformation) { Object property = PropertyUtils.getProperty(result, oppositeName); if (property == null) { throw new IllegalStateException("field " + oppositeName + " is null for " + result + ", make sure to properly implement relationship inclusions"); } if (property instanceof Iterable) { for (T potentialSource : (Iterable<T>) property) { I sourceId = (I) sourceInformation.getId(potentialSource); if (sourceId == null) { throw new IllegalStateException("id is null for " + potentialSource); } // for to-many relations we have to assigned the found resource // to all matching sources if (sourceIdSet.contains(sourceId)) { bulkResult.add(sourceId, result); } } } else { T source = (T) property; I sourceId = (I) sourceInformation.getId(source); PreconditionUtil.assertTrue("filtering not properly implemented in resource repository", sourceIdSet.contains(sourceId)); if (sourceId == null) { throw new IllegalStateException("id is null for " + source); } bulkResult.add(sourceId, result); } }
@SuppressWarnings("unchecked") public <R extends ResourceRepositoryV2<?, ?>> R getRepositoryForInterface(Class<R> repositoryInterfaceClass) { RepositoryInformationBuilder informationBuilder = moduleRegistry.getRepositoryInformationBuilder(); PreconditionUtil.assertTrue("no a valid repository interface", informationBuilder.accept(repositoryInterfaceClass)); ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) informationBuilder.build(repositoryInterfaceClass, newRepositoryInformationBuilderContext()); Class<?> resourceClass = repositoryInformation.getResourceInformation().getResourceClass(); Object actionStub = actionStubFactory != null ? actionStubFactory.createStub(repositoryInterfaceClass) : null; ResourceRepositoryV2<?, Serializable> repositoryStub = getQuerySpecRepository(resourceClass); ClassLoader classLoader = repositoryInterfaceClass.getClassLoader(); InvocationHandler invocationHandler = new ClientStubInvocationHandler(repositoryInterfaceClass, repositoryStub, actionStub); return (R) Proxy.newProxyInstance(classLoader, new Class[] { repositoryInterfaceClass, ResourceRepositoryV2.class }, invocationHandler); }
private RepositoryInformation build(Object repository, Class<? extends Object> repositoryClass, RepositoryInformationBuilderContext context) { Class<?> resourceClass = getResourceClass(repository, repositoryClass); ResourceInformationBuilder resourceInformationBuilder = context.getResourceInformationBuilder(); PreconditionUtil.assertTrue("cannot get ResourceInformation for " + resourceClass, resourceInformationBuilder.accept(resourceClass)); ResourceInformation resourceInformation = resourceInformationBuilder.build(resourceClass); String path = getPath(resourceInformation, repository); return new ResourceRepositoryInformationImpl(repositoryClass, path, resourceInformation, buildActions(repositoryClass)); }
private RepositoryInformation buildInformation(Object repository, Class<? extends Object> repositoryClass, RepositoryInformationBuilderContext context) { Class<?> sourceResourceClass = getSourceResourceClass(repository, repositoryClass); Class<?> targetResourceClass = getTargetResourceClass(repository, repositoryClass); PreconditionUtil.assertNotNull("no sourceResourceClass", sourceResourceClass); PreconditionUtil.assertNotNull("no targetResourceClass", targetResourceClass); ResourceInformationBuilder resourceInformationBuilder = context.getResourceInformationBuilder(); PreconditionUtil.assertTrue("cannot get ResourceInformation for " + sourceResourceClass, resourceInformationBuilder.accept(sourceResourceClass)); ResourceInformation sourceResourceInformation = resourceInformationBuilder.build(sourceResourceClass); ResourceInformation targetResourceInformation; if (resourceInformationBuilder.accept(targetResourceClass)) { targetResourceInformation = resourceInformationBuilder.build(targetResourceClass); } else { // support for polymorphism like relations to java.lang.Object targetResourceInformation = new ResourceInformation(context.getTypeParser(), targetResourceClass, null, null, null); } return new RelationshipRepositoryInformationImpl(repositoryClass, sourceResourceInformation, targetResourceInformation); }