geirm 01/05/20 12:44:36
Modified: src/java/org/apache/velocity/context
InternalContextAdapter.java
InternalContextAdapterImpl.java
InternalContextBase.java
InternalHousekeepingContext.java VMContext.java
Log:
Reworked the context interface stuff to enable to movement of the event
stuff out, making event support for a custom context optional, and
keeping the internal stuff internal - so only Event interface is
publicly accessable. I think this is right :)
InternalContextAdapter.java : added InternalEventContext
InternalContextAdapterImpl : added support for IEC as optional
InternalContextBase.java : added inclusion and implementaion of
IEC for AbstractContext-derived context implementations (like
VelocityContext)
InternalHousekeepingContext.java : removed EventCartridge support
as now in it's own interface.
VMContext.java : needed import statment as EC is now in different package
Revision Changes Path
1.4 +2 -2
jakarta-velocity/src/java/org/apache/velocity/context/InternalContextAdapter.java
Index: InternalContextAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/context/InternalContextAdapter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InternalContextAdapter.java 2001/03/05 11:21:41 1.3
+++ InternalContextAdapter.java 2001/05/20 19:44:34 1.4
@@ -64,10 +64,10 @@
* I will rename soon :)
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: InternalContextAdapter.java,v 1.3 2001/03/05 11:21:41 jvanzyl Exp
$
+ * @version $Id: InternalContextAdapter.java,v 1.4 2001/05/20 19:44:34 geirm Exp $
*/
public interface InternalContextAdapter
- extends InternalHousekeepingContext, Context, InternalWrapperContext
+ extends InternalHousekeepingContext, Context, InternalWrapperContext,
InternalEventContext
{
}
1.8 +82 -37
jakarta-velocity/src/java/org/apache/velocity/context/InternalContextAdapterImpl.java
Index: InternalContextAdapterImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/context/InternalContextAdapterImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InternalContextAdapterImpl.java 2001/04/22 18:29:37 1.7
+++ InternalContextAdapterImpl.java 2001/05/20 19:44:34 1.8
@@ -56,7 +56,7 @@
import org.apache.velocity.util.introspection.IntrospectionCacheData;
-import org.apache.velocity.context.EventCartridge;
+import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.runtime.resource.Resource;
@@ -68,7 +68,10 @@
* Currently, we have two context interfaces which must be supported :
* <ul>
* <li> Context : used for application/template data access
- * <li> InternalContext : used for internal housekeeping and caching
+ * <li> InternalHousekeepingContext : used for internal housekeeping and caching
+ * <li> InternalWrapperContext : used for getting root cache context and other
+ * such.
+ * <li> InternalEventContext : for event handling.
* </ul>
*
* This class implements the two interfaces to ensure that all methods are
@@ -88,16 +91,33 @@
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: InternalContextAdapterImpl.java,v 1.7 2001/04/22 18:29:37 geirm
Exp $
+ * @version $Id: InternalContextAdapterImpl.java,v 1.8 2001/05/20 19:44:34 geirm
Exp $
*/
public final class InternalContextAdapterImpl implements InternalContextAdapter
{
- /** the Context that we are wrapping */
+ /**
+ * the user data Context that we are wrapping
+ */
Context context = null;
- /** the ICB we are wrapping. We may need to make one */
+ /**
+ * the ICB we are wrapping. We may need to make one
+ * if the user data context implementation doesn't
+ * support one. The default AbstractContext-derived
+ * VelocityContext does, and it's recommended that
+ * people derive new contexts from AbstractContext
+ * rather than piecing things together
+ */
InternalHousekeepingContext icb = null;
+ /**
+ * The InternalEventContext that we are wrapping. If
+ * the context passed to us doesn't support it, no
+ * biggie. We don't make it for them - since its a
+ * user context thing, nothing gained by making one
+ * for them now
+ */
+ InternalEventContext iec = null;
/**
* CTOR takes a Context and wraps it, delegating all 'data' calls
@@ -118,41 +138,14 @@
{
icb = (InternalHousekeepingContext) context;
}
- }
-
- public InternalContextAdapterImpl( Context c, boolean avoid )
- {
- context = c;
- icb = (InternalHousekeepingContext) context;
- }
-
- public Context getInternalUserContext()
- {
- return context;
- }
-
- public EventCartridge attachEventCartridge( EventCartridge ec )
- {
- return icb.attachEventCartridge( ec );
- }
- public EventCartridge getEventCartridge()
- {
- return icb.getEventCartridge( );
- }
-
-
- public void setCurrentResource( Resource r )
- {
- icb.setCurrentResource(r);
- }
-
- public Resource getCurrentResource()
- {
- return icb.getCurrentResource();
+ if ( c instanceof InternalEventContext)
+ {
+ iec = ( InternalEventContext) context;
+ }
}
- /* --- InternalContext interface methods --- */
+ /* --- InternalHousekeepingContext interface methods --- */
public void pushCurrentTemplateName( String s )
{
@@ -184,6 +177,17 @@
icb.icachePut( key, o );
}
+ public void setCurrentResource( Resource r )
+ {
+ icb.setCurrentResource(r);
+ }
+
+ public Resource getCurrentResource()
+ {
+ return icb.getCurrentResource();
+ }
+
+
/* --- Context interface methods --- */
public Object put(String key, Object value)
@@ -211,9 +215,50 @@
return context.remove( key );
}
+
+ /* ---- InternalWrapperContext --- */
+
+ /**
+ * returns the user data context that
+ * we are wrapping
+ */
+ public Context getInternalUserContext()
+ {
+ return context;
+ }
+
+ /**
+ * Returns the base context that we are
+ * wrapping. Here, its this, but for other thing
+ * like VM related context contortions, it can
+ * be something else
+ */
public InternalContextAdapter getBaseContext()
{
return this;
}
+ /* ----- InternalEventContext ---- */
+
+ public EventCartridge attachEventCartridge( EventCartridge ec )
+ {
+ if (iec != null)
+ {
+ return iec.attachEventCartridge( ec );
+ }
+
+ return null;
+ }
+
+ public EventCartridge getEventCartridge()
+ {
+ if ( iec != null)
+ {
+ return iec.getEventCartridge( );
+ }
+
+ return null;
+ }
}
+
+
1.8 +21 -13
jakarta-velocity/src/java/org/apache/velocity/context/InternalContextBase.java
Index: InternalContextBase.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/context/InternalContextBase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InternalContextBase.java 2001/04/22 18:29:37 1.7
+++ InternalContextBase.java 2001/05/20 19:44:34 1.8
@@ -60,7 +60,7 @@
import org.apache.velocity.util.introspection.IntrospectionCacheData;
-import org.apache.velocity.context.EventCartridge;
+import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.runtime.resource.Resource;
/**
@@ -76,9 +76,9 @@
* is derived from this.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: InternalContextBase.java,v 1.7 2001/04/22 18:29:37 geirm Exp $
+ * @version $Id: InternalContextBase.java,v 1.8 2001/05/20 19:44:34 geirm Exp $
*/
-class InternalContextBase implements InternalHousekeepingContext,Serializable
+class InternalContextBase implements InternalHousekeepingContext,
InternalEventContext, Serializable
{
/**
* cache for node/context specific introspection information
@@ -90,7 +90,15 @@
*/
private Stack templateNameStack = new Stack();
+ /**
+ * EventCartridge we are to carry. Set by application
+ */
private EventCartridge eventCartridge = null;
+
+ /**
+ * Current resource - used for carrying encoding and other
+ * information down into the rendering process
+ */
private Resource currentResource = null;
/**
@@ -160,6 +168,16 @@
introspectionCache.put( key, o );
}
+ public void setCurrentResource( Resource r )
+ {
+ currentResource = r;
+ }
+
+ public Resource getCurrentResource()
+ {
+ return currentResource;
+ }
+
public EventCartridge attachEventCartridge( EventCartridge ec )
{
EventCartridge temp = eventCartridge;
@@ -172,16 +190,6 @@
public EventCartridge getEventCartridge()
{
return eventCartridge;
- }
-
- public void setCurrentResource( Resource r )
- {
- currentResource = r;
- }
-
- public Resource getCurrentResource()
- {
- return currentResource;
}
}
1.6 +1 -11
jakarta-velocity/src/java/org/apache/velocity/context/InternalHousekeepingContext.java
Index: InternalHousekeepingContext.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/context/InternalHousekeepingContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InternalHousekeepingContext.java 2001/04/22 18:18:45 1.5
+++ InternalHousekeepingContext.java 2001/05/20 19:44:35 1.6
@@ -56,8 +56,6 @@
import org.apache.velocity.util.introspection.IntrospectionCacheData;
-import org.apache.velocity.context.EventCartridge;
-
import org.apache.velocity.runtime.resource.Resource;
/**
@@ -71,7 +69,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph Reck</a>
- * @version $Id: InternalHousekeepingContext.java,v 1.5 2001/04/22 18:18:45 geirm
Exp $
+ * @version $Id: InternalHousekeepingContext.java,v 1.6 2001/05/20 19:44:35 geirm
Exp $
*/
interface InternalHousekeepingContext
{
@@ -118,14 +116,6 @@
* @param o IntrospectionCacheData object to place in cache
*/
void icachePut( Object key, IntrospectionCacheData o );
-
- /**
- * interface for the EventCartridge stuff. This will be moved
- * to a separate interface
- */
-
- EventCartridge attachEventCartridge( EventCartridge ec);
- EventCartridge getEventCartridge();
/**
* temporary fix to enable #include() to figure out
1.7 +2 -1
jakarta-velocity/src/java/org/apache/velocity/context/VMContext.java
Index: VMContext.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/context/VMContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- VMContext.java 2001/04/22 18:29:37 1.6
+++ VMContext.java 2001/05/20 19:44:35 1.7
@@ -60,6 +60,7 @@
import org.apache.velocity.runtime.directive.VMProxyArg;
import org.apache.velocity.util.introspection.IntrospectionCacheData;
import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.app.event.EventCartridge;
/**
* This is a special, internal-use-only context implementation to be
@@ -73,7 +74,7 @@
* local to the vm, protecting the global context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: VMContext.java,v 1.6 2001/04/22 18:29:37 geirm Exp $
+ * @version $Id: VMContext.java,v 1.7 2001/05/20 19:44:35 geirm Exp $
*/
public class VMContext implements InternalContextAdapter
{