001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.cms.impl.jcr;
023:
024: import org.jboss.portal.cms.CMSException;
025: import org.jboss.portal.common.invocation.AbstractInvocationContext;
026: import org.jboss.portal.common.invocation.Scope;
027: import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
028:
029: import javax.jcr.Session;
030: import java.io.Serializable;
031: import java.util.HashMap;
032: import java.util.Locale;
033: import java.util.Map;
034:
035: /**
036: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
037: * @version $Revision: 7163 $
038: */
039: public class JCRCommandContext extends AbstractInvocationContext
040: implements Serializable {
041: public static final Scope scope = Scope.THREAD_SCOPE;
042:
043: private transient final Session session;
044:
045: private transient final JCRCommandFactory commandFactory;
046:
047: private transient final Locale locale;
048:
049: private Map clusterContext = null;
050:
051: public JCRCommandContext(Session session,
052: JCRCommandFactory factory, Locale locale) {
053: this .session = session;
054: this .commandFactory = factory;
055: this .locale = locale;
056: this .addResolver(JCRCommandContext.scope,
057: new MapAttributeResolver());
058: }
059:
060: public JCRCommandFactory getCommandFactory() {
061: return commandFactory;
062: }
063:
064: public Session getSession() {
065: return session;
066: }
067:
068: public Object execute(JCRCommand cmd) throws CMSException {
069: cmd.setContext(this );
070: return cmd.execute();
071: }
072:
073: public Locale getDefaultLocale() {
074: return locale;
075: }
076:
077: /**
078: * @param key
079: * @param data
080: */
081: public void setClusterContextInfo(String key, Object data) {
082: this .getClusterContext().put(key, data);
083: }
084:
085: /**
086: * @param key
087: * @return
088: */
089: public Object getClusterContextInfo(String key) {
090: return this .getClusterContext().get(key);
091: }
092:
093: /**
094: * Instantiates the cluser context only on-demand
095: *
096: * @return
097: */
098: private Map getClusterContext() {
099: if (this .clusterContext == null) {
100: this .clusterContext = new HashMap();
101: }
102: return this.clusterContext;
103: }
104: }
|