KickJava   Java API By Example, From Geeks To Geeks.

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


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.AssociationEnd;
24 import javax.jmi.model.Reference;
25 import javax.jmi.model.RefersTo;
26 import javax.jmi.model.Exposes;
27 import javax.jmi.model.ModelPackage;
28 import javax.jmi.reflect.*;
29
30 import org.netbeans.mdr.handlers.*;
31 import org.netbeans.mdr.storagemodel.*;
32
33 /** Implementation of Exposes association, which is derived in the MOF model.
34  *
35  * @author Martin Matula
36  * @version
37  */

38 public abstract class ExposesImpl extends AssociationHandler implements Exposes {
39
40     /** Creates new ExposesImpl */
41     protected ExposesImpl(StorableAssociation storable) {
42         super(storable);
43     }
44
45     public Collection refAllLinks() {
46         // [PENDING] live collection should be returned
47
ModelPackage pkg = (ModelPackage) refImmediatePackage();
48         RefersTo assoc = pkg.getRefersTo();
49         Collection allLinks = assoc.refAllLinks();
50         ArrayList result = new ArrayList(allLinks.size());
51         RefAssociationLink link;
52
53         for (Iterator it = allLinks.iterator(); it.hasNext();) {
54             link = (RefAssociationLink) it.next();
55             result.add(new AssociationLink((StorableObject) ((BaseObjectHandler) link.refFirstEnd())._getDelegate(), (StorableObject) ((BaseObjectHandler) link.refSecondEnd())._getDelegate()));
56         }
57
58         return new IndexSetWrapper(_getMdrStorage(), result);
59     }
60
61     public boolean exists(Reference referrer, AssociationEnd exposedEnd) {
62         return exposedEnd.equals(referrer.getReferencedEnd().otherEnd());
63     }
64
65     public AssociationEnd getExposedEnd(Reference referrer) {
66         return referrer.getReferencedEnd().otherEnd();
67     }
68
69     public Collection getReferrer(AssociationEnd exposedEnd) {
70         return ((ModelPackage) refImmediatePackage()).getRefersTo().getReferent(exposedEnd.otherEnd());
71     }
72
73     public boolean add(Reference referrer, AssociationEnd exposedEnd) {
74         ModelPackage pkg = (ModelPackage) refImmediatePackage();
75         RefersTo assoc = (RefersTo) pkg.getRefersTo();
76         return assoc.add(referrer, exposedEnd.otherEnd());
77     }
78
79     public boolean remove(Reference referrer, AssociationEnd exposedEnd) {
80         ModelPackage pkg = (ModelPackage) refImmediatePackage();
81         RefersTo assoc = (RefersTo) pkg.getRefersTo();
82         return assoc.remove(referrer, exposedEnd.otherEnd());
83     }
84 }
85
Popular Tags