Using a returned SOAP array

This feels like a ridiculous question, but Google is not being any help.
How do I actually use a value returned as an instance of a subclass of
    org.xmlsoap.schemas.soap.encoding.Array? I am trying to use XFire for the client code calling another system. I have the code generating properly from the WSDL, and I can make the call that is supposed to return an instance of a class that extends Array. There is a Holder<Integer> parameter which is returning with the right size of the output. And sniffing the SOAP messages, the data is being returned in the XML document. But the API for Array doesn't seem to give me any way to access the elements. And this class adds nothing I can see to the API:
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "arEventList")
    public class ArEventList
        extends Array
    }In the test code, I try the entire API, and get back nothing of value I can see, except for the size of the array, which isn't actually stored in the Array itself but in a mutable parameter.
    EventsServiceClient client = new EventsServiceClient();
    Events events = client.getEventsPort(getServerUrl());
    Holder<Integer> countHolder = new Holder<Integer>();
    ArEventList list = events.getEventListById(getSessionToken(), 0,
                                    100000, 44, false, countHolder);
    System.out.println(list.getAny());             // => []
    System.out.println(list.getOtherAttributes()); // => {}
    System.out.println(list.getArrayType());       // => null
    System.out.println(list.getHref());            // => "#0"
    System.out.println(list.getId());              // => null
    System.out.println(list.getOffset());          // => null
    System.out.println(countHolder.value);         // => 788So how can I get at the actual elements returned in the Array?
-- Scott

Thanks for the response.
Check the XFire docs. So far, they haven't been much help.
Axis just maps WS arrays to corresponding Java arrays
of the correct type for you, I'd be highly surprised
if XFire can't do the same.I think there are underlying problems beyond this. Even simple types aren't coming back correctly. It may be a miscommunication between the Delphi-based server and XFire on the format of the SOAP documents. I'm looking into that now.
But when you say Axis maps the arrays, how do you get at them; it's not a simple cast, is it? The generated code is of a class that extends but doesn't add any behavior to the WS Array. The API of that class doesn't seem to allow any way to get at the Array of my type, unless that's what this does:
    List<Object> getAny()At a guess, that's what's going on, and the data, which I can see in the SOAP document, is not formatted by the server in a way that XFire can recognize. But I'm going to have to chew on that one some more.
Thanks again,
-- Scott

Similar Messages

  • Unique Problem: Returning SOAP+ Attachment using a class based webservice

    Hi everyone,
    Im trying to return a Soap+ attachment response back using the following:
    attachDoc(byte[] bdoc, String sTransactionNumber,
                   String sRequestedType)
    Where byte[] is the attachment and the 2 string parameters are soap message contents.
    The attachment is attached successfully to the message and i can send a response back to the clients console using :
    message.writeTo(System.out);
    My problem is that i dont know how to return this soapmessage+attachment back to the client.
    Ive tried using the return type of the method as :
    public SOAPMessage attachDoc(byte[] bdoc, String sTransactionNumber,
                   String sRequestedType)
    but i cant return a SOAPMessage return type in axis.
    Does anyone have any clues how i should sort this out so that the client gets the SOAPMessage and attachment when the method is called ?
    Please help :S
    Thanks,

    I dunno if this is what you asked for....
    Hope this helps a bit
    You may want to check this link out
    http://www-unix.globus.org/mail_archive/discuss/2007/02/msg00037.html
    MessageContext msgContext = MessageContext.getCurrentContext();
    File file = new File("filename.txt");
    org.apache.axis.attachments.AttachmentPart replyPart=
    new org.apache.axis.attachments.AttachmentPart(new DataHandler(new
    FileDataSource(file)));
    Message rspMsg= msgContext.getResponseMessage();
    rspMsg.addAttachmentPart(replyPart);
    so ur basically adding the file to the reply message.
    The link i gave has a better description, it has the entire process of sending file to server and downloading file from server codes.

  • How to define method  witch returning an array in View, using method wizard

    Dear experts.
    I would  like to define method  which returning an array in View.
    When View is opened, in "Methods" tab push "new" button, then select "Method" in Method Type window,
    push "Next" but in Method Properties window Array Type checkbox is disabled. So, it is not possible to
    define method with returning array type.
    Please anybody, help me to resolve this problem.

    Hi
    While creating method, you can see a check box over there as array type just check it that array type check box,
    or
    You can selet java native type as array by selecting "java native type"
    thanks
    anup
    Edited by: Anup Bharti on Oct 15, 2008 8:50 AM
    Edited by: Anup Bharti on Oct 15, 2008 8:51 AM

  • BPEL build error when invoke an extrenal Web Service that returns an Array

    Hello,
    I built with JDeveloper a web service that returns an Array of Java Bean classes and I try to invoke this web service from a BPEL process. The wsdl file is automatically generated by the JDev. When I built the BPEl project I obtained the following error:
    [bpelc] [Error] :-1:-1: src-resolve.4.2: Error resolving component 'SOAP-ENC:Array'. It was detected that 'SOAP-ENC:Array' is in namespace 'http://schemas.xmlsoap.org/soap/encoding/', but components from this namespace are not referenceable from schema document 'http://malangiu-ro:8988/cde-Project-context-root/CdeFactoryWS?WSDL'. If this is the incorrect namespace, perhaps the prefix of 'SOAP-ENC:Array' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'http://malangiu-ro:8988/cde-Project-context-root/CdeFactoryWS?WSDL'.
    [bpelc] [Error] :-1:-1: src-resolve.4.2: Error resolving component 'SOAPENC:Array'. It was detected that 'SOAPENC:Array' is in namespace 'http://schemas.xmlsoap.org/soap/encoding/', but components from this namespace are not referenceable from schema document 'http://malangiu-ro:8988/cde-Project-context-root/Top300FactoryWS?WSDL'. If this is the incorrect namespace, perhaps the prefix of 'SOAPENC:Array' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'http://malangiu-ro:8988/cde-Project-context-root/Top300FactoryWS?WSDL'.
    [bpelc] [Error] :-1:-1: src-resolve.4.2: Error resolving component 'SOAP-ENC:Array'. It was detected that 'SOAP-ENC:Array' is in namespace 'http://schemas.xmlsoap.org/soap/encoding/', but components from this namespace are not referenceable from schema document 'http://malangiu-ro:8988/cde-Project-context-root/CdeFactoryWS?WSDL'. If this is the incorrect namespace, perhaps the prefix of 'SOAP-ENC:Array' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'http://malangiu-ro:8988/cde-Project-context-root/CdeFactoryWS?WSDL'.
    Any hint? Thanks in advance!
    Regards,
    Marinel

    Hi,
    BPEL and BPEL PM do not have a good support for SOAPENC-Array: it would be very difficult to create such an array in BPEL or to receive it and manipulate it.
    The (unfortunately very intrusive) work around is to change the WSDL of the service to use a XML type defined using XML schema. This is all the more painful that JDev 9.0.4 does not have strong support for complex types.
    In general though, I would highly recommend this best practice:
    1) Start by define the WSDL contract first
    2) Then generate the server side skeleton to implement it
    3) Use BPEL as the client to this contract.
    By starting with the contract first, you make sure that 1) your interfaces are clean and coarse grained.
    2) things like java objects, sessions, etc to not leak through the interface (which would be the worst thing that could happen because it would closely link the client and the server.
    Sorry for not being more helpful. This will get radically cleaner in Oracle AS 10.1.3.
    Edwin

  • Information from formula that returns an array is not shown on chart

    Hello experts,
    I have a chart (combination) which should show information from a group of cells that have a formula in it and returns an array ().
    {=SUM((Plan1!L2:L43=L2)(Plan1!I2:I43=D3)Plan1!M2:M43)}
    In the spreadsheet and on the chart, while developing the dashboard, it shows perfectly.
    What happens is that while previewing.....no data is shown at all on the chart.
    Please advise on how to solve it.
    Carlos Henrique Matos da Silva - SAP BusinessObjects BI - Brazil.

    Hi Carlos,
    Excel Array entered formulae are not supported in Xcelsius.
    When you are designing the dashboard Xcelsius is using native Excel functrionality and calculation engine to display the results.  When you preview the dashboard Xcelsius convertys all of the spreadsheet formulae to Flash/ActionScript which does not have the equivalent array functionality, adn so when previewed the results do not show.
    Hope this helps
    Charles

  • Should Collections be used as return types across threads?

    I am wondering when, if ever, it is appropriate to use a Collection as the return type of a method in a multi-threaded environment. Here is our situation:
    We have four classes -- Widget, WidgetManager, ClientA, and ClientB. ClientA and ClientB are running in different Threads from each other and from the WidgetManager.
    The WidgetManager class that uses a Collection of Widgets internally, and passes the Collection (or an Iterator over it) out as a return value of a method to ClientA, which is running in another thread. ClientA would start to go through it using next() and hasNext() of the Iterator. If the WidgetManager were to get a request from ClientB running in another thread to eliminate a Widget, it would attempt to remove it from the Collection. If ClientA were still looping through the Iterator, this would throw an IllegalStateException b/c the system would be in an inconsistent state. The Iterator given to the ClientA is directly linked to the actual Collection in the WidgetManager (am I right so far?).
    In my opinion, in most cases we don't want to synchronize Collections. In the example above, if we had passed out a synchronized Collection, then the WidgetManager couldn't touch the collection while the client was looping through the Iterator. If the client got hung up while looping, then the WidgetManager would be hung up. In this case, I think that it will be better to use the toArray() method of Collection to just dump out the contents to a plain array of Objects. Actually, the WidgetManager could convert this array of Objects to an array of Widgets before passing it out, which would give us the type checking that we don't get with Containers.
    The condition where you would want to use a synchronized Collection would be when you actually want the client to do some writing or removing from the Collection. I would expect this to be pretty rare since you usually dont want to give clients access to an interal member (the Collection) of a class.
    I think that it is also possible to have read-only Collections, but I think (don't know for sure) that you would still have the same IllegalStateException or synchronization probelms.
    Can someone point out the errors in my thinking? Or should you generally only use Collections as internal members in a multi-threaded environment, and use toArray() whenever you want to pass the Collection's data outside of the class?
    Thanks for any help.
    Keith

    I haven't tested what happens when you synchronize the
    Collection, but I think that you are right. But this
    causes the problem that I mentioned in the first post.
    That is, what happens if your client STARTS running
    through the Iterator, and then stops or gets hung up
    for some reason? I assume that you're still blocked.
    And it's pretty important to me in this case to not
    t be blocked -- WidgetManager is the highest level
    class in the system.
    I'd like to know if anyone has tested this.
    The Iterator implementations used in java.util do not use any synchronization by itself, (which is what you would expect since synchronization over multiple method call will involve much more complications and slower performance) . With iterator, you have to provide the necessary synchronization yourself to maintain thread-safety like this
    Iterator itr = get Iterator from collectionInstance ;
    synchronized(collectionInstance) {
    while(itr.hasNext())
    process itr.next() ...
    As long as your client code gracefully exits the synchronized block on a stop( or hangup, given that it is detected and handled fast enough), it will not be a problem.
    Also, I'd like an example of when you WOULD want to
    return a Collection. I'm specifically interested in
    when you would want to return one in a multi-threaded
    environment, but I'm beginning to wonder when you
    would EVER want to return one from a method.
    Collections are great for internal uses, but you lose
    type-checking and you expose the internals of your
    class to modification when you use them as return
    types. And if you're returning a read-only
    Collection, you might as well return an array, right?Using a read-only proxy will be much faster and space-efficient than toArray().

  • External java function that should return String array

    Hi everyone,
    I have a split function in plsql that takes 10 times longer a java tokenizer function that i was written. So, i want to use java external function to split my plsql strings into pieces.
    I can write a java external procedure that returns types like int, float and String types. I have no problem about it.
    My problem is returning an array of strings. I found a book that has an example about how can we get directory list in plsql with java external procedure.
    (code)
    import java.io.File;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.*;
    public class JFile {
    public static oracle.sql.ARRAY dirlist (String dir)
    throws java.sql.SQLException
    Connection conn = new OracleDriver().defaultConnection( );
    ArrayDescriptor arraydesc =
    ArrayDescriptor.createDescriptor ("DIRLIST_T", conn);
    File myDir = new File (dir);
    String[] filesList = myDir.list( );
    ARRAY dirArray = new ARRAY(arraydesc, conn, filesList);
    return dirArray;
    CREATE OR REPLACE FUNCTION dirlist (dir IN VARCHAR2)
    RETURN dirlist_t
    AS
    LANGUAGE JAVA
    NAME 'myFile.dirlist(java.lang.String) return oracle.sql.ARRARY';
    (code)
    I could compile this source file in localhost but not remotehost. There are jar files ( import oracle.sql.*; import oracle.jdbc.*; ) that should be added to remote classpath. ( others have already added java classpath ). But, which classpath i should add? Oracle has own JVM and Classpath, probably i should upload these jar files to oracle classpath. Am i wrong? How can i do? Can you explain in detail? How can i return string array from java external function in Oracle ?
    I am using Oracle 11.1.0.7 on Solaris Sparc Machine.

    Hi,
    What do you mean "compile in remote host"
    Aren't you using the loadjava tool? - that should be enough, the RDBMS already "has" the jars needed.
    [A must read|http://download.oracle.com/docs/cd/B28359_01/java.111/b31225/chone.htm#BABCFIIF]
    Regards
    Peter

  • Soap Array in external WSDL

    Hi all,
    i have an webservice that i need to use as a reciever that  has a WSDL containing soap arrays instead of repeating groups.
    <xsd:complexType name="workOrderArray">
      <xsd:complexContent>
        <xsd:restriction base="soapenc:Array">
          <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:workOrder[]" />
        </xsd:restriction>
      </xsd:complexContent>
    </xsd:complexType>
    i understand that  PI is not supporting  this  but maybe somebody has found a work around ?  At the moment i 'm creating an XSD from the WSDL and then i will import the xml schema and i will see if that works.
    any other suggestions ?

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:tns="http://example/"
      xmlns:types="http://example/encodedTypes"
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <xsl:template match="/">
        <env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://example/" xmlns:types="http://example/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <xsl:copy>
              <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
          </env:Body>
        </env:Envelope>
      </xsl:template>
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="/tns:workOrderMsg/tns:workOrderArray">
        <workOrderArray soapenc:id="id1" soapenc:itemType="types:WorkOrder">
          <xsl:attribute name="soapenc:arraySize">
            <xsl:value-of select="count(./tns:workOrder)"/>
          </xsl:attribute>
          <xsl:for-each select="./tns:workOrder">
            <Item>
              <xsl:attribute name="soapenc:id">
                <xsl:value-of select="concat('id', position())"/>
              </xsl:attribute>
              <order_id xsi:type="xsd:string"><xsl:value-of select="tns:order_id"/></order_id>
              <description xsi:type="xsd:string"><xsl:value-of select="tns:description"/></description>
            </Item>
          </xsl:for-each>
        </workOrderArray>
      </xsl:template>
    </xsl:stylesheet>

  • SOAP array in database

    Hello all. I want work with soap array return from soap service. I read many article in site, but I not understand how create client in database working with array.
    Thanks.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:tns="http://example/"
      xmlns:types="http://example/encodedTypes"
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <xsl:template match="/">
        <env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://example/" xmlns:types="http://example/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <xsl:copy>
              <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
          </env:Body>
        </env:Envelope>
      </xsl:template>
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="/tns:workOrderMsg/tns:workOrderArray">
        <workOrderArray soapenc:id="id1" soapenc:itemType="types:WorkOrder">
          <xsl:attribute name="soapenc:arraySize">
            <xsl:value-of select="count(./tns:workOrder)"/>
          </xsl:attribute>
          <xsl:for-each select="./tns:workOrder">
            <Item>
              <xsl:attribute name="soapenc:id">
                <xsl:value-of select="concat('id', position())"/>
              </xsl:attribute>
              <order_id xsi:type="xsd:string"><xsl:value-of select="tns:order_id"/></order_id>
              <description xsi:type="xsd:string"><xsl:value-of select="tns:description"/></description>
            </Item>
          </xsl:for-each>
        </workOrderArray>
      </xsl:template>
    </xsl:stylesheet>

  • Return an array from dll to labview

    Hello,
    I am using "Call Library Function" where I call a C function from Labview.
    Now .. I want to return an 1 dimensional array from C DLL back to Labview.
    Can someone provide an example code how to do it.
    When I configure parameter, there are options "Array Data Pointer", "Array Handle" and "Array Handle Pointer".
    When I take the first (the simple one), so there is no way labview can know how many items are in the array.
    But what is the right to take?
    Thanks in advance
    Kind Regards

    You would run into the same problem calling a function that returns an array in C, because you cannot determine the number of items in an array in C solely from the pointer value that a function returns.  Also, it's a bad idea to return an array of unknown size as a function's return value, because that makes the calling function responsible for deallocating the memory even though the called function allocated it.  If you don't know in advance how large the array will be, then a better approach is to allocate an array of sufficient size in the calling function (or in LabVIEW, in this case) and pass that by reference to the function, then have the function's return value indicate the number of values in the array that are actually filled with data.

  • How to get the array of Complex when call a webserivce method it's return an array of user define data struct?

    When call a webservice opreation, it returns an array of complex type, sure, the calling is successed,  but i don't know how to get the return values,
    I have tried use Pendingcall.response & Pendingcall.getOutPutValues() in Pendingcall.onResult event function...
    Waiting....

    Flash Lite doesn't fully support webservices, so you will find it difficult to use the full api set.
    I suggest that you use SWX (swxformat.org) or simply HTTP requests for transactions.
    We have a tutorial on use with ColdFusion here:
    http://vimeo.com/6829083
    Mark

  • How to call a procude in oracle and return an array

    I need to call a procedure and return an array, can give some example code?

    First create ArrayDescriptor
    like:
        public ArrayDescriptor createDescriptor(Connection con, String typename) throws SQLException
            if(typename==null)
                return null;
            //WARNING! typename should be in upper case only! Otherwise Exception "invalid name pattern"
            //will be thrown!
            return ArrayDescriptor.createDescriptor(typename.toUpperCase(),con);
        }Then use SetArray function to a prepared query (just like SetInt() or
    SetString()):
    public void setArray(PreparedStatement st, int index, Object [] value, ArrayDescriptor ad) throws SQLException
            ARRAY array = new ARRAY(ad, st.getConnection(), value);
            if(st instanceof OraclePreparedStatement)
                OraclePreparedStatement opst=(OraclePreparedStatement )st;
                opst.setArray(index, array);
            else
                throw new SQLException("Oracle JDBC driver required to support setArray() operation!");
        }In the same way you could implement RegisterOutParameter() which
    accepts Array - it's provided by class OraclePreparedStatement...
    look Oracle JDBC manuals - everything is there.
    Enjoy!
    Paul

  • To use Sales Return

    Dear Gurus,
    Our client want to use sales return again into prodution,
    Example : If  Soap is sales return, they want to use in  
    production again, by crushing soap, under same BOM header.
    Can we use same soap as component with other componets  as recurrsive component, wat it affect on cosing.
    wat will be the possible things in SAP,
    Here they r not using Rework process,
    Wat r the process to use sales returns.
    Pls Give valuable inputs,
    Regards
    Hrishi.

    Hi,
    Without putting the Sales Returns directly to the BOM, try with changing the Material with little extension..
    Say your FERT is XYZ, then for sales returns change the Material to XYZ_R (with stock transfer from MAterial to Material)..
    Now Use this Material in your Satndard BOMs with some %, say you use this sales returns 10%.
    Proportinately you can have this material as BOM Component..
    Hope this will halp in defining a new process in your Plant..
    Hope this helps..
    Regards,
    Siva

  • Generated WS client is unable to unmarshal returned object array

    Hello,
    I have created web service using Sun jaxws implementation. Several methods of this ws return object array (CustomObj []). When I generate the client (using jaxws-maven-plugin - wsimport) and call these methods I always get
    empty array. I get no errors or warnings. When I generate axis client all works as expected. I think that this issue is related to jaxb but i have tried to switch between several versions ant this didn't help. CustomObj is very simple object with two attributes name and value...
    Thanks for hints...

    Hi Shepy,
    I think mapping an array of objects as response in WSDL messages is somewhat of an issue.
    Instead try moving this array of object into another XSD if i assume you are using XSDs and then make sure that response XSD holds and array of your objects.
    Regards,
    Anand

  • Getter/setter methods -- how do I use the return values

    I'm just learning Java, and I haven't been to this site since the end of July, I think. I have a question regarding getter and setter methods. I switched to the book Head First Java after a poster here recommended it. I'm only about a hundred pages into the book, so the code I'm submitting here reflects that. It's the beginnings of a program I'd eventually like to complete that will take the entered information of my CD's and alphabetize them according to whatever criteria I (or any user for that matter) choose. I realize that this is just the very beginning, and I don't expect to have the complete program completed any time soon -- it's my long term goal, but I thought I could take what I'm learning in the book and put it to practical use as I go along (or at lest try to).
    Yes I could have this already done it Excel, but where's the fun and challenge in that? :) Here's the code:
    // This program allows the user to enter CD information - Artist name, album title, and year of release -- and then organizes it according the the user's choice according to the user's criteria -- either by artist name, then title, then year of release, or by any other order according to the user's choice.
    //First, the class CDList is created, along with the necessary variables.
    class CDList{
         private String artistName;//only one string for the artist name -- including spaces.
         private String albumTitle;//only one string the title name -- including spaces.
         private int yearOfRelease;
         private String recordLabel;
         public void setArtistName(String artist){
         artistName = artist;
         public void setAlbumTitle(String album){
         albumTitle = album;
         public void setYearOfRelease(int yor){
         yearOfRelease = yor;
         public void setLabel(String label){
         recordLabel = label;
         public String getArtistName(){
         return artistName;
         public String getAlbumTitle(){
         return albumTitle;
         public int getYearOfRelease(){
         return yearOfRelease;
        public String getLabel(){
        return recordLabel;
    void printout () {
           System.out.println ("Artist Name: " + getArtistName());
           System.out.println ("Album Title: " + getAlbumTitle());
           System.out.println ("Year of Release: " + getYearOfRelease());
           System.out.println ("Record Label: " + getLabel());
           System.out.println ();
    import static java.lang.System.out;
    import java.util.Scanner;
    class CDListTestDrive {
         public static void main( String[] args ) {
              Scanner s=new Scanner(System.in);
              CDList[] Record = new CDList[4];
              int x=0;     
              while (x<4) {
              Record[x]=new CDList();
              out.println ("Artist Name: ");
              String artist = s.nextLine();
              Record[x].setArtistName(artist);
              out.println ("Album Title: ");
              String album = s.nextLine();
              Record[x].setAlbumTitle(album);
              out.println ("Year of Release: ");
              int yor= s.nextInt();
                    s.nextLine();
              Record[x].setYearOfRelease(yor);
              out.println ("Record Label: ");
              String label = s.nextLine();
              Record[x].setLabel(label);
              System.out.println();
              x=x+1;//moves to next CDList object;
              x=0;
              while (x<4) {
              Record[x].getArtistName();
              Record[x].getAlbumTitle();
              Record[x].getYearOfRelease();
              Record[x].getLabel();
              Record[x].printout();
              x=x+1;
                   out.println("Enter a Record Number: ");
                   x=s.nextInt();
                   x=x-1;
                   Record[x].getArtistName();
                Record[x].getAlbumTitle();
                Record[x].getYearOfRelease();
                Record[x].getLabel();
                Record[x].printout();
         }//end main
    }//end class          First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.
    Edited by: Straitsfan on Sep 29, 2009 2:03 PM

    Straitsfan wrote:
    First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.Yes, there is tons you could have done more efficiently. But this is something every new programmer goes through, and I will not spoil the fun. You see, in 3 to 6 months when you have learned much more Java, assuming you stick with it, you will look back at this and be like "what the hell was I thinking" and then realize just haw far you have come. So enjoy that moment and don't spoil it now by asking for what could have been better/ more efficient. If it works it works, just be happy it works.
    Straitsfan wrote:
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.First, if you posted this somewhere else you should link to that post, it is good you at least said you did, but doubleposting is considered very rude because what inevitably happens in many cases is the responses are weighed against each other. So you are basically setting anyone up who responds to the post for a trap that could make them look bad when you double post.
    You are setting you getters and setters up right as far as I can tell. Which tells me that I think you grasp that a getter lets another class get the variables data, and a setter lets another class set the data. One thing, be sure to use the full variable name so you should have setRecordLabel() and getRecodLabel() as opposed to setLabel() and getLabel(). Think about what happens if you go back and add a label field to the CDList class, bad things the way you have it currently. Sometimes shortcuts are not your friend.
    And yes, you are using the getters all wrong since you are not saving off what they return, frankly I am suprised it compiles. It works because you don't really need to use the getters where you have them since the CDList Record (should be lowercase R by the way) object already knows the data and uses it in the printout() method. Basically what you are doing in lines like:
    Record[x].getArtistName();is asking for the ArtistName in Record[x] and then getting the name and just dropping it on the floor. You need to store it in something if you want to keep it, like:
    String artistName = Record[x].getArtistName();See how that works?
    Hope this helped, keep up the good learning and good luck.
    JSG

Maybe you are looking for