KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > datatypes > xsd > XSDhexBinary


1 /******************************************************************
2  * File: XSDhexbinary.java
3  * Created by: Dave Reynolds
4  * Created on: 01-May-2004
5  *
6  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
7  * [See end of file]
8  * $Id: XSDhexBinary.java,v 1.3 2005/02/21 12:02:16 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.datatypes.xsd;
11
12 import java.util.Arrays JavaDoc;
13
14 import org.apache.xerces.impl.dv.util.HexBin;
15 import com.hp.hpl.jena.datatypes.DatatypeFormatException;
16 import com.hp.hpl.jena.graph.impl.LiteralLabel;
17
18 /**
19  * Implement hexbinary type. Most of the work is done in the superclass.
20  * This only needs to implement the unparsing.
21  *
22  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
23  * @version $Revision: 1.3 $ on $Date: 2005/02/21 12:02:16 $
24  */

25 public class XSDhexBinary extends XSDDatatype {
26     
27     /**
28      * Constructor.
29      * @param typeName the name of the XSD type to be instantiated, this is
30      * used to lookup a type definition from the Xerces schema factory.
31      */

32     public XSDhexBinary(String JavaDoc typeName) {
33         super(typeName, null);
34     }
35          
36     /**
37      * Test whether the given object is a legal value form
38      * of this datatype. Brute force implementation.
39      */

40     public boolean isValidValue(Object JavaDoc valueForm) {
41         return (valueForm instanceof byte[]);
42     }
43     
44     /**
45      * Convert a value of this datatype out
46      * to lexical form.
47      */

48     public String JavaDoc unparse(Object JavaDoc value) {
49         if (value instanceof byte[]) {
50             return HexBin.encode((byte[])value);
51         } else {
52             throw new DatatypeFormatException("base64 asked encode a non-byte arrary");
53         }
54     }
55     
56     /**
57      * Compares two instances of values of the given datatype.
58      * This ignores lang tags and just uses the java.lang.Number
59      * equality.
60      */

61     public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
62         return value1.getDatatype() == value2.getDatatype()
63             && Arrays.equals((byte[])value1.getValue(), (byte[])value2.getValue());
64 // && value1.getLexicalForm().equals(value2.getLexicalForm()); // bug tracking, not real code
65
}
66    
67
68 }
69
70
71
72 /*
73     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
74     All rights reserved.
75
76     Redistribution and use in source and binary forms, with or without
77     modification, are permitted provided that the following conditions
78     are met:
79
80     1. Redistributions of source code must retain the above copyright
81        notice, this list of conditions and the following disclaimer.
82
83     2. Redistributions in binary form must reproduce the above copyright
84        notice, this list of conditions and the following disclaimer in the
85        documentation and/or other materials provided with the distribution.
86
87     3. The name of the author may not be used to endorse or promote products
88        derived from this software without specific prior written permission.
89
90     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
91     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
92     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
93     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
94     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
95     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
96     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
97     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
99     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 */

101
Popular Tags