Package org.geotools.util

Examples of org.geotools.util.Converter


        }
       
        public Object convertToObject(String value, Locale locale) {
            for ( ConverterFactory factory : factories ) {
                try {
                    Converter converter = factory.createConverter( String.class, target, null );
                    if ( converter != null ) {
                        Object converted = converter.convert( value, target );
                        if ( converted != null ) {
                            return converted;
                        }
                    }
                }
View Full Code Here


        public String convertToString(Object value, Locale locale) {
            Set<ConverterFactory> rconverters =
                (Set<ConverterFactory>) Converters.getConverterFactories( target, String.class );
            for ( ConverterFactory cf : rconverters ) {
                try {
                    Converter converter = cf.createConverter(value.getClass(), String.class,null);
                    if ( converter == null ) {
                        continue;
                    }
                   
                    String converted = converter.convert(value, String.class);
                    if ( converted != null ) {
                        return converted;
                    }
                }
                catch (Exception e) {
View Full Code Here

                || target.isAssignableFrom(sourceClass)) {
            return target.cast( source );
        }

        for (ConverterFactory factory : factories) {
            Converter converter = factory.createConverter(sourceClass, target, hints);
            if (converter != null) {
                try {
                    T converted = converter.convert(source, target);
                    if (converted != null) {
                        return converted;
                    }
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.FINER))
                        LOGGER.log(Level.FINER,
                                "Error applying the converter " + converter.getClass() + " on ("
                                        + source + "," + target + ")", e);
                }
            }
        }
View Full Code Here

            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof Date){
                            return df.format((Date) source);
                        }
                        return null;
                    }
                };
            }
        }

        // this should handle java.util.Calendar to
        // String
        if (Calendar.class.isAssignableFrom(source)) {

            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof Calendar){
                            return df.format(((Calendar) source).getTime());
                       
                        return null;
                    }
                };
            }
        }

        if (XMLGregorianCalendar.class.isAssignableFrom(source)) {
            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof XMLGregorianCalendar){
                            return df.format(((XMLGregorianCalendar) source).toGregorianCalendar(TimeZone.getTimeZone("GMT"),Locale.getDefault(),null).getTime());
                        }
                        return null;
View Full Code Here

                || target.isAssignableFrom(sourceClass)) {
            return target.cast( source );
        }

        for (ConverterFactory factory : factories) {
            Converter converter = factory.createConverter(sourceClass, target, hints);
            if (converter != null) {
                try {
                    T converted = converter.convert(source, target);
                    if (converted != null) {
                        return converted;
                    }
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.FINER))
                        LOGGER.log(Level.FINER,
                                "Error applying the converter " + converter.getClass() + " on ("
                                        + source + "," + target + ")", e);
                }
            }
        }
View Full Code Here

            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof Date){
                            return df.format((Date) source);
                        }
                        return null;
                    }
                };
            }
        }

        // this should handle java.util.Calendar to
        // String
        if (Calendar.class.isAssignableFrom(source)) {

            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof Calendar){
                            return df.format(((Calendar) source).getTime());
                       
                        return null;
                    }
                };
            }
        }

        if (XMLGregorianCalendar.class.isAssignableFrom(source)) {
            // target is string
            if (String.class.equals(target)) {
                final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times 

                return new Converter() {
                    public Object convert(Object source, Class target) throws Exception {
                        if(source instanceof XMLGregorianCalendar){
                            return df.format(((XMLGregorianCalendar) source).toGregorianCalendar(TimeZone.getTimeZone("GMT"),Locale.getDefault(),null).getTime());
                        }
                        return null;
View Full Code Here

public class LobConverterFactory implements ConverterFactory {

    public Converter createConverter(Class<?> source, Class<?> target, Hints hints) {

        if (Blob.class.isAssignableFrom(source) && byte[].class.isAssignableFrom(target)) {
            return new Converter() {
                public <T> T convert(Object source, Class<T> target) throws Exception {
                    if (source instanceof Blob && byte[].class.isAssignableFrom(target)) {
                        Blob blob = (Blob) source;
                        InputStream blobIS = blob.getBinaryStream();
                        byte[] blobBA = new byte[blobIS.available()];
                        blobIS.read(blobBA);
                        blobIS.close();
                        return (T) blobBA;
                    }
                    return null;
                }
            };
        }

        if (Clob.class.isAssignableFrom(source) && String.class.isAssignableFrom(target)) {
            return new Converter() {
                public <T> T convert(Object source, Class<T> target) throws Exception {
                    if (source instanceof Clob && String.class.isAssignableFrom(target)) {
                        Clob clob = (Clob) source;
                        Reader clobReader = clob.getCharacterStream();
                        char[] clobChars = new char[(int) clob.length()];
View Full Code Here

                return null;

            //JD: this is a bit of a hack but delegate to the
            // commons converter in case we are executing first.
            try {
                Converter converter = new CommonsConverterFactory().createConverter(String.class,
                        target, null);
   
                if (converter != null) {
                    Object converted = null;
   
                    try {
                        converted = converter.convert(source, target);
                    } catch (Exception e) {
                        //ignore
                    }
   
                    if (converted != null) {
View Full Code Here

    private final static String RANGELIST_REGEX = "(" + RE_OPEN + RE_NUM + ";" + RE_NUM + RE_CLOSE + ")+" ; // "\\z";
    private final static Pattern RANGELIST_PATTERN = Pattern.compile(RANGELIST_REGEX);

  public Converter createConverter(Class source, Class target, Hints hints) {
    if (target.equals(Range.class) && source.equals(String.class)) {
      return new Converter() {

        public <T> T convert(Object source, Class<T> target)
            throws Exception {
          String sRange = (String) source;
          Matcher m = RANGE_PATTERN.matcher(sRange);
View Full Code Here

    private final static String RANGELIST_REGEX = "(" + RE_OPEN + RE_NUM + ";" + RE_NUM + RE_CLOSE + ")+" ; // "\\z";
    private final static Pattern RANGELIST_PATTERN = Pattern.compile(RANGELIST_REGEX);

  public Converter createConverter(Class source, Class target, Hints hints) {
    if (target.equals(Range.class) && source.equals(String.class)) {
      return new Converter() {

        public <T> T convert(Object source, Class<T> target)
            throws Exception {
          String sRange = (String) source;
          Matcher m = RANGE_PATTERN.matcher(sRange);
View Full Code Here

TOP

Related Classes of org.geotools.util.Converter

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.