Package com.hp.hpl.jena.graph.impl

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel


    }
   
    public void testBinary3() {
        // Check hexBinary
        Literal l = m.createTypedLiteral(data, XSDDatatype.XSDhexBinary);
        LiteralLabel ll = l.asNode().getLiteral();
        assertEquals("binary test 1b", ll.getDatatype(), XSDDatatype.XSDhexBinary);
        assertEquals("binary test 2b", HexBin.encode(data), ll.getLexicalForm());
       
        // Check round tripping from value
        LiteralLabel l2 = m.createTypedLiteral(ll.getLexicalForm(), XSDDatatype.XSDhexBinary).asNode().getLiteral();
        Object data2 = l2.getValue();
        assertTrue("binary test 3b", data2 instanceof byte[]);
        byte[] data2b = ((byte[])data2);
        assertEquals("binary test 4b", data2b[0], data[0]);
        assertEquals("binary test 5b", data2b[1], data[1]);
        assertEquals("binary test 6b", data2b[2], data[2]);
View Full Code Here


   
    /**
     * Check parse/unparse loop.
     */
    public void doTestRoundTrip(String lex, RDFDatatype dt, boolean testeq) {
        LiteralLabel ll = LiteralLabelFactory.createLiteralLabel( lex, "", dt );
        String lex2 = dt.unparse(ll.getValue());
        if (testeq) {
            assertEquals(lex, lex2);
        }
        LiteralLabel ll2 = LiteralLabelFactory.createLiteralLabel( lex2, "", dt );
        assertTrue( ll2.isWellFormed() );
    }
View Full Code Here

        JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = originalFlag;
        assertTrue("Detected unknown datatype", foundException);
       
        // Check we can create a literal of an unregistered java type without anything blowing up
        Object foo = new java.sql.Date(123456l);
        LiteralLabel ll = LiteralLabelFactory.create(foo);
        assertEquals(ll.getLexicalForm(), foo.toString());
    }
View Full Code Here

        RDFDatatype clothingsize = tm.getSafeTypeByName(uri + "#clothingsize");
        checkLegalLiteral("42", clothingsize, Integer.class, 42 );
        checkLegalLiteral("short", clothingsize, String.class, "short");
       
        // Check use of isValidLiteral for base versus derived combinations
        LiteralLabel iOver12 = m.createTypedLiteral("13", over12Type).asNode().getLiteral();
        LiteralLabel iDecimal14 = m.createTypedLiteral("14", XSDDatatype.XSDdecimal).asNode().getLiteral();
        LiteralLabel iDecimal10 = m.createTypedLiteral("10", XSDDatatype.XSDdecimal).asNode().getLiteral();
        LiteralLabel iString = m.createTypedLiteral("15", XSDDatatype.XSDstring).asNode().getLiteral();
        LiteralLabel iPlain = m.createLiteral("foo").asNode().getLiteral();
       
        assertTrue(over12Type.isValidLiteral(iOver12));
        assertTrue(over12Type.isValidLiteral(iDecimal14));
        assertTrue( ! over12Type.isValidLiteral(iDecimal10));
        assertTrue( ! over12Type.isValidLiteral(iString));
View Full Code Here

            Calendar calM1 = Calendar.getInstance();
            calM1.set(Calendar.YEAR,  y);
            calM1.set(Calendar.MONTH, 10);
            calM1.set(Calendar.DATE,  23);
            XSDDateTime xdtM = new XSDDateTime(calM1);
            LiteralLabel xdtM_ll = LiteralLabelFactory.create(xdtM, "", XSDDatatype.XSDdateTime);
           
            assertTrue("Pre-1000 calendar value", xdtM_ll.getLexicalForm().matches("-?[0-9]{4}-.*")) ;
            assertTrue("Pre-1000 calendar value", xdtM_ll.isWellFormed()) ;
        }
        // Illegal dateTimes
        boolean ok = false;
        boolean old = JenaParameters.enableEagerLiteralValidation;
        try {
View Full Code Here

        associated strings test equal.
    */
    private Object [][] eqTestCases()
    {
        AnonId id = AnonId.create();
        LiteralLabel L2 = LiteralLabelFactory.create( id.toString(), "", false );

        LiteralLabel LLang1 = LiteralLabelFactory.create( "xyz", "en", null) ;
        LiteralLabel LLang2 = LiteralLabelFactory.create( "xyz", "EN", null) ;

        String U2 = id.toString();
        String N2 = id.toString();
        return new Object [][]
            {
View Full Code Here

    private static final LiteralLabel L = LiteralLabelFactory.create( "ashes are burning", "en", false );
       
    public void testTripleEquals() {
        // create some nodes to test
        AnonId id = AnonId.create();
        LiteralLabel L2 = LiteralLabelFactory.create(id.toString(), "", false);
        String U2 = id.toString();
        String N2 = id.toString();

        Node[] nodes = new Node[] {
            Node.ANY,
View Full Code Here

        }
    }
    
    private static NodeId inline$(Node node)
    {
        LiteralLabel lit = node.getLiteral() ;
        // Decimal is a valid supertype of integer but we handle integers and decimals differently.
       
        if ( node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal) )
        {
            // Check lexical form.
            if ( ! XSDDatatype.XSDdecimal.isValidLiteral(lit) )
                return null ;
           
            // Not lit.getValue() because that may be a narrower type e.g. Integer.
            // .trim is how Jena does it but it rather savage. spc, \n \r \t.
            // But at this point we know it's a valid literal so the excessive
            // chopping by .trim is safe.
            BigDecimal decimal = new BigDecimal(lit.getLexicalForm().trim()) ;
            // Does range checking.
            DecimalNode dn = DecimalNode.valueOf(decimal) ;
            // null is "does not fit"
            if ( dn != null )
                // setType
                return new NodeId(dn.pack()) ;
            else
                return null ;
        }
        else    // Not decimal.
        {
            if ( XSDDatatype.XSDinteger.isValidLiteral(lit) )
            {
                // Check length of lexical form to see if it's in range of a long.
                // Long.MAX_VALUE =  9223372036854775807
                // Long.MIN_VALUE = -9223372036854775808
                // 9,223,372,036,854,775,807 is 19 digits.
               
                if ( lit.getLexicalForm().length() > 19 )
                    return null ;

                try {
                    long v = ((Number)lit.getValue()).longValue() ;
                    v = IntegerNode.pack(v) ;
                    // Value -1 is "does not fit"
                    if ( v != -1 )
                        return new NodeId(v) ;
                    else
                        return null ;
                }
                // Out of range for the type, not a long etc etc.
                catch (Throwable ex) { return null ; }
            }
        }
       
        if ( XSDDatatype.XSDdateTime.isValidLiteral(lit) )
        {
            // Could use the Jena/XSDDateTime object here rather than reparse the lexical form.
            // But this works and it's close to a release ...
            long v = DateTimeNode.packDateTime(lit.getLexicalForm()) ;
            if ( v == -1 )
                return null ;
            v = setType(v, DATETIME) ;
            return new NodeId(v) ;
        }
       
        if ( XSDDatatype.XSDdate.isValidLiteral(lit) )
        {
            long v = DateTimeNode.packDate(lit.getLexicalForm()) ;
            if ( v == -1 )
                return null ;
            v = setType(v, DATE) ;
            return new NodeId(v) ;
        }
       
        if ( XSDDatatype.XSDboolean.isValidLiteral(lit) )
        {
            long v = 0 ;
            boolean b = (Boolean) lit.getValue();
            //return new NodeValueBoolean(b, node) ;
            v = setType(v, BOOLEAN) ;
            if ( b )
                v = v | 0x01 ;
            return new NodeId(v) ;
View Full Code Here

            return new LiteralImpl(Node.createLiteral(string, "", dType), null) ;
        }

        @Override
        public Literal createTypedLiteral( Object value ) {
            LiteralLabel ll = null;
            if (value instanceof Calendar) {
                Object valuec = new XSDDateTime( (Calendar) value);
                ll = LiteralLabelFactory.create(valuec, "", XSDDatatype.XSDdateTime);
            } else {
                ll =  LiteralLabelFactory.create(value);
View Full Code Here

            if (value.isBlank()) return null;
            if (!value.isLiteral()) {
                return new ValidityReport.Report(true, "dtRange",
                    "Property " + prop + " has a typed range but was given a non literal value " + value);
            }
            LiteralLabel ll = value.getLiteral();  
            for (Iterator<RDFDatatype> i = range.iterator(); i.hasNext(); ) {
                RDFDatatype dt = i.next();
                if (!dt.isValidLiteral(ll)) {
                    return new ValidityReport.Report(true, "dtRange",
                        "Property " + prop + " has a typed range " + dt +
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.graph.impl.LiteralLabel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.