dgraham 2003/07/04 14:41:00
Modified: src/share/org/apache/struts/tiles ComponentContext.java
Log:
Formatting changes only.
Revision Changes Path
1.3 +154 -158
jakarta-struts/src/share/org/apache/struts/tiles/ComponentContext.java
Index: ComponentContext.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/ComponentContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ComponentContext.java 27 Feb 2003 19:20:51 -0000 1.2
+++ ComponentContext.java 4 Jul 2003 21:41:00 -0000 1.3
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,56 +59,54 @@
*
*/
-
package org.apache.struts.tiles;
-import java.util.Map;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.PageContext;
+
import org.apache.struts.taglib.tiles.ComponentConstants;
-import java.io.Serializable;
/**
* Component context.
*/
-public class ComponentContext implements Serializable
-{
+public class ComponentContext implements Serializable {
- /**
- * Component attributes.
- */
- private Map attributes;
-
- /**
- * EmptyIterator over component attributes.
- */
- private static Iterator EMPTY_ITERATOR = new EmptyIterator();
+ /**
+ * Component attributes.
+ */
+ private Map attributes=null;
+
+ /**
+ * EmptyIterator over component attributes.
+ */
+ private static Iterator EMPTY_ITERATOR = new EmptyIterator();
/**
* Constructor.
*/
- public ComponentContext()
- {
+ public ComponentContext() {
+ super();
}
/**
* Constructor.
* @deprecated Use [EMAIL PROTECTED] #ComponentContext(Map attributes)} instead.
*/
- public ComponentContext( ComponentDefinition instance )
- {
-// try
-// {
+ public ComponentContext(ComponentDefinition instance) {
+ // try
+ // {
// instance's attributes map is never null.
- attributes = new HashMap(instance.getAttributes());
-// }
-// catch( NullPointerException ex )
-// { // no attributes in instance : silently fail.
-// }
+ attributes = new HashMap(instance.getAttributes());
+ // }
+ // catch( NullPointerException ex )
+ // { // no attributes in instance : silently fail.
+ // }
}
/**
@@ -116,93 +114,92 @@
* Create a context and set specified attributes.
* @param attributes Attributes to initialize context.
*/
- public ComponentContext( Map attributes )
- {
- if( attributes != null )
- this.attributes = new HashMap(attributes);
- }
-
- /**
- * Add all attributes to this context.
- * Copies all of the mappings from the specified attribute map to this context.
- * New attribute mappings will replace any mappings that this context had for any
of the keys
- * currently in the specified attribute map.
- * @param newAttributes Attributes to add.
- */
- public void addAll(Map newAttributes)
- {
- if( attributes == null )
- {
- attributes = new HashMap(newAttributes);
- return;
- }
- attributes.putAll( newAttributes );
- }
-
- /**
- * Add all missing attributes to this context.
- * Copies all of the mappings from the specified attributes map to this context.
- * New attribute mappings will be added only if they don't already exist in
- * this context.
- * @param defaultAttributes Attributes to add.
- */
- public void addMissing(Map defaultAttributes)
- {
- if( defaultAttributes == null )
- return;
- if( attributes == null )
- {
- attributes = new HashMap(defaultAttributes);
- return;
- }
-
- Set entries = defaultAttributes.entrySet();
- Iterator iterator = entries.iterator();
- while( iterator.hasNext() )
- {
- Map.Entry entry = (Map.Entry)iterator.next();
- if( !attributes.containsKey( entry.getKey()) )
- {
- attributes.put(entry.getKey(), entry.getValue());
- } // end if
- } // end loop
- }
-
- /**
- * Get an attribute from context.
- * @param name Name of the attribute.
- * @return <{Object}>
- */
- public Object getAttribute(String name)
- {
- if( attributes == null )
- return null;
- return attributes.get( name );
- }
-
- /**
- * Get names of all attributes.
- * @return <{Object}>
- */
- public Iterator getAttributeNames()
- {
- if( attributes == null )
- return EMPTY_ITERATOR;
- return attributes.keySet().iterator();
- }
-
- /**
- * Put a new attribute to context.
- * @param name Name of the attribute.
- * @param value Value of the attribute.
- */
- public void putAttribute(String name, Object value)
- {
- if( attributes == null )
- attributes = new HashMap();
+ public ComponentContext(Map attributes) {
+ if (attributes != null) {
+ this.attributes = new HashMap(attributes);
+ }
+ }
+
+ /**
+ * Add all attributes to this context.
+ * Copies all of the mappings from the specified attribute map to this context.
+ * New attribute mappings will replace any mappings that this context had for
any of the keys
+ * currently in the specified attribute map.
+ * @param newAttributes Attributes to add.
+ */
+ public void addAll(Map newAttributes) {
+ if (attributes == null) {
+ attributes = new HashMap(newAttributes);
+ return;
+ }
+
+ attributes.putAll(newAttributes);
+ }
+
+ /**
+ * Add all missing attributes to this context.
+ * Copies all of the mappings from the specified attributes map to this context.
+ * New attribute mappings will be added only if they don't already exist in
+ * this context.
+ * @param defaultAttributes Attributes to add.
+ */
+ public void addMissing(Map defaultAttributes) {
+ if (defaultAttributes == null) {
+ return;
+ }
+
+ if (attributes == null) {
+ attributes = new HashMap(defaultAttributes);
+ return;
+ }
+
+ Set entries = defaultAttributes.entrySet();
+ Iterator iterator = entries.iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (!attributes.containsKey(entry.getKey())) {
+ attributes.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Get an attribute from context.
+ * @param name Name of the attribute.
+ * @return <{Object}>
+ */
+ public Object getAttribute(String name) {
+ if (attributes == null){
+ return null;
+ }
+
+ return attributes.get(name);
+ }
- attributes.put( name, value );
- }
+ /**
+ * Get names of all attributes.
+ * @return <{Object}>
+ */
+ public Iterator getAttributeNames() {
+ if (attributes == null) {
+ return EMPTY_ITERATOR;
+ }
+
+ return attributes.keySet().iterator();
+ }
+
+ /**
+ * Put a new attribute to context.
+ * @param name Name of the attribute.
+ * @param value Value of the attribute.
+ */
+ public void putAttribute(String name, Object value) {
+ if (attributes == null) {
+ attributes = new HashMap();
+ }
+
+ attributes.put(name, value);
+ }
/**
* Find object in one of the contexts.
@@ -211,16 +208,14 @@
* @param pageContext Page context.
* @return Requested bean or <code>null</code> if not found.
*/
-
- public Object findAttribute( String beanName, PageContext pageContext)
- {
- Object attribute = getAttribute(beanName);
- if( attribute == null )
- {
- attribute = pageContext.findAttribute( beanName );
- } // end if
- return attribute;
- }
+ public Object findAttribute(String beanName, PageContext pageContext) {
+ Object attribute = getAttribute(beanName);
+ if (attribute == null) {
+ attribute = pageContext.findAttribute(beanName);
+ }
+
+ return attribute;
+ }
/**
* Get object from requested context.
@@ -230,22 +225,26 @@
* @param pageContext Page context.
* @return requested bean or <code>null</code> if not found.
*/
-
- public Object getAttribute( String beanName, int scope, PageContext pageContext)
- {
- if(scope == ComponentConstants.COMPONENT_SCOPE )
- return getAttribute(beanName);
- return pageContext.getAttribute( beanName, scope );
- }
+ public Object getAttribute(
+ String beanName,
+ int scope,
+ PageContext pageContext) {
+
+ if (scope == ComponentConstants.COMPONENT_SCOPE){
+ return getAttribute(beanName);
+ }
+
+ return pageContext.getAttribute(beanName, scope);
+ }
/**
* Get component context from request.
* @param request ServletRequest.
* @return ComponentContext
*/
- static public ComponentContext getContext( ServletRequest request )
- {
- return
(ComponentContext)request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
+ static public ComponentContext getContext(ServletRequest request) {
+ return (ComponentContext) request.getAttribute(
+ ComponentConstants.COMPONENT_CONTEXT);
}
/**
@@ -253,28 +252,25 @@
* @param context ComponentContext to store.
* @param request Request to store ComponentContext.
*/
- static public void setContext( ComponentContext context, ServletRequest request )
- {
- request.setAttribute(ComponentConstants.COMPONENT_CONTEXT, context);
- }
- }
-
-class EmptyIterator implements Iterator {
-
- public boolean hasNext()
- {
- return false;
- }
-
- public Object next()
- {
- throw new java.util.NoSuchElementException();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- } // end inner class
+ static public void setContext(
+ ComponentContext context,
+ ServletRequest request) {
+
+ request.setAttribute(ComponentConstants.COMPONENT_CONTEXT, context);
+ }
+}
+class EmptyIterator implements Iterator {
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ throw new java.util.NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+} // end inner class
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]