Skip to content

Commit 1054fc7

Browse files
author
mgeipel
committed
fixed #39
1 parent 715945b commit 1054fc7

File tree

5 files changed

+128
-55
lines changed

5 files changed

+128
-55
lines changed

src/main/java/org/culturegraph/mf/morph/MorphBuilder.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class MorphBuilder extends AbstractMetamorphDomWalker {
3535

3636
private static final String NOT_FOUND = " not found.";
3737
private static final String JAVA = "java";
38+
private static final String JAVAMAP = "javamap";
3839
private static final String RECORD = "record";
3940
// private final String morphDef;
4041
private final Metamorph metamorph;
@@ -75,12 +76,20 @@ protected void handleInternalMap(final Node mapNode) {
7576
@Override
7677
protected void handleMapClass(final Node mapNode) {
7778
final Map<String, String> attributes = resolvedAttributeMap(mapNode);
78-
7979
final String mapName = resolveVars(attributes.remove(ATTRITBUTE.NAME.getString()));
80-
if (!getMapFactory().containsKey(mapNode.getLocalName())) {
80+
final Map<String, String> map;
81+
82+
if (mapNode.getLocalName().equals(JAVA)) {
83+
final String className = resolvedAttribute(mapNode, ATTRITBUTE.CLASS);
84+
map = ObjectFactory.newInstance(ObjectFactory.loadClass(className, Map.class));
85+
attributes.remove(ATTRITBUTE.CLASS.getString());
86+
ObjectFactory.applySetters(map, attributes);
87+
}else if (getMapFactory().containsKey(mapNode.getLocalName())){
88+
map = getMapFactory().newInstance(mapNode.getLocalName(), attributes);
89+
}else{
8190
throw new IllegalArgumentException("Map " + mapNode.getLocalName() + NOT_FOUND);
8291
}
83-
final Map<String, String> map = getMapFactory().newInstance(mapNode.getLocalName(), attributes);
92+
8493
metamorph.putMap(mapName, map);
8594
}
8695

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mapfile org.culturegraph.mf.morph.maps.MapFile
2-
restmap org.culturegraph.mf.morph.maps.RestMap
3-
sqlmap org.culturegraph.mf.morph.maps.SqlMap
1+
filemap org.culturegraph.mf.morph.maps.MapFile
2+
restmap org.culturegraph.mf.morph.maps.RestMap
3+
sqlmap org.culturegraph.mf.morph.maps.SqlMap
44
jndisqlmap org.culturegraph.mf.morph.maps.JndiSqlMap

src/main/resources/schemata/metamorph.xsd

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@
100100
<complexType>
101101
<choice minOccurs="0" maxOccurs="unbounded">
102102
<element ref="tns:map" />
103-
<element ref="tns:mapfile" />
103+
<element ref="tns:filemap" />
104104
<element ref="tns:sqlmap" />
105105
<element ref="tns:jndisqlmap" />
106106
<element ref="tns:restmap" />
107+
<element ref="tns:javamap" />
107108
<element ref="xi:include" />
108109
</choice>
109110
<attribute ref="xml:base" />
@@ -139,7 +140,8 @@
139140
<anyAttribute namespace="##local" processContents="lax" />
140141
</complexType>
141142
</element>
142-
143+
144+
143145
<element name="group">
144146
<complexType>
145147
<sequence>
@@ -288,8 +290,24 @@
288290
<attribute ref="xml:base" />
289291
</complexType>
290292
</element>
293+
294+
<element name="javamap">
295+
<complexType>
296+
<attribute name="name" type="string" use="required" />
297+
<attribute name="class" use="required">
298+
<simpleType>
299+
<restriction base="string">
300+
<pattern value="([\p{L}_$][\p{L}\p{N}_$]*\.)*[\p{L}_$][\p{L}\p{N}_$]*">
301+
</pattern>
302+
</restriction>
303+
</simpleType>
304+
</attribute>
305+
<anyAttribute namespace="##local" processContents="lax" />
306+
</complexType>
307+
</element>
308+
291309

292-
<element name="mapfile">
310+
<element name="filemap">
293311
<complexType>
294312
<attribute name="name" type="string" use="required" />
295313
<attribute name="files" type="string" use="required" />
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<metamorph-test version="1.0"
3-
xmlns="http://www.culturegraph.org/metamorph-test" xmlns:mm="http://www.culturegraph.org/metamorph"
4-
xmlns:cgxml="http://www.culturegraph.org/cgxml">
5-
6-
7-
8-
<test-case name="filemap">
9-
<input type="text/x-cg+xml">
10-
<cgxml:cgxml version="1.0">
11-
<cgxml:records>
12-
<cgxml:record id="1">
13-
<cgxml:literal name="1" value="gw" />
14-
<cgxml:literal name="1" value="fj" />
15-
</cgxml:record>
16-
</cgxml:records>
17-
</cgxml:cgxml>
18-
</input>
19-
20-
<transformation type="text/x-metamorph+xml">
21-
<mm:metamorph version="1">
22-
<mm:rules>
23-
<mm:data source="1">
24-
<mm:lookup in="map1" />
25-
</mm:data>
26-
27-
</mm:rules>
28-
<mm:maps>
29-
<mm:mapfile name="map1" files="maps/MARCcountries.txt" />
30-
</mm:maps>
31-
</mm:metamorph>
32-
</transformation>
33-
34-
<result type="text/x-cg+xml">
35-
<cgxml:cgxml version="1.0">
36-
<cgxml:records>
37-
<cgxml:record id="1">
38-
<cgxml:literal name="1" value="Germany" />
39-
<cgxml:literal name="1" value="Fiji" />
40-
</cgxml:record>
41-
</cgxml:records>
42-
</cgxml:cgxml>
43-
</result>
44-
</test-case>
45-
46-
</metamorph-test>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<metamorph-test version="1.0"
3+
xmlns="http://www.culturegraph.org/metamorph-test" xmlns:mm="http://www.culturegraph.org/metamorph"
4+
xmlns:cgxml="http://www.culturegraph.org/cgxml">
5+
6+
7+
8+
<test-case name="filemap">
9+
<input type="text/x-cg+xml">
10+
<cgxml:cgxml version="1.0">
11+
<cgxml:records>
12+
<cgxml:record id="1">
13+
<cgxml:literal name="1" value="gw" />
14+
<cgxml:literal name="1" value="fj" />
15+
</cgxml:record>
16+
</cgxml:records>
17+
</cgxml:cgxml>
18+
</input>
19+
20+
<transformation type="text/x-metamorph+xml">
21+
<mm:metamorph version="1">
22+
<mm:rules>
23+
<mm:data source="1">
24+
<mm:lookup in="map1" />
25+
</mm:data>
26+
27+
</mm:rules>
28+
<mm:maps>
29+
<mm:filemap name="map1" files="maps/MARCcountries.txt" />
30+
</mm:maps>
31+
</mm:metamorph>
32+
</transformation>
33+
34+
<result type="text/x-cg+xml">
35+
<cgxml:cgxml version="1.0">
36+
<cgxml:records>
37+
<cgxml:record id="1">
38+
<cgxml:literal name="1" value="Germany" />
39+
<cgxml:literal name="1" value="Fiji" />
40+
</cgxml:record>
41+
</cgxml:records>
42+
</cgxml:cgxml>
43+
</result>
44+
</test-case>
45+
46+
</metamorph-test>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<metamorph-test version="1.0"
3+
xmlns="http://www.culturegraph.org/metamorph-test" xmlns:mm="http://www.culturegraph.org/metamorph"
4+
xmlns:cgxml="http://www.culturegraph.org/cgxml">
5+
6+
7+
8+
<test-case name="filemap">
9+
<input type="text/x-cg+xml">
10+
<cgxml:cgxml version="1.0">
11+
<cgxml:records>
12+
<cgxml:record id="1">
13+
<cgxml:literal name="1" value="gw" />
14+
<cgxml:literal name="1" value="fj" />
15+
</cgxml:record>
16+
</cgxml:records>
17+
</cgxml:cgxml>
18+
</input>
19+
20+
<transformation type="text/x-metamorph+xml">
21+
<mm:metamorph version="1">
22+
<mm:rules>
23+
<mm:data source="1">
24+
<mm:lookup in="map1" />
25+
</mm:data>
26+
27+
</mm:rules>
28+
<mm:maps>
29+
<mm:javamap name="map1" class="org.culturegraph.mf.morph.maps.MapFile" files="maps/MARCcountries.txt" />
30+
</mm:maps>
31+
</mm:metamorph>
32+
</transformation>
33+
34+
<result type="text/x-cg+xml">
35+
<cgxml:cgxml version="1.0">
36+
<cgxml:records>
37+
<cgxml:record id="1">
38+
<cgxml:literal name="1" value="Germany" />
39+
<cgxml:literal name="1" value="Fiji" />
40+
</cgxml:record>
41+
</cgxml:records>
42+
</cgxml:cgxml>
43+
</result>
44+
</test-case>
45+
46+
</metamorph-test>

0 commit comments

Comments
 (0)