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

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

Many new ideas in this commit. It's still in a state of flux.
I'm exploring using decorators and class attributes with the prefix "_ows"
to declare properties that need to be in the OWS capabilities document.

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,  defaultValue=None, possibleValues=None, metadata=[],
33                 meaning=None, dataType=None, valuesUnit=None):
34        if possibleValues is None:
35            possibleValues = PossibleValues.anyValue()
36        self.possibleValues = possibleValues
37        self.defaultValue = defaultValue
38        self.metadata = metadata
39        self.meaning = meaning
40        self.dataType = dataType
41        self.valuesUnit = valuesUnit
42
43class PossibleValues(object):
44    """
45    @note: All members of the OWS PossibleValues Union are modelled in this
46        class.
47
48    @cvar ANY_VALUE: Flag selecting anyValue union attribute.
49    @cvar NO_VALUES: Flag selecting noValues union attribute.
50    @cvar ALLOWED_VALUES: Flag selecting AllowedValues union attribute.
51    @cvar VALUES_REFERENCE: Flag selecting valuesListReference union attribute
52    @ivar type: set to one of the above flags to select union attribute.
53
54    @ivar allowedValues: A collection of either values or ranges
55    @type allowedValues: Iterable of str or Range objects
56    @ivar valuesRefName
57    @type valuesRefName: None or str
58    @ivar valuesRefURI
59    @type valuesRefURI: None or str
60
61    """
62    ANY_VALUE = 1
63    NO_VALUES = 2
64    ALLOWED_VALUES = 3
65    VALUES_REFERENCE = 4
66   
67    # The union is implemented by providing a class method for each member.
68    @classmethod
69    def anyValue(klass):
70        k = klass()
71        k.type = klass.ANY_VALUE
72        return k
73
74    @classmethod
75    def noValues(klass):
76        k = klass()
77        k.type = klass.NO_VALUES
78        return k
79
80    @classmethod
81    def allowedValues(klass, valueOrRanges):
82        k = klass()
83        k.type = klass.ALLOWED_VALUES
84        k.allowedValues = valueOrRanges
85        return k
86
87    @classmethod
88    def valuesReference(klass, name, uri):
89        k = klass()
90        k.type = klass.VALUES_REFERENCE
91        k.valuesRefName = name
92        k.valuesRefURI = uri
93        return k
94
95
96class Range(object):
97    """
98    @ivar minimumValue
99    @type minimumValue: None or str
100    @ivar maximumValue
101    @type maximumValue: None or str
102    @ivar spacing
103    @type spacing: None or str
104    @ivar rangeClosure
105    @type rangeClosure: One of Range._rangeClosureValues
106
107    """
108    _rangeClosureValues = [None, 'open', 'closed', 'open-closed',
109                           'closed-open']
110   
111    def __init__(self, minumumValue=None, maximumValue=None, spacing=None,
112                 rangeClosure=None):
113        if rangeClosure not in Range._rangeClosureValues:
114            raise ValueError, 'Incorrect rangeClosure value'
115
116        self.minimumValue = minimumValue
117        self.maximumValue = maximumValue
118        self.spacing = spacing
119        self.rangeClosure = rangeClosure
120
121
122class DomainMetadata(str):
123    """
124    If you wish to attach a URI to DomainMetadata use this class, otherwise
125    you can substitute it with str.
126   
127    @ivar reference: A URI
128    @type reference: None or str
129
130    """
131
132    def __init__(self, name, reference=None):
133        super(DomainMetadata, self).__init__(name)
134        self.reference = reference
135   
136   
Note: See TracBrowser for help on using the repository browser.