Results 1 to 8 of 8
  1. #1
    dreuzel is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default Generic collection type

    I'm genericly using collections

    but I would like to kow the type (meta data ..... name ....) of the individual items in the collection.


    Is there a passive way( not changing any data) to find out the
    the class characteristics of the individual items.

    for example genericly getting the record type of a resultset after a query .

    equivalent with class.getComponentType() for an array


    thanls in advance

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    All type information for generic containers (or other generic classes) has gone during runtime, i.e. the generics mechanism is a compile time issue; the collections themselves simply manipulate Objects.

    You could try to get the class from any object in a collection; would that work for you? Why do you want that information?

    kind regards,

    Jos

  3. #3
    dreuzel is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default

    why:
    I want to be able to dynicaly react, and prepare output formatting
    ex: in JSF Component depending on the table content change my format
    the table content itself is not known by the caller, and depending on the type of selection


    the table to present can contain recordset made in selection or any entity objecrt from an other origin (specified in a List, Array(solved), or general collection
    at the time of interpretation the different objects could be even empty ...

    accessing the meta data is handled by reflection.


    get the class from an object ?
    that could be possible, but is not preferable


    Is there realy no solution ?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dreuzel View Post
    why:
    I want to be able to dynicaly react, and prepare output formatting
    ex: in JSF Component depending on the table content change my format
    the table content itself is not known by the caller, and depending on the type of selection


    the table to present can contain recordset made in selection or any entity objecrt from an other origin (specified in a List, Array(solved), or general collection
    at the time of interpretation the different objects could be even empty ...

    accessing the meta data is handled by reflection.


    get the class from an object ?
    that could be possible, but is not preferable


    Is there realy no solution ?
    If those classes don't know how they should be formatted and you (your target class) doesn't know their format all you can do is associate a format with the name of the classes. Get the name of the class, retrieve the format (if it exists) and format that particular object. Maybe a Properties object can handle it where the keys are the fully qualified class names and the associated values are the format Strings?

    kind regards,

    Jos

  5. #5
    dreuzel is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default

    this would never work, far to much overhead.
    the formatting information exists it's called meta data
    except tht java seems not to pass it ....

    per object one can detect
    isArray (simple to get at the individual classes ....)
    isIntanceOf itterable/ collection
    is a specific class

    ..
    all Entity classes have getter /setters ....
    getter have return specifications


    any class is composed of getter specs that are complex => handle later
    recursive
    as the getter setter points to txt, integer/float/numeric ......
    for the few basic types I've written het handler
    ..... so no more problem and if needed I can add
    specific handlers .. as needed

    all handlers Know of the field names , field names are translated using text resources in different titles ...... they color in Columns or rows....

    except I need to find the information in an as strctured way as possible


    example object -> class = list/array/enum...... -> handle the sub class ... by preference do not access the OBject any more
    since going from Object-> class----> object is not very structured ....


    the thing is based on verry few handlers to implement IN and output
    txt string
    txt area (edit HTML)
    numerical(integer/float/....) javascript corrects for errors
    bit/byte
    (object selecter) selector but results in the object instead of a value
    ...
    future extensions
    a phone number
    a bitmap

    passing the formatting information an other time (explicit/ proprierty) makes all obsolete ....
    since at run time using reflextion I can get at all info including the annotations ....

    the only restriction is collections ... I need to know what the content class is



    thanks for answering ,
    is there no solution to get there using collections ?







    as a record example
    Last edited by dreuzel; 12-22-2009 at 04:38 PM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Maybe if you focussed a little.
    It could just be me, but some of that seemed a little like word-salad.

    Are you implying you want to be able to take any Object in Java and, based on the underlying accesible attributes it possesses in its real Class, decide how to format the screen to display it?

    Forget about arrays and all that...is that paragraph there correct?

  7. #7
    dreuzel is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default

    somehow we are misunderstanding one another.


    Maybe it's to late on the day

    but as I get any object , and find out its class , i get to know a lot about that object .....
    as I standardize on objects as I/O structures defined using getter's and setters .... I'm fully compatible with seam, Hibernate , JSF....
    implicitely i've a world of objects (comming from messages/ db/ bussiness structures .... defined by a getter- setter interface ....

    I do not realy consider other objects but these (defined above)

    I can easily handle those objects individualy :
    and as I want to present (I/O) them i feed them to JSF
    using some proprierty JSF components ....
    Using reflection on the getter - setters i decide what to do
    prior to setting up my page ..... This works fine
    I've added some annotations to the getter//setters usable in (JSF/hibernate/seam..... that assist me in fields I'm intersted in seeing
    and not want to display, including a taborder....)

    now the second part:
    depending on the application i use lists/hashmap's...collections ...array's of the above mentioned objects
    ex: select * from invoices ...... all what happens ; i get a list of objects in clasical terms called a recordset . Feeding these the list/hashmap,collection/ array to my component I can now make list of
    presenting multiple records /objects this is classicaly called a table

    Since I'm able to present individual records .... it is easy to present
    lists of objects .....


    Instead of feeeding the object to JSF I feed the list as a whole
    this is detected by my component ( value="#{invoiceDBlist}" )
    and the component finds the Class of the individual items .... and presents then in a table


    My problem with Collections is that I can not do the getClass() without
    handling the Object (as opposed to remaining in the Class (more generic )
    area. the difference is important since Noone would know what the getter setter really ... it could execute some code (so is realy active)
    i do not want my collection scan to be active on the data, just active on the meta data.

    I know I'm living here in an object world but this is what Java is all about isn't it ???

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    OK. I see now.
    Because the type stuff of a Collection is lost at compile time then you don't know, without there being at least one object in the collection, what the collection was originally a collection of.

    Does that sound correct?

Similar Threads

  1. The Generic Trend
    By this.that in forum Advanced Java
    Replies: 9
    Last Post: 02-26-2009, 01:46 AM
  2. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 06:24 PM
  3. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM
  4. Replies: 1
    Last Post: 05-16-2008, 11:06 PM
  5. Generic array
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 12:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •