1 16 package org.apache.juddi.validator; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.juddi.datatype.CategoryBag; 21 import org.apache.juddi.util.Config; 22 import org.apache.juddi.util.Loader; 23 24 35 public class ValidatorFactory 36 { 37 private static Log log = LogFactory.getLog(ValidatorFactory.class); 39 40 private static final String IMPL_KEY = "juddi.validation"; 42 private static final String DEFAULT_IMPL = "org.apache.juddi.validation.DefaultValidation"; 43 44 private static Validator validation = null; 46 47 52 public static Validator getValidation() 53 { 54 if (validation == null) 55 validation = createValidation(); 56 return validation; 57 } 58 59 64 private static synchronized Validator createValidation() 65 { 66 if (validation != null) 67 return validation; 68 69 String className = Config.getStringProperty(IMPL_KEY,DEFAULT_IMPL); 71 72 log.debug("Validation Implementation = " + className); 74 75 Class implClass = null; 76 try 77 { 78 implClass = Loader.getClassForName(className); 80 } 81 catch(ClassNotFoundException e) 82 { 83 log.error("The specified Validation class '" + className + 84 "' was not found in classpath."); 85 log.error(e); 86 } 87 88 try 89 { 90 validation = (Validator)implClass.newInstance(); 92 } 93 catch(Exception e) 94 { 95 log.error("Exception while attempting to instantiate the " + 96 "implementation of Validation: " + implClass.getName() + 97 "\n" + e.getMessage()); 98 log.error(e); 99 } 100 101 return validation; 102 } 103 104 105 106 107 108 109 110 public static void main(String [] args) 111 throws Exception 112 { 113 Validator validation = ValidatorFactory.getValidation(); 114 if (validation != null) 115 { 116 System.out.println("Got a Validation instance: "+validation.getClass().getName()); 117 118 if (validation.validate(new CategoryBag())) 119 System.out.println("The objct was successfully validated."); 120 else 121 System.out.println("Sorry validation failed."); 122 } 123 else 124 System.out.println("Couldn't get a Validation instance."); 125 } 126 } | Popular Tags |