Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1cf1d62fc648b989f2c62d745d23c0787976fa9d (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
/*******************************************************************************
 * Copyright (c) 2016 IBM Corporation and others
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0 which
 * accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 ******************************************************************************/
package org.eclipse.osgi.internal.log;

import org.osgi.framework.ServiceReference;

public class Arguments {
	private final Object[] arguments;
	private final ServiceReference<?> serviceReference;
	private final Throwable throwable;

	public Arguments(Object... arguments) {
		if (arguments == null || arguments.length == 0) {
			this.arguments = new Object[0];
			serviceReference = null;
			throwable = null;
			return;
		}
		int length = arguments.length;
		ServiceReference<?> context = null;
		Throwable exception = null;
		Object object = arguments[arguments.length - 1];
		if (object instanceof Throwable || object instanceof ServiceReference) {
			length--;
			if (object instanceof Throwable) {
				exception = (Throwable) object;
			} else {
				context = (ServiceReference<?>) object;
			}
			if (arguments.length > 1) {
				object = arguments[arguments.length - 2];
				if ((object instanceof ServiceReference && context == null) || (object instanceof Throwable && exception == null)) {
					length--;
					if (object instanceof Throwable) {
						exception = (Throwable) object;
					} else {
						context = (ServiceReference<?>) object;
					}
				}
			}
		}
		serviceReference = context;
		throwable = exception;
		this.arguments = new Object[length];
		System.arraycopy(arguments, 0, this.arguments, 0, length);
	}

	public Object[] arguments() {
		return arguments;
	}

	public boolean isEmpty() {
		return arguments == null || arguments.length == 0;
	}

	public ServiceReference<?> serviceReference() {
		return serviceReference;
	}

	public Throwable throwable() {
		return throwable;
	}
}

Back to the top