KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmiimpl > mof > model > DependsOnImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.jmiimpl.mof.model;
20
21 import java.util.*;
22
23 import javax.jmi.model.*;
24 import javax.jmi.reflect.*;
25
26 import org.netbeans.mdr.handlers.BaseObjectHandler;
27 import org.netbeans.mdr.handlers.AssociationHandler;
28 import org.netbeans.mdr.handlers.IndexSetWrapper;
29 import org.netbeans.mdr.storagemodel.AssociationLink;
30 import org.netbeans.mdr.storagemodel.StorableAssociation;
31 import org.netbeans.mdr.storagemodel.StorableObject;
32
33 /** Implementation of DependsOn association which is derived in the MOF model.
34  *
35  * @author Martin Matula
36  * @version
37  */

38 public abstract class DependsOnImpl extends AssociationHandler implements DependsOn {
39
40     /** Creates new DependsOnImpl */
41     protected DependsOnImpl(StorableAssociation storable) {
42         super(storable);
43     }
44
45     // [PENDING] should be probably live
46
public Collection refAllLinks() {
47         HashSet allLinks = new HashSet();
48         ModelElement dependent;
49         
50         for (Iterator it = ((ModelPackage) refImmediatePackage()).getModelElement().refAllOfType().iterator(); it.hasNext();) {
51             dependent = (ModelElement) it.next();
52             for (Iterator it2 = dependent.findRequiredElements(ModelElementImpl.ALL_KINDS, true).iterator(); it2.hasNext();) {
53                 allLinks.add(new AssociationLink((StorableObject) ((BaseObjectHandler) dependent)._getDelegate(), (StorableObject) ((BaseObjectHandler) it2.next())._getDelegate()));
54             }
55         }
56
57         return new IndexSetWrapper(_getMdrStorage(), allLinks);
58     }
59
60     public boolean exists(ModelElement dependent, ModelElement provider) {
61         return dependent.isRequiredBecause(provider, new String JavaDoc[1]);
62     }
63
64     public Collection getProvider(ModelElement dependent) {
65         return dependent.findRequiredElements(ModelElementImpl.ALL_KINDS, true);
66     }
67
68     public Collection getDependent(ModelElement provider) {
69         Set result = new HashSet();
70         findDependentElements(provider, result);
71         return result;
72     }
73     
74     private void findDependentElements(ModelElement provider, Set result) {
75         Set temp = new HashSet();
76         ModelPackage pkg = (ModelPackage) refImmediatePackage();
77
78         if (provider instanceof Constraint) {
79             temp.addAll(((Constraint) provider).getConstrainedElements());
80         } else if (provider instanceof Namespace) {
81             temp.addAll(((Namespace) provider).getContents());
82             temp.addAll(pkg.getAliases().getImporter((Namespace) provider));
83             if (provider instanceof GeneralizableElement) {
84                 temp.addAll(pkg.getGeneralizes().getSubtype((GeneralizableElement) provider));
85                 if (provider instanceof Classifier) {
86                     temp.addAll(pkg.getIsOfType().getTypedElements((Classifier) provider));
87                 }
88             } else if (provider instanceof MofException) {
89                 temp.addAll(pkg.getCanRaise().getOperation((MofException) provider));
90             }
91         } else if (provider instanceof AssociationEnd) {
92             temp.addAll(pkg.getRefersTo().getReferent((AssociationEnd) provider));
93             temp.addAll(pkg.getExposes().getReferrer((AssociationEnd) provider));
94         }
95
96         temp.addAll(provider.getConstraints());
97         temp.add(provider.getContainer());
98         temp.addAll(pkg.getAttachesTo().getTag(provider));
99
100         for (Iterator it = temp.iterator(); it.hasNext();) {
101             ModelElement me = (ModelElement) it.next();
102             if (result.add(me)) {
103                 findDependentElements(me, result);
104             }
105         }
106     }
107 }
108
Popular Tags