~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/wsdl/xmlSchema/simpleRestriction.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# WSDL4R - XMLSchema simpleContent restriction definition for WSDL.
2
 
# Copyright (C) 2004  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
 
 
4
 
# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
5
 
# redistribute it and/or modify it under the same terms of Ruby's license;
6
 
# either the dual license version in 2003, or any later version.
7
 
 
8
 
 
9
 
require 'wsdl/info'
10
 
require 'xsd/namedelements'
11
 
 
12
 
 
13
 
module WSDL
14
 
module XMLSchema
15
 
 
16
 
 
17
 
class SimpleRestriction < Info
18
 
  attr_reader :base
19
 
  attr_reader :enumeration
20
 
  attr_accessor :length
21
 
  attr_accessor :pattern
22
 
 
23
 
  def initialize
24
 
    super
25
 
    @base = nil
26
 
    @enumeration = []   # NamedElements?
27
 
    @length = nil
28
 
    @pattern = nil
29
 
  end
30
 
  
31
 
  def valid?(value)
32
 
    return false unless check_restriction(value)
33
 
    return false unless check_length(value)
34
 
    return false unless check_pattern(value)
35
 
    true
36
 
  end
37
 
 
38
 
  def parse_element(element)
39
 
    case element
40
 
    when EnumerationName
41
 
      Enumeration.new   # just a parsing handler
42
 
    when LengthName
43
 
      Length.new   # just a parsing handler
44
 
    when PatternName
45
 
      Pattern.new   # just a parsing handler
46
 
    end
47
 
  end
48
 
 
49
 
  def parse_attr(attr, value)
50
 
    case attr
51
 
    when BaseAttrName
52
 
      @base = value
53
 
    end
54
 
  end
55
 
 
56
 
private
57
 
 
58
 
  def check_restriction(value)
59
 
    @enumeration.empty? or @enumeration.include?(value)
60
 
  end
61
 
 
62
 
  def check_length(value)
63
 
    @length.nil? or value.size == @length
64
 
  end
65
 
 
66
 
  def check_pattern(value)
67
 
    @pattern.nil? or @pattern =~ value
68
 
  end
69
 
end
70
 
 
71
 
 
72
 
end
73
 
end