KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > verifier > factory > DefaultEventFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.verifier.factory;
23
24 /*
25  * Class org.jboss.verifier.factory.DefaultEventFactory
26  * Copyright (C) 2000 Juha Lindfors
27  *
28  * This library is free software; you can redistribute it and/or
29  * modify it under the terms of the GNU Lesser General Public
30  * License as published by the Free Software Foundation; either
31  * version 2 of the License, or (at your option) any later version
32  *
33  * This library is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36  * Lesser General Public License for more details.
37  *
38  * You should have received a copy of the GNU Lesser General Public
39  * License along with this library; if not, write to the Free Software
40  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41  *
42  * This package and its source code is available at www.jboss.org
43  * $Id: DefaultEventFactory.java 37459 2005-10-30 00:04:02Z starksm $
44  */

45
46 // standard imports
47
import java.util.MissingResourceException JavaDoc;
48 import java.util.Properties JavaDoc;
49 import java.util.Set JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.Map JavaDoc;
52 import java.util.HashMap JavaDoc;
53 import java.util.Enumeration JavaDoc;
54
55 import java.io.InputStream JavaDoc;
56 import java.io.IOException JavaDoc;
57
58 // non-standard class dependencies
59
import org.jboss.verifier.Section;
60
61 import org.jboss.verifier.event.VerificationEvent;
62 import org.jboss.verifier.event.VerificationEventGenerator;
63
64 /**
65  *
66  * @author Juha Lindfors (jplindfo@helsinki.fi)
67  * @version $Revision: 37459 $
68  * @since JDK 1.3
69  */

70 public class DefaultEventFactory
71    implements VerificationEventFactory
72 {
73    public final static String JavaDoc DEFAULT_MESSAGE_BUNDLE =
74       "/org/jboss/verifier/DefaultMessages.properties";
75
76    private Map JavaDoc msgTable = null;
77    private String JavaDoc msgBundle;
78
79    /**
80     * Default constructor using the DEFAULT_MESSAGE_BUNDLE message
81     * file.
82     *
83     * @deprecated Use the other constructor with a specific Message
84     * Bundle for your own verification logic!
85     */

86    public DefaultEventFactory()
87    {
88       this.msgBundle = DEFAULT_MESSAGE_BUNDLE;
89       msgTable = loadErrorMessages();
90    }
91
92    /**
93     * Create a DefaultEventFactory using the specified message bundle
94     * for creating the Specification Violation Events
95     */

96    public DefaultEventFactory( String JavaDoc msgBundle )
97    {
98       this.msgBundle = "/org/jboss/verifier/" + msgBundle;
99       msgTable = loadErrorMessages();
100    }
101
102    public VerificationEvent createSpecViolationEvent(
103       VerificationEventGenerator source, Section section)
104    {
105       VerificationEvent event = new VerificationEvent(source);
106
107       event.setState(VerificationEvent.WARNING);
108       event.setSection(section);
109       event.setMessage((String JavaDoc)msgTable.get(section.getSection()));
110
111       return event;
112    }
113
114    public VerificationEvent createBeanVerifiedEvent(
115       VerificationEventGenerator source)
116    {
117       VerificationEvent event = new VerificationEvent(source);
118
119       event.setState(VerificationEvent.OK);
120       event.setMessage("Verified.");
121
122       return event;
123    }
124
125    public String JavaDoc getMessageBundle() {
126       return msgBundle;
127    }
128
129 /*
130  *****************************************************************************
131  *
132  * PRIVATE INSTANCE METHODS
133  *
134  *****************************************************************************
135  */

136
137    /*
138     * loads messages from a property file
139     */

140    private Map JavaDoc loadErrorMessages()
141    {
142       try
143       {
144          InputStream JavaDoc in = getClass().getResourceAsStream( msgBundle );
145          Properties JavaDoc props = new Properties JavaDoc();
146          props.load(in);
147
148         return props;
149       }
150       catch (IOException JavaDoc e)
151       {
152          throw new MissingResourceException JavaDoc( "I/O failure: " +
153             e.getMessage(), msgBundle, "" );
154       }
155       catch (NullPointerException JavaDoc e)
156       {
157          throw new MissingResourceException JavaDoc( "Resource not found.",
158             msgBundle, "" );
159       }
160    }
161
162 }
163 /*
164 vim:ts=3:sw=3:et
165 */

166
Popular Tags