luehe 2002/10/21 13:13:33 Modified: jasper2/src/share/org/apache/jasper/compiler BeanRepository.java Compiler.java PageDataImpl.java ParserController.java Validator.java jasper2/src/share/org/apache/jasper/util FastDateFormat.java SimplePool.java Log: Reduced visibility of fields/methods where appropriate + other cleanup Revision Changes Path 1.2 +69 -139 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/BeanRepository.java Index: BeanRepository.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/BeanRepository.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BeanRepository.java 28 Mar 2002 18:46:18 -0000 1.1 +++ BeanRepository.java 21 Oct 2002 20:13:32 -0000 1.2 @@ -73,161 +73,91 @@ import org.apache.jasper.JasperException; /** - * Holds instances of {session, application, page}-scoped beans + * Repository of {page, request, session, application}-scoped beans * * @author Mandar Raje */ -public class BeanRepository { +class BeanRepository { + + private Vector sessionBeans; + private Vector pageBeans; + private Vector appBeans; + private Vector requestBeans; + private Hashtable beanTypes; + private ClassLoader loader; + private ErrorDispatcher errDispatcher; + + /* + * Constructor. + */ + public BeanRepository(ClassLoader loader, ErrorDispatcher err) { + + this.loader = loader; + this.errDispatcher = err; - Vector sessionBeans; - Vector pageBeans; - Vector appBeans; - Vector requestBeans; - Hashtable beanTypes; - ClassLoader loader; - - public BeanRepository (ClassLoader loader) { sessionBeans = new Vector(11); - pageBeans = new Vector(11); + pageBeans = new Vector(11); appBeans = new Vector(11); - requestBeans = new Vector(11); - beanTypes = new Hashtable (); - this.loader = loader; - } - - public boolean checkSessionBean (String s) { - return sessionBeans.contains (s); - } - - public void addSessionBean (String s, String type) throws JasperException { - sessionBeans.addElement (s); - putBeanType (s, type); - } - - public boolean hasSessionBeans () { - return !sessionBeans.isEmpty (); - } - - public Enumeration getSessionBeans () { - return sessionBeans.elements (); - } - - public boolean checkApplicationBean (String s) { - return appBeans.contains (s); - } - - public void addApplicationBean (String s, String type) throws JasperException - { - appBeans.addElement (s); - putBeanType (s, type); - } - - public boolean hasApplicationBeans () { - return !appBeans.isEmpty (); - } - - public Enumeration getApplicationBeans () { - return appBeans.elements (); - } - - public boolean checkRequestBean (String s) { - return requestBeans.contains (s); - } - - public void addRequestBean (String s, String type) throws JasperException { - requestBeans.addElement (s); - putBeanType (s, type); - } - - public boolean hasRequestBeans () { - return !requestBeans.isEmpty (); - } - - public Enumeration getRequestBeans () { - return requestBeans.elements (); + requestBeans = new Vector(11); + beanTypes = new Hashtable(); } - - public boolean checkPageBean (String s) { - return pageBeans.contains (s); - } - - public void addPageBean (String s, String type) throws JasperException { - pageBeans.addElement (s); - putBeanType (s, type); - } - - public boolean hasPageBeans () { - return !pageBeans.isEmpty (); - } - - public Enumeration getPageBeans () { - return pageBeans.elements (); - } - - public boolean ClassFound (String clsname) - throws ClassNotFoundException { - Class cls = null; - //try { - cls = loader.loadClass (clsname); - //} catch (ClassNotFoundException ex) { - //return false; - //} - return !(cls == null); - } - - public Class getBeanType (String bean) throws JasperException { - Class cls = null; - try { - cls = loader.loadClass ((String)beanTypes.get(bean)); - } catch (ClassNotFoundException ex) { - throw new JasperException (ex); + + public void addBean(Node.UseBean n, String s, String type, String scope) + throws JasperException { + + if (scope == null || scope.equals("page")) { + pageBeans.addElement(s); + } else if (scope.equals("request")) { + requestBeans.addElement(s); + } else if (scope.equals("session")) { + sessionBeans.addElement(s); + } else if (scope.equals("application")) { + appBeans.addElement(s); + } else { + errDispatcher.jspError(n, "jsp.error.useBean.badScope"); } - return cls; + + putBeanType(s, type); } - - public void putBeanType (String bean, String type) throws JasperException { + + public Class getBeanType(String bean) throws JasperException { + Class clazz = null; try { - beanTypes.put (bean, type); - } catch (Exception ex) { + clazz = loader.loadClass ((String)beanTypes.get(bean)); + } catch (ClassNotFoundException ex) { throw new JasperException (ex); } + return clazz; } - - //public void putBeanType (String bean, Class type) { - //beanTypes.put (bean, type); - //} - - public void removeBeanType (String bean) { - beanTypes.remove (bean); - } - - // Not sure if this is the correct way. - // After pageContext is finalised this will change. + public boolean checkVariable (String bean) { + // XXX Not sure if this is the correct way. + // After pageContext is finalised this will change. return (checkPageBean(bean) || checkSessionBean(bean) || checkRequestBean(bean) || checkApplicationBean(bean)); } - // Ideally this method should belong to the utils. - public Class getClass (String clsname) - throws ClassNotFoundException { - Class cls = null; - if (clsname != null) { - cls = loader.loadClass (clsname); - } - return cls; - } - - public boolean beanFound (String beanName) - throws ClassNotFoundException { - try { - Beans.instantiate(Thread.currentThread().getContextClassLoader(), beanName); - return true; - } catch (java.io.IOException ex) { - // Ignore it for the time being. - return false; - } + + private void putBeanType(String bean, String type) { + beanTypes.put (bean, type); } + + private boolean checkPageBean (String s) { + return pageBeans.contains (s); + } + + private boolean checkRequestBean (String s) { + return requestBeans.contains (s); + } + + private boolean checkSessionBean (String s) { + return sessionBeans.contains (s); + } + + private boolean checkApplicationBean (String s) { + return appBeans.contains (s); + } + } 1.37 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java Index: Compiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- Compiler.java 9 Oct 2002 17:41:13 -0000 1.36 +++ Compiler.java 21 Oct 2002 20:13:32 -0000 1.37 @@ -199,7 +199,8 @@ { long t1=System.currentTimeMillis(); // Setup page info area - pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader())); + pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), + errDispatcher)); JspConfig jspConfig = options.getJspConfig(); JspConfig.JspProperty jspProperty = jspConfig.findJspProperty(ctxt.getJspFile()); 1.11 +4 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java Index: PageDataImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PageDataImpl.java 17 Oct 2002 01:35:46 -0000 1.10 +++ PageDataImpl.java 21 Oct 2002 20:13:32 -0000 1.11 @@ -90,8 +90,7 @@ * * @author Jan Luehe */ - -public class PageDataImpl extends PageData implements TagConstants { +class PageDataImpl extends PageData implements TagConstants { private static final String JSP_NAMESPACE = "http://java.sun.com/JSP/Page"; private static final String JSP_VERSION = "2.0"; 1.22 +4 -8 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java Index: ParserController.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ParserController.java 7 Oct 2002 19:36:18 -0000 1.21 +++ ParserController.java 21 Oct 2002 20:13:32 -0000 1.22 @@ -76,7 +76,7 @@ * * @author Pierre Delisle */ -public class ParserController { +class ParserController { private JspCompilationContext ctxt; private Compiler compiler; @@ -238,15 +238,14 @@ return parsedPage; } - /** ******************************************************************* + /** * Discover the properties of the page by scanning it. * Properties to find out are: - * * Is it in XML syntax? - * * What is the the page encoding + * - Is it in XML syntax? + * - What is the the page encoding * If these properties are already specified in the jsp-config element * in web.xml, then they are used. */ - private void figureOutJspDocument(String file, String encoding, InputStreamReader reader) @@ -329,9 +328,6 @@ } } - //********************************************************************* - // Utility methods - /* * Resolve the name of the file and update * baseDirStack() to keep track ot the current 1.46 +4 -13 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java Index: Validator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- Validator.java 17 Oct 2002 22:56:02 -0000 1.45 +++ Validator.java 21 Oct 2002 20:13:32 -0000 1.46 @@ -543,16 +543,7 @@ if (className == null) className = type; - if (scope == null || scope.equals("page")) { - beanInfo.addPageBean(name, className); - } else if (scope.equals("request")) { - beanInfo.addRequestBean(name, className); - } else if (scope.equals("session")) { - beanInfo.addSessionBean(name,className); - } else if (scope.equals("application")) { - beanInfo.addApplicationBean(name,className); - } else - err.jspError(n, "jsp.error.useBean.badScope"); + beanInfo.addBean(n, name, className, scope); visitBody(n); } 1.2 +25 -15 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/FastDateFormat.java Index: FastDateFormat.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/FastDateFormat.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FastDateFormat.java 28 Mar 2002 18:46:20 -0000 1.1 +++ FastDateFormat.java 21 Oct 2002 20:13:33 -0000 1.2 @@ -77,12 +77,13 @@ * * @author Stan Bailes * @author Alex Chaffee - **/ + */ public class FastDateFormat extends DateFormat { - DateFormat df; - long lastSec = -1; - StringBuffer sb = new StringBuffer(); - FieldPosition fp = new FieldPosition(DateFormat.MILLISECOND_FIELD); + + private DateFormat df; + private long lastSec = -1; + private StringBuffer sb = new StringBuffer(); + private FieldPosition fp = new FieldPosition(DateFormat.MILLISECOND_FIELD); public FastDateFormat(DateFormat df) { this.df = df; @@ -96,7 +97,7 @@ * Note: breaks functionality of fieldPosition param. Also: * there's a bug in SimpleDateFormat with "S" and "SS", use "SSS" * instead if you want a msec field. - **/ + */ public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { long dt = date.getTime(); @@ -133,15 +134,24 @@ FastDateFormat fdf = new FastDateFormat(sdf); Date d = new Date(); - d.setTime(1); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(20); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(500); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(543); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(999); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(1050); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(2543); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(12345); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); - d.setTime(12340); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(1); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(20); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(500); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(543); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(999); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(1050); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(2543); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(12345); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); + d.setTime(12340); + System.out.println(fdf.format(d) + "\t" + sdf.format(d)); final int reps = 100000; { 1.2 +13 -14 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SimplePool.java Index: SimplePool.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SimplePool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimplePool.java 28 Mar 2002 18:46:20 -0000 1.1 +++ SimplePool.java 21 Oct 2002 20:13:33 -0000 1.2 @@ -72,6 +72,9 @@ * @author Costin */ public final class SimplePool { + + private static final int DEFAULT_SIZE=16; + /* * Where the threads are held. */ @@ -80,28 +83,24 @@ private int max; private int current=-1; - Object lock; - public static final int DEFAULT_SIZE=16; + private Object lock; public SimplePool() { this.max=DEFAULT_SIZE; - pool=new Object[max]; - lock=new Object(); + this.pool=new Object[max]; + this.lock=new Object(); } public SimplePool(int max) { this.max=max; - pool=new Object[max]; - lock=new Object(); + this.pool=new Object[max]; + this.lock=new Object(); } - public void set(Object o) { - put(o); - } /** - * Add the object to the pool, silent nothing if the pool is full + * Adds the given object to the pool, and does nothing if the pool is full */ - public void put(Object o) { + public void put(Object o) { synchronized( lock ) { if( current < (max-1) ) { current += 1; @@ -113,7 +112,7 @@ /** * Get an object from the pool, null if the pool is empty. */ - public Object get() { + public Object get() { Object item = null; synchronized( lock ) { if( current >= 0 ) {
-- To unsubscribe, e-mail: <mailto:tomcat-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:tomcat-dev-help@;jakarta.apache.org>