1 22 package org.jboss.verifier.factory; 23 24 45 46 import java.util.MissingResourceException ; 48 import java.util.Properties ; 49 import java.util.Set ; 50 import java.util.Iterator ; 51 import java.util.Map ; 52 import java.util.HashMap ; 53 import java.util.Enumeration ; 54 55 import java.io.InputStream ; 56 import java.io.IOException ; 57 58 import org.jboss.verifier.Section; 60 61 import org.jboss.verifier.event.VerificationEvent; 62 import org.jboss.verifier.event.VerificationEventGenerator; 63 64 70 public class DefaultEventFactory 71 implements VerificationEventFactory 72 { 73 public final static String DEFAULT_MESSAGE_BUNDLE = 74 "/org/jboss/verifier/DefaultMessages.properties"; 75 76 private Map msgTable = null; 77 private String msgBundle; 78 79 86 public DefaultEventFactory() 87 { 88 this.msgBundle = DEFAULT_MESSAGE_BUNDLE; 89 msgTable = loadErrorMessages(); 90 } 91 92 96 public DefaultEventFactory( String 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 )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 getMessageBundle() { 126 return msgBundle; 127 } 128 129 136 137 140 private Map loadErrorMessages() 141 { 142 try 143 { 144 InputStream in = getClass().getResourceAsStream( msgBundle ); 145 Properties props = new Properties (); 146 props.load(in); 147 148 return props; 149 } 150 catch (IOException e) 151 { 152 throw new MissingResourceException ( "I/O failure: " + 153 e.getMessage(), msgBundle, "" ); 154 } 155 catch (NullPointerException e) 156 { 157 throw new MissingResourceException ( "Resource not found.", 158 msgBundle, "" ); 159 } 160 } 161 162 } 163 166 | Popular Tags |