List as a return type (Should be easy!?)

Hi all,
I'm pulling my hair out at this as it sounds like it should be easy. The method below should return a List. What am I doing wrong please?
(This is making me feel thick, any help would be very much appreciated)
Thank you,
David.
    public String[] getHrefs(String uriStr) {
          List resultList = new ArrayList();
          HTMLDocument.Iterator it = null;
          Reader rd = null;
          try {
               // Create a reader on the HTML content
               URL url = new URI(uriStr).toURL();
               URLConnection conn = url.openConnection();
               rd = new InputStreamReader(conn.getInputStream());
          } catch (Exception e) {
               System.out.println(e.toString());
          try {
               // Parse the HTML
               EditorKit kit = new HTMLEditorKit();
               HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
               doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
               kit.read(rd, doc, 0);
               // Find all the A elements in the HTML document
               it = doc.getIterator(HTML.Tag.A);
          } catch (Exception e) {
               System.out.println(e.toString());
          while ((it != null) && it.isValid()) {
               try {
                    SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
                    if (s != null) {
                         String link = (String) s.getAttribute(HTML.Attribute.HREF);
                         // If link valid, add it to the result list
                         if (link != null)
                              resultList.add(link);
                    it.next();
               } catch (Exception e) {
                    System.out.println(e.toString() + " : Skipping");
                    it.next();
          } // end While
          //     place all found links in array
          resultList.toArray(new String[resultList.size()]);
          // return array
          return resultList;
    }

resultList.toArray(new String[resultList.size()]);In that code, you are not storing the result of the 'toArray()' method which is the array that you wanted. If you look at the API of ArrayList's toArray() method, it said::
Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list.
So the result will not be stored in the array given as the parameter, instead it is stored in resulting array that is returned by the method (regardless of whether or not the parameter array is used). What you want to do is ::
String[] result = resultList.toArray(new String[resultList.size()]);
return result;or as GiddingsR replied, simply:
return resultList.toArray(new String[resultList.size()]);

Similar Messages

  • Oracle access manager - Policy domain - Return Type

    Hi,
    I have a requirement where I need to return few LDAP parameter values through Policy domain while redirecting. But the return type should be propertytype and not headervar or cookie. This is SSO integration with websphere using JAAS subject. We have inhouse TAI connector developed for integration between websphere and oracle access manager.
    Please help me to resolve this issue.
    Regards,
    Prashant

    Hi Prashant,
    OAM can return any type that you want, and OAM will set the name/value for that type - you can put "propertytype" in the type column, and the name and return attribute in the respective fields. "Cookie" and "HeaderVar" are the only types used by OAM WebGates, but your AccessGate (custom in-house connector) should be able to retrieve the values of propertytype that OAM sets.
    Regards,
    Colin

  • Return type for a PL?SQL function

    Hi,
    I am trying to register a PL/SQL function with discoverer which returns more than one numerical values. What return type should i use for this function....cant see an array or something like it from the Diccover end, when I try to register it.
    Please help.
    -S

    S.
    If you create a function, then you can pass in parameters but only return one value for the function.
    That return datatype cannot be an array, but just one value (ie: varchar, number, etc.).
    Russ

  • Should/does -MyInterface give MyInterface return types?

    The variance-overview.pdf says that List<-E> has Object as the return type of the get method. If this is true, I'm disappointed. I'd expect the following to work quite happily: List<-List<*>> myList = buildList();
    List<*> elt1 = myList.get(0);There's no obvious reason why Object should be a supertype of List.

    I'm still a bit fuzzy about contravariance, but it all depends on what your buildList() method returns. I think this is all legal code:
        List<Object> list1 = new ArrayList<Object>();
        List<List<*>> list2 = new ArrayList<List<*>>();
        list1.add (new Object());
        list2.add (new ArrayList<Integer>());
        List<-List<*>> list3;
        list3 = list2;
        list3 = list1;
        Object o = list3.get(0); // o is not a List!Either of list1, list2 or list3 will accept list.add(new ArrayList<Integer>()) - however at the price that nothing can be guaranteed about the type of the contents of the array (in the second case, the list is only guaranteed to contain Object).
    What you want is for your buildList() method to return List<+List<*>>, the variant case (since you are reading from it).
        List<ArrayList<*>> list1 = new ArrayList<ArrayList<*>>();
        List<List<*>> list2 = new ArrayList<List<*>>();
        list1.add (new ArrayList<Integer>());
        list2.add (new ArrayList<Integer>());
        List<+List<*>> list3;
        list3 = list2;
        list3 = list1;
        List<*> o = list3.get(0); // o is a List

  • 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().

  • Easy way to evaluate a complex return type in adf taskflow

    Hi,
    I use a method call in adf taskflow where I call a bpel ws . This bpel has a complex return type. I want to evaluate in the taskflow router if STATUS==true . Can this be done with pageflowscope (in the method call , I have a return value) or do I need a methodIterator / accessorIterator in the pagedef.
    thanks edwin
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="11.1.1.47.96"
    id="process_Result" Package="nl.ordina.order.view.CreditCheck"
    BeanClass="nl.ordina.order.view.CreditCheck.process_Result"
    isJavaBased="false">
    <Attribute Name="STATUS" IsUpdateable="0" Type="java.lang.Boolean"/>
    <Attribute Name="LIMIT" IsUpdateable="0" Type="java.math.BigDecimal"/>
    <Attribute Name="REASON" IsUpdateable="0" Type="java.lang.String"/>
    </JavaBean>
    Here is the methodaction in the pagedef
    <methodAction id="process" RequiresUpdateModel="true" Action="invokeMethod"
    MethodName="process" IsViewObjectMethod="false"
    DataControl="CreditCheck" InstanceName="CreditCheck"
    ReturnName="CreditCheck.methodResults.process_CreditCheck_process_result">

    nice try,
    Unfortunately your method is easily circumvented by either 1.) disabling javascript in the browser preferences or 2.) viewing the source code for the page and clearly seeing the required password or 3.) simply bookmarking and visiting protectpage.html
    It may take you 5 mins. to password protect your iweb site by using the method you've described, but it would take a visitor less than a minute to bypass the password protection. You need server-side scripting like php to enable real password protection so that information is processed on the server before the page is loaded.

  • How to add list of multiple file types to file type of file dialog box in LabVIEW

    How to add list of multiple file types to file type of file dialog box in LabVIEW?
    In file dialog box there is option to add only one file type,in the list,not by seperating commas,
    regards,
    Naresh.N

    Write the file types in pattern Input string, separated by a semicolon ;
    For example:  *.vi;*.doc;*.jpeg;*.xls
    This should return the set of files with matching extensions
    Message Edited by devchander on 09-10-2008 08:02 AM
    Message Edited by devchander on 09-10-2008 08:03 AM

  • Set attribute to a Jfield to return type number from Lov

    in my lov , i need to return type number and put it in the Jfield . after doin some search , i found the method to set the attribute on that field. PLease and need to send me any URL of doing that method if there is one. (returning type number from LOV)
    i have tried this method but it didn't work!!!
    Return object from List of values page:
    FacesContext fctx = FacesContext.getCurrentInstance();
    Application app = fctx.getApplication();
    ValueBinding vb = app.createValueBinding("#{bindings}");
    DCBindingContainer dc = (DCBindingContainer) vb.getValue(fctx);
    DCIteratorBinding dciter = (DCIteratorBinding)dc.get("PrcPartiesLawer1Iterator");
    id = (Number)dciter.getCurrentRow().getAttribute("Id");
    Name = (String)dciter.getCurrentRow().getAttribute("FullNameN");
    setId(id);
    setName(Name); AdfFacesContext.getCurrentInstance().returnFromDialog(this,null);
    return listener to assign value to Number field:
    LawyerReturnOject b = (LawyerReturnOject)returnEvent.getReturnValue();
    if(b==null)return;
    Number i = b.getId();
    getIii().setSubmittedValue(null);
    getIii().setValue(i);
    String f = b.getName();
    getInputText1().setSubmittedValue(null);
    getInputText1().setValue(f);
    AdfFacesContext af = AdfFacesContext.getCurrentInstance();
    af.addPartialTarget(getLawyerLov());
    af.addPartialTarget(getInputText1());
    and the number type is oracle.jbo.domain.number

    Hi,
    its easier to set the returned value on the ADF binding then on the component directly (at least this is less error prone)
    FacesContext fctx = FacesContext.getCurrentInstance();
    Application app = fctx.getApplication();
    ValueBinding vb = app.createValueBinding("#{bindings}");
    DCBindingContainer dc = (DCBindingContainer) vb.getValue(fctx);
    FacesCtrlAttrsBinding the_attribute = (FacesCtrlAttrsBinding ) dc.get("nameOfAttributeToUpdate");
    the_attribute.set...
    Frank

  • Guideline for deciding method return type

    Hi All,
    I have some concerns in deciding the return type of some specific methods in the application (web service application to be specific).
    Concern: There are methods like 'deleteData', 'cancelProcess', 'uploadData' etc. Ideally these methods don't require server to perform complex business logic. Now there are 2 views to decide the return type of these methods. The first approach could be to return a boolean indicating whether the operation is successful or not and the other apporach is to return void but throw an exception if anything goes wrong.
    Both approaches have their own advantages and drawbacks. Sending a boolean seems to be cleaner but in case of unsuccess caller won't get the exact exception but just a flag. In second apporach, the caller has to rely on try/catch to decide the logical flow.
    I know, there can't be any generic answer to this question but I just wanted to know comments from experts on this or probably some guidelines.
    Thanks and Regards,
    Ashish Arya

    If there is a legitimate reason why your method might not actually do what it should, then use the boolean return value.
    Example: someList.remove("foo") will return false if "foo" is not actually in the list (because remove() simply specifies that it will make sure that the element is not in the list after the call. Since this is fulfilled in this case, there's no case to throw an exception, even if it didn't actually remove anything).
    If the only reason for not doing what it should is some error condition, then throw an exception:
    Example: someList.get(100) will throw an exception, when the list has less than 101 elements.

  • About return type and parameter type in IDL

    I don't know how to define return type and parameter type in
    operations in a module which are not listed in predefined in
    IDL. can I define these types as java class?
    can someone help me where a tutorial about this in detail can
    be found?
    thanks a lot

    My understanding is that if something is not in the IDL definition, then as far as the CORBA system is concerned it doesn't exist.
    Therefore any methods you create in a class that implements an IDL defined interface, that are outside that interface, are completely free and outside the CORBA system.
    The parameters and return types of these 'local native' methods should be java classes. All methods and variables outside the IDL spec will only be visible to the local JVM.
    ciao
    Jim
    PS - there is a zip file containing a very long and fairly messy demo of this behaviour at http://clio.mit.csu.edu.au/subjects/itc327/Asg2Demo.zip
    it has an html file which describes using additional non-IDL 'local native' methods for implementing a save/load function

  • This should be easy! How can I change the background colour of my fields?

    Apologies if this has already been posted but nothing has come up via Google nor the Forum search.
    I'm sure this should be easy but it's really doing my head in!
    I have a number of textboxes, dropdown lists, etc within my form - I have set Custom backgrounds on each which are visible within Design View. However, in Preview PDF all the fields have a default blue colour and only change to my Custom backgrounds when you enter the field.
    Is there a way of removing the default colouring of fields so that it's the same as my Custom backgrounds? My Custom backgrounds are 'linear to bottom' so I don't want to just set border.fill.color to one colour.
    Thanks for any help,

    Hi,
    If you include this Javascript in the docReady event of the root node (default "form1").
    app.runtimeHighlight = false;
    This will turn off the field highlight. It doesn't prevent the user from turning back on the highlight, but it will mean that your form opens with the highlight off.
    Hope that helps,
    Niall
    Assure Dynamics

  • Problem with Billing due list, relating to Returns Credits

    Hi
    I have a query/ problem with the billing due list
    I cannot seem to be able to create billing documents via VF04 for Returns credits, only via VF01
    I have changed Billing relevance of Item category REN to be A - Delivery related,
    As we previously had problems with incorrect qty being billed IF returned delivery quantity was different to Returns order quantity   - this resolved the problem but I now cannot create billing via billing due list
    Messsage appears ' delivery type LR cannot be invoiced with billing type F2'
    If i enter billing type RE then the document is not gettting picked up at all
    when Billing relevance of item category was B, order related - all seemed to be working ok
    I have copy controls set up from LR to RE with item category REN, with pricing type G
    Please advise how i can get the Returns to appear in the billing due list
    many thanks for your help
    Tony

    Hi,
    In copy controll VTFL
    LR to F2 at item level
    REN >>> Deatila >>> Put billing quantity as - D delivery related
    Kapil

  • How to add User defined return type in service interface of AppModule

    HI All,
    I am creating service interface using AppModule. Added custom method with Java primitives and working fine. Now i want to added custom method with return type is EMP object means user defined object. How can i do so?
    Thanks in advance.

    I looked it up in the mean time ...
    The docs state that you only can use simple data type or java.util.list or AttributeList (which is a wrapper for any viewRow). So I guess you have to somehow flatten your complex data type or create a custom VO which holds it.
    http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcextservices.htm#CJAEHFJD
    Scroll down to 11.2.3
    Timo

  • It should be easier to change the default copyright company in Application Builder

    It should be easier to change the default copyright company in Application Builder.  
    I got the following from NI support to change the name of the company that is copyrighting the software.
    1. To show the desired hidden folder, you must select Tools>> Folder Options >> View >> Under 'Files and Folders'>> 'Hidden files and folders' >> check the 'Show hidden files, folders, or drives' >> Select 'ok'
    2. Navigate to C:\ProgramData
    3. Open ProgramData >> National Instruments >> LVProductDLLInfo >> 12.0.0 >>LabVIEW_ADE_120000.ini   ***Please note that the folder 12.0.0 may instead be 14.1.0 or another numeric value based on which version of LabVIEW you are using***
    4. Change the RegisteredOrganization and RegisteredOwner to the appropriate organization and owner respectively.
    The fix NI support sent me was to change the name of the current software owner.
    The company that owns the software is usually writing the program for another company that is paying to have it developed. If the software owner is not careful they may assign the copyright to their company or to the company that they developed software for last.   I am sure that the company that had software developed will be surprised if their name is not listed as the legal copyright owner.
    Stan

    I've found it now (sheepishly). It is a parameter defined in Home->Application Builder->Application 693->Application Attributes->Edit Definition. I thought it was using the database nls parameters, but it isnt. So I simply had to change the parameter value from $ to £.

  • Error 136 Functions that can be compossed must declare a return type

    Hello,
    I have downloaded the EF Final Release driver and Im working with Oracle 11g express.
    I have the following Procedure:
    PROCEDURE ProductosPedido(
    Datos Out SYS_RefCursor) IS
    BEGIN
    OPEN Datos FOR
    SELECT Nombre,
    TO_NUMBER(Precio * (SELECT SUM(unidades)
    FROM DETALLES_PEDIDO
    WHERE PRODUCTO = PRODUCTO.ID)) Importe
    FROM PRODUCTO;
    END;
    And the following config section:
    <oracle.dataaccess.client>
    <settings>
    <add name="System.Productospedido.RefCursor.Datos" value="implicitRefCursor bindinfo='mode=Output'"/>
    <add name="System.Productospedido.RefCursorMetaData.Datos.Column.0" value="implicitRefCursor metadata='ColumnName=Nombre;BaseColumnName=Nombre;BaseSchemaName=System;BaseTableName=Producto;NativeDataType=nvarchar2;ProviderType=NVarchar2;DataType=System.String;ColumnSize=50;AllowDBNull=true;IsKey=false'" />
    <add name="System.Productospedido.RefCursorMetaData.Datos.Column.1" value="implicitRefCursor metadata='ColumnName=Importe;NativeDataType=number;ProviderType=Decimal;DataType=System.Decimal;AllowDBNull=false;IsKey=false;ColumnSize=8'" />
    </settings>
    </oracle.dataaccess.client>
    I have imported succesfully in my EF Model, but when I try to consume the Procedure it gives me Error 136 Functions that can be compossed must declare a return type
    Any solutions?
    Thanks and best regards!

    A stored procedure does not have a ReturnType, therefore IsComposable="false" and it cannot be used in LINQ queries.
    This limitation is imposed by EF and not by ODP.
    You may want to create a stored function which has a ReturnType ref cursor, and include this stored function into your model. Then, under the same namespace, you create a class with a "stub" method/function and use EdmFunction() to map this stub to the stored function. For example,
    class myFuncClass
    [EdmFunction("Model.Store", "MY_STORED_FUNC_1")]
    public static <your_complex_type_or_DbDataRecord> MyFunc_1(int? column1, ...)
    throw new NotSupportedException("Direct calls are not supported");
    You should be able to call myFuncClass.MyFunc_1(x) in your LINQ query. Your stored function MY_STORED_FUNC_1 will be called in the generated query.

Maybe you are looking for