Examples of DataTypeEnum


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

        //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

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

        }
        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

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

     * 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

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

    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

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

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

        //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

Examples of org.dmd.dms.generated.enums.DataTypeEnum

   
    @Override
    // org.dmd.dms.util.GenUtility.dumpMVType(GenUtility.java:2363)
    public DataTypeEnum add(Object v) throws DmcValueException {
        synchronized(this){
            DataTypeEnum rc = typeCheck(v);
            if (value == null)
                value = new ArrayList<DataTypeEnum>();
            value.add(rc);
            return(rc);
        }
View Full Code Here

Examples of org.dmd.dms.generated.enums.DataTypeEnum

    public DataTypeEnum del(Object v){
        synchronized(this){
            if (value == null)
                return(null);
   
            DataTypeEnum key = null;
            DataTypeEnum rc = null;
            try {
                key = typeCheck(v);
            } catch (DmcValueException e) {
                throw(new IllegalStateException("Incompatible type passed to del():" + getName(),e));
            }
View Full Code Here

Examples of org.dmd.dms.generated.enums.DataTypeEnum

                throw(new IllegalStateException("Attribute: " + getAttributeInfo().name + " is not indexed. You can't use setMVnth()."));
           
            if ( (index < 0) || (index >= getAttributeInfo().indexSize))
                throw(new IllegalStateException("Index " + index + " for attribute: " + getAttributeInfo().name + " is out of range: 0 <= index < " + getAttributeInfo().indexSize));
           
            DataTypeEnum rc = null;
           
            if (v != null)
                rc = typeCheck(v);
           
            if (value == null){
View Full Code Here

Examples of org.dmd.dms.generated.enums.DataTypeEnum

        synchronized(this){
            if (value == null)
                return(false);

            try {
                DataTypeEnum val = typeCheck(v);
                return(value.contains(val));
            } catch (DmcValueException e) {
                return(false);
            }
        }
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.