List of usage examples for org.apache.commons.beanutils PropertyUtils describe
public static Map describe(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the entire set of properties for which the specified bean provides a read method.
For more details see PropertyUtilsBean
.
From source file:com.m2a.struts.M2AFormBase.java
/** * Return map of properties for this bean. * Base method uses <code>PropertyUtils.describe</code>. * Override if some properties should not be transfered * this way, or a property name should be altered. * This will return the actual public properties. * * @exception Exception on any error./*from w ww . j a v a 2 s. c om*/ */ public Map describe() throws Exception { try { return PropertyUtils.describe(this); } catch (Throwable t) { throw new ChainedException(t); } }
From source file:net.jetrix.config.ServerConfig.java
/** * Save the configuration.//from ww w. j a va 2s . co m */ public void save() throws IOException { // todo make a backup copy of the previous configuration files // save the server.xml file PrintWriter out = null; try { File file = new File(serverConfigURL.toURI()); out = new PrintWriter(file, ENCODING); } catch (URISyntaxException e) { log.log(Level.SEVERE, e.getMessage(), e); } out.println("<?xml version=\"1.0\"?>"); out.println( "<!DOCTYPE tetrinet-server PUBLIC \"-//LFJR//Jetrix TetriNET Server//EN\" \"http://jetrix.sourceforge.net/dtd/tetrinet-server.dtd\">"); out.println(); out.println("<tetrinet-server host=\"" + (host == null ? "[ALL]" : host.getHostAddress()) + "\">"); out.println(); out.println(" <!-- Server name -->"); out.println(" <name>" + getName() + "</name>"); out.println(); out.println(" <!-- Server default language (using an ISO-639 two-letter language code) -->"); out.println(" <language>" + getLocale().getLanguage() + "</language>"); out.println(); out.println(" <!-- How many seconds of inactivity before timeout occurs -->"); out.println(" <timeout>" + getTimeout() + "</timeout>"); out.println(); out.println(" <!-- How many channels should be available on the server -->"); out.println(" <max-channels>" + getMaxChannels() + "</max-channels>"); out.println(); out.println(" <!-- Maximum number of players on the server -->"); out.println(" <max-players>" + getMaxPlayers() + "</max-players>"); out.println(); out.println(" <!-- Maximum number of simultaneous connections allowed from the same IP -->"); out.println(" <max-connections>" + getMaxConnections() + "</max-connections>"); out.println(); out.println(" <!-- Typing /op <thispassword> will give player operator status -->"); out.println(" <op-password>" + getOpPassword() + "</op-password>"); out.println(); out.println(" <!-- Use this password to log on the administration console -->"); out.println(" <admin-password>" + getAdminPassword() + "</admin-password>"); out.println(); out.println(" <!-- Access Log, where requests are logged to -->"); out.println(" <access-log path=\"" + getAccessLogPath() + "\" />"); out.println(); out.println(" <!-- Error Log, where errors are logged to -->"); out.println(" <error-log path=\"" + getErrorLogPath() + "\" />"); out.println(); out.println(" <!-- Path to the channels descriptor file (relative to the current configuration file) -->"); out.println(" <channels path=\"" + getChannelsFile() + "\"/>"); out.println(); out.println(" <!-- Client listeners -->"); out.println(" <listeners>"); for (Listener listener : getListeners()) { String autostart = !listener.isAutoStart() ? " auto-start=\"false\"" : ""; out.println(" <listener class=\"" + listener.getClass().getName() + "\" port=\"" + listener.getPort() + "\"" + autostart + "/>"); } out.println(" </listeners>"); out.println(); out.println(" <!-- Services -->"); out.println(" <services>"); for (Service service : getServices()) { try { // get the parameters Map<String, Object> params = PropertyUtils.describe(service); String autostart = !service.isAutoStart() ? "auto-start=\"false\"" : ""; String classname = "class=\"" + service.getClass().getName() + "\""; if (params.size() <= 4) { out.println(" <service " + classname + " " + autostart + "/>"); } else { out.println(" <service " + classname + " " + autostart + ">"); for (String param : params.keySet()) { PropertyDescriptor desc = PropertyUtils.getPropertyDescriptor(service, param); if (!"autoStart".equals(param) && desc.getWriteMethod() != null) { out.println( " <param name=\"" + param + "\" value=\"" + params.get(param) + "\"/>"); } } out.println(" </service>"); } } catch (Exception e) { e.printStackTrace(); } } out.println(" </services>"); out.println(); out.println(" <!-- Server commands -->"); out.println(" <commands>"); Iterator<Command> commands = CommandManager.getInstance().getCommands(AccessLevel.ADMINISTRATOR); while (commands.hasNext()) { try { Command command = commands.next(); String hidden = command.isHidden() ? " hidden=\"true\"" : ""; Command command2 = command.getClass().newInstance(); String level = command2.getAccessLevel() != command.getAccessLevel() ? " access-level=\"" + command.getAccessLevel() + "\"" : ""; out.println(" <command class=\"" + command.getClass().getName() + "\"" + hidden + level + "/>"); } catch (Exception e) { log.log(Level.WARNING, e.getMessage(), e); } } out.println(" </commands>"); out.println(); out.println(" <ban>"); Iterator<Banlist.Entry> entries = Banlist.getInstance().getBanlist(); while (entries.hasNext()) { Banlist.Entry entry = entries.next(); out.println(" <host>" + entry.pattern + "</host>"); } out.println(" </ban>"); out.println(); if (!datasources.isEmpty()) { out.println(" <!-- Database connection parameters -->"); out.println(" <datasources>"); out.println(); for (DataSourceConfig datasource : datasources.values()) { out.println(" <datasource name=\"" + datasource.getName() + "\">"); out.println(" <!-- The class of the JDBC driver used -->"); out.println(" <driver>" + datasource.getDriver() + "</driver>"); out.println(); out.println(" <!-- The URL of the database (jdbc:<type>://<hostname>:<port>/<database>) -->"); out.println(" <url>" + datasource.getUrl() + "</url>"); out.println(); out.println(" <!-- The username connecting to the database -->"); out.println(" <username>" + datasource.getUsername() + "</username>"); out.println(); out.println(" <!-- The password of the user -->"); if (datasource.getPassword() != null) { out.println(" <password>" + datasource.getPassword() + "</password>"); } else { out.println(" <password/>"); } if (datasource.getMinIdle() != DataSourceManager.DEFAULT_MIN_IDLE) { out.println(); out.println(" <!-- The minimum number of idle connections -->"); out.println(" <min-idle>" + datasource.getMinIdle() + "</min-idle>"); } if (datasource.getMaxActive() != DataSourceManager.DEFAULT_MAX_ACTIVE) { out.println(); out.println(" <!-- The maximum number of active connections -->"); out.println(" <max-active>" + datasource.getMaxActive() + "</max-active>"); } out.println(" </datasource>"); out.println(); } out.println(" </datasources>"); out.println(); } if (mailSessionConfig != null) { StringBuilder buffer = new StringBuilder(); buffer.append(" <mailserver host=\"").append(mailSessionConfig.getHostname()).append("\""); buffer.append(" port=\"").append(mailSessionConfig.getPort()).append("\""); if (mailSessionConfig.isAuth()) { buffer.append(" auth=\"true\""); buffer.append(" username=\"").append(mailSessionConfig.getUsername()).append("\""); buffer.append(" password=\"").append(mailSessionConfig.getPassword()).append("\""); } if (mailSessionConfig.isDebug()) { buffer.append(" debug=\"true\""); } buffer.append("/>"); out.println(" <!-- Mail server parameters -->"); out.println(buffer.toString()); out.println(); } if (properties != null && !properties.isEmpty()) { out.println(" <!-- Extended properties -->"); out.println(" <properties>"); for (String key : properties.stringPropertyNames()) { out.println(" <property name=\"" + key + "\" value=\"" + properties.getProperty(key) + "\">"); } out.println(" </properties>"); out.println(); } out.println("</tetrinet-server>"); out.flush(); out.close(); // save the channels.xml file try { File file = new File(channelsConfigURL.toURI()); out = new PrintWriter(file, ENCODING); } catch (URISyntaxException e) { log.log(Level.SEVERE, e.getMessage(), e); } out.println("<?xml version=\"1.0\"?>"); out.println( "<!DOCTYPE tetrinet-channels PUBLIC \"-//LFJR//Jetrix Channels//EN\" \"http://jetrix.sourceforge.net/dtd/tetrinet-channels.dtd\">"); out.println(); out.println("<tetrinet-channels>"); out.println(); out.println(" <!-- Message Of The Day -->"); out.println(" <motd><![CDATA["); out.println(getMessageOfTheDay()); out.println(" ]]></motd>"); out.println(); // filter definitions Map<String, String> aliases = FilterManager.getInstance().getFilterAliases(); out.println(" <!-- Channel filters -->"); out.println(" <filter-definitions>"); for (String alias : aliases.keySet()) { out.println(" <alias name=\"" + alias + "\" class=\"" + aliases.get(alias) + "\"/>"); } out.println(" </filter-definitions>"); out.println(); // global filters out.println(" <!-- Global filters -->"); out.println(" <default-filters>"); for (FilterConfig filter : globalFilters) { saveFilter(filter, out, " "); } out.println(" </default-filters>"); out.println(); // winlists out.println(" <!-- Winlists -->"); out.println(" <winlists>"); for (Winlist winlist : WinlistManager.getInstance().getWinlists()) { WinlistConfig config = winlist.getConfig(); Properties props = config.getProperties(); if (props == null || props.isEmpty()) { out.println(" <winlist name=\"" + winlist.getId() + "\" class=\"" + winlist.getClass().getName() + "\"/>"); } else { out.println(" <winlist name=\"" + winlist.getId() + "\" class=\"" + winlist.getClass().getName() + "\">"); for (Object name : props.keySet()) { out.println(" <param name=\"" + name + "\" value=\"" + props.get(name) + "\"/>"); } out.println(" </winlist>"); } } out.println(" </winlists>"); out.println(); // default settings Settings settings = Settings.getDefaultSettings(); out.println(" <!-- Default game settings -->"); out.println(" <default-settings>"); out.println(" <!-- What level each player starts at -->"); out.println(" <starting-level>" + settings.getStartingLevel() + "</starting-level>"); out.println(); out.println(" <!-- How many lines to make before player level increases -->"); out.println(" <lines-per-level>" + settings.getLinesPerLevel() + "</lines-per-level>"); out.println(); out.println(" <!-- Number of levels to increase each time -->"); out.println(" <level-increase>" + settings.getLevelIncrease() + "</level-increase>"); out.println(); out.println(" <!-- Lines to make to get a special block -->"); out.println(" <lines-per-special>" + settings.getLinesPerSpecial() + "</lines-per-special>"); out.println(); out.println(" <!-- Number of special blocks added each time -->"); out.println(" <special-added>" + settings.getSpecialAdded() + "</special-added>"); out.println(); out.println(" <!-- Capacity of Special block inventory -->"); out.println(" <special-capacity>" + settings.getSpecialCapacity() + "</special-capacity>"); out.println(); out.println(" <!-- Play by classic rules? -->"); out.println(" <classic-rules>" + (settings.getClassicRules() ? "true" : "false") + "</classic-rules>"); out.println(); out.println(" <!-- Average together all player's game level? -->"); out.println( " <average-levels>" + (settings.getAverageLevels() ? "true" : "false") + "</average-levels>"); out.println(); out.println(" <!-- Same sequence of blocks for all players? (tetrinet 1.14 clients only) -->"); out.println(" <same-blocks>" + (settings.getSameBlocks() ? "true" : "false") + "</same-blocks>"); out.println(); out.println(" <block-occurancy>"); for (Block block : Block.values()) { out.println(" <" + block.getCode() + ">" + settings.getOccurancy(block) + "</" + block.getCode() + ">"); } out.println(" </block-occurancy>"); out.println(); out.println(" <special-occurancy>"); for (Special special : Special.values()) { out.println(" <" + special.getCode() + ">" + settings.getOccurancy(special) + "</" + special.getCode() + ">"); } out.println(" </special-occurancy>"); out.println(); out.println(" <!-- Sudden death parameters -->"); out.println(" <sudden-death>"); out.println(" <!-- Time in seconds before the sudden death begins, 0 to disable the sudden death -->"); out.println(" <time>" + settings.getSuddenDeathTime() + "</time>"); out.println(); out.println( " <!-- The message displayed when the sudden death begins. Use \"key:\" prefix to display an internationalized message -->"); out.println(" <message>" + settings.getSuddenDeathMessage() + "</message>"); out.println(); out.println(" <!-- The delay in seconds between lines additions -->"); out.println(" <delay>" + settings.getSuddenDeathDelay() + "</delay>"); out.println(); out.println(" <!-- The number of lines added -->"); out.println(" <lines-added>" + settings.getSuddenDeathLinesAdded() + "</lines-added>"); out.println(" </sudden-death>"); out.println(); out.println(" </default-settings>"); out.println(); out.println(); out.println(" <channels>"); for (Channel channel : ChannelManager.getInstance().channels()) { ChannelConfig config = channel.getConfig(); if (config.isPersistent()) { out.println(" <channel name=\"" + config.getName() + "\">"); if (config.getDescription() != null) { String description = config.getDescription(); description = description.contains("<") ? "<![CDATA[" + description + "]]>" : description; out.println(" <description>" + description + "</description>"); } if (config.getTopic() != null && config.getTopic().trim().length() > 0) { out.println(" <topic>"); out.println("<![CDATA["); out.println(config.getTopic()); out.println("]]>"); out.println(" </topic>"); } if (config.getSpeed() != Speed.MIXED) { out.println(" <speed>" + config.getSpeed().name().toLowerCase() + "</speed>"); } if (config.isPasswordProtected()) { out.println(" <password>" + config.getPassword() + "</password>"); } if (config.getAccessLevel() != AccessLevel.PLAYER) { out.println(" <access-level>" + config.getAccessLevel() + "</access-level>"); } if (config.isIdleAllowed()) { out.println(" <idle>true</idle>"); } if (!config.isVisible()) { out.println(" <visible>false</visible>"); } if (config.getMaxPlayers() != ChannelConfig.PLAYER_CAPACITY) { out.println(" <max-players>" + config.getMaxPlayers() + "</max-players>"); } if (config.getMaxSpectators() != ChannelConfig.SPECTATOR_CAPACITY) { out.println(" <max-spectators>" + config.getMaxSpectators() + "</max-spectators>"); } if (config.getWinlistId() != null) { out.println(" <winlist name=\"" + config.getWinlistId() + "\"/>"); } // channel settings settings = config.getSettings(); if (!settings.useDefaultSettings()) { out.println(" <settings>"); if (!settings.isDefaultStartingLevel()) { out.println(" <starting-level>" + settings.getStartingLevel() + "</starting-level>"); } if (!settings.isDefaultLinesPerLevel()) { out.println( " <lines-per-level>" + settings.getLinesPerLevel() + "</lines-per-level>"); } if (!settings.isDefaultLevelIncrease()) { out.println(" <level-increase>" + settings.getLevelIncrease() + "</level-increase>"); } if (!settings.isDefaultLinesPerSpecial()) { out.println(" <lines-per-special>" + settings.getLinesPerSpecial() + "</lines-per-special>"); } if (!settings.isDefaultSpecialAdded()) { out.println(" <special-added>" + settings.getSpecialAdded() + "</special-added>"); } if (!settings.isDefaultSpecialCapacity()) { out.println(" <special-capacity>" + settings.getSpecialCapacity() + "</special-capacity>"); } if (!settings.isDefaultClassicRules()) { out.println(" <classic-rules>" + (settings.getClassicRules() ? "true" : "false") + "</classic-rules>"); } if (!settings.isDefaultAverageLevels()) { out.println(" <average-levels>" + (settings.getAverageLevels() ? "true" : "false") + "</average-levels>"); } if (!settings.isDefaultSameBlocks()) { out.println(" <same-blocks>" + (settings.getSameBlocks() ? "true" : "false") + "</same-blocks>"); } if (!settings.isDefaultBlockOccurancy()) { out.println(" <block-occurancy>"); for (Block block : Block.values()) { if (settings.getOccurancy(block) != 0) { out.println(" <" + block.getCode() + ">" + settings.getOccurancy(block) + "</" + block.getCode() + ">"); } } out.println(" </block-occurancy>"); } if (!settings.isDefaultSpecialOccurancy()) { out.println(" <special-occurancy>"); for (Special special : Special.values()) { if (settings.getOccurancy(special) != 0) { out.println(" <" + special.getCode() + ">" + settings.getOccurancy(special) + "</" + special.getCode() + ">"); } } out.println(" </special-occurancy>"); } // sudden death settings if (!settings.isDefaultSuddenDeath()) { out.println(" <sudden-death>"); if (!settings.isDefaultSuddenDeathTime()) { out.println(" <time>" + settings.getSuddenDeathTime() + "</time>"); } if (!settings.isDefaultSuddenDeathMessage()) { out.println(" <message>" + settings.getSuddenDeathMessage() + "</message>"); } if (!settings.isDefaultSuddenDeathDelay()) { out.println(" <delay>" + settings.getSuddenDeathDelay() + "</delay>"); } if (!settings.isDefaultSuddenDeathLinesAdded()) { out.println(" <lines-added>" + settings.getSuddenDeathLinesAdded() + "</lines-added>"); } out.println(" </sudden-death>"); } out.println(" </settings>"); } // local filters Collection<MessageFilter> filters = channel.getLocalFilters(); if (!filters.isEmpty()) { out.println(" <filters>"); for (MessageFilter filter : filters) { saveFilter(filter.getConfig(), out, " "); } out.println(" </filters>"); } out.println(" </channel>"); out.println(); } } out.println(" </channels>"); out.println(); out.println("</tetrinet-channels>"); out.close(); }
From source file:com.feilong.core.bean.PropertyUtil.java
/** * <code>bean</code> <code>propertyNames</code><span style="color:green">?</span>,??/ * {@link java.util.LinkedHashMap LinkedHashMap} . * /*from w ww . j a v a 2 s . co m*/ * <h3>:</h3> * * <blockquote> * * <pre class="code"> * * User user = new User(); * user.setId(5L); * user.setDate(new Date()); * * LOGGER.debug("map:{}", JsonUtil.format(PropertyUtil.describe(user))); * * </pre> * * <b>:</b> * * <pre class="code"> { "id": 5, "name": "feilong", "age": null, "date": "2016-07-13 22:18:26" } * </pre> * * <hr> * * <p> * ???: * </p> * * <pre class="code"> * * User user = new User(); * user.setId(5L); * user.setDate(new Date()); * * LOGGER.debug("map:{}", JsonUtil.format(PropertyUtil.describe(user, "date", "id"))); * * </pre> * * ????: * * <pre class="code"> { "date": "2016-07-13 22:21:24", "id": 5 } * </pre> * * </blockquote> * * <h3>:</h3> * <blockquote> * <ol> * <li> the entire set of properties for which the specified bean provides a read method.</li> * <li>???class,Object??,classjava.lang.Object</li> * <li> <code>propertyNames</code>null empty,?</li> * <li>mapkey <code>propertyNames</code> ?</li> * </ol> * </blockquote> * * <h3>?:</h3> * * <blockquote> * <ol> * <li>?bean class {@link java.beans.PropertyDescriptor}</li> * <li>, {@link java.beans.PropertyDescriptor#getReadMethod()}</li> * <li> name and {@link org.apache.commons.beanutils.PropertyUtilsBean#getProperty(Object, String)} map</li> * </ol> * </blockquote> * * @param bean * Bean whose properties are to be extracted * @param propertyNames * ?? (can be nested/indexed/mapped/combo),?? <a href="../BeanUtil.html#propertyName">propertyName</a> * @return <code>propertyNames</code> nullempty, {@link PropertyUtils#describe(Object)}<br> * @throws NullPointerException * <code>bean</code> null * @see org.apache.commons.beanutils.BeanUtils#describe(Object) * @see org.apache.commons.beanutils.PropertyUtils#describe(Object) * @since 1.8.0 */ public static Map<String, Object> describe(Object bean, String... propertyNames) { Validate.notNull(bean, "bean can't be null!"); if (isNullOrEmpty(propertyNames)) { try { return PropertyUtils.describe(bean); } catch (Exception e) { throw new BeanUtilException(e); } } Map<String, Object> map = newLinkedHashMap(propertyNames.length); for (String propertyName : propertyNames) { map.put(propertyName, getProperty(bean, propertyName)); } return map; }
From source file:jp.terasoluna.fw.util.ConvertUtil.java
/** * ?????????//from ww w . j av a 2 s . c om * <p> * ?????{@link #CLASS_FIELDNAME}???? * ??????????? * ????????????????1? * ?????????? * </p> * <ul> * <li><code>null</code>?? - ??????????</li> * <li><code>Object[]</code>?? - ??????</li> * <li><code>Collection</code>?? - ?????</li> * <li>???? - ?1????????</li> * </ul> * @param obj * @return ???? * @throws IllegalArgumentException ????????? */ @SuppressWarnings("unchecked") public static List<Map<String, Object>> toListOfMap(Object obj) throws IllegalArgumentException { Object[] array = ConvertUtil.toArray(obj); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); for (Object object : array) { Map<String, Object> map = null; if (object instanceof Map) { map = (Map<String, Object>) object; } else { try { map = PropertyUtils.describe(object); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } } map.remove(CLASS_FIELDNAME); result.add(map); } return result; }
From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java
/** * copy init?/* w ww. ja v a 2 s . c o m*/ * * @param target * @param raw * @param defaultValues */ @SuppressWarnings({ "rawtypes" }) public static <T extends Object> void copyProperties(T target, Object raw, ValueEditable... defaultValues) { try { Map values = raw == null ? new HashMap() : PropertyUtils.describe(raw); if (Argument.isNotEmptyArray(defaultValues)) { for (ValueEditable edit : defaultValues) { edit.edit(raw, values); } } PropertyUtils.copyProperties(target, values); // ? optInitMethod(target); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java
@Test public void test_dynamic_layout() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS", new Locale("en", "AU")); RecordCategory recordCategory = new RecordCategory(); Date created = sdf.parse("2014-02-05 18:45:46.145000"); Date modified = sdf.parse("2014-02-12 11:55:23.121000"); recordCategory.setCreated(created);//from www . j av a 2 s. c om recordCategory.setModified(modified); recordCategory.setCreator("admin"); recordCategory.setDescription("Information Technology"); recordCategory.setIdentifier("2014-1391586274589"); FieldDescriptor descriptionField = new FieldDescriptor(); descriptionField.setOrder(1); descriptionField.setName("description"); descriptionField.setTitle("Description"); FieldDescriptor createdField = new FieldDescriptor(); createdField.setOrder(2); createdField.setName("created"); createdField.setTitle("Created"); FieldDescriptor creatorField = new FieldDescriptor(); creatorField.setOrder(3); creatorField.setName("creator"); creatorField.setTitle("Creator"); FieldDescriptor modifiedField = new FieldDescriptor(); modifiedField.setOrder(4); modifiedField.setName("modified"); modifiedField.setTitle("Modified"); FieldDescriptor modifier = new FieldDescriptor(); modifier.setOrder(5); modifier.setName("modifier"); modifier.setTitle("Modifier"); FieldDescriptor identifierField = new FieldDescriptor(); identifierField.setOrder(6); identifierField.setName("identifier"); identifierField.setTitle("Identifier"); Set<FieldDescriptor> fieldSet = new TreeSet<FieldDescriptor>(); fieldSet.add(descriptionField); fieldSet.add(createdField); fieldSet.add(creatorField); fieldSet.add(modifiedField); fieldSet.add(modifier); fieldSet.add(identifierField); @SuppressWarnings("unchecked") Map<String, Object> valueMap = PropertyUtils.describe(recordCategory); titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get(); LinearLayout dynamicLayout = new LinearLayout(titleSearchResultsActivity); dynamicLayout.setOrientation(LinearLayout.VERTICAL); int layoutHeight = LinearLayout.LayoutParams.MATCH_PARENT; int layoutWidth = LinearLayout.LayoutParams.WRAP_CONTENT; for (FieldDescriptor descriptor : fieldSet) { Object value = valueMap.get(descriptor.getName()); if (value == null) continue; TextView titleView = new TextView(titleSearchResultsActivity); titleView.setText(descriptor.getTitle()); TextView valueView = new TextView(titleSearchResultsActivity); valueView.setText(value.toString()); LinearLayout fieldLayout = new LinearLayout(titleSearchResultsActivity); fieldLayout.setOrientation(LinearLayout.HORIZONTAL); fieldLayout.addView(titleView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight)); fieldLayout.addView(valueView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight)); } }
From source file:hermes.renderers.DefaultMessageRenderer.java
/** * Depending on configuration, show the object via toString() or a list of * properties./*from w w w .java 2 s. c om*/ * * @param objectMessage * @return * @throws JMSException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ protected JComponent handleObjectMessage(final ObjectMessage objectMessage) throws JMSException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { // // Unserialize the object and display all its properties Serializable obj = objectMessage.getObject(); if (obj instanceof JComponent) { return (JComponent) obj; } else { JTextArea textPane = new JTextArea(); StringBuffer buffer = new StringBuffer(); MyConfig currentConfig = (MyConfig) getConfig(); if (obj == null) { buffer.append("Payload is null"); } else if (currentConfig.isToStringOnObjectMessage()) { buffer.append(obj.toString()); } else { buffer.append(obj.toString()).append("\n\nProperty list\n"); for (Iterator iter = PropertyUtils.describe(obj).entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); buffer.append(entry.getKey().toString()).append("=").append(entry.getValue()).append("\n"); } } textPane.setEditable(false); textPane.setText(buffer.toString()); return textPane; } }
From source file:com.m2a.struts.M2AFormBase.java
/** * // :FIXME: Needs testing. Works OK without a profile bean =:o) * Merge a profile bean with this bean to provide a unified map * of the combined parameters. Will on add properties to the map * from the profile bean if matching property on this bean is * blank or null (which includes absent). * The result is a union of the properties, with the this * bean's non-blank properties having precedence over the * profile's properties. The profile is a base that this bean * can override on the fly. If this bean does not supply a * property, then the profile property is used. * <p>/*from w w w . j a va2s . c o m*/ * If profile is null, a map of this bean's properties is returned. * <p> * The profile can be any JavaBean. * <p> * This method is forwardly-compatible with BaseMapForm. * For an instance of BaseMapForm, getMap() is used; otherwise * describe() or PropertyUtils.describe() is used. * * fixme Needs testing. Works OK without a profile bean =:o) * @param profile The profile bean, if any * @throws Exception if error transfering data to map */ protected Map merge(Object profile) throws Exception { Map formMap = null; if (this instanceof M2AMapFormBase) { M2AMapFormBase form = (M2AMapFormBase) this; formMap = form.getMap(); } else { formMap = describe(); } if (profile != null) { Map userMap = null; if (profile instanceof M2AMapFormBase) { M2AMapFormBase form = (M2AMapFormBase) profile; userMap = form.getMap(); } else if (profile instanceof M2AFormBase) { M2AFormBase form = (M2AFormBase) profile; userMap = form.describe(); } else { userMap = PropertyUtils.describe(this); } // Add user element to formMap if form element is null or blank Iterator i = userMap.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); /* String formValue = (String) formMap.get(key); if (isBlank(formValue)) { formMap.put(key,userMap.get(key)); } */ formMap.put(key, userMap.get(key)); System.err.println("M2AFormBase.merge() : key = " + key + " , value = " + userMap.get(key)); } } return formMap; }
From source file:com.softech.tbb.actionform.BaseForm.java
/** * // :FIXME: Needs testing. Works OK without a profile bean =:o) Merge a * profile bean with this bean to provide a unified map of the combined * parameters. Will on add properties to the map from the profile bean if * matching property on this bean is blank or null (which includes absent). * The result is a union of the properties, with the this bean's non-blank * properties having precedence over the profile's properties. The profile * is a base that this bean can override on the fly -- If this bean does not * supply a property, then the profile property is used. But any property * named on the userProfile is included (even if it has no match on this * bean).//from w w w. j av a 2 s .c o m * <p> * If profile is null, a map of this bean's properties is returned. * <p> * The profile can be any JavaBean. * <p> * This method is forwardly-compatible with BaseMapForm. For an instance of * BaseMapForm, getMap() is used; otherwise describe() or * PropertyUtils.describe() is used. * * :FIXME: Needs testing. Works OK without a profile bean =:o) * * @param profile * The profile bean, if any * @throws Exception * if error transfering data to map */ protected Map merge(Object profile) throws Exception { Map formMap = null; if (this instanceof BaseMapForm) { BaseMapForm form = (BaseMapForm) this; formMap = form.getMap(); } else { formMap = describe(); } if (profile != null) { Map userMap = null; if (profile instanceof BaseMapForm) { BaseMapForm form = (BaseMapForm) profile; userMap = form.getMap(); } else if (profile instanceof BaseForm) { BaseForm form = (BaseForm) profile; userMap = form.describe(); } else { userMap = PropertyUtils.describe(this); } // Add user element to formMap if form element is null or blank // Starting with the formMap, for every element in the userMap, // see if the formMap element is non-existant, null, or an empty // String. // If it is (our formMap doesn't override), add the userMap value // to the formMap. Iterator i = userMap.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String formValue = (String) formMap.get(key); if (isBlank(formValue)) { formMap.put(key, userMap.get(key)); } } } return formMap; }
From source file:com.fiveamsolutions.nci.commons.audit.DefaultProcessor.java
@SuppressWarnings("unchecked") private Object decomposeIi(Object value) { if (value == null) { return null; }/*w w w . j a va 2 s.c om*/ if (value.getClass().getName().equals("gov.nih.nci.iso21090.Ii")) { try { return PropertyUtils.describe(value).toString(); } catch (Exception e) { LOG.warn(e, e); } } return value; }