001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.ecm.core.event.impl;
020
021import java.security.Principal;
022
023import org.nuxeo.ecm.core.api.CoreSession;
024
025/**
026 * Default implementation
027 *
028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
029 */
030public class EventContextImpl extends AbstractEventContext {
031
032    private static final long serialVersionUID = 1L;
033
034    protected transient CoreSession session;
035
036    protected Principal principal;
037
038    /**
039     * Constructor to be used by derived classes
040     */
041    protected EventContextImpl() {
042    }
043
044    public EventContextImpl(Object... args) {
045        this(null, null, args);
046    }
047
048    public EventContextImpl(CoreSession session, Principal principal, Object... args) {
049        super(args);
050        this.session = session;
051        this.principal = principal;
052        updateRepositoryName();
053    }
054
055    public EventContextImpl(CoreSession session, Principal principal) {
056        this.session = session;
057        this.principal = principal;
058        args = EMPTY;
059        updateRepositoryName();
060    }
061
062    public void setArgs(Object[] args) {
063        this.args = args;
064    }
065
066    @Override
067    public CoreSession getCoreSession() {
068        return session;
069    }
070
071    @Override
072    public Principal getPrincipal() {
073        return principal;
074    }
075
076    @Override
077    public void setCoreSession(CoreSession session) {
078        this.session = session;
079        updateRepositoryName();
080    }
081
082    protected void updateRepositoryName() {
083        if (session != null) {
084            repositoryName = session.getRepositoryName();
085        }
086    }
087
088    @Override
089    public void setPrincipal(Principal principal) {
090        this.principal = principal;
091    }
092
093}