Skip to main content
summaryrefslogtreecommitdiffstats
blob: 651e111d0645351f3ec8ae8e7b57a03aec30e6ba (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
/*******************************************************************************
 * Copyright (c) 2013 BestSolution.at 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:
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
 *******************************************************************************/
package org.eclipse.fx.core.adapter;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

/**
 * Service which allows to adapt an instance to another type.
 */
public interface AdapterService {
	/**
	 * Check if the instance can be adapted to the target type
	 * 
	 * @param sourceObject
	 *            the source object
	 * @param targetType
	 *            the target type
	 * @return <code>true</code> if object can be adapted, else
	 *         <code>false</code>
	 */
	public boolean canAdapt(@Nullable Object sourceObject, @NonNull Class<?> targetType);

	/**
	 * Adapt the source object to the target type
	 * 
	 * @param sourceObject
	 *            the source object
	 * @param targetType
	 *            the target type
	 * @param valueAccesses
	 *            value access
	 * @param <A>
	 *            the type adapted to
	 * @return the adapted object or <code>null</code> if adaption was not
	 *         possible
	 */
	@Nullable
	public <A> A adapt(@Nullable Object sourceObject, @NonNull Class<A> targetType, ValueAccess... valueAccesses);

	/**
	 * Provides access to values
	 */
	public interface ValueAccess {
		/**
		 * Getting the value
		 * 
		 * @param key
		 *            the key
		 * @param <O>
		 *            the value type
		 * @return the value or <code>null</code>
		 */
		@Nullable
		public <O> O getValue(@NonNull String key);

		/**
		 * Getting the value
		 * 
		 * @param key
		 *            the key
		 * @param <O>
		 *            the value type
		 * @return the value
		 */
		@Nullable
		public <O> O getValue(@NonNull Class<O> key);
	}
}

Back to the top