Annotation of java/classes/org/w3c/jigsaw/servlet/ServletDirectoryFrame.java, revision 1.16

1.1       bmahe       1: // ServletDirectoryFrame.java
1.16    ! bmahe       2: // $Id: ServletDirectoryFrame.java,v 1.15 1998/06/08 08:52:38 bmahe Exp $
1.1       bmahe       3: // (c) COPYRIGHT MIT and INRIA, 1996.
                      4: // Please first read the full copyright statement in file COPYRIGHT.html
                      5: 
                      6: package org.w3c.jigsaw.servlet;
                      7: 
                      8: import java.io.*;
                      9: import java.net.*;
                     10: import java.util.*;
                     11: 
                     12: import javax.servlet.*;
                     13: 
1.11      bmahe      14: import org.w3c.jigsaw.http.*;
                     15: import org.w3c.util.*;
1.1       bmahe      16: import org.w3c.tools.resources.store.*;
                     17: import org.w3c.tools.resources.*;
                     18: import org.w3c.jigsaw.frames.*;
                     19: 
                     20: /**
                     21:  *  @author Alexandre Rafalovitch <alex@access.com.au>
                     22:  *  @author Anselm Baird-Smith <abaird@w3.org>
1.3       bmahe      23:  *  @author Benoit Mahe <bmahe@w3.org>
1.1       bmahe      24:  */
                     25: 
1.3       bmahe      26: public class ServletDirectoryFrame extends HTTPFrame {
1.10      bmahe      27: 
                     28:     /**
1.12      bmahe      29:      * The servlet Context.
                     30:      */
1.6       bmahe      31:     protected JigsawServletContext servletContext = null;
                     32: 
1.12      bmahe      33:     /**
                     34:      * The Session Context.
                     35:      */
1.10      bmahe      36:     protected JigsawHttpSessionContext sessionContext = null;
                     37: 
1.11      bmahe      38:     /**
                     39:      * Register the resource and add ServletProperties in httpd.
                     40:      * @param resource The resource to register.
                     41:      */
                     42:     public void registerResource(FramedResource resource) {
                     43:        super.registerResource(resource);
1.15      bmahe      44:        if (getServletProps() == null ) {
1.11      bmahe      45:            synchronized (this.getClass()) {
                     46:                httpd s = (httpd) getServer();
                     47:                if ( s != null ) {
                     48:                    // Register the CVS property sheet if not done yet:
                     49:                    ObservableProperties props = s.getProperties() ;
1.14      bmahe      50:                    s.registerPropertySet(new ServletProps(s));
1.11      bmahe      51:                }
1.6       bmahe      52:            }
                     53:        }
                     54:     }
                     55: 
                     56:     /**
                     57:      * ServletContext implementation - Lookup a given servlet.
                     58:      */
                     59: 
                     60:     public Servlet getServlet(String name) {
                     61:        if (dresource != null) {
                     62:            ResourceReference rr = dresource.lookup(name);
1.16    ! bmahe      63:            if (rr != null) {
        !            64:                try {
        !            65:                    Resource resource = rr.lock();
        !            66:                    if (resource instanceof ServletWrapper)
        !            67:                        return ((ServletWrapper) resource).getServlet();
        !            68:                } catch (InvalidResourceException ex) {
        !            69:                    return null;
        !            70:                } finally {
        !            71:                    rr.unlock();
        !            72:                }
1.6       bmahe      73:            }
                     74:        }
1.1       bmahe      75:        return null;
1.6       bmahe      76:     }
                     77: 
                     78:     /**
                     79:      * ServletContext implementation - Enumerate all servlets within context.
                     80:      */
                     81: 
                     82:     public Enumeration getServlets() {
                     83:        if (dresource != null)
                     84:            return new ServletEnumeration(this, 
                     85:                                  dresource.enumerateResourceIdentifiers());
                     86:        else
                     87:            return new ServletEnumeration(this, null);
                     88:     }
1.5       bmahe      89: 
                     90:     /**
                     91:      * ServletContext implementation - Enumerate all servlets names
                     92:      * within context.
                     93:      */
                     94: 
                     95:     public Enumeration getServletNames() {
                     96:        if (dresource != null)
                     97:            return new ServletNamesEnumeration(this, 
                     98:                               dresource.enumerateResourceIdentifiers());
                     99:        else
                    100:            return new ServletNamesEnumeration(this, null);
                    101:     }
1.1       bmahe     102: 
1.6       bmahe     103:     /**
                    104:      * ServletContext implementation - Get server informations.
                    105:      */
                    106: 
                    107:     public String getServerInfo() {
                    108:        return resource.getServer().getSoftware();
                    109:     }
                    110: 
                    111:     /**
                    112:      * ServletContext implementation - Get an attribute value.
                    113:      * We map this into the ServletWrapper attributes, without
                    114:      * support for name clashes though.
                    115:      * @param name The attribute name.
                    116:      */
                    117: 
                    118:     public Object getAttribute(String name) {
                    119:        if ( definesAttribute(name) )
                    120:            return getValue(name, null);
                    121:        else if (resource.definesAttribute(name))
                    122:            return resource.getValue(name, null);
                    123:        return null;
                    124:     }
                    125: 
1.11      bmahe     126:     protected JigsawHttpSessionContext getJigsawHttpSessionContext() {
1.15      bmahe     127:        ServletProps sprops = getServletProps();
1.11      bmahe     128:        if (sprops != null)
                    129:            return sprops.getSessionContext();
                    130:        return null;
1.15      bmahe     131:     }
                    132: 
                    133:     protected ServletProps getServletProps() {
                    134:        httpd server = (httpd) getServer();
                    135:        return (ServletProps)
                    136:            server.getPropertySet(ServletProps.SERVLET_PROPS_NAME);
1.11      bmahe     137:     }
                    138: 
1.6       bmahe     139:     /**
                    140:      * We add a <em>context</em> attribute to all our children.
                    141:      * The <em>context</em> attribute is any object implementing the
                    142:      * ServletContext interface.
                    143:      */
                    144: 
                    145:     protected void updateDefaultChildAttributes(Hashtable attrs) {
                    146:        if (servletContext == null)
1.11      bmahe     147:            servletContext = 
                    148:                new JigsawServletContext(getFrameReference(),
                    149:                                         getServer().getProperties());
1.10      bmahe     150:        if (sessionContext == null)
1.11      bmahe     151:            sessionContext = getJigsawHttpSessionContext();
1.6       bmahe     152:        attrs.put("servlet-context", servletContext);
1.10      bmahe     153:        attrs.put("session-context", sessionContext);
1.6       bmahe     154:     }
1.1       bmahe     155: 
                    156: }

Webmaster