KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > beans > TestBeans


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.deployment.spi.beans;
23
24 import javax.enterprise.deploy.model.DDBean JavaDoc;
25 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
27
28 public class TestBeans
29 {
30    /*
31     public static void main( String args[] ) {
32     //tempFunction1();
33     tempFunction2();
34     }
35     
36     public static void tempFunction2() {
37     
38     // DDBeanRootImpl impl = new DDBeanRootImpl(null,
39     // new File("c:\\eclipse\\ConfigExample.xml"), "ConfigExample.xml");
40     // DConfigBean configRoot1 = new JBossExample1ConfigBeanRoot(impl);
41     // DConfigBean configRoot2 = new JBossExample2ConfigBeanRoot(impl);
42     
43     
44     try {
45     //traverse(configRoot1, impl, 0);
46     //traverse(configRoot2, impl, 0);
47     //test_remove(configRoot2, impl);
48     //test_getClass();
49     } catch( Exception e ) {
50     System.out.println("Exception: " + e.getMessage());
51     e.printStackTrace();
52     }
53     }
54     
55
56     /*
57     public static void test_getClass() {
58     try {
59     PackagedDeployable dep = new PackagedDeployable(
60     new File("c:\\eclipse\\crimeportal\\crimeportal.war"));
61     WarConfiguration config = new WarConfiguration(dep);
62     
63     } catch( Exception e ) {
64     System.out.println("DEAD: " + e.getMessage());
65     e.printStackTrace();
66     }
67     }
68     */

69
70    public static void test_remove(DConfigBean JavaDoc config, DDBean JavaDoc dd)
71    {
72       try
73       {
74          System.out.println(config.getXpaths().length + " xpaths.");
75          String JavaDoc targetXPath = config.getXpaths()[0];
76          System.out.println(targetXPath + " is the first.");
77          DDBean JavaDoc first = dd.getChildBean(targetXPath)[0];
78          DConfigBean JavaDoc 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 JavaDoc e)
86       {
87          System.out.println("ERROR: " + e.getMessage());
88          e.printStackTrace();
89       }
90    }
91
92    public static void traverse(DConfigBean JavaDoc config, DDBean JavaDoc dd, int indent) throws ConfigurationException JavaDoc
93    {
94       indent += 3;
95       indentPrint(indent, "starting \"" + dd.getXpath() + "\", config of type " + trimClass(config.getClass()));
96       String JavaDoc[] 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 JavaDoc s = "path " + i + ": " + pathsToFollow[i];
103          DDBean JavaDoc[] 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 JavaDoc cb = config.getDConfigBean(lesserBeans[j]);
109             traverse(cb, lesserBeans[j], indent);
110          }
111       }
112
113    }
114
115    public static String JavaDoc trimClass(Class JavaDoc 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 JavaDoc y)
127    {
128       String JavaDoc s = "";
129       for (int i = 0; i < x; i++)
130          s += " ";
131       System.out.println(s + y);
132    }
133
134 }
135
Popular Tags