KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > uml > transformation > ast > TransformAssociations


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Pierre Carpentier.
23 Contributor(s): Philippe Merle.
24
25 ---------------------------------------------------------------------
26 $Id: TransformAssociations.java,v 1.1 2004/05/26 11:25:35 carpentier Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.uml.transformation.ast;
30
31 import ispuml.mdaTransformation.RuleContext;
32 import ispuml.mdaTransformation.TransformationException;
33 import ispuml.mdaTransformation.ActionBase;
34 import ispuml.mdaTransformation.rules.xml.CompositeXmlAction;
35
36 import javax.jmi.reflect.RefPackage;
37
38 import org.objectweb.openccm.uml.transformation.modfact.JmiModFactModelCreateUtils;
39
40 import java.util.Collection JavaDoc;
41 import java.util.Iterator JavaDoc;
42
43 /**
44  * An action which gets all the classes associated to a specified class.
45  */

46 public class TransformAssociations extends CompositeXmlAction {
47
48     /**
49      * Constructor.
50      */

51     public TransformAssociations() {
52         // The src property is not required. If it is not set, use the bean provided
53
// as parameter.
54
isSrcPropertyRequired = false;
55         isDstPropertyRequired = false;
56         action = new TransformAction();
57     }
58
59     /**
60      * Inner class
61      */

62     class TransformAction extends ActionBase {
63
64         /**
65          * Get the list of the associated classes of a class.
66          * @param roots The roots of the repository.
67          * @param clazz The class which is associated to the class.
68          * @return The list of the associated classes.
69          */

70         private Collection JavaDoc getAssociatedClass(Collection JavaDoc roots, Object JavaDoc clazz) {
71             Collection JavaDoc list = new java.util.ArrayList JavaDoc();
72             Iterator JavaDoc it = roots.iterator();
73             while (it.hasNext()) {
74                 Object JavaDoc obj = it.next();
75                 if (obj instanceof org.omg.uml.core.Association) {
76                     org.omg.uml.core.Association asso = (org.omg.uml.core.Association) obj;
77                     java.util.List JavaDoc connections = asso.getConnection();
78                     if (connections.size() == 2) {
79                         if (((org.omg.uml.core.AssociationEnd) connections.get(0)).getParticipant().equals(clazz)) {
80                             list.add(connections.get(1));
81                         }
82                         if (((org.omg.uml.core.AssociationEnd) connections.get(1)).getParticipant().equals(clazz)) {
83                             list.add(connections.get(0));
84                         }
85                     }
86                 }
87             }
88             return list;
89         }
90
91         /**
92          * Transform the bean and return the result.
93          * @param object
94          * @return Object
95          * @roseuid 3F1C5EBF016D
96          */

97         public Object JavaDoc execute(Object JavaDoc bean, RuleContext request) throws TransformationException {
98             Collection JavaDoc roots = JmiModFactModelCreateUtils.getRoots((RefPackage) bean);
99             Iterator JavaDoc iter = getAssociatedClass(roots, bean).iterator();
100             while (iter.hasNext()) {
101                 Object JavaDoc cur = iter.next();
102                 request.engineContext.engine.transform(cur, request);
103             }
104             return null;
105         }
106     } // end class
107

108 }
109
Popular Tags