|
| 1 | +note |
| 2 | + description: "[ |
| 3 | + The Collection Object contains all the records in the representations. |
| 4 | + This is a required object. |
| 5 | + Should have a version property.: |
| 6 | + - value MUST be set to 1.0, |
| 7 | + - if there is no version property present, set it to 1.0. |
| 8 | + Should have an href property, it should contain a valid URI |
| 9 | + ]" |
| 10 | + date: "$Date$" |
| 11 | + revision: "$Revision$" |
| 12 | + example: "[ |
| 13 | + { |
| 14 | + "collection": |
| 15 | + { |
| 16 | + "version": 1.0, |
| 17 | + "href": URI, |
| 18 | + "links": [ARRAY], |
| 19 | + "items": [ARRAY], |
| 20 | + "queries": [ARRAY], |
| 21 | + "template": {OBJECT}, |
| 22 | + "error": {OBJECT} |
| 23 | + } |
| 24 | + } |
| 25 | + ]" |
| 26 | + EIS: "name=Collection+JSON - Hypermedia Type", "protocol=URI", "src=http://www.amundsen.com/media-types/collection/", "tag=homepage, specification" |
| 27 | + |
| 28 | +class |
| 29 | + CJ_COLLECTION |
| 30 | + |
| 31 | +create |
| 32 | + make_empty, |
| 33 | + make_with_href, |
| 34 | + make_with_version, |
| 35 | + make_with_href_and_version |
| 36 | + |
| 37 | +feature {NONE} -- Initialization |
| 38 | + |
| 39 | + make_empty |
| 40 | + do |
| 41 | + make_with_version (default_version) |
| 42 | + end |
| 43 | + |
| 44 | + make_with_href (a_href: like href) |
| 45 | + require |
| 46 | + valid_href: not a_href.is_empty |
| 47 | + do |
| 48 | + make_with_href_and_version (a_href, default_version) |
| 49 | + end |
| 50 | + |
| 51 | + make_with_href_and_version (a_href: like href; a_version: like version) |
| 52 | + require |
| 53 | + valid_version: not a_version.is_empty |
| 54 | + do |
| 55 | + version := a_version |
| 56 | + href := a_href |
| 57 | + end |
| 58 | + |
| 59 | + make_with_version (a_version: like version) |
| 60 | + require |
| 61 | + valid_version: not a_version.is_empty |
| 62 | + do |
| 63 | + make_with_href_and_version (create {like href}.make_empty, a_version) |
| 64 | + end |
| 65 | + |
| 66 | +feature -- Access |
| 67 | + |
| 68 | + version: STRING |
| 69 | + -- The value should be set to `default_version' i.e: "1.0" |
| 70 | + |
| 71 | + href: STRING |
| 72 | + -- Must contain a valid URI |
| 73 | + |
| 74 | + links: detachable ARRAYED_LIST [CJ_LINK] |
| 75 | + -- may have a links array |
| 76 | + |
| 77 | + items: detachable ARRAYED_LIST [CJ_ITEM] |
| 78 | + -- may have an items array |
| 79 | + |
| 80 | + queries: detachable ARRAYED_LIST [CJ_QUERY] |
| 81 | + -- may have a queries array |
| 82 | + |
| 83 | + template: detachable CJ_TEMPLATE |
| 84 | + -- may have a template object |
| 85 | + |
| 86 | + error: detachable CJ_ERROR |
| 87 | + -- may have an error object |
| 88 | + |
| 89 | +feature -- Element Change |
| 90 | + |
| 91 | + set_version (a_version: STRING) |
| 92 | + do |
| 93 | + version := a_version |
| 94 | + ensure |
| 95 | + version_set: version ~ a_version |
| 96 | + end |
| 97 | + |
| 98 | + set_href (a_href: STRING) |
| 99 | + do |
| 100 | + href := a_href |
| 101 | + ensure |
| 102 | + href_set: href ~ a_href |
| 103 | + end |
| 104 | + |
| 105 | + add_link (a_link: CJ_LINK) |
| 106 | + local |
| 107 | + l_links: like links |
| 108 | + do |
| 109 | + l_links := links |
| 110 | + if l_links = Void then |
| 111 | + create l_links.make (1) |
| 112 | + links := l_links |
| 113 | + end |
| 114 | + l_links.force (a_link) |
| 115 | + end |
| 116 | + |
| 117 | + add_item (a_item: CJ_ITEM) |
| 118 | + local |
| 119 | + l_items: like items |
| 120 | + do |
| 121 | + l_items := items |
| 122 | + if l_items = Void then |
| 123 | + create l_items.make (1) |
| 124 | + items := l_items |
| 125 | + end |
| 126 | + l_items.force (a_item) |
| 127 | + end |
| 128 | + |
| 129 | + add_query (a_query: CJ_QUERY) |
| 130 | + local |
| 131 | + l_queries: like queries |
| 132 | + do |
| 133 | + l_queries := queries |
| 134 | + if l_queries = Void then |
| 135 | + create l_queries.make (1) |
| 136 | + queries := l_queries |
| 137 | + end |
| 138 | + l_queries.force (a_query) |
| 139 | + end |
| 140 | + |
| 141 | + set_template (a_template: CJ_TEMPLATE) |
| 142 | + do |
| 143 | + template := a_template |
| 144 | + end |
| 145 | + |
| 146 | + set_error (an_error: CJ_ERROR) |
| 147 | + do |
| 148 | + error := an_error |
| 149 | + end |
| 150 | + |
| 151 | +feature -- Constants |
| 152 | + |
| 153 | + default_version: STRING = "1.0" |
| 154 | + |
| 155 | +note |
| 156 | + copyright: "2011-2012, Javier Velilla, Jocelyn Fiat and others" |
| 157 | + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" |
| 158 | +end |
0 commit comments