protected void requireNotStarted(final Object object) { if (object != null) { throw new JoyException("Configuration is modified after component is started."); } } protected <T> T requireStarted(final T object) {
protected <T> T requireStarted(final T object) { if (object == null) { throw new JoyException("Component is not started yet and can not be used."); } return object; }
@Override public void start() { initLogger(); final String resourceName = StringUtil.replaceChar(JoyPaths.class.getName(), '.', '/') + ".class"; URL url = ClassLoaderUtil.getResourceUrl(resourceName); if (url == null) { throw new JoyException("Failed to resolve app dir, missing: " + resourceName); } final String protocol = url.getProtocol(); if (!protocol.equals("file")) { try { url = new URL(url.getFile()); } catch (MalformedURLException ignore) { } } appDir = url.getFile(); final int ndx = appDir.indexOf("WEB-INF"); appDir = (ndx > 0) ? appDir.substring(0, ndx) : SystemUtil.info().getWorkingDir(); System.setProperty(APP_DIR, appDir); log.info("Application folder: " + appDir); }
/** * Alternative way for registering Joy listeners. * Sometimes servlet container does not allow adding new listener * from already added listener. This method therefore registers * the listener <i>before</i> container actually called the * callback methods. */ public static void registerInServletContext( final ServletContext servletContext, final Class<? extends JoyContextListener> joyContextListenerClass ) { try { final JoyContextListener joyContextListener = ClassUtil.newInstance(joyContextListenerClass); joyContextListener.createJoyAndInitServletContext(servletContext); } catch (Exception e) { throw new JoyException(e); } servletContext.addListener(joyContextListenerClass); }
protected <T> T requireStarted(final T object) { if (object == null) { throw new JoyException("Component is not started yet and can not be used."); } return object; }
protected void requireNotStarted(final Object object) { if (object != null) { throw new JoyException("Configuration is modified after component is started."); } } protected <T> T requireStarted(final T object) {
@Override public void start() { initLogger(); final String resourceName = StringUtil.replaceChar(JoyPaths.class.getName(), '.', '/') + ".class"; URL url = ClassLoaderUtil.getResourceUrl(resourceName); if (url == null) { throw new JoyException("Failed to resolve app dir, missing: " + resourceName); } final String protocol = url.getProtocol(); if (!protocol.equals("file")) { try { url = new URL(url.getFile()); } catch (MalformedURLException ignore) { } } appDir = url.getFile(); final int ndx = appDir.indexOf("WEB-INF"); appDir = (ndx > 0) ? appDir.substring(0, ndx) : SystemUtil.info().getWorkingDir(); System.setProperty(APP_DIR, appDir); log.info("Application folder: " + appDir); }
/** * Alternative way for registering Joy listeners. * Sometimes servlet container does not allow adding new listener * from already added listener. This method therefore registers * the listener <i>before</i> container actually called the * callback methods. */ public static void registerInServletContext( final ServletContext servletContext, final Class<? extends JoyContextListener> joyContextListenerClass ) { try { final JoyContextListener joyContextListener = ClassUtil.newInstance(joyContextListenerClass); joyContextListener.createJoyAndInitServletContext(servletContext); } catch (Exception e) { throw new JoyException(e); } servletContext.addListener(joyContextListenerClass); }