[jboss-jira] [JBoss JIRA] Updated: (JBPM-696) Field Instanciator problems

Shai Bentin (JIRA) jira-events at jboss.com
Sun Jul 16 14:48:19 EDT 2006


     [ http://jira.jboss.com/jira/browse/JBPM-696?page=all ]

Shai Bentin updated JBPM-696:
-----------------------------

    JBoss Forum Reference: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=86134

> Field Instanciator problems
> ---------------------------
>
>                 Key: JBPM-696
>                 URL: http://jira.jboss.com/jira/browse/JBPM-696
>             Project: JBoss jBPM
>          Issue Type: Bug
>          Components: Core Engine
>    Affects Versions: jBPM 3.1.1
>         Environment: WinXP, Linux running on JBoss Application Server 4.0.3SP1, JDK1.5.0_06
>            Reporter: Shai Bentin
>         Assigned To: Tom Baeyens
>            Priority: Minor
>             Fix For:  jBPM 3.1.2
>
>
> The method getValue() is see two problems, one is jdk5 related the other is just an idea.
> In jdk5 doing if (type.isAssignableFrom(Set.class)) and such yields a 'false' even when it is supposed to be true...
> if we would write the same if in reverse:
> Set.class.isAssignableFrom(type) we will ge the desired reuslt.
> The other issue is, if we know the super type why do we impose a specific implementation, i.e. if we have a Collection, why do we impose an ArrayList. We have the user's type and we know it is of type collection so why don't we instanciate the requested type....
> Here is how I propose to write this method:
>   public static Object getValue(Class type, Element propertyElement) {
>     // parse the value
>     Object value = null;
>     try {
>       
>       if ( type == String.class ) {
>         value = propertyElement.getText();
>       } else if ( (type==Integer.class) || (type==int.class) ) {
>         value = new Integer( propertyElement.getTextTrim() );
>       } else if ( (type==Long.class) || (type==long.class) ) {
>         value = new Long( propertyElement.getTextTrim() );
>       } else if ( (type==Float.class ) || (type==float.class) ) {
>         value = new Float( propertyElement.getTextTrim() );
>       } else if ( (type==Double.class ) || (type==double.class) ) {
>         value = new Double( propertyElement.getTextTrim() );
>       } else if ( (type==Boolean.class ) || (type==boolean.class) ) {
>         value = Boolean.valueOf( propertyElement.getTextTrim() );
>       } else if ( (type==Character.class ) || (type==char.class) ) {
>         value = new Character( propertyElement.getTextTrim().charAt(0) );
>       } else if ( (type==Short.class ) || (type==short.class) ) {
>         value = new Short( propertyElement.getTextTrim() );
>       } else if ( (type==Byte.class ) || (type==byte.class) ) {
>         value = new Byte( propertyElement.getTextTrim() );
>       } else if (List.class.isAssignableFrom(type)) {
>         value = getCollection(propertyElement, (List)type.newInstance());
>       } else if (Set.class.isAssignableFrom(type)) {
>         value = getCollection(propertyElement, (Set)type.newInstance());
>       } else if (Collection.class.isAssignableFrom(type)) {
>         value = getCollection(propertyElement, (Collection)type.newInstance());
>       } else if (Map.class.isAssignableFrom(type)) {
>         value = getMap(propertyElement, (Map)type.newInstance());
>       } else if ( type==Element.class ) {
>         value = propertyElement;
>       } else {
>         Constructor constructor = type.getConstructor(new Class[]{String.class});
>         if ( (propertyElement.isTextOnly())
>              && (constructor!=null) ) {
>           value = constructor.newInstance(new Object[]{propertyElement.getTextTrim()});
>         }
>       }
>     } catch (Exception e) {
>       log.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'" );
>       throw new JbpmException( e );
>     }
>     return value;
>   }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list