How to get the values of the objects inside an object??

Hi,
I am trying to write code to display name and memory usage of all session attributes, in a recursive way.
I suppose reflection is needed here, but I can’t figure out how to get the values of the objects inside an object...
private void handleIt(String attributeName, Object attributeValue) {
     boolean isPrimitiveOrNull = ((null == attributeValue) ||
          (attributeValue.getClass().isPrimitive()));                                         
     if (isPrimitiveOrNull) {
          sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
     } else {
          sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");               
          Field[] fields = attributeValue.getClass().getDeclaredFields();
          int lim = fields.length;
          String name;
          Object value = null;
          for (int i = 0; i < lim; i++) {
               name = fields.getName();
               //LOOK AT THIS LINE: !!!!!!!!!!!!!!!!!!!!!!!!!!!
               value = fields[i].get(obj); //I don´t know what 'obj' should be??
               handleIt(name, value);
          sb.append("}");               
Any suggestions will be greatly appreciated...

I realized that massive int objects called MAX_VALUE, MIN_VALUE and SIZE where causing the StackOverflow, so I removed them from the analysis.
This is the resultant code. But I think it isn’t accurate in calculating the real size of objects being got using reflexion.
Do you or somebody have any more suggestions?
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SessionMeasurer extends HttpServlet {
     private static final long serialVersionUID = 1470488362727841992L;
     private StringBuilder sb = new StringBuilder();
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          performTask(request, response);
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          performTask(request, response);
     public void performTask(HttpServletRequest request, HttpServletResponse response) {
          HttpSession     session = request.getSession(false);     
          String attributeName = "";
          Object attributeValue = null;
          for (Enumeration<?> attributeNames = session.getAttributeNames(); attributeNames.hasMoreElements();) {
               attributeName = (String)attributeNames.nextElement();
               attributeValue = session.getAttribute(attributeName);
               handleIt(attributeName, attributeValue);               
          System.out.println(sb.toString());
     private void handleIt(String attributeName, Object attributeValue) {           
          if (attributeValue != null) {          
               boolean isPrimitive = attributeValue.getClass().isPrimitive();
               if (isPrimitive) {
                    sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
               } else {
                    sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");               
                    Field[] fields = attributeValue.getClass().getDeclaredFields();
                    String name;
                    Object value = null;
                    int lim = fields.length;
                    for (int i = 0; i < lim; i++) {
                         name = fields.getName();                                                                                                         
                         if (!name.endsWith("_VALUE") && !name.equals("SIZE") && !name.equals("serialVersionUID")) {
                              try {
                                   value = fields[i].get(attributeValue);
                              } catch(Exception e) {
                                   //PENDIENTE: Tratamiento excepción
                              handleIt(name, value);
                    sb.append("}");               
     private int sizeOf(Object obj) {
          //Valid only for Serializables
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ObjectOutputStream oos = null;     
          byte[] bytes = null;               
          try {          
               oos = new ObjectOutputStream(baos);
               oos.writeObject(obj);
               bytes = baos.toByteArray();
          } catch(Exception e) {               
               //PENDIENTE: Tratamiento excepción
          } finally {
               if (oos != null) {
                    try {
                         oos.close();
                    } catch(Exception e) {
                         //PENDIENTE: Tratamiento excepción                         
               if (baos != null) {
                    try {
                         baos.close();
                    } catch(Exception e) {
                         //PENDIENTE: Tratamiento excepción                         
          int size = -1;
          if (bytes != null) {
               size = bytes.length;
          return size;          

Similar Messages

  • How to get the object class field value in CDHDR table for vendor

    hi
    how to get the object class field value in CDHDR table for vendor

    Try KRED/KRED_N as object class in CDHDR for Vendor.

  • OIM - Task Assignment Adapter - How to get the object instance key?

    Hello experts,
    I'm trying to use a task assignment adapter to assign an approval task dynamically. Basically, the user can request a resource like "CustomApp Profiles" and we create an object form to let them choose the profile that he needs. Each profile has an owner, which is populate in a Lookup (Owner is the code and Profile is the decode).
    So, in the approval task, I need to get the profile selected by user in the object form and search into the lookup who is the owner of that profile. But I don't know how can I get the object instance key using the parameters that can be mapped to a task assignment adapter.
    Looking into the OIM documents, I believe that the easier way is using the request key, because the REQ_KEY is a foreign key in OBI table.
    Did anyone knows how can I get the object instance key using the request key? Can I use some API or should I execute a SQL statement directly in OIM database?
    Best Regards,
    Nitto

    To retry a task that is in a rejected state, you use the SCH_KEY which is the task key.  In OIM, all rejected tasks are listed in the OTI table.  It contains all the important information about a rejected or pending task.
    You can use the APIs found in the tcProvisioningOperationsIntf class to retrieve open tasks.
    -Kevin

  • How to get the caret inside a custom editor?

    I was reading through old posts the other day and noticed this by Rob Camick in this thread Re: Problem in cell selection in JTable Java Swing :
    camickr wrote:
    All KeyEvents are passed to the editor for the cell and the editor is psuedo invoked. That is, the caret is not placed on the text field used as the editor, but the character typed is added to the editor.This set me thinking about a known issue in my app which I had shelved for a "rainy day": how to get the caret into the cell editor component. I thought I'd get it out and look at it. I tried the following, in my custom cell editor:
      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                                                 int row, int column)
        JTextField ec = (JTextField) editorComponent;
        ec.setText((String) value);
        if ("".equals(ec.getText()))
          ec.setCaretPosition(0);
        else
          ec.selectAll();
        return editorComponent;
      }But it has no effect whatsoever, the user still can't type something in and then press the backspace key to useful effect. Has anyone out there solved this problem? (And why, oh why, is the caret not put into the cell editor by default, if it's a component that has a caret?)

    Replying to my own post, in case what I ended up with is of some help to others. The desired behaviour was that anything the cell contained from the previous edit would be replaced by what the user types in the current edit, i.e.:
    user starts edit, types 234, stops editing, cell displays 234...user single-clicks on cell, types 567, stops editing, cell displays 567
    My code is as follows:
        public Component getTableCellEditorComponent(JTable table, Object value,
                                                     boolean isSelected, int row,
                                                     int column)
          final JTextField ec = (JTextField) editorComponent;
          ec.setText((String) value);
          // selectAll, so that whatever the user types replaces what we just put there
          ec.selectAll();
          SwingUtilities.invokeLater(new Runnable()
            public void run()
              // make the component take the keyboard focus, so the backspace key works
              ec.requestFocus();
              SwingUtilities.invokeLater(new Runnable()
                public void run()
                  // at this point the user has typed something into the cell and we
                  // want the caret to be AFTER that character, so that the next one
                  // comes in on the RHS
                  ec.setCaretPosition(ec.getText().length());
          return editorComponent;
        }

  • How to get the details inside base domain name?

    I need to extract the details inside the base DN like ou="" ,cn="" and so on..
    Somebody please help me in getting the details inside the base domain name. I could able to get the attribute names and values for the domain name...
    Anyone please help me?
    Thanks in advance...
    Edited by: Preethi_Engineer on Aug 3, 2010 9:54 PM

    Hi Vipin,
    This code snipet show that how to find the login user to the portal
    public void LoginUser( )
        //@@begin LoginUser()
         String LogonID;
           try{
              // create an user object from the current user
              IWDClientUser wdUser=WDClientUser.getCurrentUser();
              IUser user=wdUser.getSAPUser();
              //LogonID=user.getUniqueName();
              wdComponentAPI.getMessageManager().reportSuccess(user.getFirstName()" "user.getLastName().toUpperCase());
              //wdComponentAPI.getMessageManager().reportSuccess(LogonID.toUpperCase());
              wdComponentAPI.getMessageManager().reportSuccess("Logon User ID : "+wdUser.getClientUserID().toUpperCase());
           }catch(Exception e){
              e.printStackTrace();
        //@@end
    Note:  You also need to add"com.sap.security.2.0.0" jar file into your java build path liberary.
    Thanks
    Anup
    Edited by: Anup Bharti on Oct 13, 2008 2:18 PM
    Edited by: Anup Bharti on Oct 13, 2008 2:29 PM

  • How to get the objects from a workflow item's container

    Dear all,<P/>
    We need to get the value of a variable in the container of a workflow item. I can get the workflow item list using function module <B>SAP_WAPI_CREATE_WORKLIST</B>. Then how can I get the corresponding container elements' value?<P/>
    I tried function mofule <B>SAP_WAPI_GET_OBJECTS</B>, but the returned table <B>OBJECTS</B> and <B>OBJECTS_2</B> are both empty.<P/>
    Thanks + Best Regards<P/>
    Jerome<P/>
    null

    Hi,
    Well, I think you will be getting the value as BORNAME:BORKEY. Get the KEYVALUE into your local variable. And use the <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/c5/e4acef453d11d189430000e829fbbd/frameset.htm">BOR Macros</a> to get the instance and desired contents.
    Regards
    <i><b>Raja Sekhar</b></i>

  • How to get the object from an event

    Hey, thanks for helping.
    I'm trying to get the causing object from the event so i can run a method from the causing object,
    I tred using the getSource method inherited from the Event class but it doesn't see the method I have in that object (method1)
    I have this code:
    private class Over implements MouseListener
    public void mouseClicked(MouseEvent e)
    public void mousePressed(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public void mouseEntered(MouseEvent e)
    e.getSource().method1();
    }

    By the way, MouseEvent is a subtype of ComponentEvent, so it has the method:
    Component comp = evt.getComponent();which is convenient if "method1" is a Component method.
    Another btw: the "adapter" classes allow you to write listeners without cluttering your code with empty method bodies:
    class Over extends MouseAdapter  {
        public void mouseEntered(MouseEvent e) {
    }

  • How to get the Objects which are used in the webi Report.

    Hi Expert,
    I am trying to get the list of  WebI reports and Objects which are present in the report at  BO 4.0.
    I can able to get details  for only the list of reports and universes.
    Could  any one help me to get those details.
    Regards,
    Murali S

    With 4.0, there is no longer a way to do this using just the .NET SDK because the ReportEngine SDK no longer exists for .NET.  Instead, you'll have to look at using the RESTful Web Services SDK for Webi which runs in the Web Application Container Server on your report server (NOT on the web server!)
    RESTful web services are platform-independent and don't require the installation of any SDK files.  Everything is done through standard HTTP Get, Put, and Post commands and the results are returned in either XML or JSON format.  You don't mention which service pack of 4.0 you're on, but the RESTful web services have evolved over the course of the 4.0 service packs, so more recent is definitely better.
    You can find the documentation for this in the "Development Information" section at help.sap.com/bobip40.  There is also a "space" on SCN for this at http://scn.sap.com/community/restful-sdk and there are some links on this page for various resources and sample code.
    -Dell

  • How to get a value from an object

    Here is the concept of something I want to do in PowerShell:
    $exp = get-process explorer | select *
    $pms64 = get_value( $exp, PagedMemorySize64 )
    As I see it, the value would be available to use.  Using that technique I could get other values then order them to write to a log file. 
    How should I do this? 
    Please make the answer as simple as possible.  What search term can I use to find a tutorial on this topic?
    ~jag77 We need to know what a dragon is before we study its anatomy. (Bryan Kelly, 2010)

    Hi,
    Here's a simple way to get at a single property:
    $pms64 = (Get-Process explorer).PagedMemorySize64
    $pms64
    For the purpose of writing to a log file, you'd be better off piping the object through Select-Object to get the properties you're interested in and then into Export-Csv or Out-File to create the output.
    Get-Process explorer |
    Select-Object -Property Name,Id,PagedMemorySize64 |
    Export-Csv .\explorerStats.csv -NoTypeInformation
    Some reading material:
    http://windowsitpro.com/powershell/powershell-objects
    EDIT: Also, I do highly recommend that you look through the link jrv has posted. There's good information there.
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • How to get attribute value from an object inside an object in Xpress

    Does anyone know how to get an attribute value from an object in Xpress in a workflow? I have an object structured as follows:
    <ResourceInfo accountId='mj628' tempId='3483372b787ce7dd:-5d99a0c5:130cb238483:-3600'>
    <ObjectRef type='Resource' name='Google Apps'/>
    </ResourceInfo>
    I need if possible to get the name='Google Apps', which is inside the ObjectRef, so I guess its an attribute value of an object inside an object.

    If the ResourceInfo object is accessible in a variable, i.e. named "myResInfo", you just have to check the Java API and call the relevant method:
    <invoke name='getResourceName'>
      <ref>myResInfo</ref>
    </invoke>

  • How to Get property values from Shared Object in client's load event - Very urgent

    I am using shared object to share data between two users. First user connect to shared object and set some value in shared object. Please consider that second user has not connected with the shared object yet.
    Now when second user connects to the server and try to get that property set by first user, he could get shared object but could not get properties of Shared object set by first user. I observed few times that Second user can get these properties within "Sync" event between two users. But I would like to get these values for Second user in any stage (i.e. in load event etc.). Whenever Second user tries to get the property of Shared object, the object will reset the actual property value and then return reset value.
    Anyone faced such issue while using shared object between two users. If so, I would appreciate if you could let me know your suggestions for following questions:
    1) Is there any way to get all the properties of shared object before sync event called, as I want to get it immediately when second user connect to the application and perform next task based on the values stored in shared object.
    2) Is it possible for second user to check whether any property has been set by first user? So that second user can use the property instead of reset it.
    Any kind of help would be greatly appreciated.
    Thank You.

    I am using shared object to share data between two users. First user connect to shared object and set some value in shared object. Please consider that second user has not connected with the shared object yet.
    Now when second user connects to the server and try to get that property set by first user, he could get shared object but could not get properties of Shared object set by first user. I observed few times that Second user can get these properties within "Sync" event between two users. But I would like to get these values for Second user in any stage (i.e. in load event etc.). Whenever Second user tries to get the property of Shared object, the object will reset the actual property value and then return reset value.
    Anyone faced such issue while using shared object between two users. If so, I would appreciate if you could let me know your suggestions for following questions:
    1) Is there any way to get all the properties of shared object before sync event called, as I want to get it immediately when second user connect to the application and perform next task based on the values stored in shared object.
    2) Is it possible for second user to check whether any property has been set by first user? So that second user can use the property instead of reset it.
    Any kind of help would be greatly appreciated.
    Thank You.

  • FavoriteFolder, how to get the content inside this folder

    Hi
    I have to get with the Java api consumer the content inside the favorite folder. How can i get it?
    i write this code:
                   String searchQuery = search://{'guaglanto1'}?SearchKeywords=true&SearchExact=true&SearchCaseSensitive=true;
                   ResponseHolder rh = boBIPlatform.get(searchQuery, null);
                   InfoObjects myFav = rh.getInfoObjects();
                   if (myFav == null || source.getInfoObjectArray().length == 0){
                     result="No terms matching the following search query could be found: " + searchQuery;
                             return result;
                   result ="";          
                   for (InfoObject infoObject: myFav.getInfoObjectArray()){
                     result= result+ infoObject.getName() + " has CUID: " + infoObject.getCUID()+ " type "+ infoObject.getKind() + " has childreen "+ infoObject.getChildrenObjects();
    Where guaglanto1 is the title of the favoriteFolder.This code show the CUID,name,kind and children of the favoriteFolder.  Now i want to navigate this folder and get its content (i see from InfoViewApp there are 5 web intelligent report inside the favorite folder) but i don't know how can i get that.
    Anyone can help me to resolve this problem?
    thank you
    best regard
    Andrea

    once you get the SI_ID or SI_CUID of the favorites folder you need to write an additional query to pull all its children using:
    select * from ci_infoobjects where si_parentcuid='<si_cuid of favorites folder>'
    If the favorites folder contains folders with subfolders, this will be a recursive call. You can use query://{select....} or path://
    Look at the BIPlatform documentation in API reference and there is more information on how to use query:// or path://

  • How to get the Sql inside Omni SQL portlet.

    Hi,
    We are trying to find a table/view which stores/holds the Sql and Pl/Sql code of Omni Pl/sql portlets.
    Thanks,
    Ram.

    by default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
    you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
    so, if it is null, it ran as sql server agent account.
    so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
    accurate information as the new account will show up though the job really ran as old account, to get this information, you need to  get this from the logmessage column as you mentioned above.
     try this code...
    /*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
    declare @sqlserveragentaccount varchar(2000)
    select @sqlserveragentaccount= service_account
    from sys.dm_server_services
    where servicename like '%sql%server%agent%'
    select message,isnull(name,@sqlserveragentaccount) as AccountName
    from sysjobhistory a inner join sysjobsteps b
    on a.step_id=b.step_id and a.job_id=b.job_id
    left outer join sysproxies c on c.proxy_id=b.proxy_id
    Hope it Helps!!

  • How to get all values in an object?

    Hi there,
    I have some object with values in it. Then i pushed all these
    values in an Array.
    But how can i go through all the values in the array?
    I tried this:
    for each (var something:* in allTypes) {
    trace(something);
    and
    for (var key:String in allTypes) {
    trace(allTypes[key]);
    But i don't get to see the file extensions.
    I want to write some code that if a file extention does not
    match any of the extensions
    in the array then do something.
    Can someone help me out please?
    var imageTypes:FileFilter = new FileFilter("Images (*.jpg,
    *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
    var textTypes:FileFilter = new FileFilter("Text Files (*.txt,
    *.rtf)", "*.txt; *.rtf");
    var vidTypes:FileFilter = new FileFilter("Video Files
    (*.flv)","*.flv");
    var allTypes:Array = new Array(imageTypes, textTypes,
    vidTypes);

    Hello Mrunal Mhaskar  ,
    What i understand you can do one thing  go in debug mode
    Try this code : -
    LOOP AT s_matnr_ex.
      IF s_matnr_ex-low IS NOT INITIAL.
        i_matnr-matnr = s_matnr_ex-low.
        i_matnr-option = s_matnr_ex-option.
        APPEND i_matnr.
        CLEAR : i_matnr.
      ENDIF.
    ENDLOOP.
    LOOP AT s_matnr_ex.
      IF s_matnr_ex-high IS NOT INITIAL.
        i_matnr-matnr = s_matnr_ex-high.
        i_matnr-option = s_matnr_ex-option.
        APPEND i_matnr.
        CLEAR : i_matnr.
      ENDIF.
    ENDLOOP.
    In the i_matnr table high and low values are there.
    Regards,
    Vandana.

  • How to get a value from a column inside a table

    Hi,
    I have got the following problem. I have got a table with some data inside. And a new column, which is not in the dataprovider. Now i search for an opportunity to go through the rows of the table and check the value of this column. I cant do this with the dataprovider or the rowset. My question is now how can i do this? The table object doesnt seem to have a corresponding method.
    Thanks in advance for help
    Acinonyx

    this is some code you can use (based on Winston's and others' tips):
    put this in you page bean:
    private HashSet selectedRows = new HashSet();
    public boolean isSelected() {
    TableRowDataProvider trdp = (TableRowDataProvider)getBean("currentRow");
    if (trdp == null) {
    return false;
    RowKey rowKey = trdp.getTableRow();
    if (this.selectedRows.contains(rowKey.getRowId()))
    return true;
    else
    return false;
    public void setSelected(boolean b) {
    TableRowDataProvider trdp = (TableRowDataProvider)getBean("currentRow");
    RowKey rowKey = trdp.getTableRow();
    if (checkbox1.isChecked()) {
    this.selectedRows.add(rowKey.getRowId());
    Object v = this.t_fotoDataProvider.getValue("fieldName", rowKey);
    } else {
    this.selectedRows.remove(rowKey.getRowId());
    and then bind the "selected" property of the checkbox column to the "selected" property of the page bean.
    Now, eveytime the page is submitted, you can do something useful, for example, in the setSelected() method (the row that starts with Object v = ... get's the value of some field corresponding to the checked row)
    Mauro

  • Getting the Object Access key

    This weird question,
    But does any one know how to get the object access key for Standard SAP object is changed..
    Normally when we try to do any modification on Standard SaP object it asks for and access key.. We need to enter it once, after which the object is open for editing.
    I have an SAP object which as been modified .
    I want to know that number?? Is it possible..
    Any help will be highly appreciated..
    Regards,
    Samir.

    Hi Samir,
    You have to contact SAP Support to obtain the access key for a Standard SAP Object. The correct channel for that is the OSS, where yo can raise a message requesting the same.
    But you are saying that there's one object that has already been modified. Who has done the modification ? When they have done it, they must have specified the access key. If you want to modify the same object, then the best thing for you to do is to contact the person who has changed it.
    By the way, have the modifications been done using the Modififcation Assistant?
    Regards,
    Anand Mandalika.

Maybe you are looking for

  • Home Sharing no longer works between iTunes and Apple TV.

    I've been through all the forums, tried all the solutions provided and I have come to the conclusion that Home Sharing just no longer works between iTunes on a PC and my Apple TV.  Does anyone know if this issue will be addressed or should I list my

  • Blogs in languages other than English

    Hello, I created two Web sites with iWeb - one in English, one in Italian. Unfortunately, the navigation links (read more, Add a comment, search results, prev/next etc) are in English in both blogs. In this old post someone suggested manually editing

  • Satellite Pro A300 - I get the "Windows search" if I left click any folder

    I have just purchased a Satellite Pro A300 and downgraded it to Windows XP SP3. When I left-click any folder icon on my hard drive I get the 'Windows Search' window displayed instead of opening the folder. When I right-click any folder icon, the firs

  • One Procedure is not running in the Package

    In my package i have Variable assignment - > Procedure -> Interface ( a loop ) When i am running it , the Procedure is not executing. I do not know why . Can you help me in this. Thanks

  • Service Ticket view cannot be displayed

    Hi Experts, In the Web IC, when I try to click on the "Service Ticket" button from the navigation bar, I see the following error: Cannot display view ICCMP_BTSHEAD/BTSHeader of UI Component ICCMP_BTSHEAD An exception has occurred Exception Class  CX_