KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > core > LogicalStructureType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.debug.internal.core;
12
13 import com.ibm.icu.text.MessageFormat;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.debug.core.*;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.model.*;
22 import org.eclipse.debug.core.model.IValue;
23
24 /**
25  * Proxy to a logical structure type extension.
26  */

27 public class LogicalStructureType implements ILogicalStructureType {
28
29     private IConfigurationElement fConfigurationElement;
30     private ILogicalStructureTypeDelegate fDelegate;
31     private String JavaDoc fModelId;
32     // whether the 'description' attribute has been verified to exist: it is only
33
// required when the delegate does *not* implement ILogicalStructureTypeDelegate2.
34
private boolean fVerifiedDescription = false;
35     
36     /**
37      * Constructs a new logical structure type, and verifies required attributes.
38      *
39      * @param element configuration element
40      * @exception CoreException if required attributes are missing
41      */

42     public LogicalStructureType(IConfigurationElement element) throws CoreException {
43         fConfigurationElement = element;
44         verifyAttributes();
45     }
46
47     /**
48      * Verifies required attributes.
49      *
50      * @exception CoreException if required attributes are missing
51      */

52     private void verifyAttributes() throws CoreException {
53         verifyAttributeExists("id"); //$NON-NLS-1$
54
verifyAttributeExists("class"); //$NON-NLS-1$
55
fModelId = fConfigurationElement.getAttribute("modelIdentifier"); //$NON-NLS-1$
56
if (fModelId == null) {
57             missingAttribute("modelIdentifier"); //$NON-NLS-1$
58
}
59     }
60     
61     /**
62      * Verifies the given attribute exists
63      *
64      * @exception CoreException if attribute does not exist
65      */

66     private void verifyAttributeExists(String JavaDoc name) throws CoreException {
67         if (fConfigurationElement.getAttribute(name) == null) {
68             missingAttribute(name);
69         }
70     }
71
72     private void missingAttribute(String JavaDoc attrName) throws CoreException {
73         throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(DebugCoreMessages.LogicalStructureType_7,new String JavaDoc[]{attrName}), null));
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.debug.internal.core.ILogicalStructureType#getDescription()
78      */

79     public String JavaDoc getDescription() {
80         return fConfigurationElement.getAttribute("description"); //$NON-NLS-1$
81
}
82     
83     /* (non-Javadoc)
84      * @see org.eclipse.debug.internal.core.ILogicalStructureType#getId()
85      */

86     public String JavaDoc getId() {
87         return fConfigurationElement.getAttribute("id"); //$NON-NLS-1$
88
}
89
90     /* (non-Javadoc)
91      * @see org.eclipse.debug.internal.core.ILogicalStructureType#getLogicalStructure(org.eclipse.debug.core.model.IValue)
92      */

93     public IValue getLogicalStructure(IValue value) throws CoreException {
94         return getDelegate().getLogicalStructure(value);
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.debug.internal.core.ILogicalStructureType#providesLogicalStructure(org.eclipse.debug.core.model.IValue)
99      */

100     public boolean providesLogicalStructure(IValue value) {
101         if (value.getModelIdentifier().equals(fModelId)) {
102             return getDelegate().providesLogicalStructure(value);
103         }
104         return false;
105     }
106
107     protected ILogicalStructureTypeDelegate getDelegate() {
108         if (fDelegate == null) {
109             try {
110                 fDelegate = (ILogicalStructureTypeDelegate) fConfigurationElement.createExecutableExtension("class"); //$NON-NLS-1$
111
} catch (CoreException e) {
112                 DebugPlugin.log(e);
113             }
114         }
115         return fDelegate;
116     }
117
118     /* (non-Javadoc)
119      * @see org.eclipse.debug.core.model.ILogicalStructureTypeDelegate2#getDescription(org.eclipse.debug.core.model.IValue)
120      */

121     public String JavaDoc getDescription(IValue value) {
122         ILogicalStructureTypeDelegate delegate = getDelegate();
123         if (delegate instanceof ILogicalStructureTypeDelegate2) {
124             ILogicalStructureTypeDelegate2 d2 = (ILogicalStructureTypeDelegate2) delegate;
125             return d2.getDescription(value);
126         }
127         if (!fVerifiedDescription) {
128             fVerifiedDescription = true;
129             try {
130                 verifyAttributeExists("description"); //$NON-NLS-1$
131
} catch (CoreException e) {
132                 DebugPlugin.log(e);
133             }
134         }
135         String JavaDoc description = getDescription();
136         if (description == null) {
137             return DebugCoreMessages.LogicalStructureType_0;
138         }
139         return description;
140     }
141 }
142
Popular Tags