cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components ComponentContext.java
Date Mon, 19 Jan 2004 10:33:23 GMT
cziegeler    2004/01/19 02:33:23

  Modified:    src/java/org/apache/cocoon/components ComponentContext.java
  Log:
  Avoid NPE
  
  Revision  Changes    Path
  1.3       +12 -3     cocoon-2.1/src/java/org/apache/cocoon/components/ComponentContext.java
  
  Index: ComponentContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/ComponentContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentContext.java	23 May 2003 12:14:04 -0000	1.2
  +++ ComponentContext.java	19 Jan 2004 10:33:23 -0000	1.3
  @@ -55,6 +55,7 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.DefaultContext;
  +import org.apache.cocoon.environment.Environment;
   
   /**
    * This is the {@link Context} implementation for Cocoon components.
  @@ -116,12 +117,20 @@
       public Object get( final Object key )
       throws ContextException {
           if ( key.equals(ContextHelper.CONTEXT_OBJECT_MODEL)) {
  -            return CocoonComponentManager.getCurrentEnvironment().getObjectModel();
  +            final Environment env = CocoonComponentManager.getCurrentEnvironment();
  +            if ( env == null ) {
  +                throw new ContextException("Unable to locate " + key + " (No environment
available)");
  +            }
  +            return env.getObjectModel();
           }
           if ( key instanceof String ) {
               String stringKey = (String)key;
               if ( stringKey.startsWith(OBJECT_MODEL_KEY_PREFIX) ) {
  -                final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
  +                final Environment env = CocoonComponentManager.getCurrentEnvironment();
  +                if ( env == null ) {
  +                    throw new ContextException("Unable to locate " + key + " (No environment
available)");
  +                }
  +                final Map objectModel = env.getObjectModel();
                   String objectKey = stringKey.substring(OBJECT_MODEL_KEY_PREFIX.length());
                   
                   Object o = objectModel.get( objectKey );
  
  
  

Mime
View raw message