View Javadoc

1   package net.sf.jhunlang.jmorph.factory;
2   
3   import java.util.List;
4   import java.util.LinkedList;
5   
6   import java.io.IOException;
7   import java.io.File;
8   
9   import java.net.MalformedURLException;
10  import java.net.URL;
11  
12  import net.sf.jhunlang.jmorph.parser.AbstractReader;
13  import net.sf.jhunlang.jmorph.parser.ParseException;
14  
15  public class Definition
16  {
17    // url where this definition has been read from
18    protected URL baseUrl;
19    // the url this definition should read from
20    protected URL url;
21    // the encoding of url
22    protected String encoding;
23    // reader url should be read with
24    protected AbstractReader reader;
25  
26    protected List extension = new LinkedList();
27  
28    public Definition(URL url, String encoding, AbstractReader reader)
29    {
30      this.url = url;
31      this.encoding = encoding;
32      this.reader = reader;
33      reader.setDefinition(this);
34    }
35    
36    public Definition(
37      URL baseUrl, URL url, String encoding, AbstractReader reader)
38    {
39      this(url, encoding, reader);
40      this.baseUrl = baseUrl;
41    }
42    
43  
44    public URL getBaseURL()
45    {
46      return baseUrl;
47    }
48  
49    public URL getURL()
50    {
51      return url;
52    }
53    
54    public URL getFileURL(String file)
55      throws MalformedURLException
56    {
57      return baseUrl == null ? new File(file).toURL() : new URL(baseUrl, file);
58    }
59    
60    public AbstractReader getReader()
61    {
62      return reader;
63    }
64  
65    public void addExtensionLine(String line)
66    {
67      extension.add(line);
68    }
69  
70    public List getExtensionLines()
71    {
72      return extension;
73    }
74  
75    public Object read()
76      throws IOException, ParseException
77    {
78      return reader.read(url, encoding);
79    }
80  
81    public String toString()
82    {
83      return "Definition[" + url + ", " + encoding + ", " +
84        reader.getClass() + "]";
85    }
86  }