Possible to overwrite parse method in DOM with SAX Handler?

Hi,
Is it possible to overwrite the parse method within DOM?
What a want to do is:
     private Node parseXml( String text ) throws SAXParseException, SAXException, IOException, ParserConfigurationException
          SAXParserFactory factory = SAXParserFactory.newInstance();
               factory.setNamespaceAware(true);
               SAXParser parser = factory.newSAXParser();
               TestHandler handler = new TestHandler();
               // Parse the file
               parser.parse(new InputSource(new StringReader(text)), handler);
          return (Node)handler.getRoot();
     } //end parseXml()The reason I want to use this is that within SAX I can write my own line counter so I keep a count of which node is on which line of text.
What I was thinking is that I could use SAX to return DOM Nodes with the line number attached, possibly using the node.setUserData() method?!
I have tried to play around with it and it doen't seem to work, can anyone help?
Cheers Alex

I have managaed to re-write my SAX parser to create a JTree, this works perfectly I can move through the tree and each line of text that corresponds to the node is highlighted.
My problem is however that in my application I have used the DOM structure throughout so some of the functionality is lost.
Is I understand that JAXP uses both SAX and DOM together, so I was wondering if it is possible to combine my sax parse method within the DOM?
If anything is unclear please say and I will try and explain better. The main reason for doing this is that I want to keep a reference to which line of text each node of the dom tree represents. I have not been able to implemnet one in DOM however using SAX I have managed.
Many thanks,
Alex

Similar Messages

  • Can I parse non-wellformed XML with SAX at all?

    Hi all,
    i was wondering whether its possible at all to parse XML that is not well formed with SAX.
    e.g. A HTML file that doesnt close tags and stuff like that.
    I tried implementing the fatal() method of the Handler in a a way that it consumes the exception but does not rethrow it.
    Also I tried setting the validation property to false. Both with no success.
    Any help would be appriciated.
    thx
    philipp

    Your experiments tell you the answer.
    If you have HTML tag soup, why not just run it through JTidy or HTMLTidy to make it into well-formed XHTML?

  • Is it possible to overwrite an entire iPhoto library with one photo?

    I was doing a routine download of a photo from my e-mail to my iPhoto library and pressed the "save to iPhoto".
    I then went into iPhoto (I have version 08) and all of my event folders appeared...then suddenly gray boxes started appearing and everything disappeared.
    When I went in to open iPhoto again I received a message to the effect of cannot find. We have created a new iPhoto but cannot find any of the photos in our library anywhere in searching our hard drive. Have tried all the search functions (including putting in jpg names of actual photos) and nothing is turning up. When I go into the data files - the photos are not in there. Is it possible to have somehow wiped out our entire collection of about 3000 photos? Unfortunately we did not have a back-up hard drive.....
    I tried following some of the advice posted for iPhoto losses and gray boxes appearing...however none of them work.
    Am finding it hard to believe that could have wiped out our entire collection by saving one photo? Was using iPhoto and saving a photo from the e-mail in the way I have been doing for months.
    Any advice tips would be greatly appreciated?!
    In disbelief over the possibility of entirely wiping out our collection!

    dmck;
    Welcome to the Apple Discussions.
    We have created a new iPhoto
    Do you mean you create a new iPhoto Library? How did you go about doing so? There is a possibility that you could have created a new library and overwritten the old one, thus the one library with only one photo in it. It's iffy but might have been accomplished.
    Happy New Year
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Regarding DocumentBuilder.parse method returns reference as null value.

    Hi
    We are in the process of migrating code which works on WebSphere/JBOSS to WLS..
    We are using DocumentBuilder object for parsing the Locale related xml data. I understand that the DocumentBuilder is provided by DocumentBuilderFactory which is an interface whose implementation is server specific.
    But when the Document Builder parse method is called with a valid file path, we are getting System.Out of doc.getFirstChild().getLocalName() as null (which ideally should have been the name of the first node). No Errors are observed .
    For WLS, the parser is giving the document object reference as null whereas in other servers like Websphere and JBOSS we are able to parse the same xml with proper object reference.
    Could you please help in this regard?
    Thanks and regards
    Anil

    Hi Vmotamar,
    If you think that the parsers available as part of WebLogic are causing the issues, Then you can use your Own Parsers while migrating to WebLogic Server. I mean Get the Parser Jar files which u used as part of JBoss or WebSphere and put it inside the "APP-INF\lib" directory of your EAR Application or Put them inside "WEB-INF\lib" of your WEBApplication...and then Apply ClassLoader Filtering feature provided by WebLogic ...which allows an application to use It's Own Jars\Classes ...
    Please refer to: http://forums.oracle.com/forums/thread.jspa?threadID=1109267&tstart=150 and in http://weblogic-wonders.com/weblogic/parsers_issues
    Thanks
    Jay SenSharma
    http://weblogic-wonders.com/weblogic/parsers_issues/ (WebLogic Wonders Are Here)

  • NullPointerException with SAX

    I have developed a CSV to XML parser using a JAXP with SAX Events to parse the CSV file into a DOM tree.
    Well inside the parse() method I have the following code":
    public void parse(InputSource input) throws IOException, SAXException
    BufferedReader br = null;
    if( input.getCharacterStream() != null )
    br = new BufferedReader( input.getCharacterStream() );
    else if( input.getByteStream() != null )
    br = new BufferedReader( new InputStreamReader( input.getByteStream() ) );
    else if( input.getSystemId() != null )
    URL url = new URL( input.getSystemId() );
    br = new BufferedReader( new InputStreamReader( url.openStream() ) );
    else
    throw new SAXException( "Objeto InputSource invalido" );
    ContentHandler ch = getContentHandler();
    ch.startDocument();
    ch.startElement( "", "", "file", new AttributesImpl() );
    this.parseInput( br );
    ch.endElement( "", "", "file" );
    ch.endDocument();
    Problem is that whenever the app gets to the ch.startDocument() statement it throws an java.lang.NullPointerExecption. I have no idea why this is happening, I have tested the very same code with Xalan 2 and Xercer 2 parsers and it works without problems. But using the oracle xml parser v2 throws the Exception.
    Is this a bug? should I set tome of the Transformer's attributes to an specifica value to avoid this? Where could I find more info on processing SAX events?
    Thanks,
    Fedro

    Fedro,
    Did you try it using XDK v10?

  • CL_BSP_UTILITY DOWNLOAD with delta handling

    Hi Experts,
    I use the method cl_bsp_utility=>download in the do_handle_event of a subcontroller.
    For the main controller delta handling is swiched on. (In this download method the navigation->complete is executed)
    After the do_handle_event of the subcontroller the method CL_BSP_CTRL_ADAPTER->do_request is executed. In this method some javascript coding will be append to my response data:
    parent.bspDH_newDelta("864D5C4A1F20A60FE1000000AC13AA25");
    parent.bspDH_newDeltaLoaded();
    It cones from the following statement:
    Tail part of delta handling
    IF delta_handling IS NOT INITIAL.
       mdelta_handler->PAGE_END(  ).
    ENDIF.
    The outcome is that it's not possible to open my downloaded files. Only txt files can be opened but with the javasript code in it...
    Any ideas? or is it in general not possible to use the download function together with delta handling?
    Thanks, Markus
    Edited by: Markus Doell on Jul 14, 2009 1:42 PM

    Hi,
    Try the below code in place of the cl_bsp_utility=>download.
    DATA:  L_APP_TYPE  TYPE STRING,
             L_FILENAME  TYPE STRING,
             L_XSTRING   TYPE XSTRING,    "needed for HTTP response
             L_XLEN       TYPE I.
    * Setting Content Type
      MOVE 'application/msexcel' TO L_APP_TYPE.
      MOVE 'attachment; filename=webforms.xls' TO L_FILENAME.
      CLEAR L_XSTRING.
      L_XSTRING = V_XSTRING. " Here you can directly pass your XSTRING
    * Fill HTTP request
      RESPONSE->SET_HEADER_FIELD( NAME  = 'content-type'
                                  VALUE = L_APP_TYPE ).
      RESPONSE->DELETE_HEADER_FIELD(
                          NAME = IF_HTTP_HEADER_FIELDS=>CACHE_CONTROL ).
      RESPONSE->DELETE_HEADER_FIELD(
                          NAME = IF_HTTP_HEADER_FIELDS=>EXPIRES ).
      RESPONSE->DELETE_HEADER_FIELD(
                          NAME = IF_HTTP_HEADER_FIELDS=>PRAGMA ).
      RESPONSE->SET_HEADER_FIELD(
                           NAME  = 'content-disposition'
                           VALUE = L_FILENAME ).
    * finally display XLS format in Browser
      L_XLEN = XSTRLEN( L_XSTRING ).
      RESPONSE->SET_DATA( DATA   = L_XSTRING
                          LENGTH = L_XLEN ).
      NAVIGATION->RESPONSE_COMPLETE( ).
    I have used it one of my program and it worked.
    Thanks,
    Sreekanth

  • Adobe Offline Form - Parse method is not possible for this type

    Hi All,
    I have developed an application for the offline scenario of interactive adobe form. I tried to load the adobe form from my desktop. After pressing the button "Display form" it throws an error "Parse method is not possible for this type".
    If I include wdContext.getNodeInfo().getAttribute("pdfObject").getModifiableSimpleType() in the doInit() method of the view I receive this error -
    com.sap.tc.webdynpro.progmodel.context.ContextException: MappedAttributeInfo(UploadView.pdfObject): must not modify the datatype of a mapped attribute
    When I comment it out and upload I receive the error enclosed -
    Parse method is not possible for this type
    Can someone please help me with a step by step solution to this problem?
    Any help is highly appreciated.
    Many thanks,
    Divya

    Hi Divya,
    Please try to do it as stated below:
         IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("pdfObject");
         ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
         IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)type;
    Try putting the code in wdInit() or wdDoModifyView().
    Let me know if you still face the issue.
    Regards,
    Arafat

  • Parse method is not possible for this type

    I have a file upload component and one button in a view.
    I have created a binary type context element and mapped it with fileupload component.while clicking the submit button I am getting " Parse method is not possible for this type" exception.
    help me out.
    Thanks In advance

    Hi,
    Thanks for your response. I have written the following code in wddoinit():     
    IWDAttributeInfo attributeinfo = wdContext.getNodeInfo().getAttribute(IPrivateSubstanceDocView.IFileUpload02Element.DATA);
        attributeinfo.getModifiableSimpleType();
    fileUpload02 is my context.
    but I am getting a null pointer exception over here.
    can ypu please help it.
    Actually the case is this is a window, which is opening on click of a hyperlink on another View.
    With the action method I am calling this View.
    Thus on click of a hyperlink just I am opening a new  View then here I am a browse button etc...
    PLease help if you can

  • Parse method is not possible for this type Exception in web dynpro

    I have a file upload component and one button in a view.
    I have created a binary type context element and mapped it with fileupload component.while clicking the submit button I am getting " Parse method is not possible for this type" exception.
    help me out.

    Hi sridhar,
    Use this code for Upload
    context u create one attribute(up),u assign the data type as "Resource"(which is dictionary type)
    InputStream text = null;
        int temp = 0;
        try
             File file = new File(wdContext.currentContextElement().getUp().getResourceName());
             FileOutputStream op = new FileOutputStream(file);
             if(wdContext.currentContextElement().getUp()!=null)
                  text = wdContext.currentContextElement().getUp().read(false);
                   while((temp=text.read())!=-1)
                                                                       op.write(temp);
             op.flush();
             op.close();
        catch(Exception e)
         e.printStackTrace();   

  • Syntax Error with JSON.Parse method to parse SharePoint List Items

    Hi All,
    I want to get SharePoint List data and bind that retrived data to the JQuery Grid Control.
    For this I used SPServices to get the SharePoint List data in SOAP Envelope. Now I need to parse the soap envelope and store the retrieved items in array to pass it to the Grid Control.
    While using the JSON.Parse(resporseText) method, Iam consistenly getting an Syntax Error!
    Could anyone help me with this ?
    Please find the SOAP Envelope I received from SP List as below:
    "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
    <rs:data ItemCount="2">
    <z:row ows_OBNumber='112211.000000000' ows_Project_x0020_Name='Project 1' ows_MetaInfo='11;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 1' ows_ID='11' ows_UniqueId='11;#{FBBCBCF9-666D-42F9-92D7-67188C51BC9B}' ows_owshiddenversion='1' ows_FSObjType='11;#0' ows_Created='2015-01-12 10:25:06' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:25:06' ows_FileRef='11;#sites/Lists/Projects/11_.000' />
    <z:row ows_OBNumber='1122343.00000000' ows_Project_x0020_Name='Project 2 ' ows_MetaInfo='12;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 2' ows_ID='12' ows_UniqueId='12;#{0D772B76-68E4-4769-B6FF-6A269F9C7ABD}' ows_owshiddenversion='1' ows_FSObjType='12;#0' ows_Created='2015-01-12 10:33:48' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:33:48' ows_FileRef='12;#sites/Lists/Projects/12_.000' />
    </rs:data>
    </listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>"
    Any help on this will be greatly appreciated.
    Thanks In Advance.!

    Hi,
    According to your description, there is an issue when parsing result from the data retrieved using SPServices.
    By default, SPServices returns data as XML format, however, the JSON.parse() method “Throws a SyntaxError exception if the string to parse is not valid JSON”:
    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
    To extract the data needed from the response, you can either take the demo below for as a reference:
    http://spservices.codeplex.com/wikipage?title=GetListItems
    Or use the jQuery.parseXML() function:
    http://api.jquery.com/jquery.parsexml/
    Best regards
    Patrick Liang
    TechNet Community Support

  • How can I use a 3rd party XML parser such as xerces with OC4J ?

    Hi all tech experts,
    I am using Oracle Application Server 10g Release 2 (10.1.2) and i have
    installed Portal and Wireless and OracleAS Infrastructure on the same
    computer.
    i tried all the solutions on this thread
    Use of Xerces Parser in out application with Oracle App Server 9.0.4
    but still fighting.
    I have also posted this query on OTN on following thread
    How can I use a 3rd party XML parser such as xerces with OC4J?
    but no reply....
    Please help me on this issue.
    Since OC4J is preconfigured to use the Oracle XML parser which is xmlparserv2.jar.
    i have read the following article which states that
    OC4J is preconfigured to use the Oracle XML parser. The Oracle XML parser is fully JAXP 1.1 compatible and will serve the needs of applications which require JAXP functionality. This approach does not require the download, installation, and configuration of additional XML parsers.
    The Oracle XML parser (xmlparserv2.jar) is configured to load as a system level library of OC4J through it's inclusion as an entry in the Class-Path entry of the oc4j.jar Manifest.mf file. This results in the Oracle XML parser being used for all common deployment and packaging situations. You are not permitted to modify the Manifest.mf file of oc4j.jar.
    It must be noted that configuring OC4J to run with any additional XML parser or JDBC library is not a supported configuration. We do know customers who have managed to successfully replace the system level XML parser and the Oracle JDBC drivers that ship with the product, but we do not support this type of configuration due to the possibility of unexpected system behavior and system errors that might occur from replacing the tested and certified libraries.
    If you absolutely must use an additional XML parser such as xerces, then you have to start OC4J such that the xerces.jar file is loaded at a level above the OC4J system classpath. This can be accomplished using the -Xbootclasspath flag of the JRE.
    i have also run the following command
    java -Xbootclasspath/a:d:\xerces\xerces.jar -jar oc4j.jar
    but no success.
    How could i utilize my jar's like xerces.jar and xalan.jar for parsing instead of OC4J in-built parser ?
    All reply will be highly appreciated.
    Thnx in advance to all.
    Neeraj Sidhaye
    try_catch_finally @ Y !

    Hi Neeraj Sidhaye,
    I am trying to deploy a sample xform application to the Oracle Application Server (10.1.3). However, I encountered the class loader issue that is similar to your stuation. I tried all the three solutions but the application is still use the Oracle xml paser class. I am wondering if you have any insight about this?
    Thanks for your help.
    Xingsheng Qian
    iPass Inc.
    Here is the error message I got.
    Message:
    java.lang.ClassCastException: oracle.xml.parser.v2.XMLElement
    Stack Trace:
    org.chiba.xml.xforms.exception.XFormsException: java.lang.ClassCastException: oracle.xml.parser.v2.XMLElement
         at org.chiba.xml.xforms.Container.dispatch(Unknown Source)
         at org.chiba.xml.xforms.Container.dispatch(Unknown Source)
         at org.chiba.xml.xforms.Container.initModels(Unknown Source)
         at org.chiba.xml.xforms.Container.init(Unknown Source)
         at org.chiba.xml.xforms.ChibaBean.init(Unknown Source)
         at org.chiba.adapter.servlet.ServletAdapter.init(ServletAdapter.java:153)
         at org.chiba.adapter.servlet.ChibaServlet.doGet(ChibaServlet.java:303)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:299)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:187)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.ClassCastException: oracle.xml.parser.v2.XMLElement
         at org.chiba.xml.xforms.Instance.iterateModelItems(Unknown Source)
         at org.chiba.xml.xforms.Bind.initializeModelItems(Unknown Source)
         at org.chiba.xml.xforms.Bind.init(Unknown Source)
         at org.chiba.xml.xforms.Initializer.initializeBindElements(Unknown Source)
         at org.chiba.xml.xforms.Model.modelConstruct(Unknown Source)
         at org.chiba.xml.xforms.Model.performDefault(Unknown Source)
         at org.chiba.xml.xforms.XFormsDocument.performDefault(Unknown Source)
         at org.chiba.xml.xforms.XFormsDocument.dispatchEvent(Unknown Source)
         at org.apache.xerces.dom.NodeImpl.dispatchEvent(Unknown Source)
         ... 18 more

  • Is there any possibility to combine XPath with SAX in Java?

    HI Gentlemen,
    I have an XML instance to parse. One solution works with XPath and Document builder. However, the tree in memory is too big so that I can not build it in my storage (8 GB). Does anyone of you know a method where I use an XPath expression (Java) to select a node but with a better parser (e g SAX) which is not so space hungry? Direct access of nodes is obligatory.
    Thanks, kind regards from
    Miklos HERBOLY

    As SAX  parsers do not build a DOM structure and XPath requires a DOM structure to select elements from, XPath is not usable with SAX, but some analysers support setting the XPath expressions to analyse before invoking the SAX parser and provide the result for XPath expressions.
    Refer
    https://code.google.com/p/xpath4sax/

  • JAXP & DOM with Namespaces

    A quick question: when an XML document using a namespace is parsed into a DOM tree, is Element.getNodeName() supposed to return the tag name of the element with or without the namespace prefix? Also, does Element.getElementsByTagName() follow the same standard?
    When I use the Oracle XML Parser through JAXP, Element.getNodeName() returns the namespace prefix along with the name, but Element.getElementsByTagName(String name) requires that I leave off the namespace prefix. When I use the default parser included with Java 1.4.1, the behavior is different. Does anyone know what the correct behavior is?

    The XML DOM core specification can be found here: http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20021022/core.htm
    From that, it looks like Nodes have separate fields for namespace and name, so I would lean towards there having to be separate accessors as well, so getNodeName() should not return the namespace. That should be handled by getNamespaceURI(). Although, that returns the URI, not the alias, but I don't think an alias is used in any other method anyways.
    Also, there is a getElementsByTagNameNS which allows searching for tags within a given namespace, so I would say that getElementsByTagName behaves as it should.

  • Parse siblings in DOM

    Hi,
    HELP!!!
    I went through all the possible help code from the net which tells me how to access the value/child of a tag.
    But what I need is to access the column values for each table. There are several tables in this xml file. So, I search for the table name through getElementsByTagName(), then I need to parse for the column-names. I'm not able to make it work with getNextSibling().
    <table-name>hist_client</table-name>
    <data-element>                    
    <column-name>camp_id</column-name>
    <column-name>ccr_id</column-name>
    <column-name>record_id</column-name>
    <column-name>record_num</column-name>
    </data-element>
    -thanx

    Hey Sai,
    Thanx.
    I believe I'm using the DOM parser. My code is very similar to this first program -'Reading the XML':
    http://java.sun.com/webservices/docs/1.0/tutorial/doc/JAXPXSLT5.html
    The article was quite enlightening:
    As opposed to SAX, the DOM specification covers only the tree representation of the XML document. Instantiating and using the parser is not actually covered by DOM itself, and the specific implementation must be named directly in the application code. After the input document has been parsed, the resulting DOM tree can be retrieved from the parser using the getDocument function, which returns a Document instance. The Document interface extends the Node interface and represents the root node of the document. It is then used with the appropriate unmarshaller class, similar to the SAX case.
    I'm probably using the DOM, cos I dont need to do anything more than get info about the nodes.
    Why did u ask? So, where did I go wrong???
    -s

  • Changing exception clause in method signature when overwriting a method

    Hi,
    I stumbled upon a situation by accident and am not really clear on the details surrounding it. A short description:
    Say there is some API with interfaces Foo and Bar as follows:
    public interface Foo {
       void test() throws Exception;
    public interface Bar extends Foo {
       void test();
    }Now, I find it strange that method test() for interface Bar does not need to define Exception in its throws clause. When I first started with Java I was using Java 1.4.2; I now use Java 1.6. I cannot remember ever reading about this before and I have been unable to find an explanation or tutorial on how (or why) this works.
    Consider a more practical example:
    Say there is an API that uses RMI and defines interfaces as follwows:
    public interface RemoteHelper extends Remote {
       public Object select(int uid) throws RemoteException;
    public interface LocalHelper extends RemoteHelper {
       public Object select(int uid);
    }As per the RMI spec every method defined in a Remote interface must define RemoteException in its throws clause. The LocalHelper cannot be exported remotely (this will fail at runtime due to select() in LocalHelper not having RemoteException in its clause if I remember correctly).
    However, an implementing class for LocalHelper could represent a wrapper class for RemoteHelper, like this:
    public class Helper implements LocalHelper {
       private final RemoteHelper helper;
       public Helper(RemoteHelper helper) {
          this.helper = helper;
       public Object select(int id) {
          try {
             return (this.helper.select(id));
          } catch(RemoteException e) {
             // invoke app failure mechanism
    }This can uncouple an app from RMI dependancy. In more practical words: consider a webapp that contains two Servlets: a "startup" servlet and an "invocation" servlet. The startup servlet does nothing (always returns Method Not Allowed, default behaviour of HttpServlet), except locate an RMI Registry upon startup and look up some object bound to it. It can then make this object accessible to other classes through whatever means (i.e. a singleton Engine class).
    The invocation servlet does nothing upon startup, but simply calls some method on the previously acquired remote object. However, the invocation servlet does not need to know that the object is remote. Therefore, if the startup servlet wraps the remote object in another object (using the idea described before) then the invocation servlet is effectively removed from the RMI dependancy. The wrapper class can invoke some sort of failure mechanism upon the singleton engine (i.e. removing the remote object from memory) and optionally throw some other (optionally checked) exception (i.e. IllegalStateException) to the invocation servlet.
    In this way, the invocation servlet is not bound to RMI, there can be a single point where RemoteExceptions are handled and an unchecked exception (i.e. IllegalStateException) can be handled by the Servlet API through an exception error page, displaying a "Service Unavailable" message.
    Sorry for all this extensive text; I just typed out some thoughts. In short, my question is how and why can the throws clause change when overwriting a method? It's nothing I need though, except for the clarity (e.g. is this a bad practice to do?) and was more of an observation than a question.
    PS: Unless I'm mistaken, this is basically called the "Adapter" or "Bridge" (not sure which one it is) pattern (or a close adaptation to it) right (where one class is written to provide access to another class where the method signature is different)?
    Thanks for reading,
    Yuthura

    Yuthura wrote:
    I know it may throw any checked exception, but I'm pretty certain that an interface that extends java.rmi.Remote must include at least java.rmi.RemoteException in its throws clause (unless the spec has changed in Java 1.5/1.6).No.
    A method can always throw fewer exceptions than the one it's overriding. RMI has nothing to do with it.
    See Deitel & Deilte Advanced Java 2 Platform How To Program, 1st Ed. (ISBN 0-13-089650-1), page 793 (sorry, I couldn't find the RMI spec quick enough). Quote: "Each method in a Remote interface must have a throws clause that indicates that the method can throw RemoteException".Which means that there's always a possibility of RemoteException being thrown. That's a different issue. It's not becusae the parent class can throw RE. Rather, it's because some step that will always be followed is declared to throw RE.
    I later also noticed I could not add other checked exceptions, which made sense indeed. Your explanation made perfect sense now that I heard (read) it. But just to humour my curousity, has this always been possible? Yes, Java has always worked that way.
    PS: The overwriting/-riding was a grammatical typo (English is not my native language), but I meant to say what you said.No problem. Minor detail. It's a common mistake, but I always try to encourage proper terminology.

Maybe you are looking for

  • There was an error opening this document. Access denied.

    Greetings, When I did my taxes last year (March 2012), I downloaded some pdf files from the IRS.  Form 1040 was a writable file and I filled it out as needed.  This file was saved on a Vista machine running XP.  A few months ago, I upgraded that pc t

  • Bizarre - iMac shows cog wheel and Apple Logo, ARD shows desktop

    Here's a good one for you. I have two iMacs at home. One of them, a G5 iMac (iSight), had 10.5.1, all the updates, and no external drives or other 3rd party apps to screw things up. Ok, so I did the Apple Software Update to 10.5.2 there and after goi

  • ICloud won't install on Windows 7 PC

    Down loaded iCloud, but won't load on recently new HP Desktop PC running Windows 7. Pop up window states: iCloud Control Panel There is a problem with this windows installer package. A program required for this installation to complete could not be r

  • Creating a document in WCC

    Hi to all I'm fresh in WCC so I don't know how /is there a way / to create a new document /like MS word/ in WCC? I'm looking for solution to create a new document over some kind of form , where user can input some values and according to some templat

  • DWF Codec or Way to Convert DWF to JPG

    I am trying to find anything JAVA API related to reading DWF files so I can convert them to a Raster Format ultimately to be embedded in a PDF along with other data via FOP. All sorts of stuff in the windows platform but not seeing anything for Java.