Example usage for org.apache.commons.beanutils PropertyUtils getProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getProperty.

Prototype

public static Object getProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:javax.faces.component.AbstractUIComponentPropertyTest.java

@Test
public void testExpressionWithLiteralTextValue() throws Exception {
    for (T testValue : _testValues) {
        expect(_valueExpression.isLiteralText()).andReturn(true);
        expect(_valueExpression.getValue(eq(_facesContext.getELContext()))).andReturn(testValue);
        _mocksControl.replay();//from ww w.j  a  v a  2 s  . c  o  m
        _component.setValueExpression(_property, _valueExpression);
        Assert.assertEquals(testValue, PropertyUtils.getProperty(_component, _property));
        _mocksControl.reset();
    }
}

From source file:com.meidusa.venus.validate.validator.ValidatorSupport.java

public String getMessage(Object value) {
    if (message == null) {
        return "";
    }/* w  w w.j  av a  2  s  . com*/
    String result = null;
    if (messageParameters == null || messageParameters.length == 0) {
        result = message;
    } else {
        Object[] parsedParameters = new Object[messageParameters.length];
        for (int i = 0; i < this.messageParameters.length; i++) {
            if (STAND_FOR_NAME.equals(messageParameters[i])) {
                parsedParameters[i] = this.describeValidateName();
            } else if (STAND_FOR_VALUE.equals(messageParameters[i])) {
                if (value != null) {
                    parsedParameters[i] = value.toString();
                } else {
                    parsedParameters[i] = "null";

                }
            } else {
                parsedParameters[i] = holder.findString(messageParameters[i]);
            }
        }
        result = String.format(message, parsedParameters);
    }
    Matcher matcher = validatorPattern.matcher(result);
    StringBuffer sb = new StringBuffer();
    Object obj = null;
    while (matcher.find()) {
        try {
            obj = PropertyUtils.getProperty(this, matcher.group(1));
        } catch (Exception e) {
            obj = "null";
        }
        if (obj == null) {
            obj = "null";
        }
        matcher.appendReplacement(sb, obj.toString());
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:com.mycollab.module.project.ui.components.ProjectFollowersComp.java

public void displayFollowers(final V bean) {
    this.bean = bean;
    try {//www  .  j a  va2  s .  c o m
        typeId = (Integer) PropertyUtils.getProperty(bean, "id");
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        LOG.error("Error", e);
        return;
    }
    this.removeAllComponents();

    MHorizontalLayout header = new MHorizontalLayout().withStyleName("info-hdr");
    header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    Label followerHeader = new Label(
            FontAwesome.EYE.getHtml() + " " + UserUIContext.getMessage(FollowerI18nEnum.OPT_SUB_INFO_WATCHERS),
            ContentMode.HTML);
    header.addComponent(followerHeader);

    if (hasEditPermission()) {
        final PopupView addPopupView = new PopupView(UserUIContext.getMessage(GenericI18Enum.ACTION_MODIFY),
                new MVerticalLayout());
        addPopupView.addPopupVisibilityListener(popupVisibilityEvent -> {
            PopupView.Content content = addPopupView.getContent();
            if (popupVisibilityEvent.isPopupVisible()) {
                MVerticalLayout popupComponent = (MVerticalLayout) content.getPopupComponent();
                popupComponent.removeAllComponents();
                popupComponent.with(new ELabel(UserUIContext.getMessage(FollowerI18nEnum.OPT_SUB_INFO_WATCHERS))
                        .withStyleName(ValoTheme.LABEL_H3), new ModifyWatcherPopup());
            } else {
                MVerticalLayout popupComponent = (MVerticalLayout) content.getPopupComponent();
                ModifyWatcherPopup popup = (ModifyWatcherPopup) popupComponent.getComponent(1);
                List<MonitorItem> unsavedItems = popup.getUnsavedItems();
                monitorItemService.saveMonitorItems(unsavedItems);
                loadWatchers();
            }
        });
        header.addComponent(addPopupView);
    }
    header.addComponent(ELabel.fontIcon(FontAwesome.QUESTION_CIRCLE).withStyleName(WebThemes.INLINE_HELP)
            .withDescription(UserUIContext.getMessage(FollowerI18nEnum.FOLLOWER_EXPLAIN_HELP)));

    this.addComponent(header);

    watcherLayout = new MCssLayout().withFullWidth().withStyleName(WebThemes.FLEX_DISPLAY);
    this.addComponent(watcherLayout);
    loadWatchers();
}

From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java

public List<GenericSearchResult> performQBESearch(final Entity aObject, final String[] aProperties,
        final String[] aSearchProperties, final String[] aOrderByProperties, final int aMatchMode,
        final int aMaxSearchResult) {

    final Class aType = aObject.getClass();
    return (List) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) throws SQLException {

            List<GenericSearchResult> theResult = new ArrayList<GenericSearchResult>();

            String theQueryString = "select item.id";
            for (String aProperty : aProperties) {
                if (!aProperty.startsWith("+")) {
                    theQueryString += " ,item." + aProperty;
                } else {
                    theQueryString += " ,j_" + aProperty.substring(1).toLowerCase();
                }//from ww w  .j a v  a  2 s.com
            }
            theQueryString += " from " + aType.getName() + " item ";
            for (String aProperty : aProperties) {
                if (aProperty.startsWith("+")) {
                    String theRealName = aProperty.substring(1);
                    theQueryString += " left outer join item." + theRealName + " as j_"
                            + theRealName.toLowerCase();
                }
            }

            HashMap<String, Object> theParams = new HashMap<String, Object>();

            boolean theFirst = true;
            for (int i = 0; i < aSearchProperties.length; i++) {
                String thePropertyName = aSearchProperties[i];
                Object theValue = null;
                try {
                    theValue = PropertyUtils.getProperty(aObject, thePropertyName);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                if ((theValue != null) && (!"".equals(theValue))) {
                    if (theFirst) {
                        theQueryString += " where ";
                    }
                    if (!theFirst) {
                        theQueryString += " and ";
                    }

                    if (theValue instanceof String) {
                        String theStringValue = (String) theValue;
                        if (!theStringValue.contains("%")) {
                            if (aMatchMode == MATCH_LIKE) {
                                theQueryString += "lower(item." + thePropertyName + ") like :"
                                        + thePropertyName;
                                theParams.put(thePropertyName, "%" + theStringValue.toLowerCase() + "%");
                            } else {
                                theQueryString += "lower(item." + thePropertyName + ") = :" + thePropertyName;
                                theParams.put(thePropertyName, theStringValue.toLowerCase());
                            }
                        } else {
                            theQueryString += "lower(item." + thePropertyName + ") like :" + thePropertyName;
                            theParams.put(thePropertyName, theStringValue.toLowerCase());
                        }
                    } else {
                        theQueryString += "item." + thePropertyName + " = :" + thePropertyName;
                        theParams.put(thePropertyName, theValue);
                    }

                    theFirst = false;
                }
            }

            if ((aOrderByProperties != null) && (aOrderByProperties.length > 0)) {
                theQueryString += " order by ";
                for (int i = 0; i < aOrderByProperties.length; i++) {
                    String propertyName = aOrderByProperties[i];
                    if (i > 0) {
                        theQueryString += ",";
                    }
                    theQueryString += " item." + propertyName;
                }
            }

            Query theQuery = aSession.createQuery(theQueryString);
            for (Map.Entry<String, Object> theEntry : theParams.entrySet()) {
                Object theValue = theParams.get(theEntry.getKey());
                theQuery.setParameter(theEntry.getKey(), theValue);
            }
            theQuery.setMaxResults(aMaxSearchResult);
            for (Iterator it = theQuery.list().iterator(); it.hasNext();) {
                Object[] theRow = (Object[]) it.next();
                GenericSearchResult theRowObject = new GenericSearchResult();
                theRowObject.put(GenericSearchResult.OBJECT_ID_KEY, theRow[0]);
                for (int i = 0; i < aProperties.length; i++) {
                    String thePropertyName = aProperties[i];
                    if (thePropertyName.startsWith("+")) {
                        thePropertyName = thePropertyName.substring(1);
                    }
                    theRowObject.put(thePropertyName, theRow[i + 1]);
                }
                theResult.add(theRowObject);
            }

            return theResult;
        }

    });
}

From source file:net.mlw.vlh.web.tag.AddParamTag.java

/**
 * @throws NoSuchMethodException//from   w  w w .  j  ava2  s  . c o m
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 */
public int doStartTag() throws JspException {
    ParamAddable parent = (ParamAddable) JspUtils.getParent(this, ParamAddable.class);

    if ((property != null) && (value != null)) {
        final String message = "For one parameter" + name
                + "you can not use two values (first dynamic from the property, 2nd static from the value";
        LOGGER.error(message);
        throw new JspException(message);
    }

    if (name == null) {
        // use the same name as the name of property, if name is not
        // specified
        name = property;
    }

    if (property != null) {
        DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class);
        Object bean = pageContext.getAttribute(rowTag.getBeanName());
        if (bean != null && !(bean instanceof Spacer)) {
            try {
                value = String.valueOf(PropertyUtils.getProperty(bean, property));
            } catch (Exception e) {
                LOGGER.error("<vlh:addParam> Error getting property '" + property + "'.");
                value = null;
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Row's JavaBean '" + rowTag.getBeanName() + "' is null or Valuelist is empty!");
            }
            value = null;
        }
    }

    if (value == null) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                    "The param '" + addActionParamPrefix(name) + "' is skiped, because it's value is null!");
        }
    } else {

        parent.addParam(addActionParamPrefix(name), value);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(
                    "The param '" + addActionParamPrefix(name) + "' was added with the value '" + value + "'.");
        }
    }

    release();

    return SKIP_BODY;
}

From source file:jp.go.nict.langrid.p2pgridbasis.data.langrid.converter.ConvertUtil.java

static public DataAttributes encode(Object data) throws DataConvertException {
    setLangridConverter();/* w w w .  ja  v a  2  s  .co m*/
    logger.debug("##### encode #####");
    try {
        DataAttributes attr = new DataAttributes();
        for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(data)) {
            if (PropertyUtils.isReadable(data, descriptor.getName())) {
                if (descriptor.getName().equalsIgnoreCase("supportedLanguages")) {
                    //supportedLanguages
                    attr.setAttribute(descriptor.getName(),
                            (String) converter.lookup(descriptor.getPropertyType()).convert(String.class,
                                    PropertyUtils.getProperty(data, descriptor.getName())));
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("instance")) {
                    // 
                    // 
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("wsdl")) {
                    // 
                    // 
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("interfaceDefinitions")) {
                    // 
                    // 
                    ServiceType type = (ServiceType) data;
                    Map<String, ServiceInterfaceDefinition> map = new HashMap<String, ServiceInterfaceDefinition>();
                    map = type.getInterfaceDefinitions();
                    String str = "";

                    try {
                        for (ServiceInterfaceDefinition s : map.values()) {
                            str = str + "ProtocolId=" + s.getProtocolId() + "\n";
                            str = str + "Definition="
                                    + Base64.encode(StreamUtil.readAsBytes(s.getDefinition().getBinaryStream()))
                                    + "\n";
                            str = str + "###ServiceInterfaceDefinition###\n";
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                    attr.setAttribute("interfaceDefinition_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("allowedAppProvision")) {
                    Service s = (Service) data;
                    String value = "";
                    for (String str : s.getAllowedAppProvision()) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("allowedAppProvision", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("allowedUse")) {
                    Service s = (Service) data;
                    String value = "";
                    for (String str : s.getAllowedUse()) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("allowedUse", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("supportedDomains")) {
                    Grid g = (Grid) data;
                    List<Domain> list = g.getSupportedDomains();
                    String value = "";
                    for (Domain d : list) {
                        value = value + d.getDomainId() + "\n";
                    }
                    attr.setAttribute("supportedDomain_list", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("partnerServiceNamespaceURIs")) {
                    //partnerServiceNamespaceURIs
                    BPELService s = (BPELService) data;
                    List<String> list = s.getPartnerServiceNamespaceURIs();
                    String value = "";
                    for (String str : list) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("partnerServiceNamespaceURI_list", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("serviceDeployments")) {
                    //ServiceDeployment
                    Service s = (Service) data;
                    String str = "";
                    for (ServiceDeployment sd : s.getServiceDeployments()) {
                        str = str + "GridId=" + sd.getGridId() + "\n";
                        str = str + "ServiceId=" + sd.getServiceId() + "\n";
                        str = str + "NodeId=" + sd.getNodeId() + "\n";
                        str = str + "ServicePath=" + sd.getServicePath() + "\n";
                        str = str + "Enabled=" + String.valueOf(sd.isEnabled()) + "\n";
                        str = str + "CreateTime=" + String.valueOf(sd.getCreatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "UpdateTime=" + String.valueOf(sd.getUpdatedDateTime().getTimeInMillis())
                                + "\n";
                        if (sd.getDisabledByErrorDate() != null) {
                            str = str + "ErrorDate="
                                    + String.valueOf(sd.getDisabledByErrorDate().getTimeInMillis()) + "\n";
                        }
                        if (sd.getDeployedDateTime() != null) {
                            str = str + "DeployedTime="
                                    + String.valueOf(sd.getDeployedDateTime().getTimeInMillis()) + "\n";
                        }
                        str = str + "###ServiceDeployment###\n";
                    }
                    attr.setAttribute("deployment_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("serviceEndpoints")) {
                    //ServiceEndpoint
                    StringBuilder str = new StringBuilder();
                    Service s = (Service) data;
                    for (ServiceEndpoint se : s.getServiceEndpoints()) {
                        str.append("GridId=" + se.getGridId() + "\n");
                        str.append("ProtocolId=" + se.getProtocolId() + "\n");
                        str.append("ServiceId=" + se.getServiceId() + "\n");
                        str.append("Enabled=" + String.valueOf(se.isEnabled()) + "\n");
                        str.append("Url=" + se.getUrl().toString() + "\n");
                        str.append("AuthUserName=" + se.getAuthUserName() + "\n");
                        str.append("AuthPassword=" + se.getAuthPassword() + "\n");
                        str.append("DisableReason=" + se.getDisableReason() + "\n");
                        str.append("CreateTime=" + String.valueOf(se.getCreatedDateTime().getTimeInMillis())
                                + "\n");
                        str.append("UpdateTime=" + String.valueOf(se.getUpdatedDateTime().getTimeInMillis())
                                + "\n");
                        if (se.getDisabledByErrorDate() != null) {
                            str.append("ErrorDate="
                                    + String.valueOf(se.getDisabledByErrorDate().getTimeInMillis()) + "\n");
                        }
                        str.append("###ServiceEndpoint###\n");
                    }
                    attr.setAttribute("endpoint_list", str.toString());
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("invocations")) {
                    //Invocation
                    String str = "";
                    Service s = (Service) data;
                    for (Invocation in : s.getInvocations()) {
                        str = str + "InvocationName=" + in.getInvocationName() + "\n";
                        str = str + "OwnerServiceGridId=" + in.getOwnerServiceGridId() + "\n";
                        str = str + "OwnerServiceId=" + in.getOwnerServiceId() + "\n";
                        str = str + "ServiceGridId=" + in.getServiceGridId() + "\n";
                        str = str + "ServiceId=" + in.getServiceId() + "\n";
                        str = str + "ServiceName=" + in.getServiceName() + "\n";
                        str = str + "CreateTime=" + String.valueOf(in.getCreatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "UpdateTime=" + String.valueOf(in.getUpdatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "###Invocation###\n";
                    }
                    attr.setAttribute("invocations_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("metaAttributes")) {
                    //metaAttributes
                    String str = "";
                    if (data.getClass().getName().endsWith("ResourceType")) {
                        ResourceType r = (ResourceType) data;
                        for (ResourceMetaAttribute a : r.getMetaAttributes().values()) {
                            str = str + "DomainId=" + a.getDomainId() + "\n";
                            str = str + "AttributeId=" + a.getAttributeId() + "\n";
                            str = str + "###MetaAttribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("ServiceType")) {
                        ServiceType s = (ServiceType) data;
                        for (ServiceMetaAttribute a : s.getMetaAttributes().values()) {
                            str = str + "DomainId=" + a.getDomainId() + "\n";
                            str = str + "AttributeId=" + a.getAttributeId() + "\n";
                            str = str + "###MetaAttribute###\n";
                        }
                    } else {
                        logger.info("metaAttributes : " + data.getClass().getName());
                    }
                    attr.setAttribute("metaAttribute_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("attributes")) {
                    //attribute
                    String str = "";
                    if (data.getClass().getName().endsWith("User")) {
                        User u = (User) data;
                        for (UserAttribute a : u.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getUserId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Service")) {
                        Service s = (Service) data;
                        for (ServiceAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getServiceId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Node")) {
                        Node s = (Node) data;
                        for (NodeAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getNodeId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Grid")) {
                        Grid s = (Grid) data;
                        for (GridAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Resource")) {
                        Resource s = (Resource) data;
                        for (ResourceAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getResourceId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    }
                    attr.setAttribute("attribute_list", str);
                    continue;
                } else if (data instanceof Service && (descriptor.getName().equals("alternateServiceId")
                        || descriptor.getName().equals("useAlternateServices"))) {
                    // 
                    // 
                    continue;
                }

                //Read OK
                if (data instanceof BPELService && descriptor.getName().equals("transferExecution")) {
                    // ignore
                } else {
                    attr.setAttribute(descriptor.getName(), BeanUtils.getProperty(data, descriptor.getName()));
                }
            } else if (descriptor.getPropertyType().isArray()) {
                logger.debug("name : " + descriptor.getName() + " isArray");
                // 
                // 
                attr.setAttribute(descriptor.getName(), (String) converter.lookup(descriptor.getPropertyType())
                        .convert(String.class, PropertyUtils.getProperty(data, descriptor.getName())));
            } else {
                logger.debug("Name : " + descriptor.getName());
                for (Method m : data.getClass().getMethods()) {
                    if (m.getName().equalsIgnoreCase("get" + descriptor.getName())
                            || m.getName().equalsIgnoreCase("is" + descriptor.getName())) {
                        if (m.getParameterTypes().length != 0) {
                            // 
                            // 
                            logger.debug("class : " + data.getClass().getName());
                            logger.debug("?:Skip");
                            break;
                        } else {
                            // 
                            // 
                            logger.debug("value : " + m.invoke(data));
                        }
                        attr.setAttribute(descriptor.getName(), m.invoke(data).toString());
                        break;
                    }
                }
            }
        }
        return attr;
    } catch (InvocationTargetException e) {
        throw new DataConvertException(e);
    } catch (IllegalArgumentException e) {
        throw new DataConvertException(e);
    } catch (IllegalAccessException e) {
        throw new DataConvertException(e);
    } catch (NoSuchMethodException e) {
        throw new DataConvertException(e);
    }
}

From source file:com.pasteur.ci.action.modification.ModificationRechechercheAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception/* w  w w.  ja  va2 s  . com*/
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String num_echan = (String) PropertyUtils.getProperty(form, "num_echan");

    Echantillon echantillon = new Echantillon();
    echantillon.setNum_echantillon(num_echan);
    EchantillonDAOImplement echantillonDAOImplement = new EchantillonDAOImplement(DAOFactory.getInstance());
    echantillon = (Echantillon) echantillonDAOImplement.find(echantillon);

    System.out.println("Echantillon: \n" + " idechantillon: " + echantillon.getIdechantillon() + "\n"
            + " numero echantillon: " + echantillon.getNum_echantillon() + "\n" + " idprojet: "
            + echantillon.getIdprojet() + "\n" + " date de prelevement: " + echantillon.getDate_prelevement()
            + "\n" + " idpoint_prelevement: " + echantillon.getIdpoint_prelevement() + "\n" + " idparasite: "
            + echantillon.getIdparasite() + "\n" + " idvirus: " + echantillon.getIdvirus() + "\n"
            + " idp_physico_chimique: " + echantillon.getIdp_phy_chim() + "\n" + " idcyano: "
            + echantillon.getIdcyano() + "\n" + " idautre_bacterie: " + echantillon.getIdautre_bacterie() + "\n"
            + " idautre_algue: " + echantillon.getIdautre_algue() + "\n" + "");

    AutreBacterie autreBacterie = new AutreBacterie();
    autreBacterie.setIdautre_bacterie(echantillon.getIdautre_bacterie());
    AutreBacterieDAOImplement autreBacterieDAOImplement = new AutreBacterieDAOImplement(
            DAOFactory.getInstance());
    autreBacterie = (AutreBacterie) autreBacterieDAOImplement.find(autreBacterie);

    Parasite parasite = new Parasite();
    parasite.setIdparasite(echantillon.getIdparasite());
    ParasiteDAOImplement parasiteDAOImplement = new ParasiteDAOImplement(DAOFactory.getInstance());
    parasite = (Parasite) parasiteDAOImplement.find(parasite);

    Virus virus = new Virus();
    virus.setIdvirus(echantillon.getIdvirus());
    VirusDAOImplement virusDAOImplement = new VirusDAOImplement(DAOFactory.getInstance());
    virus = (Virus) virusDAOImplement.find(virus);

    Projet projetf = new Projet();
    projetf.setIdprojet(echantillon.getIdprojet());
    ProjetDAOImplement projetDAOImplementf = new ProjetDAOImplement(DAOFactory.getInstance());
    projetf = (Projet) projetDAOImplementf.find(projetf);

    PointPrelevement pointPrelevementf = new PointPrelevement();
    pointPrelevementf.setIdpoint_prelevement(echantillon.getIdpoint_prelevement());
    PointPrelevementDAOImplement pointPrelevementDAOImplementf = new PointPrelevementDAOImplement(
            DAOFactory.getInstance());
    pointPrelevementf = (PointPrelevement) pointPrelevementDAOImplementf.find(pointPrelevementf);

    PPhyChim pphychimie = new PPhyChim();
    pphychimie.setIdp_phy_chim(echantillon.getIdp_phy_chim());
    PPhyChimDAOImplement ppcdaoi = new PPhyChimDAOImplement(DAOFactory.getInstance());
    pphychimie = (PPhyChim) ppcdaoi.find(pphychimie);

    FamilleDAOImplement famille = new FamilleDAOImplement(DAOFactory.getInstance()); //ok
    EclairageDAOImplement eclaidao = new EclairageDAOImplement(DAOFactory.getInstance()); //ok
    PointPrelevementDAOImplement pointPrelevementDAOImplement = new PointPrelevementDAOImplement(
            DAOFactory.getInstance());//ok
    ProjetDAOImplement projetDAOImplement = new ProjetDAOImplement(DAOFactory.getInstance());//ok

    GenreAlgueDAOImplement genre_algue = new GenreAlgueDAOImplement(DAOFactory.getInstance());
    EspeceAlgueDAOImplement espece_algue = new EspeceAlgueDAOImplement(DAOFactory.getInstance());
    // AutreAlgueDAOImplement autre_algue = new AutreAlgueDAOImplement(DAOFactory.getInstance());
    PratiqueDAOImplement pratique = new PratiqueDAOImplement(DAOFactory.getInstance());
    GenreCyanoDAOImplement genrecyano = new GenreCyanoDAOImplement(DAOFactory.getInstance());
    EspeceCyanoDAOImplement espececyano = new EspeceCyanoDAOImplement(DAOFactory.getInstance());
    GeneCyanoDAOImplement genecyano = new GeneCyanoDAOImplement(DAOFactory.getInstance());
    TypeGeneToxiciteDAOImplement typegenetox = new TypeGeneToxiciteDAOImplement(DAOFactory.getInstance());
    TypeToxineDAOImplement typetoxine = new TypeToxineDAOImplement(DAOFactory.getInstance());

    LigneGeneCyano ligneGeneCyano = new LigneGeneCyano();
    ligneGeneCyano.setIdcyano(echantillon.getIdcyano());
    LigneGeneCyanoDAOImplement ligneGeneCyanoDAOImplement = new LigneGeneCyanoDAOImplement(
            DAOFactory.getInstance());
    ArrayList<Object> ligneGeneCyanos = ligneGeneCyanoDAOImplement.find(ligneGeneCyano);
    for (int i = 1; i <= ligneGeneCyanos.size(); i++) {
        request.setAttribute("ligneGeneCyano_trouve" + i, (LigneGeneCyano) ligneGeneCyanos.get(i - 1));
    }

    LigneTypeToxine ligneTypeToxine = new LigneTypeToxine();
    ligneTypeToxine.setIdcyano(echantillon.getIdcyano());
    LigneTypeToxineDAOImplement ligneTypeToxineDAOImplement = new LigneTypeToxineDAOImplement(
            DAOFactory.getInstance());
    ArrayList<Object> ligneTypeToxines = ligneTypeToxineDAOImplement.find(ligneTypeToxine);
    for (int i = 1; i <= ligneTypeToxines.size(); i++) {
        request.setAttribute("ligneTypeTox_trouve" + i, (LigneTypeToxine) ligneTypeToxines.get(i - 1));
    }

    LigneTypeGeneToxicite ligneTypeGeneToxicite = new LigneTypeGeneToxicite();
    ligneTypeGeneToxicite.setIdcyano(echantillon.getIdcyano());
    LigneTypeGeneToxiciteDAOImplement typeGeneToxiciteDAOImplement = new LigneTypeGeneToxiciteDAOImplement(
            DAOFactory.getInstance());
    ArrayList<Object> ligneTypeGeneToxicites = typeGeneToxiciteDAOImplement.find(ligneTypeGeneToxicite);
    for (int i = 1; i <= ligneTypeGeneToxicites.size(); i++) {
        request.setAttribute("ligneTypeGeneToxi_trouve" + i,
                (LigneTypeGeneToxicite) ligneTypeGeneToxicites.get(i - 1));
    }

    LigneGenreCyano ligneGenreCyano = new LigneGenreCyano();
    ligneGenreCyano.setIdcyano(echantillon.getIdcyano());
    LigneGenreCyanoDAOImplement ligneGenreCyanoDAOImplement = new LigneGenreCyanoDAOImplement(
            DAOFactory.getInstance());
    ArrayList<Object> ligneGenreCyanos = ligneGenreCyanoDAOImplement.find(ligneGenreCyano);
    for (int i = 1; i <= ligneGenreCyanos.size(); i++) {
        request.setAttribute("ligneGenreCyano_trouve" + i, (LigneGenreCyano) ligneGenreCyanos.get(i - 1));
    }

    LigneFamille ligneFamille = new LigneFamille();
    ligneFamille.setIdautre_algue(echantillon.getIdautre_algue());
    LigneFamilleDAOimplement ligneFamilleDAOimplement = new LigneFamilleDAOimplement(DAOFactory.getInstance());
    ArrayList<Object> ligneFamilles = ligneFamilleDAOimplement.find(ligneFamille);
    for (int i = 1; i <= ligneFamilles.size(); i++) {
        LigneFamille ligneFamille1 = (LigneFamille) ligneFamilles.get(i - 1);
        request.setAttribute("ligneFamille_trouve" + i, ligneFamille1);
        LigneGenreAlgue ligneGenreAlgue = new LigneGenreAlgue();
        ligneGenreAlgue.setIdligne_famille(ligneFamille1.getIdligne_famille());
        LigneGenreAlgueDAOImplement ligneGenreAlgueDAOImplement = new LigneGenreAlgueDAOImplement(
                DAOFactory.getInstance());
        ArrayList<Object> ligneGenreAlgues = ligneGenreAlgueDAOImplement.find(ligneGenreAlgue);
        String listeGenreAl = "";
        for (int j = 1; j <= ligneGenreAlgues.size(); j++) {
            LigneGenreAlgue ligneGenreAlgue1 = (LigneGenreAlgue) ligneGenreAlgues.get(j - 1);
            GenreAlgue genreAlgue = new GenreAlgue();
            genreAlgue.setIdgenre_algue(ligneGenreAlgue1.getIdgenre_algue());
            GenreAlgueDAOImplement genreAlgueDAOImplement = new GenreAlgueDAOImplement(
                    DAOFactory.getInstance());
            genreAlgue = (GenreAlgue) genreAlgueDAOImplement.find(genreAlgue);
            listeGenreAl = listeGenreAl + genreAlgue.getDesign_genre_algue() + "; ";
        }
        GenreAlgue genreAlgue_ = new GenreAlgue();
        genreAlgue_.setGenreAlgue(listeGenreAl);
        request.setAttribute("ligne_listeGenreAlgue_trouve" + i, genreAlgue_);
    }

    ArrayList<Object> listePointPrelev = pointPrelevementDAOImplement.find();
    ArrayList<Object> listeProjet = projetDAOImplement.find();
    ArrayList<Object> listeclai = eclaidao.find();
    ArrayList<Object> listeFam = famille.find();
    ArrayList<Object> listGenAlg = genre_algue.find();
    ArrayList<Object> listeEspAlg = espece_algue.find();
    ArrayList<Object> listeGenreCya = genrecyano.find();
    ArrayList<Object> listeEspCya = espececyano.find();
    ArrayList<Object> listeGeneCya = genecyano.find();
    ArrayList<Object> listeTypeGeneTox = typegenetox.find();
    ArrayList<Object> listePratique = pratique.find();
    ArrayList<Object> listeTypeToxine = typetoxine.find();

    request.setAttribute("pointprelev_trouve", listePointPrelev);
    request.setAttribute("projet_trouve", listeProjet);
    request.setAttribute("eclai_trouve", listeclai);
    request.setAttribute("espece_trouve", listeEspAlg);
    request.setAttribute("genre_trouve", listGenAlg);
    request.setAttribute("famille_trouve", listeFam);
    request.setAttribute("num_trouve", echantillon);
    request.setAttribute("pratique_trouve", listePratique);
    request.setAttribute("genrecya_trouve", listeGenreCya);
    request.setAttribute("espececya_trouve", listeEspCya);
    request.setAttribute("genecya_trouve", listeGeneCya);
    request.setAttribute("typegenetox_trouve", listeTypeGeneTox);
    request.setAttribute("typetoxine_trouve", listeTypeToxine);
    //
    request.setAttribute("ab_trouve", autreBacterie);
    request.setAttribute("para_trouve", parasite);
    request.setAttribute("virus_trouve", virus);
    request.setAttribute("projet_trouvef", projetf);
    request.setAttribute("ppmt_trouvef", pointPrelevementf);
    request.setAttribute("ppchim_trouve", pphychimie);

    request.setAttribute("liste_gene_cyano_trouve", ligneGeneCyanos);

    return mapping.findForward(SUCCESS);
}

From source file:io.github.moosbusch.lumpi.util.FormUtil.java

public static Map<String, Object> getPropertyValuesMap(Object bean)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<String, Object> result = new HashMap<>();
    PropertyDescriptor[] propDescs = PropertyUtils.getPropertyDescriptors(bean.getClass());

    for (PropertyDescriptor propDesc : propDescs) {
        String propertyName = propDesc.getName();
        Object propertyValue = PropertyUtils.getProperty(bean, propertyName);
        result.put(propertyName, propertyValue);
    }/* w  ww .j  ava  2  s. c  o m*/

    return result;
}

From source file:com.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java

private void processChange(Object target, String propertyName, Object value) {
    try {/*ww w . j  av  a  2s. co m*/
        Object oldValue = PropertyUtils.getProperty(target, propertyName);

        EditorLog currentLog = new EditorLog();
        currentLog.setTarget(target);
        currentLog.setProperty(propertyName);
        currentLog.setValue(oldValue);

        EditorLog nextLog = new EditorLog();
        nextLog.setTarget(target);
        nextLog.setProperty(propertyName);
        nextLog.setValue(value);

        if (nextLog.equals(this.currentUndo)) {
            //es un undo, hay que agregarlo a la lista de redo.
            LOGGER.debug(getClass().getSimpleName() + " guardando redo:" + currentLog);
            this.data.pushRedo(currentLog);
        } else {
            //es un cambio del usuario o un redo, no importa hay que agregarlo para un posible undo
            LOGGER.debug(getClass().getSimpleName() + " guardando undo:" + currentLog);
            this.data.pushUndo(currentLog);
            if (!nextLog.equals(this.currentRedo)) {
                //es un cambio del usuario y no un redo, hay que limpiar el redo
                this.data.clearRedo();
            }
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
        EditorMonitorImpV3.LOGGER.error(ex);
    }
}

From source file:com.tikal.tallerWeb.servicio.reporte.cliente.DatosAutoReporteCliente.java

@Override
public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) {
    Sheet sheet = contexto.getSheet();//www  . j  a va2 s  .co m
    XSSFWorkbook wb = contexto.getWb();
    int initialRow = borde.getUpperRow();
    int initialColumn = borde.getLeftColumn();
    BordeSeccion r = new BordeSeccion();
    r.setLeftColumn(initialColumn);
    r.setUpperRow(initialRow);

    //escribir el primer renglon
    Row row = getRow(sheet, initialRow);
    Cell cell = row.createCell(initialColumn);
    cell.setCellValue("Auto");
    //estilo .-.
    XSSFCellStyle cellStyle = wb.createCellStyle();
    addHeaderStyle(cellStyle, wb);
    addBorders(wb, cellStyle, CellStyle.BORDER_THIN);
    cell.setCellStyle(cellStyle);
    for (int i = 1; i < encabezados.length; i++) {
        cell = row.createCell(initialColumn + i);
        cellStyle = wb.createCellStyle();
        addBorders(wb, cellStyle, CellStyle.BORDER_THIN);
        cell.setCellStyle(cellStyle);
    }
    //merge de celdas
    sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based)
            initialRow, //last row  (0-based)
            initialColumn, //first column (0-based)
            initialColumn + 7 //last column  (0-based)
    ));
    //segundo renglon encabezado
    initialRow = initialRow + 1;
    row = getRow(sheet, initialRow);
    for (int i = 0; i < encabezados.length; i++) {
        cell = row.createCell(initialColumn + i);
        cell.setCellValue(encabezados[i]);
        cellStyle = wb.createCellStyle();
        addHeaderStyle(cellStyle, wb);
        addBorders(wb, cellStyle, CellStyle.BORDER_THIN);
        cell.setCellStyle(cellStyle);
    }
    //tercer renglon encabezado
    initialRow = initialRow + 1;
    row = getRow(sheet, initialRow);
    for (int i = 0; i < atributos.length; i++) {
        cell = row.createCell(initialColumn + i);
        try {
            cell.setCellValue(PropertyUtils.getProperty(datos, "auto." + atributos[i]).toString());
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
            cell.setCellValue("");
        }
        cellStyle = wb.createCellStyle();
        addBorders(wb, cellStyle, CellStyle.BORDER_THIN);
        cell.setCellStyle(cellStyle);
    }

    r.setLowerRow(initialRow);
    r.setRightColumn(initialColumn + 7);
    paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, r);
    return r;
}