KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonicsystems > jarjar > MainProcessor


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

20
21 package com.tonicsystems.jarjar;
22
23 import com.tonicsystems.jarjar.util.*;
24 import java.util.*;
25 import java.io.IOException JavaDoc;
26
27 class MainProcessor implements JarProcessor
28 {
29     private boolean verbose;
30     private JarProcessor chain;
31     
32     public MainProcessor(List patterns, boolean verbose) {
33         this.verbose = verbose;
34         List zapList = new ArrayList();
35         List killList = new ArrayList();
36         List ruleList = new ArrayList();
37         for (Iterator it = patterns.iterator(); it.hasNext();) {
38             PatternElement pattern = (PatternElement)it.next();
39             if (pattern instanceof Zap) {
40                 zapList.add(pattern);
41             } else if (pattern instanceof Rule) {
42                 ruleList.add(pattern);
43             } else if (pattern instanceof DepKill) {
44                 killList.add(pattern);
45             }
46         }
47         Rules rules = new RulesImpl(ruleList, verbose);
48         chain = new JarProcessorChain(new JarProcessor[]{
49             ManifestProcessor.getInstance(),
50             new ZapProcessor(zapList),
51             new JarTransformerChain(new ClassTransformer[]{
52                 new DepKillTransformer(killList),
53                 new PackageTransformer(rules),
54             }),
55             new ResourceProcessor(rules),
56         });
57     }
58
59     public boolean process(EntryStruct struct) throws IOException JavaDoc {
60         String JavaDoc name = struct.name;
61         boolean result = chain.process(struct);
62         if (verbose) {
63             if (result) {
64                 if (name.equals(struct.name)) {
65                     System.err.println("Renamed " + name + " -> " + struct.name);
66                 }
67             } else {
68                 System.err.println("Removed " + name);
69             }
70         }
71         return result;
72     }
73 }
74
Popular Tags