source: TI05-delivery/ows_framework/trunk/ows_common/domain.py @ 2475

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_common/domain.py@2475
Revision 2475, 3.8 KB checked in by spascoe, 12 years ago (diff)

renaming part 2

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Classes modelling the OWS Domain package v1.1.0.
7
8@author: Stephen Pascoe
9"""
10
11from ows_common.common import Metadata
12
13class Domain(object):
14    """
15    @note: It seems unnecessary to model Domain and UnNamedDomain seperately.
16        This class models both.
17
18    @ivar defaultValue
19    @type defaultValue: None or str
20    @ivar metadata
21    @type metadata: iterable of Metadata
22    @ivar meaning
23    @type meaning: None, DomainMetadata or str
24    @ivar dataType
25    @type dataType: None, DomainMetadata or str
26    @ivar valuesUnit
27    @type valuesUnit: None or ValuesUnit
28    @ivar possibleValues
29    @type possibleValues: PossibleValues
30
31    """
32    def __init__(self, possibleValues, defaultValue=None, metadata=[],
33                 meaning=None, dataType=None, valuesUnit):
34        self.possibleValues = possibleValues
35        self.defaultValue = defaultValue
36        self.metadata = metadata
37        self.meaning = meaning
38        self.dataType = dataType
39        self.valuesUnit = valuesUnit
40
41class PossibleValues(object):
42    """
43    @note: All members of the OWS PossibleValues Union are modelled in this
44        class.
45
46    @cvar ANY_VALUE: Flag selecting anyValue union attribute.
47    @cvar NO_VALUES: Flag selecting noValues union attribute.
48    @cvar ALLOWED_VALUES: Flag selecting AllowedValues union attribute.
49    @cvar VALUES_REFERENCE: Flag selecting valuesListReference union attribute
50    @ivar type: set to one of the above flags to select union attribute.
51
52    @ivar allowedValues: A collection of either values or ranges
53    @type allowedValues: Iterable of str or Range objects
54    @ivar valuesRefName
55    @type valuesRefName: None or str
56    @ivar valuesRefURI
57    @type valuesRefURI: None or str
58
59    """
60    ANY_VALUE = 1
61    NO_VALUES = 2
62    ALLOWED_VALUES = 3
63    VALUES_REFERENCE = 4
64   
65    # The union is implemented by providing a class method for each member.
66    @classmethod
67    def anyValue(klass):
68        k = klass()
69        k.type = klass.ANY_VALUE
70        return k
71
72    @classmethod
73    def noValues(klass):
74        k = klass()
75        k.type = klass.NO_VALUES
76        return k
77
78    @classmethod
79    def allowedValues(klass, valueOrRanges):
80        k = klass()
81        k.type = klass.ALLOWED_VALUES
82        k.allowedValues = valueOrRanges
83
84    @classmethod
85    def valuesReference(klass, name, uri):
86        k = klass()
87        k.type = klass.VALUES_REFERENCE
88        k.valuesRefName = name
89        k.valuesRefURI = uri
90        return k
91
92
93class Range(object):
94    """
95    @ivar minimumValue
96    @type minimumValue: None or str
97    @ivar maximumValue
98    @type maximumValue: None or str
99    @ivar spacing
100    @type spacing: None or str
101    @ivar rangeClosure
102    @type rangeClosure: One of Range._rangeClosureValues
103
104    """
105    _rangeClosureValues = [None, 'open', 'closed', 'open-closed',
106                           'closed-open']
107   
108    def __init__(self, minumumValue=None, maximumValue=None, spacing=None,
109                 rangeClosure=None):
110        if rangeClosure not in Range._rangeClosureValues:
111            raise ValueError, 'Incorrect rangeClosure value'
112
113        self.minimumValue = minimumValue
114        self.maximumValue = maximumValue
115        self.spacing = spacing
116        self.rangeClosure = rangeClosure
117
118
119class DomainMetadata(str):
120    """
121    If you wish to attach a URI to DomainMetadata use this class, otherwise
122    you can substitute it with str.
123   
124    @ivar reference: A URI
125    @type reference: None or str
126
127    """
128    __slots__ = ['reference']
129
130    def __init__(self, name, reference=None):
131        super(DomainMetadata, self).__init__(name)
132        self.reference = reference
133   
134   
Note: See TracBrowser for help on using the repository browser.