3
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
|
|
18 |
import codecs
|
|
19 |
|
|
20 |
from cone.public import api, exceptions, utils
|
|
21 |
from cone.validation.implmlvalidation import ImplValidatorBase
|
|
22 |
from examplemlplugin import exampleml_impl
|
|
23 |
|
|
24 |
class ExamplemlValidatorBase(ImplValidatorBase):
|
|
25 |
SUPPORTED_IMPL_CLASSES = exampleml_impl.ExamplemlImpl
|
|
26 |
|
|
27 |
class ExamplemlReferenceValidator(ExamplemlValidatorBase):
|
|
28 |
PROBLEM_TYPES = ['model.implml.exampleml.invalid_ref']
|
|
29 |
|
|
30 |
def validate(self):
|
|
31 |
for output in self.impl.output_objects:
|
|
32 |
# Collect all refs
|
|
33 |
refs = set()
|
|
34 |
for ref in utils.extract_delimited_tokens(output.text): refs.add(ref)
|
|
35 |
for ref in utils.extract_delimited_tokens(output.encoding): refs.add(ref)
|
|
36 |
for ref in utils.extract_delimited_tokens(output.file): refs.add(ref)
|
|
37 |
|
|
38 |
for ref in refs:
|
|
39 |
self.check_feature_reference(ref, output.lineno, self.PROBLEM_TYPES[0])
|
|
40 |
|
|
41 |
class ExamplemlEncodingValidator(ExamplemlValidatorBase):
|
|
42 |
PROBLEM_TYPES = ['model.implml.exampleml.invalid_encoding']
|
|
43 |
|
|
44 |
def validate(self):
|
|
45 |
for output in self.impl.output_objects:
|
|
46 |
encoding = None
|
|
47 |
try:
|
|
48 |
encoding = utils.expand_refs_by_default_view(
|
|
49 |
output.encoding,
|
|
50 |
self.context.configuration.get_default_view(),
|
|
51 |
catch_not_found=False)
|
|
52 |
except exceptions.NotFound:
|
|
53 |
# Ignore invalid setting references, they are validated
|
|
54 |
# in another validator
|
|
55 |
continue
|
|
56 |
|
|
57 |
if encoding is not None:
|
|
58 |
# Check the encoding
|
|
59 |
try:
|
|
60 |
codecs.lookup(encoding)
|
|
61 |
except LookupError:
|
|
62 |
prob = api.Problem(
|
|
63 |
msg = u"Invalid encoding '%s'" % encoding,
|
|
64 |
type = self.PROBLEM_TYPES[0],
|
|
65 |
line = output.lineno,
|
|
66 |
file = self.impl.ref)
|
|
67 |
self.context.problems.append(prob)
|
|
68 |
|
|
69 |
VALIDATOR_CLASSES = [ExamplemlReferenceValidator, ExamplemlEncodingValidator]
|