1 19 package org.netbeans.jmiimpl.mof.model; 20 21 import org.netbeans.mdr.handlers.InstanceHandler; 22 import org.netbeans.mdr.storagemodel.StorableObject; 23 import javax.jmi.model.*; 24 import java.util.*; 25 26 31 public abstract class ModelElementImpl extends InstanceHandler implements ModelElement { 32 public static final java.lang.String CONTAINER_DEP = "container"; public static final java.lang.String CONTENTS_DEP = "contents"; public static final java.lang.String SIGNATURE_DEP = "signature"; public static final java.lang.String CONSTRAINT_DEP = "constraint"; public static final java.lang.String CONSTRAINED_ELEMENTS_DEP = "constrained elements"; public static final java.lang.String SPECIALIZATION_DEP = "specialization"; public static final java.lang.String IMPORT_DEP = "import"; public static final java.lang.String TYPE_DEFINITION_DEP = "type definition"; public static final java.lang.String REFERENCED_ENDS_DEP = "referenced ends"; public static final java.lang.String TAGGED_ELEMENTS_DEP = "tagged elements"; public static final java.lang.String INDIRECT_DEP = "indirect"; public static final java.lang.String ALL_DEP = "all"; 46 static final HashSet ALL_KINDS = new HashSet(); 47 48 static { 49 ALL_KINDS.add(CONTAINER_DEP); 50 ALL_KINDS.add(CONTENTS_DEP); 51 ALL_KINDS.add(SIGNATURE_DEP); 52 ALL_KINDS.add(CONSTRAINT_DEP); 53 ALL_KINDS.add(CONSTRAINED_ELEMENTS_DEP); 54 ALL_KINDS.add(SPECIALIZATION_DEP); 55 ALL_KINDS.add(IMPORT_DEP); 56 ALL_KINDS.add(TYPE_DEFINITION_DEP); 57 ALL_KINDS.add(REFERENCED_ENDS_DEP); 58 ALL_KINDS.add(TAGGED_ELEMENTS_DEP); 59 } 60 61 protected ModelElementImpl(StorableObject storable) { 62 super(storable); 63 } 64 65 private void recursiveFindDeps(Set kinds, Set result) { 66 Set temp = new HashSet(); 67 for (Iterator m = kinds.iterator(); m.hasNext();) { 68 findDepsOfKind((String ) m.next(), temp); 69 } 70 for (Iterator it = temp.iterator(); it.hasNext();) { 71 ModelElementImpl me = (ModelElementImpl) it.next(); 72 if (result.add(me)) { 73 me.recursiveFindDeps(kinds, result); 74 } 75 } 76 } 77 78 private void findDepsOfKind(String kind, Set result) { 79 if (kind.equals(CONSTRAINT_DEP)) { result.addAll(this.getConstraints()); 81 } else if (kind.equals(CONTAINER_DEP)) { result.add(this.getContainer()); 83 } else if (kind.equals(CONSTRAINED_ELEMENTS_DEP) && (this instanceof Constraint)) { result.addAll(((Constraint) this).getConstrainedElements()); 85 } else if (kind.equals(SPECIALIZATION_DEP) && (this instanceof GeneralizableElement)) { result.addAll(((GeneralizableElement) this).getSupertypes()); 87 } else if (kind.equals(IMPORT_DEP) && (this instanceof Import)) { result.add(((Import) this).getImportedNamespace()); 89 } else if (kind.equals(CONTENTS_DEP) && (this instanceof Namespace)) { result.addAll(((Namespace) this).getContents()); 91 } else if (kind.equals(SIGNATURE_DEP) && (this instanceof Operation)) { result.addAll(((Operation) this).getExceptions()); 93 } else if (kind.equals(TAGGED_ELEMENTS_DEP) && (this instanceof Tag)) { result.addAll(((Tag) this).getElements()); 95 } else if (kind.equals(TYPE_DEFINITION_DEP) && (this instanceof TypedElement)) { result.add(((TypedElement) this).getType()); 97 } else if (kind.equals(REFERENCED_ENDS_DEP) && (this instanceof Reference)) { result.add(((Reference) this).getReferencedEnd()); 99 result.add(((Reference) this).getExposedEnd()); 100 } 101 102 result.remove(null); 103 } 104 105 private boolean isDepOfKind(String kind, ModelElement otherElement) { 106 HashSet result = new HashSet(); 107 findDepsOfKind(kind, result); 108 return result.contains(otherElement); 109 } 110 111 113 public boolean isFrozen() { 114 return false; 116 } 117 118 public Collection findRequiredElements(Collection kinds, boolean recursive) { 119 _lock(false); 120 try { 121 if (kinds.contains(ALL_DEP)) { 122 return findRequiredElements(ALL_KINDS, recursive); 123 } else { 124 Set newKinds = (kinds == ALL_KINDS ? ALL_KINDS : new HashSet(kinds)); 125 Set result = new HashSet(); 126 if (recursive) { 127 recursiveFindDeps(newKinds, result); 128 } else { 129 String kind; 130 for (Iterator it = kinds.iterator(); it.hasNext();) { 131 kind = (String ) it.next(); 132 findDepsOfKind(kind, result); 133 } 134 } 135 return result; 136 } 137 } finally { 138 _unlock(); 139 } 140 } 141 142 public boolean isVisible(ModelElement otherElement) { 143 return true; 144 } 145 146 public boolean isRequiredBecause(ModelElement otherElement, String [] reason) { 147 _lock(false); 148 try { 149 for (Iterator it = ALL_KINDS.iterator(); it.hasNext();) { 150 reason[0] = (String ) it.next(); 151 if (isDepOfKind(reason[0], otherElement)) { 152 return true; 153 } 154 } 155 156 if (findRequiredElements(ALL_KINDS, true).size() > 0) { 157 reason[0] = INDIRECT_DEP; 158 } else { 159 reason[0] = ""; 160 return false; 161 } 162 163 return true; 164 } finally { 165 _unlock(); 166 } 167 } 168 169 171 public List getQualifiedName() { 172 List result; 173 Namespace container = getContainer(); 174 175 if (container == null) { 176 result = new ArrayList(); 177 } else { 178 result = new ArrayList(container.getQualifiedName()); 179 } 180 result.add(getName()); 181 return result; 182 } 183 } 184 | Popular Tags |