Package org.apache.stanbol.entityhub.servicesapi.defaults

Examples of org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum


        return getValueFactory().createText(content);
    }

    @Override
    public Object createLiteral(String content, Locale language, URI type) {
        DataTypeEnum dataType = type == null ? null : DataTypeEnum.getDataType(type.toString());
        if(language != null){
            if(type != null && !(DataTypeEnum.String == dataType || DataTypeEnum.Text == dataType)){
                throw new IllegalArgumentException("Literals with a Lanugage MUST not have NULL,"+
                    DataTypeEnum.String.getShortName()+" or "+
                    DataTypeEnum.Text.getShortName()+" assigned as type!");
            } else {
                return getValueFactory().createText(content, language.getLanguage());
            }
        } else if(type != null){ //create a typed literal
            if(dataType == null){ //the parsed type is an unknown data type
                return content; //return an string
            } else {
                Object converted = valueConverter.convert(content, dataType.getUri(), getValueFactory());
                if(converted == null){
                    log.debug("Unable to convert content '{}' to dataType '{}'",converted,dataType);
                    return content;
                } else {
                    return converted;
View Full Code Here


    private static Constraint parseConstraint(String filterString) {
        if(filterString.startsWith("d=")){
            String[] dataTypeStrings = filterString.substring(2).split(";");
            Set<String> dataTypes = new HashSet<String>();
            for(int i=0;i<dataTypeStrings.length;i++){
                DataTypeEnum dataType = DataTypeEnum.getDataTypeByShortName(dataTypeStrings[i]);
                if(dataType == null){
                    dataType = DataTypeEnum.getDataType(dataTypeStrings[i]);
                }
                if(dataType != null){
                    dataTypes.add(dataType.getUri());
                } else {
                    log.warn(String.format("DataType %s not supported! Datatype get not used by this Filter",
                        dataTypeStrings[i]));
                }
            }
View Full Code Here

        //constraint for later conversions!
        List<DataTypeEnum> sortedActiveDataTypes = new ArrayList<DataTypeEnum>(valueConstraint.getDataTypes().size());
        //NOTE: using a LinkedHashSet would slow down this code, because EnumSet
        //  gives constant processing time even for bulk operations!
        for(String dataTypeUri : valueConstraint.getDataTypes()){
            DataTypeEnum dataType = DataTypeEnum.getDataType(dataTypeUri);
            if(dataType == null){
                log.warn(String.format("DataType %s not supported"));
            } else {
                if(activeDataTypes.add(dataType)){
                    //only of set has changed to avoid duplicates in the list
                    sortedActiveDataTypes.add(dataType);
                }
            }
        }
        //2) now process the values
//        log.info(" --- Filter values ---");
        //calculating acceptable and not acceptable types needs some processing time
        //and usually values will be only of very less different types.
        //Therefore it makes sense to cache accepted and rejected types!
        Set<Class<?>> accepted = new HashSet<Class<?>>();
        Set<Class<?>> rejected = new HashSet<Class<?>>();
        //Set that stores rejected values. Such will be converted later on!
        Set<Object> needConversion = new HashSet<Object>();
        for(Iterator<Object> it = values.iterator();it.hasNext();){
            Object value = it.next();
//            if(accepted.contains(value.getClass())){
//                log.info(String.format("   + value %s(type:%s) accepted by value filter",value,value.getClass()));
                //nothing to do
//            } else
            if(rejected.contains(value.getClass())){
                it.remove(); //remove also the current value of that type
                needConversion.add(value); //save as value that need to be converted
//                log.info(String.format("   - value %s(type:%s) rejected by value filter",value,value.getClass()));
            } else { //new class ... calculate
                Set<DataTypeEnum> valueTypes = DataTypeEnum.getAllDataTypes(value.getClass());
                if(valueTypes.removeAll(activeDataTypes)){
                    accepted.add(value.getClass());
//                    log.info(String.format("   + value %s(type:%s) accepted by value filter",value,value.getClass()));
                } else {
                    rejected.add(getClass());
                    it.remove(); //remove the Item
                    needConversion.add(value); //save as value that need to be converted
//                    log.info(String.format("   - value %s(type:%s) rejected by value filter",value,value.getClass()));
                }
            }
        }
        //3) try to convert values to the active dataTypes
//        log.info(" --- Try to Convert rejected values ---");
        for(Object value : needConversion){
            Object converted = null;
            DataTypeEnum convertedTo = null;
            for(Iterator<DataTypeEnum> dataTypes = sortedActiveDataTypes.iterator(); //iterate over all active dataTypes
                converted == null && dataTypes.hasNext();){ //while converted still null and more dataTypes to try
                convertedTo = dataTypes.next();
                converted = valueConverter.convert(value, convertedTo.getUri(),valueFactory); //try the conversion
            }
            if(converted != null){
//                log.info(String.format("   + value %s(javaType=%s) successfully converted to %s(datatype=%s)",
//                        value,value.getClass().getSimpleName(),converted,convertedTo.getShortName()));
                values.add(converted);
View Full Code Here

        }
        return xmlDatatypeFactory;
    }

    public static String toString(String dataTypeUri,Date value){
        DataTypeEnum dataType = DataTypeEnum.getDataType(dataTypeUri);
        if(dataType == null){
            throw new IllegalArgumentException(String.format("Unknown dataType %s",dataType));
        }
        return toString(dataType,value);
    }
View Full Code Here

     * enforced (e.g. dateTimes without time will throw an exception)
     * @return the date
     * @throws IllegalArgumentException if the parsed value can not be converted to a date
     */
    public static Date toDate(String dataTypeUri, Object value, boolean strict){
           DataTypeEnum dataType = DataTypeEnum.getDataType(dataTypeUri);
        if(dataType == null){
            throw new IllegalArgumentException(String.format("Unknown dataType %s",dataType));
        }
        return toDate(dataType, value,strict);
    }
View Full Code Here

    private static Constraint parseConstraint(String filterString) {
        if(filterString.startsWith("d=")){
            String[] dataTypeStrings = filterString.substring(2).split(";");
            Set<String> dataTypes = new HashSet<String>();
            for(int i=0;i<dataTypeStrings.length;i++){
                DataTypeEnum dataType = DataTypeEnum.getDataTypeByShortName(dataTypeStrings[i]);
                if(dataType == null){
                    dataType = DataTypeEnum.getDataType(dataTypeStrings[i]);
                }
                if(dataType != null){
                    dataTypes.add(dataType.getUri());
                } else {
                    log.warn(String.format("DataType %s not supported! Datatype get not used by this Filter",
                        dataTypeStrings[i]));
                }
            }
View Full Code Here

        return getValueFactory().createText(content);
    }

    @Override
    public Object createLiteral(String content, Locale language, URI type) {
        DataTypeEnum dataType = type == null ? null : DataTypeEnum.getDataType(type.toString());
        if(language != null){
            if(type != null && !(DataTypeEnum.String == dataType || DataTypeEnum.Text == dataType)){
                throw new IllegalArgumentException("Literals with a Lanugage MUST not have NULL,"+
                    DataTypeEnum.String.getShortName()+" or "+
                    DataTypeEnum.Text.getShortName()+" assigned as type!");
            } else {
                return getValueFactory().createText(content, language.getLanguage());
            }
        } else if(type != null){ //create a typed literal
            if(dataType == null){ //the parsed type is an unknown data type
                return content; //return an string
            } else {
                Object converted = valueConverter.convert(content, dataType.getUri(), getValueFactory());
                if(converted == null){
                    log.debug("Unable to convert content '{}' to dataType '{}'",converted,dataType);
                    return content;
                } else {
                    return converted;
View Full Code Here

        //constraint for later conversions!
        List<DataTypeEnum> sortedActiveDataTypes = new ArrayList<DataTypeEnum>(valueConstraint.getDataTypes().size());
        //NOTE: using a LinkedHashSet would slow down this code, because EnumSet
        //  gives constant processing time even for bulk operations!
        for(String dataTypeUri : valueConstraint.getDataTypes()){
            DataTypeEnum dataType = DataTypeEnum.getDataType(dataTypeUri);
            if(dataType == null){
                log.warn(String.format("DataType %s not supported"));
            } else {
                if(activeDataTypes.add(dataType)){
                    //only of set has changed to avoid duplicates in the list
                    sortedActiveDataTypes.add(dataType);
                }
            }
        }
        //2) now process the values
//        log.info(" --- Filter values ---");
        //calculating acceptable and not acceptable types needs some processing time
        //and usually values will be only of very less different types.
        //Therefore it makes sense to cache accepted and rejected types!
        Set<Class<?>> accepted = new HashSet<Class<?>>();
        Set<Class<?>> rejected = new HashSet<Class<?>>();
        //Set that stores rejected values. Such will be converted later on!
        Set<Object> needConversion = new HashSet<Object>();
        for(Iterator<Object> it = values.iterator();it.hasNext();){
            Object value = it.next();
//            if(accepted.contains(value.getClass())){
//                log.info(String.format("   + value %s(type:%s) accepted by value filter",value,value.getClass()));
                //nothing to do
//            } else
            if(rejected.contains(value.getClass())){
                it.remove(); //remove also the current value of that type
                needConversion.add(value); //save as value that need to be converted
//                log.info(String.format("   - value %s(type:%s) rejected by value filter",value,value.getClass()));
            } else { //new class ... calculate
                Set<DataTypeEnum> valueTypes = DataTypeEnum.getAllDataTypes(value.getClass());
                if(valueTypes.removeAll(activeDataTypes)){
                    accepted.add(value.getClass());
//                    log.info(String.format("   + value %s(type:%s) accepted by value filter",value,value.getClass()));
                } else {
                    rejected.add(getClass());
                    it.remove(); //remove the Item
                    needConversion.add(value); //save as value that need to be converted
//                    log.info(String.format("   - value %s(type:%s) rejected by value filter",value,value.getClass()));
                }
            }
        }
        //3) try to convert values to the active dataTypes
//        log.info(" --- Try to Convert rejected values ---");
        for(Object value : needConversion){
            Object converted = null;
            DataTypeEnum convertedTo = null;
            for(Iterator<DataTypeEnum> dataTypes = sortedActiveDataTypes.iterator(); //iterate over all active dataTypes
                converted == null && dataTypes.hasNext();){ //while converted still null and more dataTypes to try
                convertedTo = dataTypes.next();
                converted = valueConverter.convert(value, convertedTo.getUri(),valueFactory); //try the conversion
            }
            if(converted != null){
//                log.info(String.format("   + value %s(javaType=%s) successfully converted to %s(datatype=%s)",
//                        value,value.getClass().getSimpleName(),converted,convertedTo.getShortName()));
                values.add(converted);
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum

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.