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.ArrayList;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import javax.xml.transform.TransformerException;
030:
031: import org.apache.xpath.CachedXPathAPI;
032: import org.w3c.dom.Element;
033: import org.w3c.dom.Node;
034: import org.w3c.dom.traversal.NodeIterator;
035:
036: /**
037: * @author Pavel Vlasov
038: * @version $Revision: 1.2 $
039: */
040: public class Licensor extends BasicDescriptor {
041:
042: private BasicDescriptor license;
043: protected List packages = new ArrayList();
044:
045: public Licensor(TechStack stack) {
046: super ();
047: this .stack = stack;
048: }
049:
050: public Licensor(TechStack stack, Element holder, CachedXPathAPI cxpa)
051: throws TransformerException {
052: super (holder, cxpa);
053: this .stack = stack;
054: this .licenseRef = getElementText(holder, "license-ref", cxpa);
055: Element licenseEl = (Element) cxpa.selectSingleNode(holder,
056: "license");
057: if (licenseEl != null) {
058: license = new BasicDescriptor(licenseEl, cxpa);
059: }
060: NodeIterator nit = cxpa.selectNodeIterator(holder, "package");
061: Node n;
062: while ((n = nit.nextNode()) != null) {
063: packages.add(getElementText(n));
064: }
065: }
066:
067: private String licenseRef;
068:
069: public BasicDescriptor getLicense() {
070: return license == null ? stack.findLicense(licenseRef)
071: : license;
072: }
073:
074: protected TechStack stack;
075:
076: public void toDom(Element holder) {
077: super .toDom(holder);
078: if (license != null) {
079: license.toDom(addElement(holder, "license"));
080: }
081:
082: addTextElement(holder, "license-ref", licenseRef);
083:
084: Iterator it = packages.iterator();
085: while (it.hasNext()) {
086: addTextElement(holder, "package", it.next().toString());
087: }
088: }
089:
090: public void setLicense(BasicDescriptor license) {
091: this .license = license;
092: }
093:
094: public void setLicenseRef(String licenseRef) {
095: this .licenseRef = licenseRef;
096: }
097:
098: public void addPackage(String packageName) {
099: packages.add(packageName);
100: }
101: }
|