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 *     Thierry Delprat
011 */
012
013package org.nuxeo.ecm.core.event.impl;
014
015import java.io.Serializable;
016import java.security.Principal;
017import java.util.Map;
018
019import org.nuxeo.ecm.core.api.CoreSession;
020import org.nuxeo.ecm.core.event.Event;
021
022/**
023 * Minimal eventContext implementation that can be used for events that are not bound to a CoreSession.
024 *
025 * @author Thierry Delprat
026 */
027public class UnboundEventContext extends EventContextImpl {
028
029    private static final long serialVersionUID = 1L;
030
031    protected boolean boundToCoreSession = false;
032
033    public UnboundEventContext(Principal principal, Map<String, Serializable> properties) {
034        this(null, principal, properties);
035    }
036
037    public UnboundEventContext(CoreSession session, Principal principal, Map<String, Serializable> properties) {
038        super(session, principal);
039        setProperties(properties);
040        boundToCoreSession = session != null;
041    }
042
043    @Override
044    public Event newEvent(String name) {
045        int flags = boundToCoreSession ? Event.FLAG_NONE : Event.FLAG_IMMEDIATE;
046        return newEvent(name, flags);
047    }
048
049}