Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ff6e04ee62cd799d55a276ee41ff6155c280fb4b (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
/*******************************************************************************
* Copyright (c) 2007 compeople AG 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:
* 	compeople AG (Stefan Liebig) - initial API and implementation
*  IBM - continuing development
*******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.repository.processing;

import java.io.IOException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;

public class ByteShifter extends ProcessingStep {

	protected int operand;

	public ByteShifter() {
		super();
	}

	public ByteShifter(int shiftLeft) {
		super();
		this.operand = shiftLeft;
		basicInitialize(null);
	}

	private void basicInitialize(ProcessingStepDescriptor descriptor) {
		// if the status is already set to something that not ok, we've already found a problem.
		if (!getStatus().isOK())
			return;

		int code;
		// if there is a descriptor, decide if the "bad case" is an error or info.  If no 
		// descriptor then default to error.
		if (descriptor != null)
			code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
		else
			code = IStatus.ERROR;

		// finally, check the actual setup and set the status.
		if (operand <= 0)
			setStatus(new Status(code, Activator.ID, "ByteShifter operand invalid: " + operand));
	}

	public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
		super.initialize(descriptor, context);
		try {
			operand = Integer.valueOf(descriptor.getData()).intValue();
		} catch (NumberFormatException e) {
			int code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
			setStatus(new Status(code, Activator.ID, "ByteShifter operand specification invalid", e));
			return;
		}
		basicInitialize(descriptor);
	}

	public void write(int b) throws IOException {
		getDestination().write(b == -1 ? b : b << operand);
	}

	public IStatus getStatus() {
		return Status.OK_STATUS;
	}
}

Back to the top