KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > environments > AccessRuleParticipant


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.internal.launching.environments;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.jdt.core.IAccessRule;
16 import org.eclipse.jdt.core.IJavaProject;
17 import org.eclipse.jdt.internal.launching.LaunchingPlugin;
18 import org.eclipse.jdt.launching.IVMInstall;
19 import org.eclipse.jdt.launching.LibraryLocation;
20 import org.eclipse.jdt.launching.environments.IAccessRuleParticipant;
21 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
22
23 /**
24  * Proxy to an access rule participant for an execution environment.
25  *
26  * @since 3.3
27  */

28 class AccessRuleParticipant implements IAccessRuleParticipant {
29
30     private IConfigurationElement fElement;
31     
32     private IAccessRuleParticipant fDelegate;
33     
34     /**
35      * Constructs a proxy to a rule participant contributed with the
36      * given configuration element. The element may be an
37      * <code>executionEnvironment</code> element or a <code>ruleParticipant</code>
38      * extension.
39      *
40      * @param element
41      */

42     AccessRuleParticipant(IConfigurationElement element) {
43         fElement = element;
44     }
45     
46     /* (non-Javadoc)
47      * @see org.eclipse.jdt.launching.environments.IAccessRuleParticipant#getAccessRules(org.eclipse.jdt.launching.environments.IExecutionEnvironment, org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.LibraryLocation[], org.eclipse.jdt.core.IJavaProject)
48      */

49     public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) {
50         try {
51             return getDelegate().getAccessRules(environment, vm, libraries, project);
52         } catch (CoreException e) {
53             LaunchingPlugin.log(e.getStatus());
54         }
55         IAccessRule[][] rules = new IAccessRule[libraries.length][];
56         for (int i = 0; i < rules.length; i++) {
57             rules[i] = new IAccessRule[0];
58         }
59         return rules;
60     }
61     
62     private IAccessRuleParticipant getDelegate() throws CoreException {
63         if (fDelegate == null) {
64             if (fElement.getName().equals(EnvironmentsManager.ENVIRONMENT_ELEMENT)) {
65                 fDelegate = (IAccessRuleParticipant) fElement.createExecutableExtension(EnvironmentsManager.RULE_PARTICIPANT_ELEMENT);
66             } else {
67                 fDelegate = (IAccessRuleParticipant) fElement.createExecutableExtension("class"); //$NON-NLS-1$
68
}
69         }
70         return fDelegate;
71     }
72     
73     /**
74      * Returns the id of this participant.
75      *
76      * @return participant id
77      */

78     String JavaDoc getId() {
79         if (fElement.getName().equals(EnvironmentsManager.ENVIRONMENT_ELEMENT)) {
80             return fElement.getAttribute(EnvironmentsManager.RULE_PARTICIPANT_ELEMENT);
81         } else {
82             return fElement.getAttribute("id"); //$NON-NLS-1$
83
}
84     }
85
86 }
87
Popular Tags