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 org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
28  import org.nuiton.eugene.models.object.ObjectModelAttribute;
29  import org.nuiton.eugene.models.object.ObjectModelClass;
30  import org.nuiton.eugene.models.object.ObjectModelClassifier;
31  
32  import java.util.ArrayList;
33  import java.util.Collection;
34  import java.util.List;
35  
36  /**
37   * ObjectModelAssociationClassImpl.java
38   *
39   * @author chatellier
40   * @author cedric
41   */
42  public class ObjectModelAssociationClassImpl extends ObjectModelClassImpl
43          implements ObjectModelAssociationClass {
44  
45      private static Log log = LogFactory
46              .getLog(ObjectModelAssociationClassImpl.class);
47  
48      protected List<ObjectModelAttribute> participantsAttributes;
49  
50      protected List<ObjectModelClassifier> participantsClassifiers;
51  
52      protected List<ObjectModeImplAssociationClassParticipant> participantsRefs = new ArrayList<>();
53  
54      public ObjectModelAssociationClassImpl() {
55      }
56  
57      public void addParticipant(
58              ObjectModeImplAssociationClassParticipant participant) {
59          //if (participant == null)
60          //    return new ObjectModeImplAssociationClassParticipant(this);
61          participant.postInit();
62          participant.setAssociationClass(this);
63          participantsRefs.add(participant);
64          //return participant;
65      }
66  
67      /**
68       * Returns all participants (that is association ends) attributes for this association class.
69       *
70       * @return a List containing all participants attributes for this association class.
71       * @see ObjectModelAttribute
72       */
73      @Override
74      public List<ObjectModelAttribute> getParticipantsAttributes() {
75          if (participantsAttributes == null) {
76              parseParticipantsRefs();
77          }
78          return participantsAttributes;
79      }
80  
81      /**
82       * Returns all participants (that is association ends) classifiers for this association class.
83       *
84       * @return a List containing all participants classifiers for this association class.
85       * @see ObjectModelClassifier
86       */
87      @Override
88      public List<ObjectModelClassifier> getParticipantsClassifiers() {
89          if (participantsClassifiers == null) {
90              parseParticipantsRefs();
91          }
92          return participantsClassifiers;
93      }
94  
95      protected void parseParticipantsRefs() {
96          participantsClassifiers = new ArrayList<>();
97          participantsAttributes = new ArrayList<>();
98  
99          for (ObjectModeImplAssociationClassParticipant ref : participantsRefs) {
100             ObjectModelClassifier classifier = objectModelImpl
101                     .getClassifier(ref.getName());
102             participantsClassifiers.add(classifier);
103             ObjectModelAttribute attribute = null;
104             //TODO this 
105 //            if (classifier.isClass()) {
106             if (classifier instanceof ObjectModelClass) {
107                 attribute = classifier.getAttribute(ref.getAttributeName());
108                 if (attribute == null) {
109                     log.warn("WARNING : Attribute " + ref.getAttributeName()
110                              + " not found on " + classifier.getQualifiedName());
111                     log.warn("WARNING : Assuming there is no navigability in this direction for the "
112                              + getQualifiedName() + " association class");
113                 }
114             }
115             participantsAttributes.add(attribute);
116         }
117     }
118 
119     public Collection<ObjectModeImplAssociationClassParticipant> getParticipantsRefs() {
120         return participantsRefs;
121     }
122 
123 }