How to get datatype of IMendixObjectMember?

5
How do i retrieve the datatype of a IMendixObjectMember in java? I can't find any suitable functions in the javadoc documentation.
asked
2 answers
5

If you have a IMendixObjectMember you can downcast it to the desired subclass.

 IMendixObject object = this.getYourObjectFromSomewhere();
 IMendixObjectMember<?> member = object.getMember("YourDesiredMemberName");
 if( member instanceof com.mendix.core.objectmanagement.member.MendixString ) {
      MendixString strMember = (MendixString) member;
      String value = strMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixHashString ) {
      MendixHashString hStrMember = (MendixHashString) member;
      String value = hStrMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixAutoNumber ) {
      MendixAutoNumber nrMember = (MendixAutoNumber) member;
      Long value = nrMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixEnum ) {
      MendixEnum enumMember = (MendixEnum) member;
      String value = enumMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixBinary ) {
      MendixBinary binaryMember = (MendixBinary) member;
      //some more complex stuff, see the proxie files for an example 
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixBoolean ) {
      MendixBoolean boolMember = (MendixBoolean) member;
      boolean value = boolMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixCurrency ) {
      MendixCurrency currencyMember = (MendixCurrency) member;
      Double value = currencyMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixLong ) {
      MendixLong longMember = (MendixLong) member;
      Long value = longMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixInteger ) {
      MendixInteger intMember = (MendixInteger) member;
      Integer value = intMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixFloat ) {
      MendixFloat floatMember = (MendixFloat) member;
      Double value = floatMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixObjectReference ) {
      MendixObjectReference refMember = (MendixObjectReference) member;
      IMendixIdentifier value = refMember.getValue();
 }
 else if( member instanceof com.mendix.core.objectmanagement.member.MendixObjectReferenceSet ) {
      MendixObjectReferenceSet refSetMember = (MendixObjectReferenceSet) member;
      List<IMendixIdentifier> value = refSetMember.getValue();
 }
answered
4

Hello Roeland,

You can not directly ask the member for his type.

To get the type of the member you will have to use instanceOf functionality of the Object type:

See the following example:

private String getValue( IMendixObjectMember<?> member, boolean fromCache ) { 

    Object value = null;
    // Values from cache
    if (fromCache == true)
        value = member.getValue();      

    // Values form DB
    else
        value = member.getOriginalValue();

    if( value != null ) {                       

        if( value instanceof Date )
            return parseDate( (Date)value );

        else if( value instanceof String)
            return parseString( (String)value );

        return String.valueOf( value ).trim();
    }
    else
        return "";              
}

I hope this will help you.

answered