How to implement array of objects or vector of objects?

Hello, i am working on a javabean that is connecting to a database and executes an sql string. The javabean returns the records retrieved in a tabular format.
Currently i can achieve the above requireement, but only through using a simple table-formatted string, this is not dynamic and a 2d array approach would not be dynamic either.
I have read a little about using a dynamic approach, possiblya vector of objects, or array list of objects to solve the problem, but i don't really know how to start, could anybody help me??
The code i have so far is:
package webtech;
import java.sql.*;
public class questiona {
/* Step 1) Initialize Variables*/
String result = "";
String query = "select id, name, url, thumb_url, keywords, category, author from mytable;";
String url = "";
String driver = "";
String uname = "";
String dpass = "";
/*Step 2) Make a database connection*/
private Connection dbconn = null;
public questiona()
try
Class.forName(driver);
dbconn = DriverManager.getConnection(url, uname, dpass);
/*Create an SQL statement*/
Statement statement = dbconn.createStatement();
if (statement.execute(query))
{/*Step 3) If we have a result lets loop through*/
ResultSet results = statement.getResultSet();
ResultSetMetaData metadata = results.getMetaData();
/*Validate result. Note switch to while loop if we plan on multiple results from query*/
if(results != null)
/*Use results setmetadata object to determine the columns*/
int li_columns = metadata.getColumnCount();
result += " <tr>\n\r";
result += " <td>" + metadata.getColumnLabel(1) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(2) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(3) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(4) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(5) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(6) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(7) + "</td>\n\r";
result += " </tr>\n\r";
/*loop throught the columns and append data to our table*/
while(results.next())
result += " <tr>\n\r";
result += " <td>" + results.getObject(1).toString() +"</td>\n\r";
result += " <td>" + results.getObject(2).toString() +"</td>\n\r";
result += " <td>" + results.getObject(3).toString() +"</td>\n\r";
result += " <td>" + results.getObject(4).toString() +"</td>\n\r";
result += " <td>" + results.getObject(5).toString() +"</td>\n\r";
result += " <td>" + results.getObject(6).toString() +"</td>\n\r";
result += " <td>" + results.getObject(7).toString() +"</td>\n\r";
result += " </tr>\n\r";
catch (ClassNotFoundException e)
{     result = "<tr><td> Error in database";
result += " <br/>" + e.toString() + "</td></tr>";
catch (SQLException e)
{     result = "<tr><td> Error in SQL";
result += " <br/>" + e.toString() + "</td></tr>";
finally
try {
if (dbconn !=null)
{ dbconn.close();}
catch (SQLException e)
{   result  = " <tr><td> Error in closing connection.";
result += " <br/>" + e.toString() + "</td></tr>";
public String getResults() {
return result;
}

Cross-post
http://forum.java.sun.com/thread.jspa?threadID=604770

Similar Messages

  • How to return array of object

    public class A{
    public class B{
    publc C[] sample()
    int i=0;
    ResultSet rset = s.executeQuery("select name, id  from emp ");
    while(rs.next()){
    name = rset.getString("nam");
    id = rset.getInt("id");
    c.setName(name )
    c[i].setId(id)
    return c[]
    public class C{
    // here i have getter and setter metod for name & id
    When I try to return the object c[]..i am getting "cannot conver from C to C[]".
    Can u pls help me, how to return array of object and how to get name and id values in other class using this array object
    Thanks for ur help

    public class Starting{
    public long empID;
    Data data = new Data();
    Value[] value;
    int count = 0;
         public static void executeDe(){
              value = new Value[100]
              try{
                     data.getDetails()
                     processDetails(value);
                   }catch(Exception e){e.printStackTrace();}
         public static void processDetails(Value[] value){
         count = data.i;
              int i;
              for(i=0;i<count;i++){
                  empID=value.getempID(); \\ here i am not getting all values..... am getting only last value of the array
    public class Data{
    public long empID;
    public int i=0;
    static Value[] value = new Value[100];
    public static Value[] getDetails(){
    Connection con=null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@" + hostname + ":1521:" + sid, user, password);
    System.out.println(" conn " + con);
    System.out.println("");
    Statement s=con.createStatement();
    try{
         ResultSet rset = s.executeQuery("select EMPID from Employee ");
         while(rset.next()){
    empID = rset.getLong("EMPID");
    value[i].setCycleID(cy_i);
    i++;
         rset.close();
         con.close();
    }catch (SQLException sqle){sqle.printStackTrace();}
         finally{
              try{
              s.close();
         con.close();
              }catch(SQLException e){e.printStackTrace();}
    catch(Exception e){e.printStackTrace();}
    return value;
         public class Value {
         public static long cycleID;
              public static void setempID(long empID) {
                   Value.empID = empID;
              public static long getempID() {
                   return empID;
    This is my actual code..... I am able to set the values in Value class from Data class using getDetails() method, which is returning array of value object.
    In Starting class, I am trying to get values using value[i].. i am getting last value of the array. This is my actual problem... here i want to get all values.
    Please help me how to resolve this.

  • How to pass array of Object in A Procedure using OCCI.......

    I m also trying for How to pass Object to a procedureb using OCCI...
    Steps....
    1. I created A type.....
    2. Then I created a VARRAY using that Type.
    3.After that I have written An Procedure with object as a parameter..
    now using OCCI how do u bind the parameter with this . plz note that using OTT
    i have already created the class representation of above object type i.e class
    four Files Created 1> demo.h 2>registermapping.h
    3> demo.cpp 2>registermapping.cpp
    After I want to Pass the Values in A Vector...
    vctor<full_name *> vect;
    stmt=con->createStatement("BEGIN Add_Object(:1); END;");
    full_name *name1 = new full_name; //Giving the Error here Given below....
    name1->
    name1->
    Through name1 Which Function I will call in which I will Pass a String....
    like
    name1->readSQL("Sanjay"); Or I have to add a function......
    vect.push_back(name1);
    setVector(stmt,1,vect,"FULL_NAME");
    error C2259: 'FullName' : cannot instantiate abstract class
    can u plz suggest me Why this Error is Giving......?
    How to pass the data?
    setFirst_name() and setLast_name() this two function I will add in Demo.cpp which one created automativcally by Using OTT command.....or other way plz tell me Boss ....
    Can u lz Suggest me ASAP....

    hi Nishant ,
    What u have done Now I mm trying ....
    can u Plz Suggest me......
    How to pass and Array of Object in Procedure using OCCI... Doing....
    90% finished Two Error's Are Coming...
    1> If I create the Class then Data Not Inserting table......
    2> If I will create the Class through OTT command.......
    then U can't Instantiate Object It is DIsplying ,this is Abstract Class(PObject)...
    Beco'z the below Method is Not adding Automatically by OTT command which is Pure Virtual Function.....
    But I added this Function Still SAme Error Giving..
    getSQLTypeName(oracle::occi::Environment env, void *schName,
    unsigned int &schNameLen, void **typeName,
         unsigned int &typeNameLen) const
    Plz Suggest me....
    regard's
    sanjay

  • How to implement a Session Object.

    Hi,
    If anybody show me any example of how to implement
    session object so that I can store any parameters such as user id and use it later on. And also if there is any good web site for reference about using session object.
    thanks

    You can use the the session.setAttribute and session.getAttribute methods.
    For example let's say you would want to store a username in the session after a user has logged on:
    String usrname = request.getParameter("username");
    session.setAttribute("myStoredUsername", usrname);
    you can then retrieve it using the get method. Remember that the entities stored inside a session object are generic objects and need to be cast to be used:
    String usrname2 = (String)session.getAttribute("username");
    Hope this helps
    Chelman

  • How to Sort Array of Object

    Hallo. I have an array of objects. Each object has id and name. How can i sort by name or by id??
    Thx for all
    Max

    array.sortOn("name");

  • How to do Array of objects

    Hi,
    I was wondering if XMP is capable of holding an array of multiple objects. We have historical data that is represented with multiple fields. The normal schema would look like:
      <rdf:Description rdf:about="" xmlns:nef="http://ns.phics.com/nefclient/1.0/">
             <nef:Division>BTF</nef:Division>
             <nef:Season>0914</nef:Season>
             <nef:Sku>91346</nef:Sku>
             <nef:Usage>Print</nef:Usage>
             <nef:Status>Approved</nef:Status>
          </rdf:Description>
    How can I add this addionional data some?
              <nef:History>
                   <nef:issue>blah01</nef:issue>
                   <nef:date>12-12-12</nef:date>
                   <nef:color>red</nef:color>
                   <nef:issue>blah02</nef:issue>
                   <nef:date>1-12-10</nef:date>
                   <nef:color>blue</nef:color>
                   <nef:issue>blah03</nef:issue>
                   <nef:date>02-12-08</nef:date>
                   <nef:color>red</nef:color>
                   <nef:issue>blah04</nef:issue>
                   <nef:date>11-09-06</nef:date>
                   <nef:color>white</nef:color>   
               </nef:History>
    Thank you for your time
    Dean Krueger

    Hi Dean,
    what you want to do is perfectly supported in XMP. The History property would be an array (ordered or unordered, as you like) and each array element is a struct with three fields.
    It would look like this:
    <nef:History>
         <rdf:Bag>
              <rdf:li  rdf:parseType="Resource">
                   <nef:issue>issue</nef:issue>
                   <nef:date>date</nef:date>
                   <nef:color>color</nef:color>
              </rdf:li>
              ...etc
         </rdf:Bag>
    </nef:History>
    If you are using the XMP toolkit in your program, you can refer to the Programmer's Guide for reference how to create such an array.
    regards
    Jörg

  • How to manage Arrays as Object members

    I found a realy strange behavior with the instanciation of a
    Class which contains an Array member.
    Here is the code wich is self explanatory.

    Create the array instance in the constructor.
    class MyObj {
    public var tab:Array;
    function MyObj(index) {
    this.tab= new Array();
    "Chris_007" <[email protected]> wrote in
    message
    news:[email protected]...
    > I found a realy strange behavior with the instanciation
    of a Class which
    > contains an Array member.
    >
    > Here is the code wich is self explanatory.
    >
    >
    >
    >
    >
    > class MyObj {
    > //
    > public var tab:Array = new Array();
    > private var objectName:String;
    > private var theIndex:Number;
    > //
    > // Constructeur
    > function MyObj(index) {
    > this.theIndex = index;
    > // Object name
    > this.objectName = "name#" + index;
    > for (var i = 0; i < 3; i++) {
    > this.tab
    = index * 3 + i;
    > }
    > }
    > //
    > function printObject() {
    > trace(" Printing Object name --> " +
    this.objectName);
    > for (var i = 0; i < 3; i++) {
    > trace(" tab[" + i + "] : " + this.tab);
    > }
    > }
    > //
    > function getClone() {
    > return new MyObj(theIndex);
    > }
    > }
    >
    >
    > // And the main scenario code
    > //
    > var index:Number = 0;
    > //
    > var objArray:Array = new Array();
    > //
    > var oob:MyObj;
    > //
    > function printMyArray(arr:Array):Void {
    > for (var i = 0; i < arr.length; i++) {
    > trace(" tab[" + i + "] : " + arr
    > }
    > }
    > //
    > // Filling in the Array
    > for (var i = 0; i < 4; i++) {
    > oob = new MyObj(index);
    > // oobj = oob.getClone();
    > trace("-- New object #" + i + " created. MyObj[" + index
    + "]");
    > oob.printObject();
    > objArray = oob;
    > trace("-- Now entered into the array -- printing from
    object #" + i );
    > objArray
    .printObject();
    > trace("-- or printing from the scenario -- objArray[" +
    i + "] is realy
    > stored");
    > printMyArray(objArray.tab);
    > trace("____________________________________");
    > index += 1;
    > }
    > //
    > // Printing the array of pointers to MyObj
    > trace("___________________________________________");
    > trace("And now, all in one...\nPrinting the array of
    pointers to MyObj
    > trace("___________________________________________");
    > for (var i = 0; i < 4; i++) {
    > objArray
    .printObject();
    > }
    > trace("------ Or directly from the scenario -------");
    > for (var i = 0; i < 4; i++) {
    > trace(" Printing from scenario Object name --> " +
    objArray.objectName);
    > printMyArray(objArray
    .tab);
    > }
    > trace("___________________________________________");
    > trace("They are all the same ?!\nIt seems to have lost
    something !!!!");
    > trace("___________________________________________");
    > //
    > //
    > trace("\nAmazingly, the array's elements do not refer to
    the same
    object\n");
    > //
    > trace("objArray[0] == objArray[0] ? -->" +
    (objArray[0] == objArray[0]));
    > trace("objArray[0] == objArray[1] ? -->" +
    (objArray[0] == objArray[1]));
    > trace("objArray[0] instanceof MyObj ? -->" +
    (objArray[0] instanceof
    MyObj));
    > trace("");
    > //
    > trace("\nThey realy seem to point different objects
    !\n");
    > //
    > // So, why do they have different outputs ?
    > //
    > //
    > //
    > // It seems the 'new' constructor creates a new Object
    'MyObj'
    > // which always resides at the same memory location.
    > // 'oob' is in fact a pointer, and objArray[] an array
    of pointers,
    > // as so an array of memory addresses.
    > // The objArray[] elements are pointers which always
    refer to the
    > // the same memory zone, which in fact contains the last
    content of the
    > object.
    > //
    > //
    > // And then manualy
    > //
    >
    trace("**********************************************************");
    > trace("\nAnd then another way to create each new object
    manualy\n");
    >
    trace("**********************************************************");
    > //
    > //
    > var otherObjArray:Array = new Array();
    > //
    > var oob0 = new MyObj(100);
    > trace("-- New object created #100");
    > oob0.printObject();
    > otherObjArray[0] = oob0;
    > trace("-- Now entered into the array --
    otherObjArray[0]");
    > otherObjArray[0].printObject();
    > //
    > var oob1 = new MyObj(200);
    > trace("-- New object created #200");
    > oob1.printObject();
    > otherObjArray[1] = oob1;
    > trace("-- Now entered into the array --
    otherObjArray[1]");
    > otherObjArray[1].printObject();
    > //
    > var oob2 = new MyObj(300);
    > trace("-- New object created #300");
    > oob2.printObject();
    > otherObjArray[2] = oob2;
    > trace("-- Now entered into the array --
    otherObjArray[2]");
    > otherObjArray[2].printObject();
    > //
    > trace("___________________________________________");
    > trace("And now, all in one...\nEnjoy the show !!!!");
    > trace("___________________________________________");
    > otherObjArray[0].printObject();
    > otherObjArray[1].printObject();
    > otherObjArray[2].printObject();
    > //
    > trace("\nThe problem seems to reside in the way the
    Arrays members are
    managed
    > by the Objects !\n");
    > trace("\nHELP me please to find the bug\n");
    > //
    >

  • Array of Object

    How to create array of object dynamically and the class is also having constructor.
    like:
    class Cir{
    private double radius;
    Cir(double r){
    redius=r;
    10 objects are to be created within for loop

    Cir c[]=new Cir[10]
    for(int i=0;i<10;i++)
    c [ i ] =new Cir(radious);
    Message was edited by:
    ramireddi

  • Implement a View Object with multiple entity objects

    Hi
    In 'How to' section on the 'otn.oracle.com' (Jdeveloper) web site is tutorial how to implement a View Object with multiple updateable dependent entity objects.
    It allows user to insert an employee and a department at the same time.
    But I would like to change this example to insert a new department only if it does not already exist. How to change this sample?
    Is there any other way to this?
    Thanks
    Regards
    Gorazd

    Once again the structure, sorry.
    ViewObject
    |-ParentEntityObject
    ..|-PId
    ..|-PAttribute
    ..|-CId (FK)
    |-ParentChildAssociation
    |-ChildEntityObject
    ..|-CId
    ..|-CAttribute
    Christian

  • How do I insert an object in an array?

    How can I insert an object in an array of variable size?
    I input two numbers from keyboard
    1
    2that form the following object (Pair)
    (1,2)
    how can I add such objects to an array
    private Pair s[];
    e.g.
    public PairList(int x){
    top = -1;
    s = new Pair[x];
    }//constructor
    public void getPairs()throws FullException{
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    try{
    a=input.readLine();b=input.readLine();
    }//try
    catch(IOException e){System.out.println("Can't read input");}//catch
    int x=0;
    int y=0;
    try{
    x=Integer.parseInt(a);}//try
    catch(NumberFormatException e){}
    try{
    y=Integer.parseInt(b);}//try
    catch(NumberFormatException e){}
    Pair k=new Pair(x,y);
    System.out.println(k);
    s[++top]=k; --here is my problem
    }//getPairs

    I tried making as few changes to your code as possible, but your idea should basically work. Potential problems:
    1. Doesn't allow for more input than 1 pair.
    2. By storing pair in an array, you must know the exact size of the array you will need beforehand. You might be better off storing the Pair(s) in a Vector and then converting that to an array.
    3.Your exception handlers need some work. Basically, your exception handlers put out a message or do nothing and then you continue processing. Not good.
    4. No cleanup of file resources after you have completed
    import java.io.*;
    public class PairList{
         private Pair s[];
         private int top;
         public PairList(int x){
              top = -1;
              s = new Pair[x];
         }//constructor
         public void getPairs()throws Exception{
              BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
              String a = null, b = null;
              try{
                   a=input.readLine();
                   b=input.readLine();
              }//try
              catch(IOException e){
                   System.out.println("Can't read input");
              }//catch
              int x=0;
              int y=0;
              try{
                   x=Integer.parseInt(a);
              }//try
              catch(NumberFormatException e){
              try{
                   y=Integer.parseInt(b);}//try
              catch(NumberFormatException e){
              Pair k=new Pair(x,y);
              System.out.println(k.toString());
              s[++top]=k; //here is my problem
         }//getPairs
    class Pair {
         private int xx;
         private int yy;
         public Pair(int x, int y) {
              xx = x;
              yy = y;
         public String toString() {
              return("X = " + xx + "  Y = " + yy);
    }

  • How to make arrays or repeat objects in circle?

    Hello,
    1 - How to make arrays without copying and pasting? Fig-1
    2 - how to create objects repeated in circles? Fig-2
    Regards and Thanks

    1) Patterns
    2) One option is Scripting (or Actions).
    http://forums.adobe.com/message/3472806#3472806
    Edit: That was only for text layers, you could give this a try:
    // xonverts to smart object, copies and rotates a layer;
    // for photoshop cs5 on mac;
    // 2011; use it at your own risk;
    #target photoshop
    ////// filter for checking if entry is numeric and positive, thanks to xbytor //////
    posNumberKeystrokeFilter = function() {
              this.text = this.text.replace(",", ".");
              this.text = this.text.replace("-", "");
              if (this.text.match(/[^\-\.\d]/)) {
                        this.text = this.text.replace(/[^\-\.\d]/g, '');
    posNumberKeystrokeFilter2 = function() {
              this.text = this.text.replace(",", "");
              this.text = this.text.replace("-", "");
              this.text = this.text.replace(".", "");
              if (this.text.match(/[^\-\.\d]/)) {
                        this.text = this.text.replace(/[^\-\.\d]/g, '');
              if (this.text == "") {this.text = "2"}
              if (this.text == "1") {this.text = "2"}
    var theCheck = photoshopCheck();
    if (theCheck == true) {
    // do the operations;
    var myDocument = app.activeDocument;
    var myResolution = myDocument.resolution;
    var originalUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var dlg = new Window('dialog', "set circle-radius for arrangement", [500,300,840,450]);
    // field for radius;
    dlg.radius = dlg.add('panel', [15,17,162,67], 'inner radius');
    dlg.radius.number = dlg.radius.add('edittext', [12,12,60,32], "30", {multiline:false});
    dlg.radius.numberText = dlg.radius.add('statictext', [65,14,320,32], "mm radius ", {multiline:false});
    dlg.radius.number.onChange = posNumberKeystrokeFilter;
    dlg.radius.number.active = true;
    // field for number;
    dlg.number = dlg.add('panel', [172,17,325,67], 'number of copies');
    dlg.number.value = dlg.number.add('edittext', [12,12,60,32], "30", {multiline:false});
    dlg.number.value.onChange = posNumberKeystrokeFilter2;
    dlg.number.value.text = "12";
    // buttons for ok, and cancel;
    dlg.buttons = dlg.add('panel', [15,80,325,130], '');
    dlg.buttons.buildBtn = dlg.buttons.add('button', [13,13,145,35], 'OK', {name:'ok'});
    dlg.buttons.cancelBtn = dlg.buttons.add('button', [155,13,290,35], 'Cancel', {name:'cancel'});
    // show the dialog;
    dlg.center();
    var myReturn = dlg.show ();
    if (myReturn == true) {
    // the layer;
              var theLayer = smartify(myDocument.activeLayer);
              app.togglePalettes();
    // get layer;
              var theName = myDocument.activeLayer.name;
              var theBounds = theLayer.bounds;
              var theWidth = theBounds[2] - theBounds[0];
              var theHeight = theBounds[3] - theBounds[1];
              var theOriginal = myDocument.activeLayer;
              var theHorCenter = (theBounds[0] + ((theBounds[2] - theBounds[0])/2));
              var theVerCenter = (theBounds[1] + ((theBounds[3] - theBounds[1])/2));
    // create layerset;
              var myLayerSet = myDocument.layerSets.add();
              theOriginal.visible = false;
              myLayerSet.name = theName + "_rotation";
    // create copies;
              var theNumber = dlg.number.value.text;
              var theLayers = new Array;
              for (var o = 0; o < theNumber; o++) {
                        var theCopy = theLayer.duplicate(myLayerSet, ElementPlacement.PLACEATBEGINNING);
                        theLayers.push(theCopy);
    // calculate the radius in pixels;
              var theRadius = Number(dlg.radius.number.text) / 10 * myResolution / 2.54;
              myDocument.selection.deselect();
    // get the angle;
              theAngle = 360 / theNumber;
    // work through the layers;
              for (var d = 0; d < theNumber; d++) {
                        var thisAngle = theAngle * d ;
                        var theLayer = theLayers[d];
    // determine the offset for outer or inner radius;
                        var theMeasure = theRadius + theHeight/2;
    //                    var theMeasure = theRadius + theWidth/2;
                        var theHorTarget = Math.cos(radiansOf(thisAngle)) * theMeasure;
                        var theVerTarget = Math.sin(radiansOf(thisAngle)) * theMeasure;
    // do the transformations;
                        rotateAndMove(myDocument, theLayer, thisAngle + 90, - theHorCenter + theHorTarget + (myDocument.width / 2), - theVerCenter + theVerTarget + (myDocument.height / 2));
    // reset;
    app.preferences.rulerUnits = originalUnits;
    app.togglePalettes()
    ////// function to determine if open document is eligible for operations //////
    function photoshopCheck () {
    var checksOut = true;
    if (app.documents.length == 0) {
              alert ("no open document");
              checksOut = false
    else {
              if (app.activeDocument.activeLayer.isBackgroundLayer == true) {
                        alert ("please select a non background layer");
                        checksOut = false
              else {}
    return checksOut
    ////// function to smartify if not //////
    function smartify (theLayer) {
    // make layers smart objects if they are not already;
              if (theLayer.kind != LayerKind.SMARTOBJECT) {
                        myDocument.activeLayer = theLayer;
                        var id557 = charIDToTypeID( "slct" );
                        var desc108 = new ActionDescriptor();
                        var id558 = charIDToTypeID( "null" );
                        var ref77 = new ActionReference();
                        var id559 = charIDToTypeID( "Mn  " );
                        var id560 = charIDToTypeID( "MnIt" );
                        var id561 = stringIDToTypeID( "newPlacedLayer" );
                        ref77.putEnumerated( id559, id560, id561 );
                        desc108.putReference( id558, ref77 );
                        executeAction( id557, desc108, DialogModes.NO );
                        return myDocument.activeLayer
              else {return theLayer}
    ////// radians //////
    function radiansOf (theAngle) {
              return theAngle * Math.PI / 180
    ////// rotate and move //////
    function rotateAndMove (myDocument, theLayer, thisAngle, horizontalOffset, verticalOffset) {
    // do the transformations;
    myDocument.activeLayer = theLayer;
    // =======================================================
    var idTrnf = charIDToTypeID( "Trnf" );
        var desc3 = new ActionDescriptor();
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc4 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc4.putUnitDouble( idHrzn, idPxl, horizontalOffset );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc4.putUnitDouble( idVrtc, idPxl, verticalOffset );
        var idOfst = charIDToTypeID( "Ofst" );
        desc3.putObject( idOfst, idOfst, desc4 );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc3.putUnitDouble( idAngl, idAng, Number(thisAngle) );
    executeAction( idTrnf, desc3, DialogModes.NO );

  • How to implement Strategy pattern in ABAP Objects?

    Hello,
    I have a problem where I need to implement different algorithms, depending on the type of input. Example: I have to calculate a Present Value, sometimes with payments in advance, sometimes payment in arrear.
    From documentation and to enhance my ABAP Objects skills, I would like to implement the strategy pattern. It sounds the right solution for the problem.
    Hence I need some help in implementing this pattern in OO. I have some basic OO skills, but still learning.
    Has somebody already implemented this pattern in ABAP OO and can give me some input. Or is there any documentation how to implement it?
    Thanks and regards,
    Tapio

    Keshav has already outlined required logic, so let me fulfill his answer with a snippet
    An Interface
    INTERFACE lif_payment.
      METHODS pay CHANGING c_val TYPE p.
    ENDINTERFACE.
    Payment implementations
    CLASS lcl_payment_1 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                 
    CLASS lcl_payment_2 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                   
    CLASS lcl_payment_1 IMPLEMENTATION.
      METHOD pay.
        "do something with c_val i.e.
        c_val = c_val - 10.
      ENDMETHOD.                   
    ENDCLASS.                  
    CLASS lcl_payment_2 IMPLEMENTATION.
      METHOD pay.
        "do something else with c_val i.e.
        c_val = c_val + 10.
      ENDMETHOD.  
    Main class which uses strategy pattern
    CLASS lcl_main DEFINITION.
      PUBLIC SECTION.
        "during main object creation you pass which payment you want to use for this object
        METHODS constructor IMPORTING ir_payment TYPE REF TO lif_payment.
        "later on you can change this dynamicaly
        METHODS set_payment IMPORTING ir_payment TYPE REF TO lif_payment.
        METHODS show_payment_val.
        METHODS pay.
      PRIVATE SECTION.
        DATA payment_value TYPE p.
        "reference to your interface whcih you will be working with
        "polimorphically
        DATA mr_payment TYPE REF TO lif_payment.
    ENDCLASS.                  
    CLASS lcl_main IMPLEMENTATION.
      METHOD constructor.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD set_payment.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD show_payment_val.
        WRITE /: 'Payment value is now ', me->payment_value.
      ENDMETHOD.                  
      "hide fact that you are using composition to access pay method
      METHOD pay.
        mr_payment->pay( CHANGING c_val = payment_value ).
      ENDMETHOD.                   ENDCLASS.                  
    Client application
    PARAMETERS pa_pay TYPE c. "1 - first payment, 2 - second
    DATA gr_main TYPE REF TO lcl_main.
    DATA gr_payment TYPE REF TO lif_payment.
    START-OF-SELECTION.
      "client application (which uses stategy pattern)
      CASE pa_pay.
        WHEN 1.
          "create first type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_1.
        WHEN 2.
          "create second type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_2.
      ENDCASE.
      "pass payment type to main object
      CREATE OBJECT gr_main
        EXPORTING
          ir_payment = gr_payment.
      gr_main->show_payment_val( ).
      "now client doesn't know which object it is working with
      gr_main->pay( ).
      gr_main->show_payment_val( ).
      "you can also use set_payment method to set payment type dynamically
      "client would see no change
      if pa_pay = 1.
        "now create different payment to set it dynamically
        CREATE OBJECT gr_payment TYPE lcl_payment_2.
        gr_main->set_payment( gr_payment ).
        gr_main->pay( ).
        gr_main->show_payment_val( ).
      endif.
    Regads
    Marcin

  • How to pass Array of Java objects to Callable statement

    Hi ,
    I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
    So I am having and array list of some object say xyz which has two attributes string and double type.
    Now I need to pass this to a PL/SQL Procedure as IN parameter.
    Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
    And we will use a record type from SQL to map this to our array of java objects.
    So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
    Please help
    Thanks

    I seem to remember that that is in one of Oracle's online sample programs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

  • How to list an array of objects using struts in jsp and ActionForm

    I am using the struts ActionForm and need to know how to display an Array of objects. I am assuming it would look like this in the ActionForm:
    private AddRmvParts addRmv[];
    But I am not sure how the getter and setter in the ActionForm should look. Should it be a Collection or an Iterator?
    I am thinking I need to use an iterator in the jsp page to display it.
    I am also wondering if the AddRmvParts class I have can be the same class that gets populated by the retrieval of data from the database. This class has 10 fields that need to display on the jsp page in 1 row and then multiple rows of these 10 fields.
    Thanks.

    Most probably the easiest way to make it accessible in your page is as a collection.
    ie
    public Collection getAddRmvParts()
    You can use the <logic:iterate> or a <c:forEach>(JSTL) tag to loop through the collection
    As long as the individual items in the collection provide get/set methods you can access them with the dot syntax:
    Example using JSTL:
    <c:forEach var="addRmvPart" items="${addRmvParts}">
      <c:out value="${addRmvPart.id} ${addRmvPart.name} ${addRmvPart.description}"/>
    </c:forEach>

  • How to update an object property located in an array of objects

    Hello all,
    I have a script that creates custom objects and populates them and saves them into an array. This array of objects is later converted to a CSV file for reuse later on. On a subsequent need to run the script and to save time and avoid recollecting
    data I have previously amassed, I read in the contents of the csv file and put this data into an arryOfObjects.
    I need to manipulate the data in specific objects but I can't figure out how to accomplish that task.
    I can identify the correct object within the array with the following command. I have been trying to pipe that result into either set-variable or set-itemproperty without success.
    $arrayOfObjects | select-object | where HostName -like $_.'name'
    This works, I can see my desired object and the data fields contained within it.
    I now need to modify one of the property fields. (Alias).
    I have been trying the following as a line of thought, but so far without success. It doesn't fail/error out, but it doesn't update the data either.
    $arrayOfObjects | select-object | where HostName -like $_.'name' | set-itemproperty -name Alias -value "newAlias"
    I'm wondering if I need to specify something for the -path argument, but since the array is in memory and not a registry location or a file I am not sure what I should use, if this is the problem at all.
    Any suggestions would be appreciated.
    Thanks
    Smitty

    yes, I have redacted things, and obscured other things because I can not go around posting critical infrastructure information out on the internet.
    Here is the first three lines of my .csv file
    "OrigIP","AL_HostName","AL_Found","AL_Enabled","AL_Status","N_HostName","InREDACTED","N_Found","Delta","IsStale","Ping","InDNS","InAD","Location","Alias","IsServer","HostType","OS","ApplianceName","FQDN","ChatterValue"
    "10.24.11.4","ABCD","yes","yes","never","abcd.domain.com","yes","yes","*","*","Y","Y","N","TEST","*","*","eventlog","","","ABCD.DOMAIN.COM","*"
    "10.24.12.18","EFGH","yes","yes","Dec 30 2014 09:15:00","efgh.domain.com","yes","yes","-25","No","Y","Y","Y","TEST","*","yes","eventlog","xxxxxx","","EFGH.DOMAIN.COM","*"
    When I import this file I create a new custom object (objectCurrent) which I populate with the data from the csv file. I then store this object into an array of objects (objectCollection).
    All of the data is present.
    I then read in a new csv file that would contain most of the same hosts, but possibly additional new ones. upon importing the second csv file I loop through the entries.
     I have a conditional statement that checks to see if the host name from the second csv file, if it isn't then treat it like a new object and go fill in all of the details of the object using my various functions, etc.
    Import-CSV$currentALReport-Delimiter","|ForEach-Object
         if($objectCollection.N_HostName
    -notcontains$_.'name')
            # then create a new currentObject and go populate the properties of the object 
         elseif ($objectCollection.N_HostName -contains $_.'name') {
              # copy this object and update the object's AL_Status (which is the last reported message date info)
                  # send that to the function that will parse it, compare Julian dates and see if it falls within my
                  # criteria as being stale.  if so set the IsStale property to Yes, but reguardless set the AL_Status
                  # newest last reported message data
    JRV states that "The "select object" does nothing at all unless you have a column in your CSV called "object".  The where clause will do nothing because it is syntatctically wrong and illogical. "
    I beg to differ.  Using the above command :   with the script running and the current focus ($_.'name') equals "abcd.domain.com"
     $arrayOfObjects | select-object | where N_HostName -like $_.'name'
    It obtain a single object within my array of objects similar to this:
    IP: 1.2.3.4
    N_HostName: abcd.domain.com
    IsStale: No
    LastMsgDate: Dec 30 2014 09:15:00
    Delta: 1
    Ping: Yes
    InDNS: Yes
    InAD: Yes
    Alias: *
    (other fields omitted for brevity) I could get any of my existing objects if I match the hostname
    If I used only the command "  $objectCollection | Select-Object "    it returns every object in my array.
    So to narrow down the selection to a single object I add the " | where N_HostName -like $_.'name'  "
    which gives me the exact object I am searching for.
    My only question is how can I modify the contents of the object that I have specified within the array of object???

Maybe you are looking for