List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties
public static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo
classes).
For more details see PropertyUtilsBean
.
From source file:br.gov.jfrj.siga.ex.bl.ExBL.java
public ExModelo getCopia(ExModelo exModOrigem) throws AplicacaoException { ExModelo exModCopia = new ExModelo(); try {/*from w w w . j a v a2 s . c o m*/ PropertyUtils.copyProperties(exModCopia, exModOrigem); // novo id exModCopia.setId(null); exModCopia.setHisDtFim(null); exModCopia.setHisDtIni(null); exModCopia.atribuirAtivo(); } catch (Exception e) { throw new AplicacaoException("Erro ao copiar as propriedades do modelo anterior."); } return exModCopia; }
From source file:nl.ucan.navigate.NestedPath.java
private static DynaBean getDynaBean(Object instance) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(instance.getClass()); LazyDynaBean lazyBean = new LazyDynaBean(dynaClass); PropertyUtils.copyProperties(lazyBean, instance); return lazyBean; }
From source file:org.apache.falcon.regression.Entities.ClusterMerlin.java
public ClusterMerlin(String clusterData) { final Cluster cluster = (Cluster) TestEntityUtil.fromString(EntityType.CLUSTER, clusterData); try {// ww w .j av a2 s.c o m PropertyUtils.copyProperties(this, cluster); } catch (ReflectiveOperationException e) { Assert.fail("Can't create ClusterMerlin: " + ExceptionUtils.getStackTrace(e)); } }
From source file:org.apache.falcon.regression.Entities.FeedMerlin.java
public FeedMerlin(final Feed feed) { try {//from w w w.j av a2 s. c o m PropertyUtils.copyProperties(this, feed); this.setACL(feed.getACL()); } catch (ReflectiveOperationException e) { Assert.fail("Can't create FeedMerlin: " + ExceptionUtils.getStackTrace(e)); } }
From source file:org.apache.falcon.regression.Entities.ProcessMerlin.java
public ProcessMerlin(final Process process) { try {/* ww w . j av a 2 s . c o m*/ PropertyUtils.copyProperties(this, process); } catch (ReflectiveOperationException e) { Assert.fail("Can't create ProcessMerlin: " + ExceptionUtils.getStackTrace(e)); } }
From source file:org.apache.struts.webapp.example.EditRegistrationAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); String action = request.getParameter("action"); if (action == null) { action = "Create"; }/*from w w w . j av a2 s. c o m*/ if (log.isDebugEnabled()) { log.debug("EditRegistrationAction: Processing " + action + " action"); } // Is there a currently logged on user? User user = null; if (!"Create".equals(action)) { user = (User) session.getAttribute(Constants.USER_KEY); if (user == null) { if (log.isDebugEnabled()) { log.debug(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); } } RegistrationForm regform = (RegistrationForm) form; if (user != null) { if (log.isTraceEnabled()) { log.trace(" Populating form from " + user); } try { PropertyUtils.copyProperties(regform, user); regform.setAction(action); regform.setPassword(null); regform.setPassword2(null); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t == null) t = e; log.error("RegistrationForm.populate", t); throw new ServletException("RegistrationForm.populate", t); } catch (Throwable t) { log.error("RegistrationForm.populate", t); throw new ServletException("RegistrationForm.populate", t); } } // Set a transactional control token to prevent double posting if (log.isTraceEnabled()) { log.trace(" Setting transactional control token"); } saveToken(request); // Forward control to the edit user registration page if (log.isTraceEnabled()) { log.trace(" Forwarding to 'success' page"); } return (mapping.findForward("success")); }
From source file:org.apache.struts.webapp.example.EditSubscriptionAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); String action = request.getParameter("action"); if (action == null) { action = "Create"; }//from ww w . jav a 2 s .c o m String host = request.getParameter("host"); if (log.isDebugEnabled()) { log.debug("EditSubscriptionAction: Processing " + action + " action"); } // Is there a currently logged on user? User user = (User) session.getAttribute(Constants.USER_KEY); if (user == null) { if (log.isTraceEnabled()) { log.trace(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); } // Identify the relevant subscription Subscription subscription = user.findSubscription(request.getParameter("host")); if ((subscription == null) && !action.equals("Create")) { if (log.isTraceEnabled()) { log.trace(" No subscription for user " + user.getUsername() + " and host " + host); } return (mapping.findForward("failure")); } if (subscription != null) { session.setAttribute(Constants.SUBSCRIPTION_KEY, subscription); } SubscriptionForm subform = (SubscriptionForm) form; subform.setAction(action); if (!action.equals("Create")) { if (log.isTraceEnabled()) { log.trace(" Populating form from " + subscription); } try { PropertyUtils.copyProperties(subform, subscription); subform.setAction(action); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t == null) t = e; log.error("SubscriptionForm.populate", t); throw new ServletException("SubscriptionForm.populate", t); } catch (Throwable t) { log.error("SubscriptionForm.populate", t); throw new ServletException("SubscriptionForm.populate", t); } } // Forward control to the edit subscription page if (log.isTraceEnabled()) { log.trace(" Forwarding to 'success' page"); } return (mapping.findForward("success")); }
From source file:org.apache.struts.webapp.example.SaveRegistrationAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes and parameters we will need HttpSession session = request.getSession(); RegistrationForm regform = (RegistrationForm) form; String action = regform.getAction(); if (action == null) { action = "Create"; }/* w w w. jav a 2 s . c o m*/ UserDatabase database = (UserDatabase) servlet.getServletContext().getAttribute(Constants.DATABASE_KEY); if (log.isDebugEnabled()) { log.debug("SaveRegistrationAction: Processing " + action + " action"); } // Is there a currently logged on user (unless creating)? User user = (User) session.getAttribute(Constants.USER_KEY); if (!"Create".equals(action) && (user == null)) { if (log.isTraceEnabled()) { log.trace(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); } // Was this transaction cancelled? if (isCancelled(request)) { if (log.isTraceEnabled()) { log.trace(" Transaction '" + action + "' was cancelled"); } session.removeAttribute(Constants.SUBSCRIPTION_KEY); return (mapping.findForward("success")); } // Validate the transactional control token ActionMessages errors = new ActionMessages(); if (log.isTraceEnabled()) { log.trace(" Checking transactional control token"); } if (!isTokenValid(request)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.transaction.token")); } resetToken(request); // Validate the request parameters specified by the user if (log.isTraceEnabled()) { log.trace(" Performing extra validations"); } String value = null; value = regform.getUsername(); if (("Create".equals(action)) && (database.findUser(value) != null)) { errors.add("username", new ActionMessage("error.username.unique", regform.getUsername())); } if ("Create".equals(action)) { value = regform.getPassword(); if ((value == null) || (value.length() < 1)) { errors.add("password", new ActionMessage("error.password.required")); } value = regform.getPassword2(); if ((value == null) || (value.length() < 1)) { errors.add("password2", new ActionMessage("error.password2.required")); } } // Report any errors we have discovered back to the original form if (!errors.isEmpty()) { this.saveErrors(request, errors); this.saveToken(request); return (mapping.getInputForward()); } // Update the user's persistent profile information try { if ("Create".equals(action)) { user = database.createUser(regform.getUsername()); } String oldPassword = user.getPassword(); PropertyUtils.copyProperties(user, regform); if ((regform.getPassword() == null) || (regform.getPassword().length() < 1)) { user.setPassword(oldPassword); } } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t == null) { t = e; } log.error("Registration.populate", t); throw new ServletException("Registration.populate", t); } catch (Throwable t) { log.error("Registration.populate", t); throw new ServletException("Subscription.populate", t); } try { database.save(); } catch (Exception e) { log.error("Database save", e); } // Log the user in if appropriate if ("Create".equals(action)) { session.setAttribute(Constants.USER_KEY, user); if (log.isTraceEnabled()) { log.trace(" User '" + user.getUsername() + "' logged on in session " + session.getId()); } } // Remove the obsolete form bean if (mapping.getAttribute() != null) { if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute()); else session.removeAttribute(mapping.getAttribute()); } // Forward control to the specified success URI if (log.isTraceEnabled()) { log.trace(" Forwarding to success page"); } return (mapping.findForward("success")); }
From source file:org.apache.struts.webapp.example.SaveSubscriptionAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes and parameters we will need MessageResources messages = getResources(request); HttpSession session = request.getSession(); SubscriptionForm subform = (SubscriptionForm) form; String action = subform.getAction(); if (action == null) { action = "?"; }/*from w ww. jav a 2s .c o m*/ if (log.isDebugEnabled()) { log.debug("SaveSubscriptionAction: Processing " + action + " action"); } // Is there a currently logged on user? User user = (User) session.getAttribute(Constants.USER_KEY); if (user == null) { if (log.isTraceEnabled()) { log.trace(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); } // Was this transaction cancelled? if (isCancelled(request)) { if (log.isTraceEnabled()) { log.trace(" Transaction '" + action + "' was cancelled"); } session.removeAttribute(Constants.SUBSCRIPTION_KEY); return (mapping.findForward("success")); } // Is there a related Subscription object? Subscription subscription = (Subscription) session.getAttribute(Constants.SUBSCRIPTION_KEY); if ("Create".equals(action)) { subscription = user.createSubscription(request.getParameter("host")); } if (subscription == null) { if (log.isTraceEnabled()) { log.trace(" Missing subscription for user '" + user.getUsername() + "'"); } response.sendError(HttpServletResponse.SC_BAD_REQUEST, messages.getMessage("error.noSubscription")); return (null); } // Was this transaction a Delete? if (action.equals("Delete")) { if (log.isTraceEnabled()) { log.trace(" Deleting mail server '" + subscription.getHost() + "' for user '" + user.getUsername() + "'"); } user.removeSubscription(subscription); session.removeAttribute(Constants.SUBSCRIPTION_KEY); try { UserDatabase database = (UserDatabase) servlet.getServletContext() .getAttribute(Constants.DATABASE_KEY); database.save(); } catch (Exception e) { log.error("Database save", e); } return (mapping.findForward("success")); } // All required validations were done by the form itself // Update the persistent subscription information if (log.isTraceEnabled()) { log.trace(" Populating database from form bean"); } try { PropertyUtils.copyProperties(subscription, subform); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t == null) t = e; log.error("Subscription.populate", t); throw new ServletException("Subscription.populate", t); } catch (Throwable t) { log.error("Subscription.populate", t); throw new ServletException("Subscription.populate", t); } try { UserDatabase database = (UserDatabase) servlet.getServletContext().getAttribute(Constants.DATABASE_KEY); database.save(); } catch (Exception e) { log.error("Database save", e); } // Remove the obsolete form bean and current subscription if (mapping.getAttribute() != null) { if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute()); else session.removeAttribute(mapping.getAttribute()); } session.removeAttribute(Constants.SUBSCRIPTION_KEY); // Forward control to the specified success URI if (log.isTraceEnabled()) { log.trace(" Forwarding to success page"); } return (mapping.findForward("success")); }
From source file:org.apache.struts.webapp.example2.EditRegistrationAction.java
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed.// w ww . j a va 2s.c o m * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need Locale locale = getLocale(request); MessageResources messages = getResources(request); HttpSession session = request.getSession(); String action = request.getParameter("action"); if (action == null) action = "Create"; if (log.isDebugEnabled()) { log.debug("EditRegistrationAction: Processing " + action + " action"); } // Is there a currently logged on user? User user = null; if (!"Create".equals(action)) { user = (User) session.getAttribute(Constants.USER_KEY); if (user == null) { if (log.isDebugEnabled()) { log.debug(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); } } // Populate the user registration form if (form == null) { if (log.isTraceEnabled()) { log.trace(" Creating new RegistrationForm bean under key " + mapping.getAttribute()); } form = new RegistrationForm(); if ("request".equals(mapping.getScope())) request.setAttribute(mapping.getAttribute(), form); else session.setAttribute(mapping.getAttribute(), form); } RegistrationForm regform = (RegistrationForm) form; if (user != null) { if (log.isTraceEnabled()) { log.trace(" Populating form from " + user); } try { PropertyUtils.copyProperties(regform, user); regform.setAction(action); regform.setPassword(null); regform.setPassword2(null); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t == null) t = e; log.error("RegistrationForm.populate", t); throw new ServletException("RegistrationForm.populate", t); } catch (Throwable t) { log.error("RegistrationForm.populate", t); throw new ServletException("RegistrationForm.populate", t); } } // Set a transactional control token to prevent double posting if (log.isTraceEnabled()) { log.trace(" Setting transactional control token"); } saveToken(request); // Forward control to the edit user registration page if (log.isTraceEnabled()) { log.trace(" Forwarding to 'success' page"); } if ("Create".equals(action)) { return (mapping.findForward("register")); } else { return (mapping.findForward("success")); } }