01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.text.bundle;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
15: import org.eclipse.osgi.util.ManifestElement;
16: import org.eclipse.pde.internal.core.ibundle.IBundle;
17:
18: public class RequiredExecutionEnvironmentHeader extends
19: CompositeManifestHeader {
20:
21: private static final long serialVersionUID = 1L;
22:
23: public RequiredExecutionEnvironmentHeader(String name,
24: String value, IBundle bundle, String lineDelimiter) {
25: super (name, value, bundle, lineDelimiter);
26: }
27:
28: protected PDEManifestElement createElement(ManifestElement element) {
29: return new ExecutionEnvironment(this , element.getValue());
30: }
31:
32: public boolean hasExecutionEnvironment(IExecutionEnvironment env) {
33: return hasElement(env.getId());
34: }
35:
36: public void addExecutionEnvironment(IExecutionEnvironment env) {
37: addManifestElement(new ExecutionEnvironment(this , env.getId()));
38: }
39:
40: /**
41: * @param environment
42: * @param index
43: */
44: public void addExecutionEnvironment(
45: ExecutionEnvironment environment, int index) {
46: addManifestElement(environment, index, true);
47: }
48:
49: public void addExecutionEnvironments(Object[] envs) {
50: ArrayList list = new ArrayList(envs.length);
51: for (int i = 0; i < envs.length; i++) {
52: ExecutionEnvironment env = null;
53: if (envs[i] instanceof ExecutionEnvironment) {
54: env = (ExecutionEnvironment) envs[i];
55: } else if (envs[i] instanceof IExecutionEnvironment) {
56: env = new ExecutionEnvironment(this ,
57: ((IExecutionEnvironment) envs[i]).getId());
58: }
59: if (env != null && !hasElement(env.getName()))
60: list.add(env);
61: }
62:
63: if (list.size() > 0)
64: addManifestElements((ExecutionEnvironment[]) list
65: .toArray(new ExecutionEnvironment[list.size()]));
66: }
67:
68: public void addExecutionEnvironments(ExecutionEnvironment[] envs) {
69: addManifestElements(envs);
70: }
71:
72: public ExecutionEnvironment removeExecutionEnvironment(
73: ExecutionEnvironment env) {
74: return (ExecutionEnvironment) removeManifestElement(env);
75: }
76:
77: /**
78: * Remove operation performed using the actual object rather than its value
79: * @param environment
80: * @return
81: */
82: public ExecutionEnvironment removeExecutionEnvironmentUnique(
83: ExecutionEnvironment environment) {
84: return (ExecutionEnvironment) removeManifestElement(
85: environment, true);
86: }
87:
88: public ExecutionEnvironment[] getEnvironments() {
89: PDEManifestElement[] elements = getElements();
90: ExecutionEnvironment[] result = new ExecutionEnvironment[elements.length];
91: System.arraycopy(elements, 0, result, 0, elements.length);
92: return result;
93: }
94:
95: }
|