removed a debug
[lwes-java.git] / src / main / java / org / lwes / EventFactory.java
blobe31fe4ec4ee23ddf666950508498309c9e5545b0
1 /*======================================================================*
2 * Copyright (c) 2008, Yahoo! Inc. All rights reserved. *
3 * *
4 * Licensed under the New BSD License (the "License"); you may not use *
5 * this file except in compliance with the License. Unless required *
6 * by applicable law or agreed to in writing, software distributed *
7 * under the License is distributed on an "AS IS" BASIS, WITHOUT *
8 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
9 * See the License for the specific language governing permissions and *
10 * limitations under the License. See accompanying LICENSE file. *
11 *======================================================================*/
13 package org.lwes;
15 import org.lwes.db.EventTemplateDB;
17 import java.io.File;
18 import java.io.InputStream;
20 public class EventFactory {
22 /* the DB for type checking and validation */
23 private EventTemplateDB eventTemplateDB = null;
25 /* the references to the ESF files for validation */
26 File esfFile = null;
27 String esfFilePath = null;
28 InputStream esfInputStream = null;
30 boolean eventTemplateDBInit = false;
32 /**
33 * EventFactory constructor. Creates an empty event template database.
35 public EventFactory() {
36 eventTemplateDB = new EventTemplateDB();
39 /**
40 * Gets the ESF file used for validation.
42 * @return the File object
44 public File getESFFile() {
45 return esfFile;
48 /**
49 * Sets an ESF file for validation.
51 * @param esfFile the File object to set
53 public void setESFFile(File esfFile) {
54 this.esfFile = esfFile;
57 /**
58 * Gets the path of an ESF file used for validation.
60 * @return the ESF file path
62 public String getESFFilePath() {
63 return this.esfFilePath;
66 /**
67 * Sets the path of an ESF file to use for validation.
69 * @param path the path to the ESF file
71 public void setESFFilePath(String path) {
72 this.esfFilePath = path;
75 /**
76 * Gets an InputStream of the ESF file to use for validation.
78 * @return the ESF InputStream object
80 public InputStream getESFInputStream() {
81 return this.esfInputStream;
84 /**
85 * Sets the InputStream of an ESF file to use for validation
87 * @param input the InputStream to use
89 public void setESFInputStream(InputStream input) {
90 this.esfInputStream = input;
93 /**
94 * Initializes the EventFactory along with pointers to the ESF file
96 * @throws EventSystemException if there is an exception with setting the ESF files
98 public void initialize() throws EventSystemException {
99 if (esfFilePath != null) {
100 File esfFile = new File(esfFilePath);
101 eventTemplateDB.setESFFile(esfFile);
104 if (esfFile != null) {
105 eventTemplateDB.setESFFile(esfFile);
108 if (esfInputStream != null) {
109 eventTemplateDB.setESFInputStream(esfInputStream);
111 eventTemplateDBInit = eventTemplateDB.initialize();
115 * Creates a validated event named <tt>eventName</tt>.
117 * @param eventName the name of the event
118 * @return the Event object
119 * @throws EventSystemException if there is a problem creating the event
121 public Event createEvent(String eventName) throws EventSystemException {
122 return createEvent(eventName, Event.DEFAULT_ENCODING);
126 * Create a validated event named <tt>eventName</tt> with specified encoding.
128 * @param eventName the name of the event
129 * @param encoding the encoding to use
130 * @return the Event object
131 * @throws EventSystemException if there is a problem creating the event
133 public Event createEvent(String eventName, short encoding) throws EventSystemException {
134 return createEvent(eventName, true, encoding);
138 * Create an event named <tt>eventName</tt> and optionally validate the event.
140 * @param eventName the name of the event
141 * @param validate whether or not to validate the event against the EventTemplateDB
142 * @return the Event object
143 * @throws EventSystemException if there is a problem creating the event
145 public Event createEvent(String eventName, boolean validate) throws EventSystemException {
146 return createEvent(eventName, validate, Event.DEFAULT_ENCODING);
150 * Create an event named <tt>eventName</tt> with optional validation and specified encoding
152 * @param eventName the name of the event
153 * @param validate whether or not to validate the event against the EventTemplateDB
154 * @param encoding the encoding to use
155 * @return the Event object
156 * @throws EventSystemException if there is a problem creating the event
158 public Event createEvent(String eventName, boolean validate, short encoding) throws EventSystemException {
159 if (validate && !eventTemplateDBInit) {
160 throw new EventSystemException("Event template db not initialized");
162 return new Event(eventName, validate, eventTemplateDB, encoding);
166 * Create an event from an array of bytes
168 * @param bytes the byte array
169 * @return the Event object
170 * @throws EventSystemException if there is a problem creating the event
172 public Event createEvent(byte[] bytes) throws EventSystemException {
173 Event e = null;
174 e = new Event(bytes, eventTemplateDB);
175 return e;
179 * Create an event from an array of bytes, with optional validation
181 * @param bytes the byte array
182 * @param validate whether or not to validate this event against the EventTemplateDB
183 * @return the Event object
184 * @throws EventSystemException if there is a problem creating the event
186 public Event createEvent(byte[] bytes, boolean validate) throws EventSystemException {
187 if (validate && !eventTemplateDBInit) {
188 throw new EventSystemException("Event template db not initialized");
190 return new Event(bytes, validate, eventTemplateDB);