Examples of LiteralLabel


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

     * @param value the value of the literal
     * @param dtype the type of the literal, null for old style "plain" literals
     */
    @Override
    public Literal createTypedLiteral(Object value, RDFDatatype dtype) {
        LiteralLabel ll = LiteralLabelFactory.create(value, "", dtype);
        return new LiteralImpl( NodeFactory.createLiteral(ll), this );
    }
View Full Code Here

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

     * @throws DatatypeFormatException if lex is not a legal form of dtype
     */
    @Override
    public Literal createTypedLiteral(String lex, String typeURI)  {
        RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
        LiteralLabel ll = LiteralLabelFactory.createLiteralLabel( lex, "", dt );
        return new LiteralImpl( NodeFactory.createLiteral(ll), this );
    }
View Full Code Here

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

     * @param typeURI the URI of the type of the literal, null for old style "plain" literals
     */
    @Override
    public Literal createTypedLiteral(Object value, String typeURI) {
        RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
        LiteralLabel ll = LiteralLabelFactory.create(value, "", dt);
        return new LiteralImpl(NodeFactory.createLiteral(ll), this);
    }
View Full Code Here

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

    public Literal createTypedLiteral( Object value )
    {
        // Catch special case of a Calendar which we want to act as if it were an XSDDateTime
        if (value instanceof Calendar)
            return createTypedLiteral( (Calendar)value );
        LiteralLabel ll = LiteralLabelFactory.create( value );
        return new LiteralImpl( NodeFactory.createLiteral( ll ), this);
    }
View Full Code Here

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

            }
            return new NodeValueNode(node) ;
        }

        // Typed literal
        LiteralLabel lit = node.getLiteral() ;
       
        // This includes type testing
        //if ( ! lit.getDatatype().isValidLiteral(lit) )
        // Use this - already calculated when the node is formed.
        if ( !node.getLiteral().isWellFormed() )
View Full Code Here

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

    private static NodeValue _setByValue(Node node)
    {
        if ( NodeUtils.hasLang(node) )
            // Check for RDF 1.1!
            return null ;
        LiteralLabel lit = node.getLiteral() ;
        String lex = lit.getLexicalForm() ;
        RDFDatatype datatype = lit.getDatatype() ;

        // Quick check.
        // Only XSD supported.
        // And (for testing) roman numerals.
        String datatypeURI = datatype.getURI() ;
        if ( ! datatypeURI.startsWith(xsdNamespace) && ! SystemARQ.EnableRomanNumerals )
        {
            // Not XSD.
            return null ;
        }

        try { // DatatypeFormatException - should not happen
           
            if ( SystemARQ.SameValueAsString && XSDstring.isValidLiteral(lit) )
                    // String - plain or xsd:string
                return new NodeValueString(lit.getLexicalForm(), node) ;
           
            // Otherwise xsd:string is like any other unknown datatype.
            // Ditto literals with language tags (which are handled by nodeToNodeValue)
           
            // isValidLiteral is a value test - not a syntactic test. 
            // This makes a difference in that "1"^^xsd:decimal" is a
            // valid literal for xsd:integer (all other cases are subtypes of xsd:integer)
            // which we want to become integer anyway).

            // Order here is promotion order integer-decimal-float-double
           
            if ( ! datatype.equals(XSDdecimal) )
            {
                // XSD integer and derived types
                if ( XSDinteger.isValidLiteral(lit) )
                {
                    String s = node.getLiteralLexicalForm() ;
                    if ( s.startsWith("+") )
                        // BigInteger does not accept leading "+"
                        s = s.substring(1) ;
                    // Includes subtypes (int, byte, postiveInteger etc).
                    // NB Known to be valid for type by now
                    BigInteger integer = new BigInteger(s) ;
                    return new NodeValueInteger(integer, node) ;
                }
            }
           
            if ( datatype.equals(XSDdecimal) && XSDdecimal.isValidLiteral(lit) )
            {
                BigDecimal decimal = new BigDecimal(lit.getLexicalForm()) ;
                return new NodeValueDecimal(decimal, node) ;
            }
           
            if ( datatype.equals(XSDfloat) && XSDfloat.isValidLiteral(lit) )
            {
                // NB If needed, call to floatValue, then assign to double.
                // Gets 1.3f != 1.3d right
                float f = ((Number)lit.getValue()).floatValue() ;
                return new NodeValueFloat(f, node) ;
            }

            if ( datatype.equals(XSDdouble) && XSDdouble.isValidLiteral(lit) )
            {
                double d = ((Number)lit.getValue()).doubleValue() ;
                return new NodeValueDouble(d, node) ;
            }

            // XXX Pending Jena update ...
            if ( ( datatype.equals(XSDdateTime) || dtXSDdateTimeStamp.equals(datatypeURI) ) &&
                    XSDdateTime.isValid(lex) )
            {
                XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDdate) && XSDdate.isValidLiteral(lit) )
            {
                // Jena datatype support works on masked dataTimes.
                XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDtime) && XSDtime.isValidLiteral(lit) )
            {
                // Jena datatype support works on masked dataTimes.
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDgYear) && XSDgYear.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgYearMonth) && XSDgYearMonth.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgMonth) && XSDgMonth.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDgMonthDay) && XSDgMonthDay.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgDay) && XSDgDay.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            // XXX Pending Jena update ...
            if ( ( datatype.equals(XSDduration) ||
                   dtXSDdayTimeDuration.equals(datatypeURI) ||
                   dtXSDyearMonthDuration.equals(datatypeURI) ) &&
                   XSDduration.isValid(lex) ) // use lex
            {
                Duration duration = xmlDatatypeFactory.newDuration(lex) ;
               
                if ( dtXSDdayTimeDuration.equals(datatypeURI) && ! XSDFuncOp.isDayTime(duration) )
                    return null ;
                if ( dtXSDyearMonthDuration.equals(datatypeURI) && ! XSDFuncOp.isYearMonth(duration) )
                    return null ;
               
                return new NodeValueDuration(duration, node) ;
            }
           
            if ( datatype.equals(XSDboolean) && XSDboolean.isValidLiteral(lit) )
            {
                boolean b = ((Boolean)lit.getValue()).booleanValue() ;
                return new NodeValueBoolean(b, node) ;
            }
           
            // If wired into the TypeMapper via RomanNumeralDatatype.enableAsFirstClassDatatype
//            if ( RomanNumeralDatatype.get().isValidLiteral(lit) )
//            {
//                int i = ((RomanNumeral)lit.getValue()).intValue() ;
//                return new NodeValueInteger(i) ;
//            }
           
            // Not wired in
            if ( SystemARQ.EnableRomanNumerals )
            {
                if ( lit.getDatatypeURI().equals(RomanNumeralDatatype.get().getURI()) )
                {
                    Object obj = RomanNumeralDatatype.get().parse(lit.getLexicalForm()) ;
                    if ( obj instanceof Integer )
                        return new NodeValueInteger(((Integer)obj).longValue()) ;
                    if ( obj instanceof RomanNumeral )
                        return new NodeValueInteger( ((RomanNumeral)obj).intValue() ) ;
                    throw new ARQInternalErrorException("DatatypeFormatException: Roman numeral is unknown class") ;
View Full Code Here

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

            return new LiteralImpl(NodeFactory.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

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

        return n ;
    }
   
    public static int nodeToInt(Node node)
    {
        LiteralLabel lit = node.getLiteral() ;
       
        if ( ! XSDDatatype.XSDinteger.isValidLiteral(lit) )
            return Integer.MIN_VALUE ;
        int i = ((Number)lit.getValue()).intValue() ;
        return i ;
    }
View Full Code Here

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

        return i ;
    }
   
    public static long nodeToLong(Node node)
    {
        LiteralLabel lit = node.getLiteral() ;
       
        if ( ! XSDDatatype.XSDinteger.isValidLiteral(lit) )
            return Long.MIN_VALUE ;
        long i = ((Number)lit.getValue()).longValue() ;
        return i ;
    }
View Full Code Here

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

        return i ;
    }
   
    public static float nodeToFloat(Node node)
    {
        LiteralLabel lit = node.getLiteral();
       
        if ( ! XSDDatatype.XSDfloat.isValidLiteral(lit) )
            return Float.NaN;
        float f = ((Number)lit.getValue()).floatValue();
        return f;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.