protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
/** * Get an implementation instance of the DAO Interface. * * @param daoInterface the interface of the DAO * @return the implementation of the DAO * @throws BusinessObjectDaoCreationException if the factory is not able to instantiate the DAO */ public <T extends BusinessObjectDAO> T getDAO(final Class<T> daoInterface) throws BusinessObjectDaoCreationException { ensureSessionExists(); if (daoInterface == null) { throw new IllegalArgumentException("daoInterface is null"); } if (!daoInterface.isInterface()) { throw new IllegalArgumentException(daoInterface.getName() + " is not an interface"); } Class<T> daoImplClass; try { daoImplClass = loadClass(daoInterface); if (daoImplClass != null) { final Constructor<T> constructor = daoImplClass.getConstructor(APISession.class); return constructor.newInstance(session); } } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new BusinessObjectDaoCreationException(e); } throw new BusinessObjectDaoCreationException("No Implementation of the DAO available."); }
/** * Get an implementation instance of the DAO Interface. * * @param daoInterface the interface of the DAO * @return the implementation of the DAO * @throws BusinessObjectDaoCreationException if the factory is not able to instantiate the DAO */ public <T extends BusinessObjectDAO> T getDAO(final Class<T> daoInterface) throws BusinessObjectDaoCreationException { ensureSessionExists(); if (daoInterface == null) { throw new IllegalArgumentException("daoInterface is null"); } if (!daoInterface.isInterface()) { throw new IllegalArgumentException(daoInterface.getName() + " is not an interface"); } Class<T> daoImplClass; try { daoImplClass = loadClass(daoInterface); if (daoImplClass != null) { final Constructor<T> constructor = daoImplClass.getConstructor(APISession.class); return constructor.newInstance(session); } } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new BusinessObjectDaoCreationException(e); } throw new BusinessObjectDaoCreationException("No Implementation of the DAO available."); }