KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > bundle > RequiredExecutionEnvironmentHeader


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.text.bundle;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
16 import org.eclipse.osgi.util.ManifestElement;
17 import org.eclipse.pde.internal.core.ibundle.IBundle;
18
19 public class RequiredExecutionEnvironmentHeader extends CompositeManifestHeader {
20     
21     private static final long serialVersionUID = 1L;
22     
23     public RequiredExecutionEnvironmentHeader(String JavaDoc name, String JavaDoc value, IBundle bundle, String JavaDoc lineDelimiter) {
24         super(name, value, bundle, lineDelimiter);
25     }
26     
27     protected PDEManifestElement createElement(ManifestElement element) {
28         return new ExecutionEnvironment(this, element.getValue());
29     }
30     
31     public boolean hasExecutionEnvironment(IExecutionEnvironment env) {
32         return hasElement(env.getId());
33     }
34     
35     public void addExecutionEnvironment(IExecutionEnvironment env) {
36         addManifestElement(new ExecutionEnvironment(this, env.getId()));
37     }
38     
39     public void addExecutionEnvironments(Object JavaDoc[] envs) {
40         ArrayList JavaDoc list = new ArrayList JavaDoc(envs.length);
41         for (int i = 0; i < envs.length; i++) {
42             ExecutionEnvironment env = null;
43             if (envs[i] instanceof ExecutionEnvironment) {
44                 env = (ExecutionEnvironment)envs[i];
45             } else if (envs[i] instanceof IExecutionEnvironment) {
46                 env = new ExecutionEnvironment(this, ((IExecutionEnvironment)envs[i]).getId());
47             }
48             if (env != null && !hasElement(env.getName()))
49                 list.add(env);
50         }
51         
52         if (list.size() > 0)
53             addManifestElements((ExecutionEnvironment[])list.toArray(new ExecutionEnvironment[list.size()]));
54      }
55     
56     public void addExecutionEnvironments(ExecutionEnvironment[] envs) {
57         addManifestElements(envs);
58     }
59     
60     public ExecutionEnvironment removeExecutionEnvironment(ExecutionEnvironment env) {
61         return (ExecutionEnvironment)removeManifestElement(env);
62     }
63      
64     public ExecutionEnvironment[] getEnvironments() {
65         PDEManifestElement[] elements = getElements();
66         ExecutionEnvironment[] result = new ExecutionEnvironment[elements.length];
67         System.arraycopy(elements, 0, result, 0, elements.length);
68         return result;
69    }
70     
71 }
72
Popular Tags