1 19 20 21 22 package org.netbeans.modules.xml.xam.spi; 23 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Collections ; 27 import java.util.List ; 28 import org.netbeans.modules.xml.xam.Model; 29 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 30 import org.openide.util.Lookup; 31 32 33 42 public class Validation { 43 44 private static Collection <Validator> validators; 45 46 static { 47 lookupProviders(); 49 } 50 51 private List <ResultItem> validationResult; 52 private List <Model> validatedModels; 53 54 public Validation() { 55 initialise(); 57 } 58 59 60 61 69 public void validate(Model model, ValidationType validationType) { 70 72 if (validatedModels.contains(model)) 73 return; 74 75 validatedModels.add(model); 76 for(Validator provider: validators) { 78 ValidationResult result = provider.validate(model, this, validationType); 79 if (result != null) { 80 validationResult.addAll(result.getValidationResult()); 82 83 validatedModels.addAll(result.getValidatedModels()); 85 } 86 } 87 } 88 89 90 91 94 public List <ResultItem> getValidationResult() { 95 return validationResult; 96 } 97 98 99 102 public List <Model> getValidatedModels() { 103 return Collections.unmodifiableList(validatedModels); 104 } 105 106 107 114 public enum ValidationType { 115 COMPLETE, PARTIAL 116 } 117 118 119 120 123 private void initialise() { 124 validationResult = new ArrayList <ResultItem>(); 125 validatedModels = new ArrayList <Model>(); 126 } 127 128 129 132 private static void lookupProviders() { 133 134 if(validators != null) 135 return; 136 137 validators = new ArrayList <Validator>(); 138 139 Lookup.Result result = Lookup.getDefault().lookup( 141 new Lookup.Template(Validator.class)); 142 143 for(Object obj: result.allInstances()) { 144 Validator validator = (Validator) obj; 145 validators.add(validator); 146 } 147 } 149 150 151 152 } 153 | Popular Tags |