View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2005, University of Innsbruck, Austria
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  package com.ontotext.wsmo4j.ontology;
19  
20  import java.math.BigDecimal;
21  import java.math.BigInteger;
22  
23  import org.omwg.logicalexpression.terms.Visitor;
24  import org.omwg.ontology.*;
25  
26  /**
27   * Interface or class description
28   *
29   * <pre>
30   * Created on Sep 5, 2005
31   * Committed by $Author$
32   * </pre>
33   *
34   * @author Holger Lausen (holger.lausen@deri.org)
35   *
36   * @version $Revision$ $Date$
37   */
38  public class SimpleDataValueImpl implements SimpleDataValue{
39  
40      Object value = null;
41      SimpleDataType type = null;
42      
43      public SimpleDataValueImpl(SimpleDataType type, String value){
44          if (!WsmlDataType.WSML_STRING.equals(
45                  type.getIRI().toString())){
46              throw new IllegalArgumentException("Simple type string must have type wsml#string!");
47          }
48          this.type = type;
49          this.value = value;
50      }
51      
52      public SimpleDataValueImpl(SimpleDataType type, BigInteger value){
53          if (!WsmlDataType.WSML_INTEGER.equals(
54                  type.getIRI().toString())){
55              throw new IllegalArgumentException("Simple type integer must have type wsml#integer!");
56          }
57          this.type = type;
58          this.value = value;
59      }
60  
61      public SimpleDataValueImpl(SimpleDataType type, BigDecimal value){
62          if (!WsmlDataType.WSML_DECIMAL.equals(
63                  type.getIRI().toString())){
64              throw new IllegalArgumentException("Simple type decimal must have type wsml#decimal!");
65          }
66          this.type = type;
67          this.value = value;
68      }
69  
70      public String asString() {
71          return value.toString();
72      }
73      
74      public String toString() {
75          return asString();
76      }
77  
78      public WsmlDataType getType() {
79          return type;
80      }
81  
82      public Object getValue() {
83          return value;
84      }
85  
86      public void accept(Visitor v) {
87          v.visitSimpleDataValue(this);
88      }
89  
90      public boolean equals(Object o){
91          if (o == null || !(o instanceof SimpleDataValue)){
92              return false;
93          }
94          SimpleDataValue v = (SimpleDataValue)o;
95          if (!v.getType().getIRI().toString().equals(type.getIRI().toString())){
96              return false;
97          }
98          return v.getValue().equals(value);
99      }
100     
101     public int hashCode(){
102         return value.hashCode();
103     }
104 }
105 
106 /*
107  * $Log$
108  * Revision 1.2  2005/09/16 14:02:44  alex_simov
109  * Identifier.asString() removed, use Object.toString() instead
110  * (Implementations MUST override toString())
111  *
112  * Revision 1.1  2005/09/06 18:33:42  holgerlausen
113  *   support for datatypes: updated implementation according to interfaces
114  *   renamed WsmlDataTypeImpl to SimpleDataTypeImpl
115  *   moved DataValueImpl to ComplexDataValueImpl
116  *   added SimpleDataValueImpl for basic strings, decimal, ints
117  *
118  */