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.persistence.*; 28 import org.netbeans.mdr.handlers.*; 29 30 35 public abstract class NamespaceImpl extends ModelElementImpl implements Namespace { 36 37 protected NamespaceImpl(StorableObject storable) { 38 super(storable); 39 } 40 41 private static final HashMap contains = new HashMap(); 42 43 public static void clearContains() { 44 contains.clear(); 45 } 46 47 protected static StorableAssociation resolveContains(StorableFeatured storable) throws StorageException { 48 StorableAssociation result = (StorableAssociation) contains.get(storable.getOutermostPackageId()); 49 50 if (result == null) { 51 result = storable.getClassProxy().getReferenceDescriptor(MOFConstants.SH_MODEL_MODEL_ELEMENT_CONTAINER).getAssociation(); 52 contains.put(storable.getOutermostPackageId(), result); 53 } 54 55 return result; 56 } 57 58 60 public ModelElement lookupElement(String name) throws NameNotFoundException { 61 _lock(false); 62 try { 63 Collection contents; 64 65 contents = getContents(); 84 85 for(Iterator it = contents.iterator(); it.hasNext();) { 86 ModelElement el = (ModelElement) it.next(); 87 if (el.getName().equals(name)) { 88 return el; 89 } 90 } 91 } finally { 93 _unlock(); 94 } 95 96 throw new NameNotFoundException(name); 97 } 98 99 public ModelElement resolveQualifiedName(List qualifiedName) throws NameNotResolvedException { 100 if (qualifiedName.size() < 1) { 101 throw new DebugException("No qualified name provided."); 102 } 103 104 ModelElement element; 105 Iterator qnIterator = qualifiedName.iterator(); 106 String name = (String ) qnIterator.next(); 107 ArrayList rest = new ArrayList(); 108 109 _lock(false); 110 try { 111 try { 112 element = lookupElement(name); 113 } catch (NameNotFoundException e) { 114 throw new NameNotResolvedException("InvalidName", qualifiedName); 115 } 116 117 for (; qnIterator.hasNext();) { 118 rest.add(qnIterator.next()); 119 } 120 121 if (rest.size() >= 1) { 122 if (element instanceof Namespace) { 123 element = ((Namespace) element).resolveQualifiedName(rest); 124 } else { 125 throw new NameNotResolvedException("NotNameSpace", qualifiedName); 126 } 127 } 128 } finally { 129 _unlock(); 130 } 131 132 return element; 133 } 134 135 public boolean nameIsValid(String proposedName) { 136 _lock(false); 137 try { 138 if (this instanceof GeneralizableElement) { 139 ((GeneralizableElement) this).lookupElementExtended(proposedName); 140 } else { 141 this.lookupElement(proposedName); 142 } 143 return false; 144 } catch (NameNotFoundException e) { 145 return true; 146 } finally { 147 _unlock(); 148 } 149 } 150 151 public List findElementsByType(javax.jmi.model.MofClass ofType, boolean includeSubtypes ) { 152 _lock(false); 153 try { 154 ArrayList result = new ArrayList(); 155 Collection contents = getContents(); 156 RefObject element; 157 158 for (Iterator it = contents.iterator(); it.hasNext();) { 159 element = (RefObject) it.next(); 160 if (element.refIsInstanceOf(ofType, includeSubtypes)) { 161 result.add(element); 162 } 163 } 164 165 return result; 166 } finally { 167 _unlock(); 168 } 169 } 170 171 173 } 174 | Popular Tags |