KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > util > ConfigurationElementMemento


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.ui.internal.util;
13
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.ui.IMemento;
16
17 public final class ConfigurationElementMemento implements IMemento {
18
19     private IConfigurationElement configurationElement;
20
21     public ConfigurationElementMemento(
22             IConfigurationElement configurationElement) {
23         if (configurationElement == null) {
24             throw new NullPointerException JavaDoc();
25         }
26
27         this.configurationElement = configurationElement;
28     }
29
30     public IMemento createChild(String JavaDoc type) {
31         return null;
32     }
33
34     public IMemento createChild(String JavaDoc type, String JavaDoc id) {
35         return null;
36     }
37
38     public IMemento getChild(String JavaDoc type) {
39         IConfigurationElement[] configurationElements = configurationElement
40                 .getChildren(type);
41
42         if (configurationElements != null && configurationElements.length >= 1) {
43             return new ConfigurationElementMemento(configurationElements[0]);
44         }
45
46         return null;
47     }
48
49     public IMemento[] getChildren(String JavaDoc type) {
50         IConfigurationElement[] configurationElements = configurationElement
51                 .getChildren(type);
52
53         if (configurationElements != null && configurationElements.length >= 1) {
54             IMemento mementos[] = new ConfigurationElementMemento[configurationElements.length];
55
56             for (int i = 0; i < configurationElements.length; i++) {
57                 mementos[i] = new ConfigurationElementMemento(
58                         configurationElements[i]);
59             }
60
61             return mementos;
62         }
63
64         return new IMemento[0];
65     }
66
67     public Float JavaDoc getFloat(String JavaDoc key) {
68         String JavaDoc string = configurationElement.getAttribute(key);
69
70         if (string != null) {
71             try {
72                 return new Float JavaDoc(string);
73             } catch (NumberFormatException JavaDoc eNumberFormat) {
74             }
75         }
76
77         return null;
78     }
79
80     public String JavaDoc getID() {
81         return configurationElement.getAttribute(TAG_ID);
82     }
83
84     public Integer JavaDoc getInteger(String JavaDoc key) {
85         String JavaDoc string = configurationElement.getAttribute(key);
86
87         if (string != null) {
88             try {
89                 return new Integer JavaDoc(string);
90             } catch (NumberFormatException JavaDoc eNumberFormat) {
91             }
92         }
93
94         return null;
95     }
96
97     public String JavaDoc getString(String JavaDoc key) {
98         return configurationElement.getAttribute(key);
99     }
100
101     public String JavaDoc getTextData() {
102         return configurationElement.getValue();
103     }
104
105     public void putFloat(String JavaDoc key, float value) {
106     }
107
108     public void putInteger(String JavaDoc key, int value) {
109     }
110
111     public void putMemento(IMemento memento) {
112     }
113
114     public void putString(String JavaDoc key, String JavaDoc value) {
115     }
116
117     public void putTextData(String JavaDoc data) {
118     }
119 }
120
Popular Tags