001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.activities;
011:
012: import org.eclipse.ui.IMemento;
013:
014: final class Persistence {
015: final static String PACKAGE_BASE = "activities"; //$NON-NLS-1$
016:
017: final static String PACKAGE_FULL = "org.eclipse.ui.activities"; //$NON-NLS-1$
018:
019: final static String PACKAGE_PREFIX = "org.eclipse.ui"; //$NON-NLS-1$
020:
021: final static String TAG_ACTIVITY = "activity"; //$NON-NLS-1$
022:
023: final static String TAG_ACTIVITY_REQUIREMENT_BINDING = "activityRequirementBinding"; //$NON-NLS-1$
024:
025: final static String TAG_DEFAULT_ENABLEMENT = "defaultEnablement"; //$NON-NLS-1$
026:
027: final static String TAG_ACTIVITY_ID = "activityId"; //$NON-NLS-1$
028:
029: final static String TAG_ACTIVITY_PATTERN_BINDING = "activityPatternBinding"; //$NON-NLS-1$
030:
031: final static String TAG_CATEGORY = "category"; //$NON-NLS-1$
032:
033: final static String TAG_CATEGORY_ACTIVITY_BINDING = "categoryActivityBinding"; //$NON-NLS-1$
034:
035: final static String TAG_CATEGORY_ID = "categoryId"; //$NON-NLS-1$
036:
037: final static String TAG_REQUIRED_ACTIVITY_ID = "requiredActivityId"; //$NON-NLS-1$
038:
039: final static String TAG_ID = "id"; //$NON-NLS-1$
040:
041: final static String TAG_NAME = "name"; //$NON-NLS-1$
042:
043: final static String TAG_PATTERN = "pattern"; //$NON-NLS-1$
044:
045: final static String TAG_SOURCE_ID = "sourceId"; //$NON-NLS-1$
046:
047: final static String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
048:
049: static ActivityRequirementBindingDefinition readActivityRequirementBindingDefinition(
050: IMemento memento, String sourceIdOverride) {
051: if (memento == null) {
052: throw new NullPointerException();
053: }
054:
055: String childActivityId = memento
056: .getString(TAG_REQUIRED_ACTIVITY_ID);
057: String parentActivityId = memento.getString(TAG_ACTIVITY_ID);
058: if (childActivityId == null || parentActivityId == null) {
059: return null;
060: }
061: String sourceId = sourceIdOverride != null ? sourceIdOverride
062: : memento.getString(TAG_SOURCE_ID);
063: return new ActivityRequirementBindingDefinition(
064: childActivityId, parentActivityId, sourceId);
065: }
066:
067: static String readDefaultEnablement(IMemento memento) {
068: if (memento == null) {
069: throw new NullPointerException();
070: }
071:
072: return memento.getString(TAG_ID);
073: }
074:
075: static ActivityDefinition readActivityDefinition(IMemento memento,
076: String sourceIdOverride) {
077: if (memento == null) {
078: throw new NullPointerException();
079: }
080:
081: String id = memento.getString(TAG_ID);
082: if (id == null) {
083: return null;
084: }
085: String name = memento.getString(TAG_NAME);
086: if (name == null) {
087: return null;
088: }
089: String description = memento.getString(TAG_DESCRIPTION);
090: if (description == null) {
091: description = ""; //$NON-NLS-1$
092: }
093: String sourceId = sourceIdOverride != null ? sourceIdOverride
094: : memento.getString(TAG_SOURCE_ID);
095: return new ActivityDefinition(id, name, sourceId, description);
096: }
097:
098: static ActivityPatternBindingDefinition readActivityPatternBindingDefinition(
099: IMemento memento, String sourceIdOverride) {
100: if (memento == null) {
101: throw new NullPointerException();
102: }
103:
104: String activityId = memento.getString(TAG_ACTIVITY_ID);
105: if (activityId == null) {
106: return null;
107: }
108: String pattern = memento.getString(TAG_PATTERN);
109: if (pattern == null) {
110: return null;
111: }
112: String sourceId = sourceIdOverride != null ? sourceIdOverride
113: : memento.getString(TAG_SOURCE_ID);
114: return new ActivityPatternBindingDefinition(activityId,
115: pattern, sourceId);
116: }
117:
118: static CategoryActivityBindingDefinition readCategoryActivityBindingDefinition(
119: IMemento memento, String sourceIdOverride) {
120: if (memento == null) {
121: throw new NullPointerException();
122: }
123:
124: String activityId = memento.getString(TAG_ACTIVITY_ID);
125: if (activityId == null) {
126: return null;
127: }
128: String categoryId = memento.getString(TAG_CATEGORY_ID);
129: if (categoryId == null) {
130: return null;
131: }
132: String sourceId = sourceIdOverride != null ? sourceIdOverride
133: : memento.getString(TAG_SOURCE_ID);
134: return new CategoryActivityBindingDefinition(activityId,
135: categoryId, sourceId);
136: }
137:
138: static CategoryDefinition readCategoryDefinition(IMemento memento,
139: String sourceIdOverride) {
140: if (memento == null) {
141: throw new NullPointerException();
142: }
143:
144: String id = memento.getString(TAG_ID);
145: if (id == null) {
146: return null;
147: }
148: String name = memento.getString(TAG_NAME);
149: if (name == null) {
150: return null;
151: }
152: String description = memento.getString(TAG_DESCRIPTION);
153: if (description == null) {
154: description = ""; //$NON-NLS-1$
155: }
156: String sourceId = sourceIdOverride != null ? sourceIdOverride
157: : memento.getString(TAG_SOURCE_ID);
158: return new CategoryDefinition(id, name, sourceId, description);
159: }
160:
161: private Persistence() {
162: //no-op
163: }
164: }
|