1 19 package org.netbeans.jmiimpl.mof.model; 20 21 import java.util.*; 22 import javax.jmi.model.*; 23 import javax.jmi.reflect.*; 24 25 import org.netbeans.mdr.util.*; 26 import org.netbeans.mdr.storagemodel.*; 27 import org.netbeans.mdr.handlers.*; 28 import org.netbeans.mdr.persistence.StorageException; 29 30 35 public abstract class GeneralizableElementImpl extends NamespaceImpl implements GeneralizableElement { 36 37 protected GeneralizableElementImpl(StorableObject storable) { 38 super(storable); 39 } 40 41 private Collection extendedNamespace() { 42 try { 43 StorableFeatured storable = (StorableFeatured) _getDelegate(); 44 StorableAssociation assoc = resolveContains(storable); 45 Collection result = new ArrayList((Collection) assoc.queryObjects(assoc.getEnd1Name(), storable.getMofId())); 46 47 if (this instanceof GeneralizableElement) { 48 Collection supertypes = ((GeneralizableElement) this).allSupertypes(); 49 50 for (Iterator it = supertypes.iterator(); it.hasNext();) { 51 storable = (StorableFeatured) ((BaseObjectHandler) it.next())._getDelegate(); 52 result.addAll((Collection) assoc.queryObjects(assoc.getEnd1Name(), storable.getMofId())); 53 } 54 } 55 56 if (this instanceof MofPackage) { 57 ArrayList imports = new ArrayList(); 58 Object temp; 59 60 for (Iterator it = result.iterator(); it.hasNext();) { 61 temp = it.next(); 62 if (temp instanceof Import) { 63 imports.add(((BaseObjectHandler) ((Import) temp).getImportedNamespace())._getDelegate()); 64 } 65 } 66 67 result.addAll(imports); 68 } 69 70 return result; 71 } catch (StorageException e) { 72 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 73 } 74 } 75 76 private void allSupertypes2(List result, Set visited) { 77 List tempElements = getSupertypes(); 78 GeneralizableElementImpl element; 79 80 for (Iterator it = tempElements.iterator(); it.hasNext();) { 81 element = (GeneralizableElementImpl) it.next(); 82 if (visited.add(element)) { 83 element.allSupertypes2(result, visited); 84 result.add(element); 85 } 86 } 87 } 88 89 91 public List allSupertypes() { 92 _lock(false); 93 try { 94 List result = new ArrayList(); 95 allSupertypes2(result, new HashSet()); 96 return result; 97 } finally { 98 _unlock(); 99 } 100 } 101 102 public ModelElement lookupElementExtended(String name) throws NameNotFoundException { 103 _lock(false); 104 try { 105 Collection contents = extendedNamespace(); 106 for (Iterator it = contents.iterator(); it.hasNext();) { 119 ModelElement el = (ModelElement) _getRepository().getHandler((StorableBaseObject) it.next()); 120 if (el.getName().equals(name)) { 121 return el; 122 } 123 } 124 } finally { 126 _unlock(); 127 } 128 129 throw new NameNotFoundException(name); 130 } 131 132 public List findElementsByTypeExtended(javax.jmi.model.MofClass ofType, boolean includeSubtypes) { 133 _lock(false); 134 try { 135 ArrayList result = new ArrayList(); 136 RefObject element; 137 Collection contents = extendedNamespace(); 138 139 for (Iterator it = contents.iterator(); it.hasNext();) { 140 element = (RefObject) _getRepository().getHandler((StorableObject) it.next()); 141 if (element.refIsInstanceOf(ofType, includeSubtypes)) { 142 result.add(element); 143 } 144 } 145 146 return result; 147 } finally { 148 _unlock(); 149 } 150 } 151 152 154 } 155 | Popular Tags |