001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.util;
011:
012: import org.eclipse.core.runtime.IConfigurationElement;
013: import org.eclipse.ui.IMemento;
014:
015: public final class ConfigurationElementMemento implements IMemento {
016:
017: private IConfigurationElement configurationElement;
018:
019: public ConfigurationElementMemento(
020: IConfigurationElement configurationElement) {
021: if (configurationElement == null) {
022: throw new NullPointerException();
023: }
024:
025: this .configurationElement = configurationElement;
026: }
027:
028: public IMemento createChild(String type) {
029: return null;
030: }
031:
032: public IMemento createChild(String type, String id) {
033: return null;
034: }
035:
036: public IMemento getChild(String type) {
037: IConfigurationElement[] configurationElements = configurationElement
038: .getChildren(type);
039:
040: if (configurationElements != null
041: && configurationElements.length >= 1) {
042: return new ConfigurationElementMemento(
043: configurationElements[0]);
044: }
045:
046: return null;
047: }
048:
049: public IMemento[] getChildren(String type) {
050: IConfigurationElement[] configurationElements = configurationElement
051: .getChildren(type);
052:
053: if (configurationElements != null
054: && configurationElements.length >= 1) {
055: IMemento mementos[] = new ConfigurationElementMemento[configurationElements.length];
056:
057: for (int i = 0; i < configurationElements.length; i++) {
058: mementos[i] = new ConfigurationElementMemento(
059: configurationElements[i]);
060: }
061:
062: return mementos;
063: }
064:
065: return new IMemento[0];
066: }
067:
068: public Float getFloat(String key) {
069: String string = configurationElement.getAttribute(key);
070:
071: if (string != null) {
072: try {
073: return new Float(string);
074: } catch (NumberFormatException eNumberFormat) {
075: }
076: }
077:
078: return null;
079: }
080:
081: public String getType() {
082: return configurationElement.getName();
083: }
084:
085: public String getID() {
086: return configurationElement.getAttribute(TAG_ID);
087: }
088:
089: public Integer getInteger(String key) {
090: String string = configurationElement.getAttribute(key);
091:
092: if (string != null) {
093: try {
094: return new Integer(string);
095: } catch (NumberFormatException eNumberFormat) {
096: }
097: }
098:
099: return null;
100: }
101:
102: public String getString(String key) {
103: return configurationElement.getAttribute(key);
104: }
105:
106: public Boolean getBoolean(String key) {
107: String string = configurationElement.getAttribute(key);
108: if (string == null) {
109: return null;
110: }
111: return Boolean.valueOf(string);
112: }
113:
114: public String getTextData() {
115: return configurationElement.getValue();
116: }
117:
118: public String[] getAttributeKeys() {
119: return configurationElement.getAttributeNames();
120: }
121:
122: public void putFloat(String key, float value) {
123: }
124:
125: public void putInteger(String key, int value) {
126: }
127:
128: public void putMemento(IMemento memento) {
129: }
130:
131: public void putString(String key, String value) {
132: }
133:
134: public void putBoolean(String key, boolean value) {
135: }
136:
137: public void putTextData(String data) {
138: }
139: }
|