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 006 package fc.web.servlet; 007 008 import java.io.*; 009 import java.util.*; 010 import java.util.logging.*; 011 import javax.servlet.*; 012 013 import fc.io.*; 014 import fc.util.*; 015 016 /** 017 Loads properties for a servlet. Intended to be used in 018 application/context scope by all servlets belonging to one web 019 context/application. 020 <p> 021 ThreadSafety: This class <b>is</b> thread safe and can be used by 022 multiple threads concurrently. 023 024 @author hursh jain 025 @version 1.0 12/30/2001 026 */ 027 public class ServletPropertyMgr extends PropertyMgr 028 { 029 ServletContext context; 030 031 /** 032 @param context the {@link javax.servlet.ServletContext} 033 to load init parameters from. 034 */ 035 public ServletPropertyMgr(ServletContext context) 036 throws IOException 037 { 038 this.context = context; 039 } 040 041 public String get(String name) { 042 return context.getInitParameter(name); 043 } 044 045 public void save() { 046 throw new RuntimeException("not implemented"); 047 } 048 049 public String set(String name, String backup) { 050 throw new RuntimeException("not implemented"); 051 } 052 053 /** 054 Overrides the {@link fc.app.PropertyMgr#handleError} method 055 to <b>not</b>exit the application is case of an error. 056 Instead an error is logged and a ServletException is thrown. 057 **/ 058 protected 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 }