KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > uml > transformation > rules > xml > TransformAssociatedClass


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: TransformAssociatedClass.java,v 1.1 2004/05/26 11:25:35 carpentier Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.uml.transformation.rules.xml;
30
31 import ispuml.mdaTransformation.RuleContext;
32 import ispuml.mdaTransformation.TransformationException;
33 import ispuml.mdaTransformation.rules.xml.BeanProperty;
34 import ispuml.mdaTransformation.rules.xml.RuleCallXmlAction;
35
36 /**
37  * Class to transform a class which is associated with the
38  * current bean according to a particular stereotype.
39  *
40  * @author Pierre Carpentier
41  */

42 public class TransformAssociatedClass extends RuleCallXmlAction {
43
44     /** The search stereotype of the association. */
45     private String JavaDoc associatedClassWithStereotype;
46     
47     /** The Util class which offers methods to retrieve the associated class. */
48     private AssociatedClassUtils assoClassUtils;
49     
50     
51     /**
52      * Default Constructor
53      */

54     public TransformAssociatedClass () {
55         super();
56         assoClassUtils = new AssociatedClassUtils();
57     }
58     
59
60     /**
61      * Sets the stereotype of the search association.
62      * @param stereotype The stereotype.
63      */

64     public void setAssociatedClassWithStereotype(String JavaDoc stereotype) {
65         associatedClassWithStereotype = stereotype;
66     }
67     
68
69     /**
70      * Sets the 'srcProperty' inherited attribute with a value corresponding
71      * to the associated class.
72      * @param bean
73      * @param request
74      * @throws TransformationException If no association with the search stereotype exists.
75      */

76     private void setSrcAssociatedClassWithStereotype(Object JavaDoc bean, RuleContext context) throws TransformationException {
77         Object JavaDoc value = assoClassUtils.getAssociatedClass(bean, associatedClassWithStereotype, null, context.engineContext.getModel(bean));
78         if (value != null) {
79             if (srcProperty == null) {
80                 srcProperty = new BeanProperty();
81             }
82             ((BeanProperty) srcProperty).setBeanName(associatedClassWithStereotype);
83             context.putAttribute(associatedClassWithStereotype, value);
84         } else {
85             throw new TransformationException("The Association stereotyped '" + associatedClassWithStereotype + "' is not present.");
86         }
87     }
88     
89
90     /**
91      * Gets the source value.
92      * This method overloadeds the method defined in CompositeXmlAction
93      * in order to consider the associated class as the source bean.
94      * @param bean The current bean.
95      * @param request The context.
96      * @return The source value.
97      * @throws TransformationException
98      */

99     protected Object JavaDoc getSrcValue(Object JavaDoc bean, RuleContext request) throws TransformationException {
100         setSrcAssociatedClassWithStereotype(bean, request);
101         return super.getSrcValue(bean, request);
102     }
103
104 }
105
Popular Tags