1 22 package org.jboss.deployment.spi.beans; 23 24 import javax.enterprise.deploy.model.DDBean ; 25 import javax.enterprise.deploy.spi.DConfigBean ; 26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 28 public class TestBeans 29 { 30 69 70 public static void test_remove(DConfigBean config, DDBean dd) 71 { 72 try 73 { 74 System.out.println(config.getXpaths().length + " xpaths."); 75 String targetXPath = config.getXpaths()[0]; 76 System.out.println(targetXPath + " is the first."); 77 DDBean first = dd.getChildBean(targetXPath)[0]; 78 DConfigBean cnfg = config.getDConfigBean(first); 79 System.out.println("cnfg has " + cnfg.getXpaths().length + " sub kids"); 80 config.removeDConfigBean(cnfg); 81 System.out.println("cnfg has " + cnfg.getXpaths().length + " sub kids"); 82 System.out.println(config.getXpaths().length + " xpaths."); 83 84 } 85 catch (Exception e) 86 { 87 System.out.println("ERROR: " + e.getMessage()); 88 e.printStackTrace(); 89 } 90 } 91 92 public static void traverse(DConfigBean config, DDBean dd, int indent) throws ConfigurationException 93 { 94 indent += 3; 95 indentPrint(indent, "starting \"" + dd.getXpath() + "\", config of type " + trimClass(config.getClass())); 96 String [] pathsToFollow = config.getXpaths(); 97 if (pathsToFollow.length > 0) 98 indentPrint(indent, "- There are " + pathsToFollow.length + " xpaths returned."); 99 indent += 4; 100 for (int i = 0; i < pathsToFollow.length; i++) 101 { 102 String s = "path " + i + ": " + pathsToFollow[i]; 103 DDBean [] lesserBeans = dd.getChildBean(pathsToFollow[i]); 104 indentPrint(indent, s + " , " + lesserBeans.length + " found."); 105 106 for (int j = 0; j < lesserBeans.length; j++) 107 { 108 DConfigBean cb = config.getDConfigBean(lesserBeans[j]); 109 traverse(cb, lesserBeans[j], indent); 110 } 111 } 112 113 } 114 115 public static String trimClass(Class c) 116 { 117 int dot = c.getName().lastIndexOf('.'); 118 int dollar = c.getName().lastIndexOf('$'); 119 if (dollar == -1) 120 { 121 return c.getName().substring(dot + 1); 122 } 123 return c.getName().substring(dollar + 1); 124 } 125 126 public static void indentPrint(int x, String y) 127 { 128 String s = ""; 129 for (int i = 0; i < x; i++) 130 s += " "; 131 System.out.println(s + y); 132 } 133 134 } 135 | Popular Tags |