KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > export > ExportAC


1 /*
2   Copyright (C) 2003-2004 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.export;
19
20 import java.io.File JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.FileWriter JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.io.Writer JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import org.objectweb.jac.core.AspectComponent;
28 import org.objectweb.jac.core.NameRepository;
29
30 public class ExportAC extends AspectComponent implements ExportConf {
31     HashSet JavaDoc roots = new HashSet JavaDoc();
32
33     NameRepository nr;
34     public ExportAC() {
35         nr = (NameRepository)NameRepository.get();
36     }
37
38     /**
39      * Declare some objects as roots to start exporting from.
40      * @param nameExpr a regular expression matching the name of root objects
41      */

42     public void addRoot(String JavaDoc nameExpr) {
43         roots.add(nameExpr);
44     }
45
46     HashSet JavaDoc allow = new HashSet JavaDoc();
47     public void allowExport(String JavaDoc classExpr) {
48         allow.add(classExpr);
49     }
50
51     HashSet JavaDoc deny = new HashSet JavaDoc();
52     public void denyExport(String JavaDoc classExpr) {
53         deny.add(classExpr);
54     }
55
56     public static final String JavaDoc DEFAULT_ENCODING = "UTF-8";
57
58     /**
59      * Exports all objects to a stream
60      *
61      * @param out stream to export to
62      * @param encoding charset encoding to use (UTF-8 ,iso-8859-1,...)
63      *
64      * @see #export(OutputStream)
65      * @see #export(File)
66      * @see #export(File,String)
67      */

68     public void export(OutputStream JavaDoc out, String JavaDoc encoding) throws IOException JavaDoc {
69         Exporter exporter = new Exporter(roots,allow,deny);
70         exporter.export(out, encoding);
71     }
72
73     /**
74      * Exports all objects to a stream with the default charset
75      * encoding, which is UTF-8.
76      *
77      * @param out stream to export to
78      *
79      * @see #export(OutputStream,String)
80      * @see #export(File)
81      * @see #export(File,String)
82      */

83     public void export(OutputStream JavaDoc out) throws IOException JavaDoc {
84         export(out,DEFAULT_ENCODING);
85     }
86
87     /**
88      * Exports all objects to a file with the default charset
89      * encoding, which is UTF-8.
90      *
91      * @param file file to export to
92      *
93      * @see #export(File,String)
94      * @see #export(OutputStream)
95      * @see #export(OutputStream,String)
96      */

97     public void export(File JavaDoc file) throws IOException JavaDoc {
98         export(file,DEFAULT_ENCODING);
99     }
100
101
102     /**
103      * Exports all objects to a file with the default charset
104      * encoding, which is UTF-8.
105      *
106      * @param file file to export to
107      * @param encoding charset encoding to use (UTF-8 ,iso-8859-1,...)
108      *
109      * @see #export(File)
110      * @see #export(OutputStream)
111      * @see #export(OutputStream,String)
112      */

113     public void export(File JavaDoc file, String JavaDoc encoding) throws IOException JavaDoc {
114         FileOutputStream JavaDoc writer = new FileOutputStream JavaDoc(file);
115         try {
116             export(writer,encoding);
117         } finally {
118             writer.close();
119         }
120     }
121 }
122
Popular Tags