1 11 12 package org.eclipse.ui.internal.contexts; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.ui.IMemento; 19 import org.eclipse.ui.internal.util.Util; 20 21 final class Persistence { 22 23 final static String PACKAGE_BASE = "contexts"; 25 final static String PACKAGE_FULL = "org.eclipse.ui.contexts"; 27 final static String PACKAGE_PREFIX = "org.eclipse.ui"; 29 final static String TAG_CONTEXT = "context"; 31 final static String TAG_ID = "id"; 33 final static String TAG_NAME = "name"; 35 41 final static String TAG_PARENT = "parent"; 43 final static String TAG_PARENT_ID = "parentId"; 45 51 final static String TAG_PARENT_SCOPE = "parentScope"; 53 final static String TAG_SOURCE_ID = "sourceId"; 55 static ContextDefinition readContextDefinition(IMemento memento, 56 String sourceIdOverride) { 57 if (memento == null) throw new NullPointerException (); 58 59 String id = memento.getString(TAG_ID); 60 String name = memento.getString(TAG_NAME); 61 String parentId = memento.getString(TAG_PARENT_ID); 62 String sourceId = sourceIdOverride != null ? sourceIdOverride : memento 63 .getString(TAG_SOURCE_ID); 64 65 69 if (parentId == null) { 70 parentId = memento.getString(TAG_PARENT_SCOPE); 72 } 73 if (parentId == null) { 74 parentId = memento.getString(TAG_PARENT); 76 } 77 79 return new ContextDefinition(id, name, parentId, sourceId); 80 } 81 82 static List readContextDefinitions(IMemento memento, String name, 83 String sourceIdOverride) { 84 if (memento == null || name == null) throw new NullPointerException (); 85 86 IMemento[] mementos = memento.getChildren(name); 87 88 if (mementos == null) throw new NullPointerException (); 89 90 List list = new ArrayList (mementos.length); 91 92 for (int i = 0; i < mementos.length; i++) 93 list.add(readContextDefinition(mementos[i], sourceIdOverride)); 94 95 return list; 96 } 97 98 static void writeContextDefinition(IMemento memento, 99 ContextDefinition contextDefinition) { 100 if (memento == null || contextDefinition == null) 101 throw new NullPointerException (); 102 103 memento.putString(TAG_ID, contextDefinition.getId()); 104 memento.putString(TAG_NAME, contextDefinition.getName()); 105 memento.putString(TAG_PARENT_ID, contextDefinition.getParentId()); 106 memento.putString(TAG_SOURCE_ID, contextDefinition.getSourceId()); 107 } 108 109 static void writeContextDefinitions(IMemento memento, String name, 110 List contextDefinitions) { 111 if (memento == null || name == null || contextDefinitions == null) 112 throw new NullPointerException (); 113 114 contextDefinitions = new ArrayList (contextDefinitions); 115 Iterator iterator = contextDefinitions.iterator(); 116 117 while (iterator.hasNext()) 118 Util.assertInstance(iterator.next(), ContextDefinition.class); 119 120 iterator = contextDefinitions.iterator(); 121 122 while (iterator.hasNext()) 123 writeContextDefinition(memento.createChild(name), 124 (ContextDefinition) iterator.next()); 125 } 126 127 131 private Persistence() { 132 } 134 } 135 | Popular Tags |