View Javadoc
1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.ui.editors.model;
26  
27  import java.util.Set;
28  
29  import org.omwg.ontology.*;
30  import org.wsmo.common.*;
31  import org.wsmo.common.exception.InvalidModelException;
32  import org.wsmostudio.ui.Utils;
33  
34  public class AttributeModel extends EntityModel {
35      
36      public AttributeModel(Attribute wsmoAttr) {
37          super(wsmoAttr);
38      }
39      
40      public Attribute getAttribute() {
41          return (Attribute)getAdapter(Attribute.class);
42      }
43      
44      public void addType(Type type) throws InvalidModelException {
45          getAttribute().addType(type);
46          setChanged();
47      }
48  
49      public void removeType(Type type) throws InvalidModelException {
50          getAttribute().removeType(type);
51          setChanged();
52      }
53      
54      public void setConstraining(boolean constraining) {
55          getAttribute().setConstraining(constraining);
56          setChanged();
57      }
58  
59      public void setInverseOf(Identifier attrRef) {
60          getAttribute().setInverseOf(attrRef);
61          setChanged();
62      }
63  
64      public void setMaxCardinality(int max) {
65          getAttribute().setMaxCardinality(max);
66          setChanged();
67      }
68  
69      public void setMinCardinality(int min) {
70          getAttribute().setMinCardinality(min);
71          setChanged();
72      }
73  
74      public void setReflexive(boolean reflexive) {
75          getAttribute().setReflexive(reflexive);
76          setChanged();
77      }
78  
79      public void setSymmetric(boolean symmetric) {
80          getAttribute().setSymmetric(symmetric);
81          setChanged();
82      }
83  
84      public void setTransitive(boolean transitive) {
85          getAttribute().setTransitive(transitive);
86          setChanged();
87      }
88      
89      public void setConcept(Concept newConcept) throws InvalidModelException {
90          
91          Attribute thisAttr = this.getAttribute();
92          Attribute newAttr = newConcept.createAttribute(thisAttr.getIdentifier());
93          newAttr.setConstraining(thisAttr.isConstraining());
94          newAttr.setInverseOf(thisAttr.getInverseOf());
95          newAttr.setMaxCardinality(thisAttr.getMaxCardinality());
96          newAttr.setMinCardinality(thisAttr.getMinCardinality());
97          newAttr.setReflexive(thisAttr.isReflexive());
98          newAttr.setSymmetric(thisAttr.isSymmetric());
99          newAttr.setTransitive(thisAttr.isTransitive());
100         for(Type range : thisAttr.listTypes()) {
101             newAttr.addType(range);
102         }
103         for(IRI key : thisAttr.listNFPValues().keySet()) {
104             for(Object value : thisAttr.listNFPValues(key)) {
105                 if (value instanceof Identifier) {
106                     newAttr.addNFPValue(key, (Identifier)value);
107                 }
108                 else if (value instanceof Value) {
109                     newAttr.addNFPValue(key, (Value)value);
110                 }
111             }
112         }
113         if (getMasterModel() instanceof ConceptModel) {
114             ((ConceptModel)getMasterModel()).removeAttribute(thisAttr);
115         }
116         else {
117             thisAttr.getConcept().removeAttribute(thisAttr);
118             getMasterModel().setChanged();
119         }
120         
121         this.wsmoDelegate = newAttr;
122         Set<ObservableModel> uiModels = Utils.findModelsForEntity(newConcept);
123         if (uiModels.size() > 0) {
124             setMasterModel(uiModels.iterator().next());
125         }
126         setChanged();
127     }
128 
129 }
130 
131 /*
132  * $Log$
133  * Revision 1.3  2006/02/20 12:46:54  alex_simov
134  * wsmo4j api change: inverseOf attributes handled by IRI
135  *
136  * Revision 1.2  2006/01/09 12:51:14  alex_simov
137  * Copyright message in header updated
138  *
139  * Revision 1.1  2005/11/09 16:16:08  alex_simov
140  * UIModels notification improved
141  *
142  *
143  */