1 23 package org.hammurapi.inspectors.techstack; 24 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import javax.xml.transform.TransformerException ; 30 31 import org.apache.xpath.CachedXPathAPI; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.traversal.NodeIterator; 35 36 40 public class Licensor extends BasicDescriptor { 41 42 private BasicDescriptor license; 43 protected List packages=new ArrayList (); 44 45 public Licensor(TechStack stack) { 46 super(); 47 this.stack=stack; 48 } 49 50 public Licensor(TechStack stack, Element holder, CachedXPathAPI cxpa) throws TransformerException { 51 super(holder, cxpa); 52 this.stack=stack; 53 this.licenseRef=getElementText(holder, "license-ref", cxpa); 54 Element licenseEl=(Element ) cxpa.selectSingleNode(holder, "license"); 55 if (licenseEl!=null) { 56 license=new BasicDescriptor(licenseEl, cxpa); 57 } 58 NodeIterator nit = cxpa.selectNodeIterator(holder, "package"); 59 Node n; 60 while ((n=nit.nextNode())!=null) { 61 packages.add(getElementText(n)); 62 } 63 } 64 65 private String 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 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 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 licenseRef) { 92 this.licenseRef = licenseRef; 93 } 94 95 public void addPackage(String packageName) { 96 packages.add(packageName); 97 } 98 } 99 | Popular Tags |