001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     bstefanescu
011 */
012package org.nuxeo.ecm.core.event.impl;
013
014import java.security.Principal;
015
016import org.nuxeo.ecm.core.api.CoreSession;
017
018/**
019 * Default implementation
020 *
021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
022 */
023public class EventContextImpl extends AbstractEventContext {
024
025    private static final long serialVersionUID = 1L;
026
027    protected CoreSession session;
028
029    protected Principal principal;
030
031    /**
032     * Constructor to be used by derived classes
033     */
034    protected EventContextImpl() {
035    }
036
037    public EventContextImpl(Object... args) {
038        this(null, null, args);
039    }
040
041    public EventContextImpl(CoreSession session, Principal principal, Object... args) {
042        super(args);
043        this.session = session;
044        this.principal = principal;
045        updateRepositoryName();
046    }
047
048    public EventContextImpl(CoreSession session, Principal principal) {
049        this.session = session;
050        this.principal = principal;
051        args = EMPTY;
052        updateRepositoryName();
053    }
054
055    public void setArgs(Object[] args) {
056        this.args = args;
057    }
058
059    @Override
060    public CoreSession getCoreSession() {
061        return session;
062    }
063
064    @Override
065    public Principal getPrincipal() {
066        return principal;
067    }
068
069    @Override
070    public void setCoreSession(CoreSession session) {
071        this.session = session;
072        updateRepositoryName();
073    }
074
075    protected void updateRepositoryName() {
076        if (session != null) {
077            repositoryName = session.getRepositoryName();
078        }
079    }
080
081    @Override
082    public void setPrincipal(Principal principal) {
083        this.principal = principal;
084    }
085
086}