nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2005 IBM Corporation and others. |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 7 | * |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
david_williams | 5677702 | 2005-04-11 06:21:55 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.html.core.internal.validate; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 12 | |
| 13 | import java.util.Iterator; |
| 14 | import java.util.Vector; |
| 15 | |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 16 | import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; |
david_williams | 3bcfe39 | 2005-04-13 04:49:36 +0000 | [diff] [blame] | 17 | import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; |
| 18 | import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 19 | import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; |
| 20 | |
| 21 | abstract class CompositeValidator extends ValidationComponent { |
| 22 | |
| 23 | protected Vector components = new Vector(); |
| 24 | |
| 25 | /** |
| 26 | * CompositeValidator constructor comment. |
| 27 | */ |
| 28 | public CompositeValidator() { |
| 29 | super(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | */ |
| 34 | public void setReporter(ValidationReporter reporter) { |
| 35 | super.setReporter(reporter); |
| 36 | |
| 37 | Iterator i = components.iterator(); |
| 38 | while (i.hasNext()) { |
| 39 | ValidationAdapter component = (ValidationAdapter) i.next(); |
| 40 | if (component == null) |
| 41 | continue; |
| 42 | component.setReporter(reporter); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | */ |
| 48 | public void validate(IndexedRegion node) { |
| 49 | Iterator i = components.iterator(); |
| 50 | while (i.hasNext()) { |
| 51 | ValidationComponent component = (ValidationComponent) i.next(); |
| 52 | if (component == null) |
| 53 | continue; |
| 54 | component.validate(node); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | */ |
| 60 | void add(ValidationComponent validator) { |
| 61 | components.add(validator); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * This method registers all components in 'validators'. |
| 66 | * Each derivative must call this methid in its constructor. |
| 67 | */ |
| 68 | protected void register(ValidationComponent[] validators) { |
| 69 | for (int i = 0; i < validators.length; i++) { |
| 70 | if (validators[i] != null) |
| 71 | add(validators[i]); |
| 72 | } |
| 73 | } |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 74 | } |