1 /***************************************************************************
2 * Copyright (C) 2003-2009 eXo Platform SAS.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Affero General Public License
6 * as published by the Free Software Foundation; either version 3
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see<http://www.gnu.org/licenses/>.
16 *
17 **************************************************************************/
18 package org.exoplatform.services.cms.actions;
19
20 import javax.jcr.observation.Event;
21
22 /**
23 * Created by The eXo Platform SARL
24 * Author : Hoang Van Hung
25 * hunghvit@gmail.com
26 * Jan 4, 2010
27 */
28
29 /**
30 * Extends javax.jcr.observation.Event for defining more event Now, Event has 4
31 * defined event types: NODE_ADDED, NODE_REMOVED, PROPERTY_ADDED, PROPERTY_REMOVED,
32 * PROPERTY_CHANGED. DMS added more event below to support some events come from dms
33 * and get value of event type by name
34 */
35 public abstract class DMSEvent implements Event {
36
37 public static final int READ = 2048;
38
39 public static final int SCHEDULE = 4096;
40
41 public static int getEventTypes(String[] lifecycle) throws NoSuchFieldException, IllegalAccessException {
42 if (lifecycle == null)
43 throw new IllegalArgumentException("lifecycle null");
44 int eventType = 0;
45 for (String event : lifecycle) {
46 eventType = eventType | getEventType(event);
47 }
48 return eventType;
49 }
50
51 public static int getEventType(String event) throws NoSuchFieldException, IllegalAccessException {
52 if (event == null) throw new IllegalArgumentException("event null");
53 try {
54 return DMSEvent.class.getField(event.toUpperCase()).getInt(null);
55 } catch (NoSuchFieldException ns){
56 throw ns;
57 } catch (IllegalAccessException ace) {
58 throw ace;
59 }
60 }
61 }