0
|
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 |
|
3
|
17 |
import pkg_resources
|
|
18 |
from cone.public import exceptions, plugin, utils
|
0
|
19 |
import exampleml_impl
|
|
20 |
import exampleml_model
|
|
21 |
|
|
22 |
class ExamplemlReader(plugin.ReaderBase):
|
|
23 |
NAMESPACE = 'http://www.example.org/xml/exampleml/1'
|
3
|
24 |
NAMESPACE_ID = 'exampleml'
|
|
25 |
ROOT_ELEMENT_NAME = 'exampleml'
|
|
26 |
SCHEMA_PROBLEM_SUB_ID = 'exampleml'
|
0
|
27 |
FILE_EXTENSIONS = ['exampleml']
|
|
28 |
|
|
29 |
@classmethod
|
|
30 |
def read_impl(cls, resource_ref, configuration, etree):
|
|
31 |
reader = ExamplemlReader()
|
|
32 |
outputs = reader._read_outputs(etree)
|
|
33 |
return exampleml_impl.ExamplemlImpl(resource_ref, configuration, outputs)
|
|
34 |
|
3
|
35 |
@classmethod
|
|
36 |
def get_schema_data(cls):
|
|
37 |
return pkg_resources.resource_string('examplemlplugin', 'xsd/exampleml.xsd')
|
|
38 |
|
0
|
39 |
def _read_outputs(self, elem):
|
|
40 |
"""
|
|
41 |
Read output objects from the given XML element.
|
|
42 |
"""
|
|
43 |
result = []
|
|
44 |
for subelem in elem.findall("{%s}output" % self.NAMESPACE):
|
|
45 |
result.append(self._read_output_elem(subelem))
|
|
46 |
return result
|
|
47 |
|
|
48 |
def _read_output_elem(self, elem):
|
|
49 |
"""
|
|
50 |
Read an <output> element into an Output object.
|
|
51 |
"""
|
|
52 |
file = elem.get('file')
|
|
53 |
if file is None:
|
|
54 |
raise exceptions.ParseError("Element <output> does not have the mandatory 'file' attribute")
|
|
55 |
return exampleml_model.Output(file = file,
|
|
56 |
encoding = elem.get('encoding', 'UTF-8'),
|
3
|
57 |
text = elem.text or '',
|
|
58 |
lineno = utils.etree.get_lineno(elem))
|