KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: XSDbase64binary.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: XSDbase64Binary.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.Base64;
15 import com.hp.hpl.jena.datatypes.DatatypeFormatException;
16 import com.hp.hpl.jena.graph.impl.LiteralLabel;
17
18 /**
19  * Implement base64binary 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 XSDbase64Binary 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 XSDbase64Binary(String JavaDoc typeName) {
33         super(typeName, byte[].class);
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 Base64.encode((byte[])value);
51         } else {
52             throw new DatatypeFormatException("base64 asked encode an unwrapped byte array");
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     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
73     All rights reserved.
74
75     Redistribution and use in source and binary forms, with or without
76     modification, are permitted provided that the following conditions
77     are met:
78
79     1. Redistributions of source code must retain the above copyright
80        notice, this list of conditions and the following disclaimer.
81
82     2. Redistributions in binary form must reproduce the above copyright
83        notice, this list of conditions and the following disclaimer in the
84        documentation and/or other materials provided with the distribution.
85
86     3. The name of the author may not be used to endorse or promote products
87        derived from this software without specific prior written permission.
88
89     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
90     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
91     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
92     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
93     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
94     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
95     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
96     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
97     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
98     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99 */

100
Popular Tags