KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > modules > output > RequestAttributeMap


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.modules.output;
18
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23 import org.apache.cocoon.environment.Request;
24
25 /**
26  * Abstraction layer to encapsulate different output
27  * destinations. This module outputs to a request attribute
28  * java.util.Map object that contains all the attributes that were
29  * set. Configuration option <key-prefix> defaults to
30  * "org.apache.cocoon.components.modules.output.OutputModule"
31  *
32  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
33  * @version CVS $Id: RequestAttributeMap.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public class RequestAttributeMap extends AbstractOutputModule implements OutputModule {
36     
37     public final String JavaDoc PREFIX = "org.apache.cocoon.components.modules.output.OutputModule";
38     public final String JavaDoc TRANS_PREFIX = "org.apache.cocoon.components.modules.output.OutputModule.RequestAttributeMap.transient";
39     
40     /**
41      * communicate an attribute value to further processing logic.
42      * @param modeConf column's mode configuration from resource
43      * description. This argument is optional.
44      * @param objectModel The objectModel
45      * @param name The attribute's label, consisting of "table.column"
46      * or "table.column[index]" in case of multiple attributes of the
47      * same spec.
48      * @param value The attriute's value.
49      * */

50     public void setAttribute( Configuration modeConf, Map JavaDoc objectModel, String JavaDoc name, Object JavaDoc value ) {
51         if (getLogger().isDebugEnabled())
52             getLogger().debug("setting transient ['"+name+"'] to ['"+value+"']");
53         super.transientSetAttribute(objectModel, TRANS_PREFIX, name, value );
54     }
55     
56     
57     /**
58      * If a database transaction needs to rollback, this is called to
59      * inform the further processing logic about this fact. All
60      * already set attribute values are invalidated. <em>This is difficult
61      * because only the request object can be used to synchronize this
62      * and build some kind of transaction object. Beaware that sending
63      * your data straight to some beans or other entities could result
64      * in data corruption!</em>
65      * */

66     public void rollback( Configuration modeConf, Map JavaDoc objectModel, Exception JavaDoc e ) {
67         if (getLogger().isDebugEnabled())
68             getLogger().debug("rolling back");
69         super.rollback(objectModel, TRANS_PREFIX);
70     }
71     
72     
73     /**
74      * Signal that the database transaction completed
75      * successfully. See notes on @link{rollback}.
76      * */

77     public void commit( Configuration modeConf, Map JavaDoc objectModel ) {
78         if (getLogger().isDebugEnabled())
79             getLogger().debug("prepare commit");
80         Map JavaDoc aMap = super.prepareCommit(objectModel,TRANS_PREFIX);
81         if (aMap == null) {
82             // nothing to do
83
return;
84         }
85         
86         String JavaDoc prefix = (String JavaDoc) this.settings.get("key-prefix", PREFIX);
87         Request request = ObjectModelHelper.getRequest(objectModel);
88         Object JavaDoc temp = request.getAttribute(prefix);
89         Map JavaDoc old = null;
90         if (temp == null) {
91             old = aMap;
92         } else {
93             old = (Map JavaDoc) temp;
94             old.putAll(aMap);
95         }
96         request.setAttribute(prefix, old);
97         if (getLogger().isDebugEnabled())
98             getLogger().debug("done commit to ['"+prefix+"']");
99     }
100     
101 }
102
Popular Tags