Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 277   Methods: 12
NCLOC: 163   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComplexDataValueImpl.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2005, OntoText Lab. / SIRMA
 5    University of Innsbruck, Austria
 6   
 7    This library is free software; you can redistribute it and/or modify it under
 8    the terms of the GNU Lesser General Public License as published by the Free
 9    Software Foundation; either version 2.1 of the License, or (at your option)
 10    any later version.
 11    This library is distributed in the hope that it will be useful, but WITHOUT
 12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 13    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 14    details.
 15    You should have received a copy of the GNU Lesser General Public License along
 16    with this library; if not, write to the Free Software Foundation, Inc.,
 17    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 18    */
 19   
 20    package com.ontotext.wsmo4j.ontology;
 21   
 22    /**
 23    * <p>Title: WSMO4J</p>
 24    * <p>Description: WSMO API and a Reference Implementation</p>
 25    * <p>Copyright: Copyright (c) 2004-2005</p>
 26    * <p>Company: OntoText Lab. / SIRMA </p>
 27    * @author not attributable
 28    * @version 1.0
 29    *
 30    */
 31   
 32    import java.math.*;
 33    import java.util.*;
 34   
 35    import org.deri.wsmo4j.io.serializer.wsml.*;
 36    import org.omwg.logicalexpression.terms.*;
 37    import org.omwg.ontology.*;
 38   
 39    public class ComplexDataValueImpl implements ComplexDataValue {
 40   
 41    private WsmlDataType dataType;
 42    private SimpleDataValue[] values;
 43    private Object value;
 44   
 45  0 public ComplexDataValueImpl(ComplexDataType type, SimpleDataValue[] vals) {
 46  0 assert type != null;
 47  0 assert vals != null;
 48  0 this.dataType = type;
 49  0 int arity = vals.length;
 50  0 this.values = new SimpleDataValue[arity];
 51  0 System.arraycopy(vals, 0, this.values, 0, arity);
 52  0 this.value = createJavaValueFromSimpleTypes(type, vals);
 53    }
 54   
 55  0 public ComplexDataValueImpl(ComplexDataType type, SimpleDataValue vals) {
 56  0 this(type, new SimpleDataValue[] {vals});
 57    }
 58   
 59  0 public WsmlDataType getType() {
 60  0 return dataType;
 61    }
 62   
 63  0 public int getArity() {
 64  0 return values.length;
 65    }
 66   
 67  0 public SimpleDataValue getArgumentValue(byte pos) {
 68  0 if (pos < 0
 69    || pos >= values.length) {
 70  0 throw new IllegalArgumentException(
 71    "Invalid argument position for type '"
 72    + dataType.toString()
 73    + "'!");
 74    }
 75  0 return values[pos];
 76    }
 77   
 78  0 public String asString() {
 79  0 VisitorSerializeWSMLTerms v = new VisitorSerializeWSMLTerms(null);
 80  0 this.accept(v);
 81  0 return v.getSerializedObject();
 82    }
 83   
 84  0 public Object getValue() {
 85  0 return value;
 86    }
 87   
 88  0 public String toString() {
 89  0 return asString();
 90    }
 91   
 92  0 public void accept(Visitor v) {
 93  0 v.visitComplexDataValue(this);
 94    }
 95   
 96  0 public boolean equals(Object object) {
 97  0 if (object == this) {
 98  0 return true;
 99    }
 100  0 if (object == null
 101    || false == object instanceof ComplexDataValue) {
 102  0 return false;
 103    }
 104  0 ComplexDataValue testVal = (ComplexDataValue) object;
 105  0 if (false == dataType.equals(testVal.getType())) {
 106  0 return false;
 107    }
 108  0 if (dataType.getIRI().toString().equals(WsmlDataType.WSML_DOUBLE)||
 109    dataType.getIRI().toString().equals(WsmlDataType.WSML_FLOAT)){
 110  0 return value.equals(testVal.getValue());
 111    }
 112   
 113  0 if (testVal.getArity()!=getArity()){
 114  0 return false;
 115    }
 116   
 117  0 for(byte i = 0; i < values.length; i++) {
 118  0 if (!values[i].equals(testVal.getArgumentValue(i))) {
 119  0 return false;
 120    }
 121    }
 122  0 return true;
 123    }
 124   
 125  0 public int hashCode() {
 126  0 return dataType.hashCode();
 127    }
 128   
 129  0 private Object createJavaValueFromSimpleTypes(ComplexDataType type, SimpleDataValue[] v){
 130  0 String typeIRI = type.getIRI().toString();
 131  0 if (typeIRI.equals(WsmlDataType.WSML_FLOAT)){
 132  0 return new Float(values[0].toString());
 133  0 }else if (typeIRI.equals(WsmlDataType.WSML_DOUBLE)){
 134  0 return new Double(values[0].toString());
 135  0 }else if (typeIRI.equals(WsmlDataType.WSML_BOOLEAN)){
 136  0 return Boolean.valueOf(values[0].toString());
 137  0 }else if (typeIRI.equals(WsmlDataType.WSML_DURATION)){
 138    //TODO: equality will return wrong results with respect to spec
 139    //http://www.w3.org/TR/xmlschema-2/#duration
 140  0 return values[0].toString();
 141  0 }else if (typeIRI.equals(WsmlDataType.WSML_DATETIME)){
 142  0 Calendar cal;
 143  0 if (values.length==8){ //including offset
 144  0 int offset = (((BigInteger) values[6].getValue()).intValue()*60+
 145    ((BigInteger) values[7].getValue()).intValue())*1000;
 146  0 cal = new GregorianCalendar(new SimpleTimeZone(offset,""));
 147    }else{
 148  0 cal = new GregorianCalendar();
 149    }
 150  0 cal.set(
 151    ((BigInteger) values[0].getValue()).intValue(),
 152    ((BigInteger) values[1].getValue()).intValue()-1,
 153    ((BigInteger) values[2].getValue()).intValue(),
 154    ((BigInteger) values[3].getValue()).intValue(),
 155    ((BigInteger) values[4].getValue()).intValue(),
 156    ((BigDecimal) values[5].getValue()).intValue());
 157  0 return cal;
 158  0 }else if (typeIRI.equals(WsmlDataType.WSML_DATE)){
 159  0 Calendar cal;
 160  0 if (values.length==5){ //including offset
 161  0 int offset = (((BigInteger) values[3].getValue()).intValue()*60+
 162    ((BigInteger) values[4].getValue()).intValue())*1000;
 163  0 cal = new GregorianCalendar(new SimpleTimeZone(offset,""));
 164    }else{
 165  0 cal = new GregorianCalendar();
 166    }
 167  0 cal.set(
 168    ((BigInteger) values[0].getValue()).intValue(),
 169    ((BigInteger) values[1].getValue()).intValue()-1,
 170    ((BigInteger) values[2].getValue()).intValue());
 171  0 return cal;
 172  0 }else if (typeIRI.equals(WsmlDataType.WSML_TIME)){
 173  0 Calendar cal;
 174  0 if (values.length==5){ //including offset
 175  0 int offset = (((BigInteger) values[3].getValue()).intValue()*60+
 176    ((BigInteger) values[4].getValue()).intValue())*1000;
 177  0 cal = new GregorianCalendar(new SimpleTimeZone(offset,""));
 178    }else{
 179  0 cal = new GregorianCalendar();
 180    }
 181  0 cal.set(1970,1,1,
 182    ((BigInteger) values[0].getValue()).intValue(),
 183    ((BigInteger) values[1].getValue()).intValue(),
 184    ((BigDecimal) values[2].getValue()).intValue());
 185  0 return cal;
 186  0 }else if (typeIRI.equals(WsmlDataType.WSML_IRI)){
 187  0 throw new UnsupportedOperationException("Data type "+typeIRI+" not supported!");
 188  0 }else if (typeIRI.equals(WsmlDataType.WSML_SQNAME)){
 189  0 throw new UnsupportedOperationException("Data type "+typeIRI+" not supported!");
 190  0 }else if (typeIRI.equals(WsmlDataType.WSML_GYEARMONTH)){
 191  0 return new Integer[] {
 192    new Integer(""+values[0].getValue()),
 193    new Integer(""+values[1].getValue())};
 194  0 }else if (typeIRI.equals(WsmlDataType.WSML_GMONTHDAY)){
 195  0 return new Integer[] {
 196    new Integer(""+values[0].getValue()),
 197    new Integer(""+values[1].getValue())};
 198  0 }else if (typeIRI.equals(WsmlDataType.WSML_GYEAR)){
 199  0 return new Integer(""+values[0].getValue());
 200  0 }else if (typeIRI.equals(WsmlDataType.WSML_GDAY)){
 201  0 return new Integer(""+values[0].getValue());
 202  0 }else if(typeIRI.equals(WsmlDataType.WSML_GMONTH)){
 203  0 return new Integer(""+values[0].getValue());
 204  0 }else if (typeIRI.equals(WsmlDataType.WSML_HEXBINARY)){
 205  0 return ""+values[0];
 206  0 }else if (typeIRI.equals(WsmlDataType.WSML_BASE64BINARY)){
 207  0 return ""+values[0];
 208    }else{
 209  0 throw new UnsupportedOperationException("Data type "+typeIRI+" not supported!");
 210    }
 211    }
 212    }
 213   
 214    /*
 215    * $Log$
 216    * Revision 1.8 2007/09/04 08:18:06 lcekov
 217    * DataTypeFactory.createWsmlTime must support milliseconds
 218    * https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
 219    *
 220    * Revision 1.7 2007/06/22 12:35:09 lcekov
 221    * DataTypeFactory.createWsmlDateTime must support milliseconds
 222    * https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
 223    *
 224    * Revision 1.6 2007/04/02 12:13:21 morcen
 225    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 226    *
 227    * Revision 1.5 2006/11/10 14:18:44 holgerlausen
 228    * Fixed Bug with Illegalargument Exception when compaing datatypes with different arities
 229    *
 230    * Revision 1.4 2005/10/17 17:36:37 holgerlausen
 231    * toString() to behave equaly then Serializer
 232    *
 233    * Revision 1.3 2005/09/30 11:56:11 alex_simov
 234    * minor fixes
 235    *
 236    * Revision 1.2 2005/09/21 08:15:39 holgerlausen
 237    * fixing java doc, removing asString()
 238    *
 239    * Revision 1.1 2005/09/06 18:33:42 holgerlausen
 240    * support for datatypes: updated implementation according to interfaces
 241    * renamed WsmlDataTypeImpl to SimpleDataTypeImpl
 242    * moved DataValueImpl to ComplexDataValueImpl
 243    * added SimpleDataValueImpl for basic strings, decimal, ints
 244    *
 245    * Revision 1.7 2005/09/02 13:32:45 ohamano
 246    * move logicalexpression packages from ext to core
 247    * move tests from logicalexpression.test to test module
 248    *
 249    * Revision 1.6 2005/09/02 09:43:32 ohamano
 250    * integrate wsmo-api and le-api on api and reference implementation level; full parser, serializer and validator integration will be next step
 251    *
 252    * Revision 1.5 2005/08/19 09:00:49 marin_dimitrov
 253    * -
 254    *
 255    * Revision 1.4 2005/07/04 15:25:16 alex_simov
 256    * DataValue/DataType changes
 257    *
 258    * Revision 1.3 2005/06/25 13:19:44 damyan_rm
 259    * serializing to String changed
 260    *
 261    * Revision 1.2 2005/06/23 10:47:46 alex_simov
 262    * hashCode() added
 263    *
 264    * Revision 1.1 2005/06/01 12:09:05 marin_dimitrov
 265    * v0.4.0
 266    *
 267    * Revision 1.3 2005/05/30 15:07:05 alex
 268    * toString() delegates to asString()
 269    *
 270    * Revision 1.2 2005/05/26 10:06:47 damian
 271    * asString modified
 272    *
 273    * Revision 1.1 2005/05/12 15:19:39 alex
 274    * initial commit
 275    *
 276    *
 277    */