View Javadoc
1   /*
2    * #%L
3    * EUGene :: EUGene
4    * %%
5    * Copyright (C) 2004 - 2012 CodeLutin, Chatellier Eric
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program 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
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.nuiton.eugene.models.object.xml;
24  
25  import org.apache.commons.digester3.Digester;
26  import org.apache.commons.digester3.RuleSetBase;
27  
28  /**
29   * DigesterObjectModelRuleSet
30   *
31   * Definit principalement :
32   * - la classe d'implementation a utiliser pour chaque noeud
33   * - la methode a appeler apres chaque noeud
34   *
35   * Ce jeu de regle ne cree pas l'element racine.
36   * Il doit etre cree et ajoute a la pile digester avant l'appel a
37   * {@code Digester.parse(File)}.
38   *
39   * Exemple:
40   * <code>
41   * ObjectModel monModel = new ObjectModelImpl()
42   * Digester d = new Digester();
43   * d.push(monModel);
44   * d.parse(file);
45   * </code>
46   *
47   * @author chatellier
48   */
49  public class DigesterObjectModelRuleSet extends RuleSetBase {
50  
51      protected String prefix;
52  
53      public DigesterObjectModelRuleSet() {
54          this("");
55      }
56  
57      public DigesterObjectModelRuleSet(String prefix) {
58          super("http://nuiton.org/eugene/objectModel/v1");
59          this.prefix = prefix;
60      }
61  
62      @Override
63      public void addRuleInstances(Digester d) {
64  
65          //d.addFactoryCreate("objectModel", DigesterObjectModelFactory.class);
66          // root element must be present on stask
67          d.addSetProperties("objectModel");
68  
69          d.addObjectCreate("objectModel/package", ObjectModelPackageImpl.class);
70          d.addSetProperties("objectModel/package");
71          d.addSetNext("objectModel/package", "addPackage");
72  
73          d.addObjectCreate("objectModel/class", ObjectModelClassImpl.class);
74          d.addSetProperties("objectModel/class");
75          d.addSetNext("objectModel/class", "addClass");
76  
77          d.addObjectCreate("objectModel/class/class", ObjectModelClassImpl.class);
78          d.addSetProperties("objectModel/class/class");
79          d.addSetNext("objectModel/class/class", "addInnerClassifier");
80  
81          d.addObjectCreate("objectModel/interface", ObjectModelInterfaceImpl.class);
82          d.addSetProperties("objectModel/interface");
83          d.addSetNext("objectModel/interface", "addInterface");
84  
85          d.addObjectCreate("objectModel/enumeration", ObjectModelEnumerationImpl.class);
86          d.addSetProperties("objectModel/enumeration");
87          d.addSetNext("objectModel/enumeration", "addEnumeration");
88  
89          d.addObjectCreate("objectModel/enumeration/literal", ObjectModelImplRef.class);
90          d.addSetProperties("objectModel/enumeration/literal");
91          d.addSetNext("objectModel/enumeration/literal", "addLiteral");
92  
93          d.addObjectCreate("objectModel/associationClass", ObjectModelAssociationClassImpl.class);
94          d.addSetProperties("objectModel/associationClass");
95          d.addSetNext("objectModel/associationClass", "addAssociationClass");
96  
97          d.addObjectCreate("*/participant", ObjectModeImplAssociationClassParticipant.class);
98          d.addSetProperties("*/participant");
99          d.addSetNext("*/participant", "addParticipant");
100 
101         d.addObjectCreate("*/stereotype", ObjectModelImplRef.class);
102         d.addSetProperties("*/stereotype");
103         d.addSetNext("*/stereotype", "addStereotype");
104 
105         d.addObjectCreate("*/dependency", ObjectModelDependencyImpl.class);
106         d.addSetProperties("*/dependency");
107         d.addSetNext("*/dependency", "addDependency");
108 
109         d.addObjectCreate("*/attribute", ObjectModelAttributeImpl.class);
110         d.addSetProperties("*/attribute");
111         d.addSetNext("*/attribute", "addAttribute");
112 
113         d.addObjectCreate("*/interface", ObjectModelImplRef.class);
114         d.addSetProperties("*/interface");
115         d.addSetNext("*/interface", "addInterface");
116 
117         d.addObjectCreate("*/superclass", ObjectModelImplSuperClassRef.class);
118         d.addSetProperties("*/superclass");
119         d.addSetNext("*/superclass", "addSuperclass");
120 
121         d.addObjectCreate("*/operation", ObjectModelOperationImpl.class);
122         d.addSetProperties("*/operation");
123         d.addSetNext("*/operation", "addOperation");
124 
125         d.addObjectCreate("*/operation/returnParameter", ObjectModelParameterImpl.class);
126         d.addSetProperties("*/operation/returnParameter");
127         d.addSetNext("*/operation/returnParameter", "setReturnParameter");
128 
129         d.addObjectCreate("*/operation/parameter", ObjectModelParameterImpl.class);
130         d.addSetProperties("*/operation/parameter");
131         d.addSetNext("*/operation/parameter", "addParameter");
132 
133         d.addObjectCreate("*/operation/exceptionParameter", ObjectModelParameterImpl.class);
134         d.addSetProperties("*/operation/exceptionParameter");
135         d.addSetNext("*/operation/exceptionParameter", "addExceptionParameter");
136 
137         d.addObjectCreate("*/tagValue", ObjectModelImplTagValue.class);
138         d.addSetProperties("*/tagValue");
139         d.addSetNext("*/tagValue", "addTagValue");
140 
141         d.addObjectCreate("*/comment", String.class);
142         d.addSetProperties("*/comment");
143         d.addSetNext("*/comment", "addComment");
144     }
145 }