Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 523d7fac39fa43b0718a9cc7472c873b8725df8b (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
114
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc. 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.launch.core.persistence.filetransfer;

import java.util.List;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.tcf.te.launch.core.lm.interfaces.IFileTransferLaunchAttributes;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListPersistenceDelegate;
import org.eclipse.tcf.te.launch.core.persistence.AbstractItemListXMLParser;
import org.eclipse.tcf.te.runtime.services.interfaces.filetransfer.IFileTransferItem;

/**
 * File transfer persistence delegate.
 */
public class FileTransfersPersistenceDelegate {

	private static final String TAG_FILE_TRANSFER = "fileTransfer"; //$NON-NLS-1$

	private static final AbstractItemListPersistenceDelegate<IFileTransferItem> delegate =
					new AbstractItemListPersistenceDelegate<IFileTransferItem>(TAG_FILE_TRANSFER, IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS) {
		@Override
		protected AbstractItemListXMLParser<IFileTransferItem> getXMLParser() {
			return new AbstractItemListXMLParser<IFileTransferItem>(TAG_FILE_TRANSFER) {
				@Override
				protected Class<?> getReadClass() {
					return IFileTransferItem.class;
				}
			};
		}
	};

	/**
	 * Saves the selected file transfer items to the specified launch configuration working copy. If the
	 * selected file transfer items are <code>null</code> or empty, the attribute will be removed from
	 * the specified launch configuration working copy.
	 *
	 * @param wc The launch configuration working copy. Must not be <code>null</code>.
	 * @param items The file transfer items to save or <code>null</code>.
	 */
	public final static void setFileTransfers(ILaunchConfigurationWorkingCopy wc, IFileTransferItem[] items) {
		delegate.setItems(wc, items);
	}

	/**
	 * Saves the selected file transfer items to the specified launch specification. If the selected
	 * file transfer items are <code>null</code> or empty, the attribute will be removed from the
	 * specified launch specification.
	 *
	 * @param launchSpec The launch specification. Must not be <code>null</code>.
	 * @param items The file transfer items to save or <code>null</code>.
	 */
	public final static void setFileTransfers(ILaunchSpecification launchSpec, IFileTransferItem[] items) {
		delegate.setItems(launchSpec, items);
	}

	/**
	 * Writes the given file transfer items into a string encoded in XML.
	 *
	 * @param items The file transfer items to encode. Must not be <code>null</code>.
	 * @return The full XML representation of the given items or <code>null</code>.
	 */
	public final static String encodeFileTransferItems(IFileTransferItem[] items) {
		return delegate.encodeItems(items);
	}

	/**
	 * Reads the selected file transfer items from the given XML encoded string.
	 *
	 * @param encodedItems The selected file transfer items encoded as XML string. Must not be <code>null</code>.
	 * @return The selected file transfer items or an empty array.
	 */
	public final static IFileTransferItem[] decodeFileTransferItems(String encodedItems) {
		List<IFileTransferItem> list = delegate.decodeItems(encodedItems);
		return list.toArray(new IFileTransferItem[list.size()]);
	}

	/**
	 * Returns the list of configured file transfer items from the given launch configuration.
	 * <p>
	 * If the given launch configuration is <code>null</code> and the method will return an empty
	 * array.
	 *
	 * @param configuration The launch configuration or <code>null</code>.
	 * @return The list of configured file transfer items or an empty array.
	 */
	public static final IFileTransferItem[] getFileTransfers(ILaunchConfiguration configuration) {
		List<IFileTransferItem> list = delegate.getItems(configuration);
		return list.toArray(new IFileTransferItem[list.size()]);
	}

	/**
	 * Returns the list of configured file transfer items from the given launch specification.
	 * <p>
	 * If the given launch specification is <code>null</code> and the method will return an empty
	 * array.
	 *
	 * @param launchSpec The launch specification or <code>null</code>.
	 * @return The list of configured file transfer items or an empty array.
	 */
	public static final IFileTransferItem[] getFileTransfers(ILaunchSpecification launchSpec) {
		List<IFileTransferItem> list = delegate.getItems(launchSpec);
		return list.toArray(new IFileTransferItem[list.size()]);
	}
}

Back to the top