001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi.inspectors.techstack;
024:
025: import java.util.Collection;
026: import java.util.Iterator;
027:
028: import javax.xml.transform.TransformerException;
029:
030: import org.apache.xpath.CachedXPathAPI;
031: import org.w3c.dom.Element;
032:
033: /**
034: * @author Pavel Vlasov
035: * @version $Revision: 1.1 $
036: */
037: public class Product extends Licensor {
038:
039: private Publisher publisher;
040:
041: public Product(TechStack stack, Publisher publisher) {
042: super (stack);
043: this .publisher = publisher;
044: publisher.addProduct(this );
045: }
046:
047: /**
048: * @param holder
049: * @param cxpa
050: * @throws TransformerException
051: */
052: public Product(TechStack stack, Publisher publisher,
053: Element holder, CachedXPathAPI cxpa)
054: throws TransformerException {
055: super (stack, holder, cxpa);
056: this .publisher = publisher;
057: publisher.addProduct(this );
058: this .stack = stack;
059: ignore = "yes".equals(holder.getAttribute("ignore"));
060: }
061:
062: public void addClient(String client) {
063: if (!ignore) {
064: super .addClient(client);
065: getLicense().addClient(client);
066: publisher.addClient(client);
067: }
068: }
069:
070: private boolean ignore;
071:
072: public boolean isIgnore() {
073: return ignore;
074: }
075:
076: public void setIgnore(boolean ignore) {
077: this .ignore = ignore;
078: }
079:
080: public void toDom(Element holder) {
081: super .toDom(holder);
082: holder.setAttribute("ignore", ignore ? "yes" : "no");
083: }
084:
085: /**
086: * @param packageName
087: * @return Matched package name or null
088: */
089: public boolean match(String packageName, Collection clients) {
090: Iterator it = packages.iterator();
091: while (it.hasNext()) {
092: String pn = (String) it.next();
093: if (pn.equals(packageName)
094: || packageName.startsWith(pn + ".")) {
095: Iterator cit = clients.iterator();
096: while (cit.hasNext()) {
097: addClient((String) cit.next());
098: }
099: return true;
100: }
101: }
102: return false;
103: }
104:
105: public BasicDescriptor getLicense() {
106: BasicDescriptor ret = super .getLicense();
107: return ret == null ? publisher.getLicense() : ret;
108: }
109:
110: public void addClients(Collection clients) {
111: Iterator it = clients.iterator();
112: while (it.hasNext()) {
113: addClient((String) it.next());
114: }
115:
116: }
117: }
|