Skip to content

Package: ValidationService

ValidationService

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Mat Hansen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.common.spi.validation;
15:
16: import java.util.Iterator;
17: import java.util.Set;
18:
19: import org.eclipse.emf.common.util.Diagnostic;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider;
22: import org.eclipse.emfforms.common.spi.validation.exception.ValidationCanceledException;
23: import org.eclipse.emfforms.common.spi.validation.filter.DiagnosticFilter;
24: import org.eclipse.emfforms.common.spi.validation.filter.ObjectFilter;
25: import org.eclipse.emfforms.common.spi.validation.filter.SubTreeFilter;
26: import org.eclipse.emfforms.common.spi.validation.filter.ValidationFilter;
27:
28: /**
29: * Generic EMF validation service which allows validation of a collection of {@link EObject}s
30: * honoring defined EValidators. Additionally custom {@link Validator}s can be registered
31: * i.e. if the feature set of the EValidators is insufficient.
32: *
33: * @author Mat Hansen <mhansen@eclipsesource.com>
34: */
35: public interface ValidationService {
36:
37:         /**
38:          * Adds a validation provider to the list of known validators.
39:          *
40:          * @param validator the {@link Validator} to add
41:          */
42:         void addValidator(Validator validator);
43:
44:         /**
45:          * Removes a validation provider from the list of known validators.
46:          *
47:          * @param validator the {@link Validator} to remove
48:          */
49:         void removeValidator(Validator validator);
50:
51:         /**
52:          * Registers a validation filter.
53:          *
54:          * @param <Filter> an {@link ValidationFilter} implementation
55:          * @param filter the {@link ValidationFilter} to register
56:          * @deprecated Use addSubTreeFilter, addObjectFilter and addDiagnosticFilter instead
57:          */
58:         @Deprecated
59:         <Filter extends ValidationFilter> void registerValidationFilter(Filter filter);
60:
61:         /**
62:          * Unregisters a validation filter.
63:          *
64:          * @param <Filter> an {@link ValidationFilter} implementation
65:          * @param filter the {@link ValidationFilter} to unregister
66:          * @deprecated Use removeSubTreeFilter, removeObjectFilter and removeDiagnosticFilter instead
67:          */
68:         @Deprecated
69:         <Filter extends ValidationFilter> void unregisterValidationFilter(Filter filter);
70:
71:         /**
72:          * Registers a {@link ValidationResultListener}.
73:          *
74:          * @param listener the {@link ValidationResultListener} to register
75:          */
76:         void registerValidationResultListener(ValidationResultListener listener);
77:
78:         /**
79:          * Unregisters a {@link ValidationResultListener}.
80:          *
81:          * @param listener the {@link ValidationResultListener} to unregister
82:          */
83:         void unregisterValidationResultListener(ValidationResultListener listener);
84:
85:         /**
86:          * Set a {@link SubstitutionLabelProvider} to be used for substituting labels in {@link Diagnostic}s.
87:          *
88:          * @see org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider
89:          *
90:          * @param substitutionLabelProvider the {@link SubstitutionLabelProvider} to be set for this service
91:          */
92:         void setSubstitutionLabelProvider(SubstitutionLabelProvider substitutionLabelProvider);
93:
94:         /**
95:          * Validates the given eObject.
96:          *
97:          * @param eObject the eObject to validate
98:          * @return the resulting {@link Diagnostic}, or null if the eObject is filtered by a {@link ValidationFilter}
99:          */
100:         Diagnostic validate(EObject eObject);
101:
102:         /**
103:          * Uses the given iterator to validate all eObjects in a collection.
104:          *
105:          * @param eObjects the list to validate
106:          * @return the resulting set of {@link Diagnostic}s
107:          * @throws ValidationCanceledException in case {@link #cancel()} has been called
108:          */
109:         Set<Diagnostic> validate(Iterator<EObject> eObjects) throws ValidationCanceledException;
110:
111:         /**
112:          * Returns true as long as a validation is in process.
113:          * Not applicable for single validation runs with {@link #validate(EObject)}.
114:          * See {@link #cancel()} to interrupt a running validation process.
115:          *
116:          * @return true as long as a validation is running, false otherwise.
117:          */
118:         boolean isBusy();
119:
120:         /**
121:          * Allows to cancel the current validation run (if any).
122:          * Not applicable for single validation runs with {@link #validate(EObject)}.
123:          */
124:         void cancel();
125:
126:         /**
127:          * Adds a {@link SubTreeFilter} to skip specific sub trees during the validation. <code>null</code>
128:          * is ignored.
129:          *
130:          * @param subTreeFilter {@link SubTreeFilter}
131:          */
132:         void addSubTreeFilter(SubTreeFilter subTreeFilter);
133:
134:         /**
135:          * Adds an {@link ObjectFilter} to skip specific EObjects during the validation. <code>null</code> is
136:          * ignored.
137:          *
138:          * @param objectFilter {@link ObjectFilter}
139:          */
140:         void addObjectFilter(ObjectFilter objectFilter);
141:
142:         /**
143:          * Adds a {@link DiagnosticFilter} to remove specific {@link Diagnostic} from the result of a
144:          * validation. <code>null</code> is ignored.
145:          *
146:          * @param diagnosticFilter {@link DiagnosticFilter}
147:          */
148:         void addDiagnosticFilter(DiagnosticFilter diagnosticFilter);
149:
150:         /**
151:          * Removes a {@link SubTreeFilter}.
152:          *
153:          * @param subTreeFilter {@link SubTreeFilter}
154:          */
155:         void removeSubTreeFilter(SubTreeFilter subTreeFilter);
156:
157:         /**
158:          * Removes an {@link ObjectFilter}.
159:          *
160:          * @param objectFilter {@link ObjectFilter}
161:          */
162:         void removeObjectFilter(ObjectFilter objectFilter);
163:
164:         /**
165:          * Removes a {@link DiagnosticFilter}.
166:          *
167:          * @param diagnosticFilter {@link DiagnosticFilter}
168:          */
169:         void removeDiagnosticFilter(DiagnosticFilter diagnosticFilter);
170:
171: }