View Javadoc
1   /*
2    * #%L
3    * EUGene :: EUGene
4    * %%
5    * Copyright (C) 2004 - 2010 CodeLutin
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 com.google.common.collect.ImmutableSet;
26  import org.nuiton.eugene.models.object.ObjectModelModifier;
27  import org.nuiton.eugene.models.object.ObjectModelParameter;
28  import org.nuiton.eugene.models.object.ObjectModelUMLModifier;
29  
30  import java.util.Set;
31  
32  /**
33   * ObjectModelParameterImpl.
34   *
35   * Created: 14 janv. 2004
36   *
37   * @author Cédric Pineau - pineau@codelutin.com Copyright Code Lutin
38   */
39  public class ObjectModelParameterImpl extends ObjectModelElementImpl implements
40          ObjectModelParameter {
41  
42      protected String type;
43  
44      protected int minMultiplicity = 1;
45  
46      protected int maxMultiplicity = 1;
47  //    protected String ordering = "unspecified";
48  
49      /**
50       * Unique n'est utile que pour les collections pour indiquer que la
51       * collection ne peut prendre qu'une valeur identique (Set) si unique
52       * est false la collection peut prendre plusieurs fois la meme valeur
53       * (List)
54       */
55      protected String defaultValue;
56  
57      private static Set<ObjectModelModifier> authorizedModifiers;
58  
59      public static final String PROPERTY_ORDERED = "ordered";
60  
61      public ObjectModelParameterImpl() {
62          // Do not put in postInit has it has to be done before fields are push into the instance
63          addModifier(ObjectModelUMLModifier.UNIQUE); // Unique by default
64      }
65  
66      @Override
67      public void postInit() {
68          super.postInit();
69      }
70  
71      @Override
72      protected Set<ObjectModelModifier> getAuthorizedModifiers() {
73          if (authorizedModifiers == null) {
74              // No particular modifier ?
75              authorizedModifiers = ImmutableSet.of(
76                      (ObjectModelModifier) ObjectModelUMLModifier.UNIQUE,
77                      ObjectModelUMLModifier.ORDERED,
78                      ObjectModelUMLModifier.UNIQUE);
79          }
80          return authorizedModifiers;
81      }
82  
83      public void setType(String type) {
84          this.type = type;
85      }
86  
87      public void setMinMultiplicity(int minMultiplicity) {
88          this.minMultiplicity = minMultiplicity;
89      }
90  
91      public void setMaxMultiplicity(int maxMultiplicity) {
92          this.maxMultiplicity = maxMultiplicity;
93      }
94  
95      public void setOrdering(String ordering) {
96          setOrdered(PROPERTY_ORDERED.equals(ordering));
97  //        this.ordering = ordering;
98      }
99  
100     public void setUnique(boolean unique) {
101         addOrRemoveModifier(ObjectModelUMLModifier.UNIQUE, unique);
102     }
103 
104     public void setDefaultValue(String defaultValue) {
105         this.defaultValue = defaultValue;
106     }
107 
108     @Override
109     public String getType() {
110         return type;
111     }
112 
113     @Override
114     public String getDefaultValue() {
115         return defaultValue;
116     }
117 
118     @Override
119     public int getMinMultiplicity() {
120         return minMultiplicity;
121     }
122 
123     @Override
124     public int getMaxMultiplicity() {
125         return maxMultiplicity;
126     }
127 
128     @Override
129     public boolean isOrdered() {
130         return modifiers.contains(ObjectModelUMLModifier.ORDERED);
131     }
132 
133     public void setOrdered(boolean ordered) {
134         addOrRemoveModifier(ObjectModelUMLModifier.ORDERED, ordered);
135     }
136 
137     @Override
138     public boolean isUnique() {
139         return modifiers.contains(ObjectModelUMLModifier.UNIQUE);
140     }
141 
142     @Override
143     public String toString() {
144         return getType() + " " + getName() + "<<" + getStereotypes()
145                + ">> tagvalue: " + getTagValues();
146     }
147 }