1 4 5 package org.objectweb.fractal.jar; 6 7 import java.io.ByteArrayInputStream ; 8 import java.io.Serializable ; 9 import java.util.ArrayList ; 10 import java.util.HashMap ; 11 import java.util.HashSet ; 12 import java.util.List ; 13 import java.util.Map ; 14 import java.util.Set ; 15 16 import org.objectweb.fractal.adl.Node; 17 import org.objectweb.fractal.adl.components.Component; 18 import org.objectweb.fractal.adl.components.ComponentContainer; 19 import org.objectweb.fractal.adl.components.ComponentDefinition; 20 import org.objectweb.fractal.adl.xml.XMLParser; 21 22 public class Package implements Serializable { 23 24 String name; 25 26 Map files; 28 List packageDependencies; 30 List dependentPackages; 32 public Package (String name) { 33 this.name = name; 34 this.files = new HashMap (); 35 this.packageDependencies = new ArrayList (); 36 this.dependentPackages = new ArrayList (); 37 } 38 39 Set computeDependencies () throws Exception { 40 int dash = name.indexOf('-'); 41 String n = name.substring(0, dash); 42 String v = name.substring(dash + 1); 43 44 Set s = new HashSet (); 45 getDependencies((PackageFile)files.get( 46 v + '/' + n.replace('.', '/') + ".fractal"), s); 47 48 return s; 49 } 50 51 private void getDependencies (PackageFile file, Set s) throws Exception { 52 XMLParser p = new XMLParser(); 53 Node n = p.parse(new ByteArrayInputStream (file.content), file.name); 54 getDependencies(n, s); 55 } 56 57 private void getDependencies (Node n, Set s) throws Exception { 58 if (n instanceof ComponentContainer) { 59 Component[] components = ((ComponentContainer)n).getComponents(); 60 for (int i = 0; i < components.length; ++i) { 61 getDependencies((Node)components[i], s); 62 } 63 } 64 if (n instanceof ComponentDefinition) { 65 getDependencies(((ComponentDefinition)n).getExtends(), s); 66 } 67 if (n instanceof Component) { 68 getDependencies(((Component)n).getDefinition(), s); 69 } 70 } 71 72 private void getDependencies (String definitions, Set s) throws Exception { 73 if (definitions == null) { 74 return; 75 } 76 int comma = definitions.indexOf(','); 77 if (comma != -1) { 78 getDependencies(definitions.substring(0, comma), s); 79 getDependencies(definitions.substring(comma + 1), s); 80 return; 81 } 82 int dash = definitions.indexOf('-'); 83 String definition = definitions.substring(0, dash); 84 String version = definitions.substring(dash + 1); 85 86 PackageFile file = (PackageFile)files.get( 87 version + '/' + definition.replace('.', '/') + ".fractal"); 88 89 if (file == null) { 90 s.add(definitions); 91 } else { 92 getDependencies(file, s); 93 } 94 } 95 96 public String toString () { 97 return name; 98 } 99 } 100 | Popular Tags |