1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/**
* <copyright>
*
* Copyright (c) 2005, 2006 Springsite BV (The Netherlands) and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Taal
* </copyright>
*
* $Id: LobjAction.java,v 1.1 2006/11/20 08:18:12 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.sample;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
import lobj.LobjFactory;
import lobj.LobjPackage;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;
/**
* Tests the capa, detach and update
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
* @version $Revision: 1.1 $
*/
public class LobjAction extends AbstractTestAction {
/**
* Constructor for ClassHierarchyParsing.
*
* @param arg0
*/
public LobjAction() {
super(LobjPackage.eINSTANCE);
}
/** Creates an item, an address and links them to a po. */
public void doAction(TestStore store) {
final LobjFactory factory = LobjFactory.eINSTANCE;
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("learningobjects", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
try {
{
store.beginTransaction();
// loadResource(rs, "TestLU.learningobjects");
// loadResource(rs, "TestBlock.learningobjects");
loadResource(rs, "Lang_de.learningobjects");
for (Iterator resources = rs.getResources().iterator(); resources.hasNext();) {
final Resource res = (Resource) resources.next();
for (Iterator it = res.getContents().iterator(); it.hasNext();) {
Object obj = it.next();
store.store(obj);
}
}
store.commitTransaction();
}
store.refresh();
rs = new ResourceSetImpl();
{
store.beginTransaction();
// loadResource(rs, "TestLU.learningobjects");
// loadResource(rs, "TestBlock.learningobjects");
loadResource(rs, "Lang_de.learningobjects");
for (Iterator resources = rs.getResources().iterator(); resources.hasNext();) {
final Resource res = (Resource) resources.next();
for (Iterator it = res.getContents().iterator(); it.hasNext();) {
Object obj = it.next();
store.store(obj);
}
}
store.commitTransaction();
}
} catch (IOException e) {
throw new StoreTestException("Exception", e);
}
}
/** Loads a resource */
private void loadResource(ResourceSet rs, String name) throws IOException {
final URI uri = URI.createFileURI("/home/mtaal/mytmp/" + name);
Resource res = rs.getResource(uri, false);
if (res == null) {
res = rs.createResource(uri);
res.load(Collections.EMPTY_MAP);
}
}
}
|