Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/tags/RELEASE_1_0_1/lib/XMLSchemaDatatypes.rb

Revision 8, 3.2 kB (checked in by nakahiro, 8 years ago)

Added 'int'.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to author date id revision
Line 
1 =begin
2 SOAP4R
3 Copyright (C) 2000 NAKAMURA Hiroshi.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 2 of the License, or (at your option) any later
8 version.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 PRATICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 675 Mass
16 Ave, Cambridge, MA 02139, USA.
17 =end
18
19 ###
20 ## XMLSchamaDatatypes general definitions.
21 #
22 module XSD
23   #Namespace = 'http://www.w3.org/1999/XMLSchema'
24   #InstanceNamespace = 'http://www.w3.org/1999/XMLSchema-instance'
25   Namespace = 'http://www.w3.org/1999/XMLSchema/'
26   InstanceNamespace = 'http://www.w3.org/1999/XMLSchema/instance/'
27 end
28
29
30 ###
31 ## The base class of all datatypes with Namespace.
32 #
33 class NSDBase
34   public
35
36   attr_reader :typeName
37   attr_accessor :namespace
38
39   def initialize( typeName, namespace )
40     @typeName = typeName
41     @namespace = namespace
42   end
43 end
44
45
46 ###
47 ## The base class of XSD datatypes.
48 #
49 class XSDBase < NSDBase
50   include XSD
51
52   public
53
54   attr_accessor :data
55
56   def initialize( typeName )
57     super( typeName, Namespace )
58     @data = nil
59   end
60
61   def to_s()
62     @data.to_s
63   end
64 end
65
66
67 ###
68 ## Basic datatypes.
69 #
70 class XSDNull < XSDBase
71   def initialize()
72     super( 'null' )
73   end
74 end
75
76 class XSDBoolean < XSDBase
77   public
78
79   def initialize( initBoolean = false )
80     super( 'boolean' )
81     set( initBoolean )
82   end
83
84   def set( newBoolean )
85     if newBoolean.is_a?( String )
86       if newBoolean.downcase == 'true'
87         @data = true
88       else
89         @data = false
90       end
91     else
92       @data = newBoolean ? true : false
93     end
94   end
95 end
96
97 class XSDString < XSDBase
98   public
99
100   def initialize( initString = nil )
101     super( 'string' )
102     set( initString ) if initString
103   end
104
105   def set( newString )
106     @data = String.new( newString )
107   end
108 end
109
110 class XSDDecimal < XSDBase
111   public
112
113   def initialize( initDecimal = nil )
114     super( 'decimal' )
115     set( initDecimal ) if initDecimal
116   end
117
118   def set( newDecimal )
119     @data = newDecimal.to_f
120   end
121 end
122
123 class XSDTimeInstant < XSDBase
124   require 'parsedate2'
125
126   public
127
128   def initialize( initTimeInstant = nil )
129     super( 'timeInstant' )
130     set( initTimeInstant ) if initTimeInstant
131   end
132
133   def set( newTimeInstant )
134     if ( newTimeInstant.is_a?( Time ))
135       @data = newTimeInstant.dup
136     else
137       ( year, mon, mday, hour, min, sec, zone, wday ) = ParseDate.parsedate( newTimeInstant.to_s )
138       @data = Time.mktime( year, mon, mday, hour, min, sec )
139     end
140   end
141 end
142
143
144 ###
145 ## Derived types
146 #
147 class XSDInteger < XSDDecimal
148   public
149
150   def initialize( initInteger = nil )
151     super()
152     @typeName = 'integer'
153     set( initInteger ) if initInteger
154   end
155
156   def set( newInteger )
157     @data = newInteger.to_i
158   end
159 end
160
161 class XSDInt < XSDInteger
162   public
163
164   def initialize( initInt = nil )
165     super()
166     @typeName = 'int'
167     set( initInt ) if initInt
168   end
169
170   def set( newInt )
171     @data = newInt.to_i
172   end
173 end
Note: See TracBrowser for help on using the browser.