org.geotools.util.Converters.getConverterFactories()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.geotools.util.Converters.getConverterFactories()方法的一些代码示例,展示了Converters.getConverterFactories()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converters.getConverterFactories()方法的具体详情如下:
包路径:org.geotools.util.Converters
类名称:Converters
方法名:getConverterFactories

Converters.getConverterFactories介绍

[英]Returns a set of all available ConverterFactory's which can handle convert from the source to destination class.

This method essentially returns all factories in which the following returns non null.

factory.createConverter( source, target );

[中]返回可处理从源类到目标类的转换的所有可用ConverterFactory的集合。
此方法实质上返回所有工厂,在这些工厂中,以下内容返回非null。

factory.createConverter( source, target );

代码示例

代码示例来源:origin: geotools/geotools

/**
   * Processed the {@link ConverterFactory} extension point.
   *
   * @return A collection of converter factories.
   * @since 2.4
   */
  static ConverterFactory[] factories() {
    if (factories == null) {
      Collection<ConverterFactory> factoryCollection =
          getConverterFactories(GeoTools.getDefaultHints());
      factories =
          (ConverterFactory[])
              factoryCollection.toArray(
                  new ConverterFactory[factoryCollection.size()]);
    }
    return factories;
  }
}

代码示例来源:origin: geotools/geotools

public void testLookupStringToCharset() {
  Set<ConverterFactory> s = Converters.getConverterFactories(String.class, Charset.class);
  for (ConverterFactory cf : s) {
    if (cf instanceof CharsetConverterFactory) {
      return;
    }
  }
  fail("CharsetConverterFactory not found");
}

代码示例来源:origin: geotools/geotools

public void testLookupCharsetToString() {
  Set<ConverterFactory> s = Converters.getConverterFactories(Charset.class, String.class);
  for (ConverterFactory cf : s) {
    if (cf instanceof CharsetConverterFactory) {
      return;
    }
  }
  fail("CharsetConverterFactory not found");
}

代码示例来源:origin: geotools/geotools

public void setUp() throws Exception {
  factories = Converters.getConverterFactories(Geometry.class, Geometry.class);
  File testData = TestData.file(this, "converter/tests.txt");
  assertNotNull("Cannot find test file (converter.txt)", testData);
  BufferedReader reader = null;
  try {
    reader = new BufferedReader(new FileReader(testData));
    String line = null;
    while ((line = reader.readLine()) != null) tests.add(line);
  } finally {
    if (reader != null) reader.close();
  }
  super.setUp();
}

代码示例来源:origin: geotools/geotools

@Test
public void testCRSConverterFactory() {
  // make sure the class is registered and assigned
  Set<ConverterFactory> set = Converters.getConverterFactories(STRING_CLASS, CRS_CLASS);
  assertNotNull(set);
  assertFalse(set.isEmpty());
  assertEquals(set.size(), 1);
  assertSame(set.iterator().next().getClass(), CRSConverterFactory.class);
  // make sure the class is registered also for the inverse process
  Set<ConverterFactory> set1 = Converters.getConverterFactories(CRS_CLASS, STRING_CLASS);
  assertNotNull(set1);
  assertFalse(set1.isEmpty());
  assertEquals(set1.size(), 1);
  assertSame(set1.iterator().next().getClass(), CRSConverterFactory.class);
  //
  assertNull(new CRSConverterFactory().createConverter(null, null, null));
  assertNull(new CRSConverterFactory().createConverter(String.class, null, null));
  assertNull(new CRSConverterFactory().createConverter(String.class, Double.class, null));
}

代码示例来源:origin: geotools/geotools

@Test
public void testInterpolationConverterFactory() {
  // make sure the class is registered and assigned
  Set<ConverterFactory> set =
      Converters.getConverterFactories(String.class, INTERPOLATION_CLASS);
  assertNotNull(set);
  assertFalse(set.isEmpty());
  assertEquals(set.size(), 1);
  assertSame(set.iterator().next().getClass(), InterpolationConverterFactory.class);
  //
  assertNull(new InterpolationConverterFactory().createConverter(null, null, null));
  assertNull(new InterpolationConverterFactory().createConverter(String.class, null, null));
  assertNull(
      new InterpolationConverterFactory()
          .createConverter(String.class, Double.class, null));
}

代码示例来源:origin: org.geotools/gt2-main

/**
   * Processed the {@link ConverterFactory} extension point.
   * 
   * @return A collection of converter factories.
   * @since 2.4 
   */
  static Collection factories() {
    if(factories == null)
    factories = getConverterFactories(GeoTools.getDefaultHints());
    return factories;
  }
}

代码示例来源:origin: org.geoserver.web/gs-web-core

public <C> IConverter<C> getConverter(Class<C> type) {
  Set<ConverterFactory> factories = Converters.getConverterFactories(String.class, type);
  if (!factories.isEmpty()) {
    return new GeoToolsConverter<C>(factories, type);
  }
  return null;
}

代码示例来源:origin: org.geoserver.web/web-core

public IConverter getConverter(Class type) {
  Set factories = Converters.getConverterFactories( String.class, type );
  if ( !factories.isEmpty() ) {
    return new GeoToolsConverter( factories, type );
  }
  return null;
}

代码示例来源:origin: org.geoserver.web/gs-web-core

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) {
        LOGGER.log(Level.WARNING, "Error converting \"" + value + "\" to String", e);
      }
    }
    return value.toString();
  }
}

代码示例来源:origin: org.geoserver.web/web-core

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) {
        //TODO: log this
      }
    }
    
    return value.toString();
  }
}

代码示例来源:origin: org.geotools/gt-app-schema

/**
 * Test that normal Attribute shouldn't be affected by the converter.
 */
public void testAttribute() {
  AttributeDescriptor descriptor = new AttributeDescriptorImpl(XSSchema.STRING_TYPE,
      ComplexFeatureConstants.SIMPLE_CONTENT, 1, 1, true, (Object) null);
  Attribute att = new AttributeImpl("rini", descriptor, null);
  Set<ConverterFactory> factories = Converters.getConverterFactories(att.getClass(), String.class);
  for (ConverterFactory factory : factories) {
    assertFalse(factory instanceof ComplexAttributeConverterFactory);
  }
}

相关文章