private static Object convert(Object value, Class<?> type) { if(value.getClass() == type) { return value; } if (value instanceof String) { String str = (String)value; return StringUtil.valueOf(str, type); } return value; }
private static Class<?> setProperty(Object bean, Object value, final Method method, final String propertyName) { final Class<?> argType = method.getParameterTypes()[0]; try { Object[] params = new Object[] {value}; if (value != null && !argType.isAssignableFrom(value.getClass())) { params = new Object[] {StringUtil.valueOf(value.toString(), argType)}; } method.invoke(bean, params); } catch (Throwable e) { throw new InvalidPropertyException(CorePlugin.Event.TEIID10044, propertyName, value, argType, e); } return argType; }
private static Class<?> setProperty(Object bean, Object value, final Method method, final String propertyName) { final Class<?> argType = method.getParameterTypes()[0]; try { Object[] params = new Object[] {value}; if (value != null && !argType.isAssignableFrom(value.getClass())) { params = new Object[] {StringUtil.valueOf(value.toString(), argType)}; } method.invoke(bean, params); } catch (Throwable e) { throw new InvalidPropertyException(CorePlugin.Event.TEIID10044, propertyName, value, argType, e); } return argType; }
@SuppressWarnings("serial") @Override public BasicConnectionFactory<FtpFileConnectionImpl> createConnectionFactory()throws ResourceException { final Map<String, String> map = StringUtil.valueOf(this.fileMapping, Map.class); return new BasicConnectionFactory<FtpFileConnectionImpl>() { @Override public FtpFileConnectionImpl getConnection() throws ResourceException { try { return new FtpFileConnectionImpl(createClient(), parentDirectory, map); } catch (IOException e) { throw new ResourceException(e); } }}; }
/** * Search for the property first in the environment, then in the system properties * @param key * @param defaultValue * @param clazz * @return */ public static <T> T getHierarchicalProperty(String key, T defaultValue, Class<T> clazz) { String stringVal = System.getenv(key); if(stringVal != null) { stringVal = stringVal.trim(); if (stringVal.length() != 0) { return StringUtil.valueOf(stringVal, clazz); } } stringVal = System.getProperty(key); if(stringVal != null) { stringVal = stringVal.trim(); if (stringVal.length() != 0) { return StringUtil.valueOf(stringVal, clazz); } } return defaultValue; }
/** * Search for the property first in the environment, then in the system properties * @param key * @param defaultValue * @param clazz * @return */ public static <T> T getHierarchicalProperty(String key, T defaultValue, Class<T> clazz) { String stringVal = System.getenv(key); if(stringVal != null) { stringVal = stringVal.trim(); if (stringVal.length() != 0) { return StringUtil.valueOf(stringVal, clazz); } } stringVal = System.getProperty(key); if(stringVal != null) { stringVal = stringVal.trim(); if (stringVal.length() != 0) { return StringUtil.valueOf(stringVal, clazz); } } return defaultValue; }
@SuppressWarnings("serial") @Override public BasicConnectionFactory<FtpFileConnectionImpl> createConnectionFactory()throws ResourceException { final Map<String, String> map = StringUtil.valueOf(this.fileMapping, Map.class); return new BasicConnectionFactory<FtpFileConnectionImpl>() { @Override public FtpFileConnectionImpl getConnection() throws ResourceException { try { return new FtpFileConnectionImpl(createClient(), parentDirectory, map); } catch (IOException e) { throw new ResourceException(e); } }}; }
@Override @SuppressWarnings("serial") public BasicConnectionFactory<FileConnectionImpl> createConnectionFactory() throws ResourceException { if (this.parentDirectory == null) { throw new InvalidPropertyException(UTIL.getString("parentdirectory_not_set")); //$NON-NLS-1$ } final Map<String, String> map = StringUtil.valueOf(this.fileMapping, Map.class); return new BasicConnectionFactory<FileConnectionImpl>() { @Override public FileConnectionImpl getConnection() throws ResourceException { return new FileConnectionImpl(parentDirectory, map, allowParentPaths); } }; }
Object array = Array.newInstance(type.getComponentType(), values.length); for (int i = 0; i < values.length; i++) { Array.set(array, i, valueOf(values[i], type.getComponentType()));
Object array = Array.newInstance(type.getComponentType(), values.length); for (int i = 0; i < values.length; i++) { Array.set(array, i, valueOf(values[i], type.getComponentType()));
@Test public void testValueOf() throws Exception { assertEquals(Integer.valueOf(21), StringUtil.valueOf("21", Integer.class)); //$NON-NLS-1$ assertEquals(Boolean.valueOf(true), StringUtil.valueOf("true", Boolean.class)); //$NON-NLS-1$ assertEquals("Foo", StringUtil.valueOf("Foo", String.class)); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(Float.valueOf(10.12f), StringUtil.valueOf("10.12", Float.class)); //$NON-NLS-1$ assertEquals(Double.valueOf(121.123), StringUtil.valueOf("121.123", Double.class)); //$NON-NLS-1$ assertEquals(Long.valueOf(12334567L), StringUtil.valueOf("12334567", Long.class)); //$NON-NLS-1$ assertEquals(Short.valueOf((short)21), StringUtil.valueOf("21", Short.class)); //$NON-NLS-1$ List list = StringUtil.valueOf("foo,bar,x,y,z", List.class); //$NON-NLS-1$ assertEquals(5, list.size()); assertTrue(list.contains("foo")); //$NON-NLS-1$ assertTrue(list.contains("x")); //$NON-NLS-1$ int[] values = StringUtil.valueOf("1,2,3,4,5", new int[0].getClass()); //$NON-NLS-1$ assertEquals(5, values.length); assertEquals(5, values[4]); Map m = StringUtil.valueOf("foo=bar,x=,y=z", Map.class); //$NON-NLS-1$ assertEquals(3, m.size()); assertEquals(m.get("foo"), "bar"); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(m.get("x"), ""); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(EnumTest.HELLO, StringUtil.valueOf("HELLO", EnumTest.class)); //$NON-NLS-1$ assertEquals(new URL("http://teiid.org"), StringUtil.valueOf("http://teiid.org", URL.class)); //$NON-NLS-1$ //$NON-NLS-2$ } }
this.scriptEngineManager = vdbMetadata.getAttachment(ScriptEngineManager.class); this.importedModels = this.vdbMetaData.getImportedModels(); this.allowedLanguages = StringUtil.valueOf(vdbMetadata.getPropertyValue(ALLOWED_LANGUAGES), Set.class); if (this.allowedLanguages == null) { this.allowedLanguages = Collections.emptySet();
this.scriptEngineManager = vdbMetadata.getAttachment(ScriptEngineManager.class); this.importedModels = this.vdbMetaData.getImportedModels(); this.allowedLanguages = StringUtil.valueOf(vdbMetadata.getPropertyValue(ALLOWED_LANGUAGES), Set.class); if (this.allowedLanguages == null) { this.allowedLanguages = Collections.emptySet();
this.scriptEngineManager = vdbMetadata.getAttachment(ScriptEngineManager.class); this.importedModels = this.vdbMetaData.getImportedModels(); this.allowedLanguages = StringUtil.valueOf(vdbMetadata.getPropertyValue(ALLOWED_LANGUAGES), Set.class); if (this.allowedLanguages == null) { this.allowedLanguages = Collections.emptySet();