protected ConnectionOptions newConnectionOptions(URI uri, Map<String, String> query) throws Exception { return BeanSupport.setData(uri, new ConnectionOptions(), query); } }
/** * This is the default implementation. * Sub classes are should provide a proper implementation for their schemas. */ protected URI internalNewURI(T bean) throws Exception { String query = BeanSupport.getData(null, bean); return new URI(getSchemaName(), null, "//", query, null); }
public static String getData(List<String> ignored, Object... beans) throws Exception { StringBuilder sb = new StringBuilder(); boolean empty = true; synchronized (beanUtils) { for (Object bean : beans) { if (bean != null) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { if (!empty) { sb.append("&"); } empty = false; sb.append(descriptor.getName()).append("=").append(encodeURI(value)); } } } } } } return sb.toString(); }
public static <P> Properties getProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { properties.put(descriptor.getName(), value); } } } } return properties; }
private static String createQuery(Map<String, Object> params, String query) throws Exception { StringBuilder cb; boolean empty; if (query == null) { cb = new StringBuilder(); empty = true; } else { cb = new StringBuilder(query); empty = false; } for (Map.Entry<String, Object> entry : params.entrySet()) { if (entry.getValue() != null) { if (!empty) { cb.append("&"); } else { empty = false; } cb.append(BeanSupport.encodeURI(entry.getKey())); cb.append("="); cb.append(BeanSupport.encodeURI(entry.getValue().toString())); } } return cb.toString(); } }
public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides) throws URISyntaxException { try { Map<String, String> rc = new HashMap<>(); if (uri != null && !uri.isEmpty()) { String[] parameters = uri.split("&"); for (String parameter : parameters) { int p = parameter.indexOf("="); if (p >= 0) { String name = BeanSupport.decodeURI(parameter.substring(0, p)); String value = BeanSupport.decodeURI(parameter.substring(p + 1)); rc.put(name, value); } else { if (!parameter.trim().isEmpty()) { rc.put(parameter, null); } } } } if (propertyOverrides != null) { for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) { rc.put(entry.getKey(), entry.getValue()); } } return rc; } catch (UnsupportedEncodingException e) { throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); } }
@Override protected void populateProperties(Properties props) { try { URI uri = toURI(); if (uri != null) { props.put(Context.PROVIDER_URL, uri.toASCIIString()); props.put("brokerURL", uri.toASCIIString()); } BeanSupport.getProperties(this, props); } catch (IOException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
@Override protected void buildFromProperties(Properties props) { String url = props.getProperty(Context.PROVIDER_URL); if (url == null || url.isEmpty()) { url = props.getProperty("brokerURL"); } if (url != null && url.length() > 0) { setBrokerURL(url); } if (url == null || url.isEmpty()) { throw new IllegalArgumentException(Context.PROVIDER_URL + " or " + "brokerURL is required"); } try { BeanSupport.setProperties(this, props); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
private static String createQuery(Map<String, Object> params, String query) throws Exception { StringBuilder cb; boolean empty; if (query == null) { cb = new StringBuilder(); empty = true; } else { cb = new StringBuilder(query); empty = false; } for (Map.Entry<String, Object> entry : params.entrySet()) { if (entry.getValue() != null) { if (!empty) { cb.append("&"); } else { empty = false; } cb.append(BeanSupport.encodeURI(entry.getKey())); cb.append("="); cb.append(BeanSupport.encodeURI(entry.getValue().toString())); } } return cb.toString(); } }
public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides) throws URISyntaxException { try { Map<String, String> rc = new HashMap<>(); if (uri != null && !uri.isEmpty()) { String[] parameters = uri.split("&"); for (String parameter : parameters) { int p = parameter.indexOf("="); if (p >= 0) { String name = BeanSupport.decodeURI(parameter.substring(0, p)); String value = BeanSupport.decodeURI(parameter.substring(p + 1)); rc.put(name, value); } else { if (!parameter.trim().isEmpty()) { rc.put(parameter, null); } } } } if (propertyOverrides != null) { for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) { rc.put(entry.getKey(), entry.getValue()); } } return rc; } catch (UnsupportedEncodingException e) { throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); } }
@Override protected void populateProperties(Properties props) { try { URI uri = toURI(); if (uri != null) { props.put(Context.PROVIDER_URL, uri.toASCIIString()); props.put("brokerURL", uri.toASCIIString()); } BeanSupport.getProperties(this, props); } catch (IOException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
@Override protected void buildFromProperties(Properties props) { String url = props.getProperty(Context.PROVIDER_URL); if (url == null || url.isEmpty()) { url = props.getProperty("brokerURL"); } if (url != null && url.length() > 0) { setBrokerURL(url); } if (url == null || url.isEmpty()) { throw new IllegalArgumentException(Context.PROVIDER_URL + " or " + "brokerURL is required"); } try { BeanSupport.setProperties(this, props); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
public void populateObject(URI uri, T bean) throws Exception { BeanSupport.setData(uri, bean, parseQuery(uri.getQuery(), null)); }
@Override protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception { String query = BeanSupport.getData(null, bean); TransportConfiguration[] staticConnectors = bean.getStaticConnectors(); return TCPServerLocatorSchema.getURI(query, staticConnectors); } }
public static String getData(List<String> ignored, Object... beans) throws Exception { StringBuilder sb = new StringBuilder(); boolean empty = true; synchronized (beanUtils) { for (Object bean : beans) { if (bean != null) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { if (!empty) { sb.append("&"); } empty = false; sb.append(descriptor.getName()).append("=").append(encodeURI(value)); } } } } } } return sb.toString(); }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
private static String createQuery(Map<String, Object> params, String query) throws Exception { StringBuilder cb; boolean empty; if (query == null) { cb = new StringBuilder(); empty = true; } else { cb = new StringBuilder(query); empty = false; } for (Map.Entry<String, Object> entry : params.entrySet()) { if (entry.getValue() != null) { if (!empty) { cb.append("&"); } else { empty = false; } cb.append(BeanSupport.encodeURI(entry.getKey())); cb.append("="); cb.append(BeanSupport.encodeURI(entry.getValue().toString())); } } return cb.toString(); } }
public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides) throws URISyntaxException { try { Map<String, String> rc = new HashMap<>(); if (uri != null && !uri.isEmpty()) { String[] parameters = uri.split("&"); for (String parameter : parameters) { int p = parameter.indexOf("="); if (p >= 0) { String name = BeanSupport.decodeURI(parameter.substring(0, p)); String value = BeanSupport.decodeURI(parameter.substring(p + 1)); rc.put(name, value); } else { if (!parameter.trim().isEmpty()) { rc.put(parameter, null); } } } } if (propertyOverrides != null) { for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) { rc.put(entry.getKey(), entry.getValue()); } } return rc; } catch (UnsupportedEncodingException e) { throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); } }
@Override protected void populateProperties(Properties props) { try { URI uri = toURI(); if (uri != null) { props.put(Context.PROVIDER_URL, uri.toASCIIString()); props.put("brokerURL", uri.toASCIIString()); } BeanSupport.getProperties(this, props); } catch (IOException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }