KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > techstack > Publisher


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi.inspectors.techstack;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import javax.xml.transform.TransformerException JavaDoc;
30
31 import org.apache.xpath.CachedXPathAPI;
32 import org.w3c.dom.Element JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34 import org.w3c.dom.traversal.NodeIterator;
35
36 import com.pavelvlasov.xml.dom.DomSerializable;
37
38 /**
39  * @author Pavel Vlasov
40  * @version $Revision: 1.1 $
41  */

42 public class Publisher extends Licensor {
43     
44     public Publisher(TechStack stack) {
45         super(stack);
46     }
47     
48     public Publisher(TechStack stack, Element JavaDoc holder, CachedXPathAPI cxpa) throws TransformerException JavaDoc {
49         super(stack, holder, cxpa);
50         NodeIterator nit = cxpa.selectNodeIterator(holder, "product");
51         Node JavaDoc n;
52         while ((n=nit.nextNode())!=null) {
53             new Product(stack, this, (Element JavaDoc) n, cxpa);
54         }
55     }
56         
57     private Collection JavaDoc products=new ArrayList JavaDoc();
58     
59     void addProduct(Product product) {
60         products.add(product);
61         
62     }
63     
64     public void toDom(Element JavaDoc holder) {
65         super.toDom(holder);
66         Iterator JavaDoc it=products.iterator();
67         while (it.hasNext()) {
68             ((DomSerializable) it.next()).toDom(addElement(holder, "product"));
69         }
70     }
71     
72     /**
73      * Matches package name and adds clients if matched
74      * @param packageName
75      * @param clients
76      * @return true if matched.
77      */

78     public boolean match(String JavaDoc packageName, Collection JavaDoc clients) {
79         Iterator JavaDoc it=products.iterator();
80         while (it.hasNext()) {
81             Product product=(Product) it.next();
82             if (product.match(packageName, clients)) {
83                 return true;
84             }
85         }
86         return false;
87     }
88     
89     /**
90      * Matches package with publisher prefix and returns 'product' part of package.
91      * @param packageName
92      * @return
93      */

94     public String JavaDoc[] match(String JavaDoc packageName) {
95         Iterator JavaDoc it=packages.iterator();
96         while (it.hasNext()) {
97             String JavaDoc pn=(String JavaDoc) it.next();
98             if (pn.equals(packageName)) {
99                 return new String JavaDoc[] {packageName, null};
100             } else if (packageName.startsWith(pn+".")) {
101                 int idx=packageName.indexOf('.', pn.length()+1);
102                 if (idx==-1) {
103                     return new String JavaDoc[] {pn, packageName.substring(pn.length()+1)};
104                 } else {
105                     return new String JavaDoc[] {pn, packageName.substring(pn.length()+1, idx)};
106                 }
107             }
108         }
109         return null;
110     }
111 }
112
Popular Tags