001/* 002 * Copyright (c) 2006-2012 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 org.nuxeo.ecm.core.event.Event; 015import org.nuxeo.ecm.core.event.EventContext; 016 017/** 018 * Event implementation. 019 * 020 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 021 */ 022public class EventImpl implements Event { 023 024 private static final long serialVersionUID = 1L; 025 026 protected final String name; 027 028 protected final long time; 029 030 protected final EventContext ctx; 031 032 protected int flags; 033 034 protected Exception rollbackException; 035 036 protected String rollbackMessage; 037 038 public EventImpl(String name, EventContext ctx, int flags, long creationTime) { 039 this.name = name; 040 this.ctx = ctx; 041 time = creationTime; 042 this.flags = flags; 043 } 044 045 public EventImpl(String name, EventContext ctx, int flags) { 046 this(name, ctx, flags, System.currentTimeMillis()); 047 } 048 049 public EventImpl(String name, EventContext ctx) { 050 this(name, ctx, FLAG_NONE); 051 } 052 053 @Override 054 public int getFlags() { 055 return flags; 056 } 057 058 @Override 059 public EventContext getContext() { 060 return ctx; 061 } 062 063 @Override 064 public String getName() { 065 return name; 066 } 067 068 @Override 069 public long getTime() { 070 return time; 071 } 072 073 @Override 074 public void cancel() { 075 flags |= FLAG_CANCEL; 076 } 077 078 @Override 079 public void markRollBack() { 080 flags |= FLAG_ROLLBACK; 081 } 082 083 @Override 084 public void markRollBack(String message, Exception exception) { 085 markRollBack(); 086 if (message == null && exception != null) { 087 message = exception.getMessage(); 088 } 089 rollbackMessage = message; 090 rollbackException = exception; 091 } 092 093 @Override 094 public void markBubbleException() { 095 flags |= FLAG_BUBBLE_EXCEPTION; 096 } 097 098 @Override 099 public boolean isBubbleException() { 100 return (flags & FLAG_BUBBLE_EXCEPTION) != 0; 101 } 102 103 @Override 104 public boolean isMarkedForRollBack() { 105 return (flags & FLAG_ROLLBACK) != 0; 106 } 107 108 @Override 109 public boolean isCanceled() { 110 return (flags & FLAG_CANCEL) != 0; 111 } 112 113 @Override 114 public boolean isInline() { 115 return (flags & FLAG_INLINE) != 0; 116 } 117 118 @Override 119 public void setInline(boolean isInline) { 120 if (isInline) { 121 flags |= FLAG_INLINE; 122 } else { 123 flags &= ~FLAG_INLINE; 124 } 125 } 126 127 @Override 128 public boolean isCommitEvent() { 129 return (flags & FLAG_COMMIT) != 0; 130 } 131 132 @Override 133 public void setIsCommitEvent(boolean isCommit) { 134 if (isCommit) { 135 flags |= FLAG_COMMIT; 136 } else { 137 flags &= ~FLAG_COMMIT; 138 } 139 } 140 141 @Override 142 public boolean isLocal() { 143 return (flags & FLAG_LOCAL) != 0; 144 } 145 146 @Override 147 public void setLocal(boolean isLocal) { 148 if (isLocal) { 149 flags |= FLAG_LOCAL; 150 } else { 151 flags &= ~FLAG_LOCAL; 152 } 153 } 154 155 @Override 156 public boolean isPublic() { 157 return !isLocal(); 158 } 159 160 @Override 161 public void setPublic(boolean isPublic) { 162 setLocal(!isPublic); 163 } 164 165 @Override 166 public boolean isImmediate() { 167 return (flags & FLAG_IMMEDIATE) != 0; 168 } 169 170 @Override 171 public void setImmediate(boolean immediate) { 172 if (immediate) { 173 flags |= FLAG_IMMEDIATE; 174 } else { 175 flags &= ~FLAG_IMMEDIATE; 176 } 177 } 178 179 @Override 180 public Exception getRollbackException() { 181 return rollbackException; 182 } 183 184 @Override 185 public String getRollbackMessage() { 186 return rollbackMessage; 187 } 188 189}