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