001// Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 
002// The Molly framework is freely distributable under the terms of an
003// MIT-style license. For details, see the molly pages web site at:
004// http://www.mollypages.org/. Use, modify, have fun !
005
006package fc.web.servlet;
007
008import java.io.*;
009import java.util.*;
010import java.util.logging.*;
011import javax.servlet.*;
012
013import fc.io.*;
014import fc.util.*;
015
016/** 
017Loads properties for a servlet. Intended to be used in
018application/context scope by all servlets belonging to one web
019context/application.
020<p>
021ThreadSafety: This class <b>is</b> thread safe and can be used by
022multiple threads concurrently.
023
024@author hursh jain 
025@version 1.0 12/30/2001
026*/
027public class ServletPropertyMgr extends PropertyMgr
028{
029ServletContext context;
030
031/**
032@param  context  the {@link javax.servlet.ServletContext}
033         to load init parameters from.
034*/
035public ServletPropertyMgr(ServletContext context) 
036  throws IOException
037  {
038  this.context = context;
039  }
040
041public String get(String name) {
042  return context.getInitParameter(name);    
043  }
044
045public void save() {
046  throw new RuntimeException("not implemented");
047  }
048  
049public String set(String name, String backup) {
050  throw new RuntimeException("not implemented");
051  }
052
053/**
054Overrides the {@link fc.app.PropertyMgr#handleError} method
055to <b>not</b>exit the application is case of an error.
056Instead an error is logged and a ServletException is thrown.
057**/
058protected void handleError(String str) throws PropertyNotFoundException
059  {
060  //don't specify 'this' for the object because then that prints the
061  //entire list of loaded properties every time - leads to too much clutter
062  System.err.println("Property: '" + str + "' not found"); 
063  throw new PropertyNotFoundException("Could not load required property: " + str);
064  }
065}