Package: ValidateBeforeSaveStrategy

ValidateBeforeSaveStrategy

nameinstructionbranchcomplexitylinemethod
ValidateBeforeSaveStrategy()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
precondition(Resource)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
save(Resource)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2015 RCP Vision (http://www.rcp-vision.com) and others.
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
7: *
8: * Contributors:
9: * Lorenzo Bettini - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.emf.parsley.resource;
12:
13: import java.io.IOException;
14:
15: import org.eclipse.emf.ecore.resource.Resource;
16: import org.eclipse.emf.parsley.validation.IssueReporter;
17: import org.eclipse.emf.parsley.validation.ValidationRunner;
18:
19: import com.google.inject.Inject;
20:
21: /**
22: * Before saving the {@link Resource} it validates it, and effectively save it
23: * only if there are no errors.
24: *
25: * @author Lorenzo Bettini - initial API and implementation
26: *
27: */
28: public class ValidateBeforeSaveStrategy extends ResourceSaveStrategy {
29:
30:         @Inject
31:         private ValidationRunner validationRunner;
32:
33:         @Inject
34:         private IssueReporter issueReporter;
35:
36:         @Override
37:         public boolean save(Resource resource) throws IOException {
38:•                if (!precondition(resource)) {
39:                         return false;
40:                 }
41:                 return super.save(resource);
42:         }
43:
44:         protected boolean precondition(Resource resource) {
45:•                return validationRunner.validate(resource, issueReporter).size() == 0;
46:         }
47: }