restructuring
[lwes-java.git] / src / main / java / org / lwes / EventFactory.java
blob27a769aab8d7dcd7e34b20ae76c3a6bb3f48c6b4
1 package org.lwes;
3 import org.lwes.db.EventTemplateDB;
5 import java.io.File;
6 import java.io.InputStream;
8 public class EventFactory {
10 /* the DB for type checking and validation */
11 private EventTemplateDB eventTemplateDB = null;
13 /* the references to the ESF files for validation */
14 File esfFile = null;
15 String esfFilePath = null;
16 InputStream esfInputStream = null;
18 boolean eventTemplateDBInit = false;
20 /**
21 * EventFactory constructor. Creates an empty event template database.
23 public EventFactory() {
24 eventTemplateDB = new EventTemplateDB();
27 /**
28 * Gets the ESF file used for validation.
30 * @return the File object
32 public File getESFFile() {
33 return esfFile;
36 /**
37 * Sets an ESF file for validation.
39 * @param esfFile the File object to set
41 public void setESFFile(File esfFile) {
42 this.esfFile = esfFile;
45 /**
46 * Gets the path of an ESF file used for validation.
48 * @return the ESF file path
50 public String getESFFilePath() {
51 return this.esfFilePath;
54 /**
55 * Sets the path of an ESF file to use for validation.
57 * @param path the path to the ESF file
59 public void setESFFilePath(String path) {
60 this.esfFilePath = path;
63 /**
64 * Gets an InputStream of the ESF file to use for validation.
66 * @return the ESF InputStream object
68 public InputStream getESFInputStream() {
69 return this.esfInputStream;
72 /**
73 * Sets the InputStream of an ESF file to use for validation
75 * @param input the InputStream to use
77 public void setESFInputStream(InputStream input) {
78 this.esfInputStream = input;
81 /**
82 * Initializes the EventFactory along with pointers to the ESF file
84 * @throws EventSystemException if there is an exception with setting the ESF files
86 public void initialize() throws EventSystemException {
87 if (esfFilePath != null) {
88 File esfFile = new File(esfFilePath);
89 eventTemplateDB.setESFFile(esfFile);
92 if (esfFile != null) {
93 eventTemplateDB.setESFFile(esfFile);
96 if (esfInputStream != null) {
97 eventTemplateDB.setESFInputStream(esfInputStream);
99 eventTemplateDBInit = eventTemplateDB.initialize();
103 * Creates a validated event named <tt>eventName</tt>.
105 * @param eventName the name of the event
106 * @return the Event object
107 * @throws EventSystemException if there is a problem creating the event
109 public Event createEvent(String eventName) throws EventSystemException {
110 return createEvent(eventName, Event.DEFAULT_ENCODING);
114 * Create a validated event named <tt>eventName</tt> with specified encoding.
116 * @param eventName the name of the event
117 * @param encoding the encoding to use
118 * @return the Event object
119 * @throws EventSystemException if there is a problem creating the event
121 public Event createEvent(String eventName, short encoding) throws EventSystemException {
122 return createEvent(eventName, true, encoding);
126 * Create an event named <tt>eventName</tt> and optionally validate the event.
128 * @param eventName the name of the event
129 * @param validate whether or not to validate the event against the EventTemplateDB
130 * @return the Event object
131 * @throws EventSystemException if there is a problem creating the event
133 public Event createEvent(String eventName, boolean validate) throws EventSystemException {
134 return createEvent(eventName, validate, Event.DEFAULT_ENCODING);
138 * Create an event named <tt>eventName</tt> with optional validation and specified encoding
140 * @param eventName the name of the event
141 * @param validate whether or not to validate the event against the EventTemplateDB
142 * @param encoding the encoding to use
143 * @return the Event object
144 * @throws EventSystemException if there is a problem creating the event
146 public Event createEvent(String eventName, boolean validate, short encoding) throws EventSystemException {
147 if (validate && !eventTemplateDBInit) {
148 throw new EventSystemException("Event template db not initialized");
150 return new Event(eventName, validate, eventTemplateDB, encoding);
154 * Create an event from an array of bytes
156 * @param bytes the byte array
157 * @return the Event object
158 * @throws EventSystemException if there is a problem creating the event
160 public Event createEvent(byte[] bytes) throws EventSystemException {
161 Event e = null;
162 e = new Event(bytes, eventTemplateDB);
163 return e;
167 * Create an event from an array of bytes, with optional validation
169 * @param bytes the byte array
170 * @param validate whether or not to validate this event against the EventTemplateDB
171 * @return the Event object
172 * @throws EventSystemException if there is a problem creating the event
174 public Event createEvent(byte[] bytes, boolean validate) throws EventSystemException {
175 if (validate && !eventTemplateDBInit) {
176 throw new EventSystemException("Event template db not initialized");
178 return new Event(bytes, validate, eventTemplateDB);