/** * Remove a lifecycle event listener from this component. * * @param listener The listener to remove */ public void removeLifecycleListener(LifecycleListener listener) { synchronized (listenersLock) { int n = -1; for (int i = 0; i < listeners.length; i++) { if (listeners[i] == listener) { n = i; break; } } if (n < 0) return; LifecycleListener results[] = new LifecycleListener[listeners.length - 1]; int j = 0; for (int i = 0; i < listeners.length; i++) { if (i != n) results[j++] = listeners[i]; } listeners = results; } }
/** * Remove a lifecycle event listener from this component. * * @param listener * The listener to remove */ public void removeLifecycleListener(LifecycleListener listener) { synchronized (listenersLock) { int n = -1; for (int i = 0; i < listeners.length; i++) { if (listeners[i] == listener) { n = i; break; } } if (n < 0) return; LifecycleListener results[] = new LifecycleListener[listeners.length - 1]; int j = 0; for (int i = 0; i < listeners.length; i++) { if (i != n) results[j++] = listeners[i]; } listeners = results; } }
/** * Handle the beginning of an XML element. * * @param attributes The attributes of this element * * @exception Exception if a processing error occurs */ public void begin(Attributes attributes) throws Exception { // Instantiate a new LifecyleListener implementation object String className = listenerClass; if (attributeName != null) { String value = attributes.getValue(attributeName); if (value != null) className = value; } Class clazz = Class.forName(className); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); // Add this LifecycleListener to our associated component Lifecycle lifecycle = (Lifecycle) digester.peek(); lifecycle.addLifecycleListener(listener); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = null; synchronized (listeners) { interested = (LifecycleListener[]) listeners.clone(); } for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * 增加生命周期的监听,用数组存储 * Add a lifecycle event listener to this component. * * @param listener The listener to add */ public void addLifecycleListener(LifecycleListener listener) { synchronized (listenersLock) { LifecycleListener results[] = new LifecycleListener[listeners.length + 1]; for (int i = 0; i < listeners.length; i++) results[i] = listeners[i]; results[listeners.length] = listener; listeners = results; } }
public ListenersInfo(Container container, ContainerListener[] containerListeners, LifecycleListener[] lifecycleListeners) { this.container = container; this.containerListeners = containerListeners; this.lifecycleListeners = lifecycleListeners; }
/** * Deploy a web application for the specified user if they have such an * application in the defined directory within their home directory. * * @param user Username owning the application to be deployed * @param home Home directory of this user */ private void deploy(String user, String home) { // Does this user have a web application to be deployed? String contextPath = "/~" + user; if (host.findChild(contextPath) != null) return; File app = new File(home, directoryName); if (!app.exists() || !app.isDirectory()) return; /* File dd = new File(app, "/WEB-INF/web.xml"); if (!dd.exists() || !dd.isFile() || !dd.canRead()) return; */ host.getLogger().info(sm.getString("userConfig.deploy", user)); // Deploy the web application for this user try { Class clazz = Class.forName(contextClass); Context context = (Context) clazz.newInstance(); context.setPath(contextPath); context.setDocBase(app.toString()); if (context instanceof Lifecycle) { clazz = Class.forName(configClass); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); ((Lifecycle) context).addLifecycleListener(listener); } host.addChild(context); } catch (Exception e) { host.getLogger().error(sm.getString("userConfig.error", user), e); } }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Add a lifecycle event listener to this component. * * @param listener The listener to add */ public void addLifecycleListener(LifecycleListener listener) { synchronized (listenersLock) { LifecycleListener results[] = new LifecycleListener[listeners.length + 1]; for (int i = 0; i < listeners.length; i++) results[i] = listeners[i]; results[listeners.length] = listener; listeners = results; } }
/** * Add a lifecycle event listener to this component. * * @param listener * The listener to add */ public void addLifecycleListener(LifecycleListener listener) { synchronized (listenersLock) { LifecycleListener results[] = new LifecycleListener[listeners.length + 1]; for (int i = 0; i < listeners.length; i++) results[i] = listeners[i]; results[listeners.length] = listener; listeners = results; } }
/** * Add a lifecycle event listener to this component. * * @param listener The listener to add */ public void addLifecycleListener(LifecycleListener listener) { synchronized (listeners) { LifecycleListener results[] = new LifecycleListener[listeners.length + 1]; for (int i = 0; i < listeners.length; i++) results[i] = listeners[i]; results[listeners.length] = listener; listeners = results; } }
/** * Deploy a web application for the specified user if they have such an * application in the defined directory within their home directory. * * @param user * Username owning the application to be deployed * @param home * Home directory of this user */ private void deploy(String user, String home) { // Does this user have a web application to be deployed? String contextPath = "/~" + user; if (host.findChild(contextPath) != null) return; File app = new File(home, directoryName); if (!app.exists() || !app.isDirectory()) return; /* * File dd = new File(app, "/WEB-INF/web.xml"); if (!dd.exists() || * !dd.isFile() || !dd.canRead()) return; */ host.getLogger().info(sm.getString("userConfig.deploy", user)); // Deploy the web application for this user try { Class<?> clazz = Class.forName(contextClass); Context context = (Context) clazz.newInstance(); context.setPath(contextPath); context.setDocBase(app.toString()); clazz = Class.forName(configClass); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); context.addLifecycleListener(listener); host.addChild(context); } catch (Exception e) { host.getLogger().error(sm.getString("userConfig.error", user), e); } }
/** * Store the specified Server properties. * * @param writer PrintWriter to which we are storing * @param indent Number of spaces to indent this element * @param server Object to be stored * * @exception Exception if an exception occurs while storing */ private void storeServer(PrintWriter writer, int indent, Server server) throws Exception { // Store the beginning of this element writer.println("<?xml version='1.0' encoding='utf-8'?>"); for (int i = 0; i < indent; i++) { writer.print(' '); } writer.print("<Server"); storeAttributes(writer, server); writer.println(">"); // Store nested <Listener> elements if (server instanceof Lifecycle) { LifecycleListener listeners[] = ((Lifecycle) server).findLifecycleListeners(); for (int i = 0; i < listeners.length; i++) { storeListener(writer, indent + 2, listeners[i]); } } // Store nested <GlobalNamingResources> element NamingResources globalNamingResources = server.getGlobalNamingResources(); if (globalNamingResources != null) { for (int i = 0; i < indent + 2; i++) { writer.print(' '); } writer.println("<GlobalNamingResources>"); storeNamingResources(writer, indent + 4, globalNamingResources); for (int i = 0; i < indent + 2; i++) { writer.print(' '); } writer.println("</GlobalNamingResources>"); } // Store nested <Service> elements Service services[] = server.findServices(); for (int i = 0; i < services.length; i++) { storeService(writer, indent + 2, services[i]); } // Store the ending of this element for (int i = 0; i < indent; i++) { writer.print(' '); } writer.println("</Server>"); }
/** * Deploy a web application for the specified user if they have such an * application in the defined directory within their home directory. * * @param user Username owning the application to be deployed * @param home Home directory of this user */ private void deploy(String user, String home) { // Does this user have a web application to be deployed? String contextPath = "/~" + user; if (host.findChild(contextPath) != null) return; File app = new File(home, directoryName); if (!app.exists() || !app.isDirectory()) return; /* File dd = new File(app, "/WEB-INF/web.xml"); if (!dd.exists() || !dd.isFile() || !dd.canRead()) return; */ log(sm.getString("userConfig.deploy", user)); // Deploy the web application for this user try { Class clazz = Class.forName(contextClass); Context context = (Context) clazz.newInstance(); context.setPath(contextPath); context.setDocBase(app.toString()); if (context instanceof Lifecycle) { clazz = Class.forName(configClass); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); ((Lifecycle) context).addLifecycleListener(listener); } host.addChild(context); } catch (Exception e) { log(sm.getString("userConfig.error", user), e); } }
/** * Get the lifecycle listeners associated with this lifecycle. If this * Lifecycle has no listeners registered, a zero-length array is returned. */ @Override public LifecycleListener[] findLifecycleListeners() { return new LifecycleListener[0]; }
@Override public void removeLifecycleListener(LifecycleListener listener) { // NO-OP }
/** * {@inheritDoc} */ @Override public void addLifecycleListener(LifecycleListener listener) { lifecycle.addLifecycleListener(listener); }
@Override public void addLifecycleListener(LifecycleListener listener) { // NO-OP }
/** * {@inheritDoc} */ @Override public LifecycleListener[] findLifecycleListeners() { return lifecycle.findLifecycleListeners(); }
/** * {@inheritDoc} */ @Override public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); }
/** * Store the specified Connector properties. * * @param writer PrintWriter to which we are storing * @param indent Number of spaces to indent this element * @param connector Object whose properties are being stored * * @exception Exception if an exception occurs while storing */ private void storeConnector(PrintWriter writer, int indent, Connector connector) throws Exception { // Store the beginning of this element for (int i = 0; i < indent; i++) { writer.print(' '); } writer.print("<Connector"); storeAttributes(writer, connector); writer.println(">"); // Store nested <Factory> element ServerSocketFactory factory = connector.getFactory(); if (factory != null) { storeFactory(writer, indent + 2, factory); } // Store nested <Listener> elements if (connector instanceof Lifecycle) { LifecycleListener listeners[] = ((Lifecycle) connector).findLifecycleListeners(); if (listeners == null) { listeners = new LifecycleListener[0]; } for (int i = 0; i < listeners.length; i++) { if (listeners[i].getClass().getName().equals (SERVER_LISTENER_CLASS_NAME)) { continue; } storeListener(writer, indent + 2, listeners[i]); } } // Store the ending of this element for (int i = 0; i < indent; i++) { writer.print(' '); } writer.println("</Connector>"); }
/** * Get the lifecycle listeners associated with this lifecycle. If this * Lifecycle has no listeners registered, a zero-length array is returned. */ @Override public LifecycleListener[] findLifecycleListeners() { return lifecycle.findLifecycleListeners(); }
@Override public LifecycleListener[] findLifecycleListeners() { return null; }
public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); }
/** * Notify all lifecycle event listeners that a particular event has occurred * for this Container. The default implementation performs this notification * synchronously using the calling thread. * * @param type * Event type * @param data * Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Remove a lifecycle event listener from this component. * * @param listener The listener to remove */ @Override public void removeLifecycleListener(LifecycleListener listener) { // NOOP }
/** * Return a listener that provides the required configuration items for JSP * processing. From the standard Tomcat global web.xml. Pass this to * {@link Context#addLifecycleListener(LifecycleListener)} and then pass the * result of {@link #noDefaultWebXmlPath()} to * {@link ContextConfig#setDefaultWebXml(String)}. * @return a listener object that configures default JSP processing. */ public LifecycleListener getDefaultWebXmlListener() { return new DefaultWebXmlListener(); }
/** * Get the lifecycle listeners associated with this lifecycle. If this * Lifecycle has no listeners registered, a zero-length array is returned. */ public LifecycleListener[] findLifecycleListeners() { return lifecycle.findLifecycleListeners(); }
/** * Remove a lifecycle event listener from this component. * * @param listener The listener to add */ public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); }
/** * Get the lifecycle listeners associated with this lifecycle. If this * Lifecycle has no listeners registered, a zero-length array is returned. */ public LifecycleListener[] findLifecycleListeners() { return listeners; }
/** * Add a lifecycle event listener to this component. * * @param listener The listener to add */ public void addLifecycleListener(LifecycleListener listener) { lifecycle.addLifecycleListener(listener); }
/** * Remove a LifecycleEvent listener from this component. * * @param listener The listener to remove */ public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); }