KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
27 import java.util.List 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 /**
37  * @author Pavel Vlasov
38  * @version $Revision: 1.2 $
39  */

40 public class Licensor extends BasicDescriptor {
41
42     private BasicDescriptor license;
43     protected List JavaDoc packages=new ArrayList JavaDoc();
44
45     public Licensor(TechStack stack) {
46         super();
47         this.stack=stack;
48     }
49     
50     public Licensor(TechStack stack, Element JavaDoc holder, CachedXPathAPI cxpa) throws TransformerException JavaDoc {
51         super(holder, cxpa);
52         this.stack=stack;
53         this.licenseRef=getElementText(holder, "license-ref", cxpa);
54         Element JavaDoc licenseEl=(Element JavaDoc) cxpa.selectSingleNode(holder, "license");
55         if (licenseEl!=null) {
56             license=new BasicDescriptor(licenseEl, cxpa);
57         }
58         NodeIterator nit = cxpa.selectNodeIterator(holder, "package");
59         Node JavaDoc n;
60         while ((n=nit.nextNode())!=null) {
61             packages.add(getElementText(n));
62         }
63     }
64
65     private String JavaDoc licenseRef;
66
67     public BasicDescriptor getLicense() {
68         return license==null ? stack.findLicense(licenseRef) : license;
69     }
70
71     protected TechStack stack;
72     
73     public void toDom(Element JavaDoc holder) {
74         super.toDom(holder);
75         if (license!=null) {
76             license.toDom(addElement(holder, "license"));
77         }
78         
79         addTextElement(holder, "license-ref", licenseRef);
80         
81         Iterator JavaDoc it=packages.iterator();
82         while (it.hasNext()) {
83             addTextElement(holder, "package", it.next().toString());
84         }
85     }
86     
87     public void setLicense(BasicDescriptor license) {
88         this.license = license;
89     }
90     
91     public void setLicenseRef(String JavaDoc licenseRef) {
92         this.licenseRef = licenseRef;
93     }
94
95     public void addPackage(String JavaDoc packageName) {
96         packages.add(packageName);
97     }
98 }
99
Popular Tags