blob: ad20c2cfcfdf4ef6c2ababd7cc3e4a741ffcb7ee (
plain) (
blame)
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
104
105
106
107
108
109
110
111
112
113
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.emf.cdo.transfer;
import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Eike Stepper
* @since 4.2
*/
public abstract class CDOTransferSystem
{
private boolean readOnly;
protected CDOTransferSystem(boolean readOnly)
{
this.readOnly = readOnly;
}
public abstract String getType();
protected ResourceSet provideResourceSet()
{
return null;
}
public boolean isReadOnly()
{
return readOnly;
}
public CDOTransferType getDefaultTransferType(CDOTransferElement element)
{
if (element.isDirectory())
{
return CDOTransferType.FOLDER;
}
return null;
}
public abstract URI getURI(IPath path);
public CDOTransferElement getElement(String path)
{
return getElement(new Path(path));
}
public abstract CDOTransferElement getElement(IPath path);
public abstract CDOTransferElement getElement(URI uri);
public abstract void createFolder(IPath path);
public Resource createModel(ResourceSet resourceSet, IPath path)
{
URI uri = getURI(path);
return resourceSet.createResource(uri);
}
public abstract void createBinary(IPath path, InputStream source, IProgressMonitor monitor);
public abstract void createText(IPath path, InputStream source, String encoding, IProgressMonitor monitor);
public void saveModels(EList<Resource> resources, IProgressMonitor monitor)
{
try
{
monitor.beginTask("", resources.size());
for (Resource resource : resources)
{
if (monitor.isCanceled())
{
throw new OperationCanceledException();
}
monitor.subTask("Saving " + resource.getURI());
resource.save(null);
monitor.worked(1);
}
}
catch (IOException ex)
{
throw new IORuntimeException(ex);
}
finally
{
monitor.done();
}
}
}
|