KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import javax.xml.transform.TransformerException JavaDoc;
29
30 import org.apache.xpath.CachedXPathAPI;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * @author Pavel Vlasov
35  * @version $Revision: 1.1 $
36  */

37 public class Product extends Licensor {
38
39     private Publisher publisher;
40     
41    public Product(TechStack stack, Publisher publisher) {
42         super(stack);
43         this.publisher=publisher;
44         publisher.addProduct(this);
45     }
46     
47     /**
48      * @param holder
49      * @param cxpa
50      * @throws TransformerException
51      */

52     public Product(TechStack stack, Publisher publisher, Element JavaDoc holder, CachedXPathAPI cxpa) throws TransformerException JavaDoc {
53         super(stack, holder, cxpa);
54         this.publisher=publisher;
55         publisher.addProduct(this);
56         this.stack=stack;
57         ignore="yes".equals(holder.getAttribute("ignore"));
58     }
59     
60     public void addClient(String JavaDoc client) {
61         if (!ignore) {
62             super.addClient(client);
63             getLicense().addClient(client);
64             publisher.addClient(client);
65         }
66     }
67     
68     private boolean ignore;
69
70     public boolean isIgnore() {
71         return ignore;
72     }
73     public void setIgnore(boolean ignore) {
74         this.ignore = ignore;
75     }
76     
77     public void toDom(Element JavaDoc holder) {
78         super.toDom(holder);
79         holder.setAttribute("ignore", ignore ? "yes" : "no");
80     }
81     
82     /**
83      * @param packageName
84      * @return Matched package name or null
85      */

86     public boolean match(String JavaDoc packageName, Collection JavaDoc clients) {
87         Iterator JavaDoc it=packages.iterator();
88         while (it.hasNext()) {
89             String JavaDoc pn=(String JavaDoc) it.next();
90             if (pn.equals(packageName) || packageName.startsWith(pn+".")) {
91                 Iterator JavaDoc cit=clients.iterator();
92                 while (cit.hasNext()) {
93                     addClient((String JavaDoc) cit.next());
94                 }
95                 return true;
96             }
97         }
98         return false;
99     }
100
101     public BasicDescriptor getLicense() {
102         BasicDescriptor ret=super.getLicense();
103         return ret==null ? publisher.getLicense() : ret;
104     }
105
106     public void addClients(Collection JavaDoc clients) {
107         Iterator JavaDoc it=clients.iterator();
108         while (it.hasNext()) {
109             addClient((String JavaDoc) it.next());
110         }
111         
112     }
113 }
114
Popular Tags