View Javadoc

1   /*
2    * $Id: Base.java,v 1.11 2005/03/29 15:07:42 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   package com.bbn.swede.core.dom;
9   
10  import com.bbn.swede.core.IOWLDocument;
11  import com.hp.hpl.jena.rdf.arp.MalformedURIException;
12  
13  /***
14   * Custom attribute node implementation for xml:base.
15   * @author jlerner
16   */
17  public class Base extends AttributeNode
18  {
19     /***
20      * Creates a Base node.
21      * @param sValue The value of the attribute.
22      */
23     public Base(String sValue)
24     {
25        super(sValue);
26        //Don't set document URI here - it should be handled by init once
27        //the tree is fully built
28  //      setDocumentURI();
29     }
30  
31     /***
32      * Sets the containing document's URI to match the value of its xml:base.
33      */
34     protected void setDocumentURI()
35     {
36        IOWLDocument doc = (IOWLDocument) getOWLDocument();
37        if (doc == null)
38        {
39           return;
40        }
41        try
42        {
43           doc.setURI(getValue());
44        }
45        catch (MalformedURIException e)
46        {
47           //TODO: place some kind of marker indicating that the xml:base attribute is invalid
48           e.printStackTrace();
49        }
50     }
51  
52     /*
53      *  (non-Javadoc)
54      * @see com.bbn.swede.core.dom.OASTNode#getNodeType()
55      */
56     public int getNodeType()
57     {
58        return OASTNode.BASE;
59     }
60  
61     /*
62      *  (non-Javadoc)
63      * @see com.bbn.swede.core.dom.OASTNode#getQName()
64      */
65     public String getQName()
66     {
67        return "xml:base";
68     }
69  
70     /*
71      *  (non-Javadoc)
72      * @see com.bbn.swede.core.dom.OASTNode#init()
73      */
74     protected void init()
75     {
76        super.init();
77        setDocumentURI();
78     }
79  
80     /*
81      *  (non-Javadoc)
82      * @see com.bbn.swede.core.dom.OASTNode#cleanup()
83      */
84     protected void cleanup()
85     {
86        super.cleanup();
87        IOWLDocument doc = (IOWLDocument) getOWLDocument();
88        if (doc != null)
89        {
90           try
91           {
92              doc.setURI(null);
93           }
94           catch (MalformedURIException e)
95           {
96              //non-error, just keeping the compiler happy
97           }
98        }
99     }
100 
101 }