mappum 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +15 -0
  3. data/README +53 -0
  4. data/Rakefile +48 -0
  5. data/VERSION +1 -0
  6. data/bin/mapserver.rb +4 -0
  7. data/java-api/pom.xml +63 -0
  8. data/java-api/src/main/java/pl/ivmx/mappum/JavaTransform.java +12 -0
  9. data/java-api/src/main/java/pl/ivmx/mappum/MappumApi.java +83 -0
  10. data/java-api/src/main/java/pl/ivmx/mappum/TreeElement.java +23 -0
  11. data/java-api/src/main/java/pl/ivmx/mappum/WorkdirLoader.java +12 -0
  12. data/java-api/src/test/java/iv/Client.java +237 -0
  13. data/java-api/src/test/java/iv/Person.java +261 -0
  14. data/java-api/src/test/java/pl/ivmx/mappum/MappumTest.java +122 -0
  15. data/java-api/src/test/resources/map/example_map.rb +88 -0
  16. data/lib/mappum.rb +46 -0
  17. data/lib/mappum/autoconv_catalogue.rb +43 -0
  18. data/lib/mappum/dsl.rb +255 -0
  19. data/lib/mappum/java_transform.rb +107 -0
  20. data/lib/mappum/map.rb +194 -0
  21. data/lib/mappum/mapserver/mapgraph.rb +192 -0
  22. data/lib/mappum/mapserver/mapserver.rb +213 -0
  23. data/lib/mappum/mapserver/maptable.rb +80 -0
  24. data/lib/mappum/mapserver/views/doc.erb +15 -0
  25. data/lib/mappum/mapserver/views/main.erb +39 -0
  26. data/lib/mappum/mapserver/views/maptable.erb +16 -0
  27. data/lib/mappum/mapserver/views/rubysource.erb +25 -0
  28. data/lib/mappum/mapserver/views/transform-ws.wsdl.erb +50 -0
  29. data/lib/mappum/mapserver/views/ws-error.erb +10 -0
  30. data/lib/mappum/open_xml_object.rb +68 -0
  31. data/lib/mappum/ruby_transform.rb +199 -0
  32. data/lib/mappum/xml_transform.rb +382 -0
  33. data/mappum.gemspec +117 -0
  34. data/sample/address_fixture.xml +11 -0
  35. data/sample/crm.rb +9 -0
  36. data/sample/crm_client.xsd +28 -0
  37. data/sample/erp.rb +7 -0
  38. data/sample/erp_person.xsd +44 -0
  39. data/sample/example_conversions.rb +12 -0
  40. data/sample/example_map.rb +92 -0
  41. data/sample/example_notypes.rb +77 -0
  42. data/sample/example_when.rb +13 -0
  43. data/sample/person_fixture.xml +23 -0
  44. data/sample/person_fixture_any.xml +26 -0
  45. data/sample/server/map/example_any.rb +28 -0
  46. data/sample/server/map/example_soap4r.rb +59 -0
  47. data/sample/server/mapserver.sh +1 -0
  48. data/sample/server/schema/crm_client.xsd +29 -0
  49. data/sample/server/schema/erp/erp_person.xsd +38 -0
  50. data/test/test_conversions.rb +24 -0
  51. data/test/test_example.rb +175 -0
  52. data/test/test_openstruct.rb +129 -0
  53. data/test/test_soap4r.rb +108 -0
  54. data/test/test_when.rb +35 -0
  55. data/test/test_xml_any.rb +62 -0
  56. metadata +164 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ nbproject/
2
+ pkg/
3
+ .project
4
+ .buildpath
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ == mappum
2
+
3
+ Copyright 2009 by Jan Topinski
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README ADDED
@@ -0,0 +1,53 @@
1
+ == mappum
2
+
3
+ Mappum is the tree to tree (object, bean etc.) mapping DSL. The example of usage
4
+ is provided below. More documentation will follow.
5
+
6
+ Mappum.catalogue_add "CRM-ERP" do
7
+
8
+ map ERP::Person, CRM::Client do |p, c|
9
+
10
+ #simple mapping
11
+ map p.title <=> c.title
12
+
13
+ #map with simple function call
14
+ map p.person_id << c.key.downcase
15
+ map p.person_id.upcase >> c.key
16
+
17
+ #dictionary use
18
+ map p.sex <=> c.sex_id, :dict => {"F" => "1", "M" => "2"}
19
+
20
+ #submaps
21
+ map p.address(ERP::Address) <=> c.address(CRM::Address) do |a, b|
22
+ map a.street <=> b.street
23
+ #etc.
24
+ end
25
+
26
+ #subobject to fields
27
+ map p.main_phone(ERP::Phone) <=> c.self do |a, b|
28
+ map a.number <=> b.main_phone
29
+ map a.type <=> b.main_phone_type
30
+ end
31
+
32
+ #compilcated function call
33
+ map p.name >> c.surname do |name|
34
+ name + "ski"
35
+ end
36
+ map p.name << c.surname do |name|
37
+ if name =~ /ski/
38
+ name[0..-4]
39
+ else
40
+ name
41
+ end
42
+ end
43
+ #field to array and array to field
44
+ map p.email1 <=> c.emails[0]
45
+ map p.email2 <=> c.emails[1]
46
+ map p.email3 <=> c.emails[2]
47
+
48
+ map p.phones(ERP::Phone)[] <=> c.phones[] do |a, b|
49
+ map a.number <=> b.self
50
+ end
51
+
52
+ end
53
+ end
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+ require 'rubygems'
6
+ require 'rake'
7
+ require 'rake/clean'
8
+ require 'rake/rdoctask'
9
+ require 'rake/testtask'
10
+ require 'spec/rake/spectask'
11
+
12
+ Rake::RDocTask.new do |rdoc|
13
+ files =['README', 'LICENSE', 'lib/**/*.rb']
14
+ rdoc.rdoc_files.add(files)
15
+ rdoc.main = "README" # page to start on
16
+ rdoc.title = "rupper Docs"
17
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
18
+ rdoc.options << '--line-numbers'
19
+ end
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.test_files = FileList['test/**/*.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new do |t|
26
+ t.spec_files = FileList['spec/**/*.rb']
27
+ end
28
+
29
+ begin
30
+ require 'jeweler'
31
+ Jeweler::Tasks.new do |gemspec|
32
+ gemspec.name = "mappum"
33
+ gemspec.summary = "Mappum is the tree to tree (object, bean etc.) mapping DSL."
34
+ gemspec.email = "jtopinski@chatka.org"
35
+ gemspec.homepage = "http://wiki.github.com/simcha/mappum"
36
+ gemspec.description = ""
37
+ gemspec.authors = ["Jan Topiński"]
38
+ gemspec.add_dependency('facets', '>= 2.5.2')
39
+ gemspec.add_dependency('soap4r', '>= 1.5.8')
40
+ gemspec.add_dependency('sinatra', '>= 0.9.2')
41
+ gemspec.add_dependency('thin', '>= 1.2.2')
42
+ gemspec.add_dependency('syntax', '>= 1.0.0')
43
+ end
44
+ Jeweler::GemcutterTasks.new
45
+ rescue LoadError
46
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bin/mapserver.rb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/ruby1.8
2
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
+
4
+ load 'mappum/mapserver/mapserver.rb'
data/java-api/pom.xml ADDED
@@ -0,0 +1,63 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
+
6
+ <modelVersion>4.0.0</modelVersion>
7
+
8
+ <groupId>pl.ivmx.mappum</groupId>
9
+ <artifactId>mappum-core</artifactId>
10
+ <packaging>jar</packaging>
11
+ <version>0.2.0</version>
12
+ <name>Mappum Java API</name>
13
+
14
+ <properties>
15
+ <jruby-version>1.3.1</jruby-version>
16
+ <jsr223-version>20080611</jsr223-version>
17
+ <soap4r-version>1.5.8</soap4r-version>
18
+ <junit-version>3.8.1</junit-version>
19
+ <jdk-version>1.5</jdk-version>
20
+ </properties>
21
+
22
+ <build>
23
+ <resources>
24
+ <resource>
25
+ <directory>../lib</directory>
26
+ </resource>
27
+ </resources>
28
+
29
+ <plugins>
30
+ <plugin>
31
+ <groupId>org.apache.maven.plugins</groupId>
32
+ <artifactId>maven-compiler-plugin</artifactId>
33
+ <configuration>
34
+ <source>${jdk-version}</source>
35
+ <target>${jdk-version}</target>
36
+ </configuration>
37
+ </plugin>
38
+ </plugins>
39
+ </build>
40
+ <dependencies>
41
+ <dependency>
42
+ <groupId>pl.ivmx.mappum</groupId>
43
+ <artifactId>mappum-jruby-complete</artifactId>
44
+ <version>${jruby-version}</version>
45
+ </dependency>
46
+ <dependency>
47
+ <groupId>com.sun.script</groupId>
48
+ <artifactId>jruby-engine</artifactId>
49
+ <version>${jsr223-version}</version>
50
+ </dependency>
51
+ <dependency>
52
+ <groupId>javax.script</groupId>
53
+ <artifactId>script-api</artifactId>
54
+ <version>1.0</version>
55
+ </dependency>
56
+ <dependency>
57
+ <groupId>junit</groupId>
58
+ <artifactId>junit</artifactId>
59
+ <version>${junit-version}</version>
60
+ <scope>test</scope>
61
+ </dependency>
62
+ </dependencies>
63
+ </project>
@@ -0,0 +1,12 @@
1
+ package pl.ivmx.mappum;
2
+
3
+ public interface JavaTransform {
4
+ /**
5
+ * Transforms Pojo (plain old java bean)
6
+ * @param from
7
+ * @return
8
+ */
9
+ public Object transform(Object from, String map, Object to);
10
+ public Object transform(Object from, String map);
11
+ public Object transform(Object from);
12
+ }
@@ -0,0 +1,83 @@
1
+ package pl.ivmx.mappum;
2
+
3
+ import javax.script.ScriptContext;
4
+ import javax.script.ScriptEngine;
5
+ import javax.script.ScriptEngineManager;
6
+ import javax.script.ScriptException;
7
+
8
+ public class MappumApi {
9
+ private MappumApi rubyMappum;
10
+
11
+ public MappumApi() {
12
+ this(true);
13
+ }
14
+ public MappumApi(boolean initialize){
15
+ if(initialize){
16
+ ScriptEngineManager m = new ScriptEngineManager();
17
+ ScriptEngine rubyEngine = m.getEngineByName("jruby");
18
+ if(rubyEngine == null){
19
+ throw new RuntimeException("No jruby jsr-223 engine found download jruby an jruby-engine jars.");
20
+ }
21
+ ScriptContext context = rubyEngine.getContext();
22
+ //context.setAttribute("this_mappum",this, ScriptContext.ENGINE_SCOPE);
23
+ try {
24
+ String script = "require 'mappum/java_transform'\n" +
25
+ "return Mappum::JavaApi.new\n";
26
+ Object o = rubyEngine.eval(script, context);
27
+ rubyMappum = (MappumApi) o;
28
+ } catch (ScriptException e) {
29
+ throw new RuntimeException(e);
30
+ }
31
+ }
32
+ }
33
+ @SuppressWarnings("unused")
34
+ private void setRubyImpl(MappumApi mappum) {
35
+ rubyMappum = mappum;
36
+ }
37
+
38
+
39
+ public WorkdirLoader getWorkdirLoader() {
40
+ return getWorkdirLoader(null,null,null);
41
+ }
42
+ public WorkdirLoader getWorkdirLoader(String schemaPath, String mapDir,String basedir) {
43
+ return rubyMappum.getWorkdirLoader(schemaPath, mapDir, basedir);
44
+ }
45
+
46
+ /**
47
+ * Load maps from class patch. Old definitions are removed first.
48
+ *
49
+ */
50
+ public void loadMaps() {
51
+ loadMaps(null);
52
+ }
53
+ /**
54
+ * Load maps from class patch. Old definitions are removed first.
55
+ *
56
+ * @param dir - directory to load maps from (all jars and folders are scanned)
57
+ */
58
+ public void loadMaps(String dir) {
59
+ loadMaps(dir, true);
60
+ }
61
+ /**
62
+ * Load maps from class patch.
63
+ *
64
+ * @param dir - directory to load maps from (all jars and folders are scanned)
65
+ * @param reload - when true (default) old definitions are removed first
66
+ */
67
+ public void loadMaps(String dir, boolean reload) {
68
+ rubyMappum.loadMaps(dir, reload);
69
+ }
70
+ public JavaTransform getJavaTransform(){
71
+ return getJavaTransform(null);
72
+ }
73
+ public JavaTransform getJavaTransform(String catalogue){
74
+ return rubyMappum.getJavaTransform(catalogue);
75
+ }
76
+ public void startServer(){
77
+ rubyMappum.startServer();
78
+ }
79
+ public static void main(String[] args){
80
+ MappumApi mappumApi = new MappumApi();
81
+ mappumApi.startServer();
82
+ }
83
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ */
4
+ package pl.ivmx.mappum;
5
+
6
+ import java.util.List;
7
+
8
+ /**
9
+ * @author Jan Topinski (jtopinski@ivmx.pl)
10
+ *
11
+ */
12
+ public interface TreeElement {
13
+ public String getName();
14
+ public void setName(String name);
15
+ public List<TreeElement> getElements();
16
+ public void setElements(List<TreeElement> elems);
17
+ public boolean getIsArray();
18
+ public void setIsArray(boolean isArray);
19
+ public String getClazz();
20
+ public void setClazz(String clazz);
21
+
22
+
23
+ }
@@ -0,0 +1,12 @@
1
+ package pl.ivmx.mappum;
2
+
3
+ import java.util.List;
4
+
5
+ public interface WorkdirLoader {
6
+ public void generateAndRequire();
7
+ public List<TreeElement> definedElementTrees();
8
+ /**
9
+ * Clean tmpdir
10
+ */
11
+ public void cleanup();
12
+ }
@@ -0,0 +1,237 @@
1
+ package iv;
2
+
3
+ import java.util.Date;
4
+
5
+ public class Client {
6
+
7
+ /**
8
+ * @author Jan Topinski (jtopinski@ivmx.pl)
9
+ *
10
+ */
11
+ public static class Address {
12
+ private String street;
13
+ private String city;
14
+ /**
15
+ * @return the street
16
+ */
17
+ public String getStreet() {
18
+ return street;
19
+ }
20
+ /**
21
+ * @param street the street to set
22
+ */
23
+ public void setStreet(String street) {
24
+ this.street = street;
25
+ }
26
+ /**
27
+ * @return the city
28
+ */
29
+ public String getCity() {
30
+ return city;
31
+ }
32
+ /**
33
+ * @param city the city to set
34
+ */
35
+ public void setCity(String city) {
36
+ this.city = city;
37
+ }
38
+ }
39
+ public static class NameType {
40
+ private String name;
41
+ private String type;
42
+ /**
43
+ * @return the street
44
+ */
45
+ public String getName() {
46
+ return name;
47
+ }
48
+ /**
49
+ * @param street the street to set
50
+ */
51
+ public void setName(String name) {
52
+ this.name = name;
53
+ }
54
+ /**
55
+ * @return the city
56
+ */
57
+ public String getType() {
58
+ return type;
59
+ }
60
+ /**
61
+ * @param city the city to set
62
+ */
63
+ public void setType(String type) {
64
+ this.type = type;
65
+ }
66
+ }
67
+ private String test;
68
+ private String title;
69
+ private String cid;
70
+ private String first_name;
71
+ private String surname;
72
+ private String sexId;
73
+ private String[] phones;
74
+ private String[] emails;
75
+ private String mainPhone;
76
+ private String mainPhoneType;
77
+ private Address address;
78
+ private String orderBy;
79
+ private NameType[] partners;
80
+ private Date updated;
81
+
82
+ public Date getUpdated() {
83
+ return updated;
84
+ }
85
+ public void setUpdated(Date updated) {
86
+ this.updated = updated;
87
+ }
88
+ public String getOrderBy() {
89
+ return orderBy;
90
+ }
91
+
92
+ public void setOrderBy(String orderBy) {
93
+ this.orderBy = orderBy;
94
+ }
95
+ public NameType[] getPartners() {
96
+ return partners;
97
+ }
98
+
99
+ public void setPartners(NameType[] partners) {
100
+ this.partners = partners;
101
+ }
102
+ /**
103
+ * @return the test
104
+ */
105
+ public String getTest() {
106
+ return test;
107
+ }
108
+ /**
109
+ * @param test the test to set
110
+ */
111
+ public void setTest(String test) {
112
+ this.test = test;
113
+ }
114
+ /**
115
+ * @return the title
116
+ */
117
+ public String getTitle() {
118
+ return title;
119
+ }
120
+ /**
121
+ * @param title the title to set
122
+ */
123
+ public void setTitle(String title) {
124
+ this.title = title;
125
+ }
126
+ /**
127
+ * @return the id
128
+ */
129
+ public String getCid() {
130
+ return cid;
131
+ }
132
+ /**
133
+ * @param id the id to set
134
+ */
135
+ public void setCid(String id) {
136
+ this.cid = id;
137
+ }
138
+ /**
139
+ * @return the first_name
140
+ */
141
+ public String getFirst_name() {
142
+ return first_name;
143
+ }
144
+ /**
145
+ * @param first_name the first_name to set
146
+ */
147
+ public void setFirst_name(String first_name) {
148
+ this.first_name = first_name;
149
+ }
150
+ /**
151
+ * @return the surname
152
+ */
153
+ public String getSurname() {
154
+ return surname;
155
+ }
156
+ /**
157
+ * @param surname the surname to set
158
+ */
159
+ public void setSurname(String surname) {
160
+ this.surname = surname;
161
+ }
162
+ /**
163
+ * @return the sexId
164
+ */
165
+ public String getSexId() {
166
+ return sexId;
167
+ }
168
+ /**
169
+ * @param sexId the sexId to set
170
+ */
171
+ public void setSexId(String sexId) {
172
+ this.sexId = sexId;
173
+ }
174
+ /**
175
+ * @return the phones
176
+ */
177
+ public String[] getPhones() {
178
+ return phones;
179
+ }
180
+ /**
181
+ * @param phones the phones to set
182
+ */
183
+ public void setPhones(String[] phones) {
184
+ this.phones = phones;
185
+ }
186
+ /**
187
+ * @return the emails
188
+ */
189
+ public String[] getEmails() {
190
+ return emails;
191
+ }
192
+ /**
193
+ * @param emails the emails to set
194
+ */
195
+ public void setEmails(String[] emails) {
196
+ this.emails = emails;
197
+ }
198
+ /**
199
+ * @return the mainPhone
200
+ */
201
+ public String getMainPhone() {
202
+ return mainPhone;
203
+ }
204
+ /**
205
+ * @param mainPhone the mainPhone to set
206
+ */
207
+ public void setMainPhone(String mainPhone) {
208
+ this.mainPhone = mainPhone;
209
+ }
210
+ /**
211
+ * @return the mainPhoneType
212
+ */
213
+ public String getMainPhoneType() {
214
+ return mainPhoneType;
215
+ }
216
+ /**
217
+ * @param mainPhoneType the mainPhoneType to set
218
+ */
219
+ public void setMainPhoneType(String mainPhoneType) {
220
+ this.mainPhoneType = mainPhoneType;
221
+ }
222
+ /**
223
+ * @return the address
224
+ */
225
+ public Address getAddress() {
226
+ return address;
227
+ }
228
+ /**
229
+ * @param address the address to set
230
+ */
231
+ public void setAddress(Address address) {
232
+ this.address = address;
233
+ }
234
+
235
+
236
+ }
237
+