/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ import java.util.Properties; import java.util.Map.Entry; /** * * @author Kabir Khan * @version $Revision: 1.1 $ */ public class RunIt { class NonStatic1 { NonStatic2 nonstatic2; public NonStatic1() { nonstatic2 = new NonStatic2(); } class NonStatic2 { NonStatic3 nonstatic3; public NonStatic2() { nonstatic3 = new NonStatic3(); } class NonStatic3 { } } } static class Static1 { Static2 static2; public Static1() { static2 = new Static2(); } static class Static2 { Static3 static3; public Static2() { static3 = new Static3(); } static class Static3 { } } } public RunIt() { NonStatic1 nonstatic1 = new NonStatic1(); Static1 static1 = new Static1(); Class ns3 = nonstatic1.nonstatic2.nonstatic3.getClass(); System.out.println("========= declaring "); outputClass(ns3, NonStatic1.class, false); System.out.println("\n========= enclosing "); outputClass(ns3, NonStatic1.class, true); Class s3 = static1.static2.static3.getClass(); System.out.println("========= declaring "); outputClass(s3, Static1.class, false); System.out.println("\n========= enclosing "); outputClass(s3, Static1.class, true); } private void outputClass(Class clazz, Class topLevel, boolean enclosing) { System.out.println(clazz.getName()); if (clazz == topLevel || clazz == null) return; clazz = enclosing ? clazz.getEnclosingClass() : clazz.getDeclaringClass(); outputClass(clazz, topLevel, enclosing); } public static void main(String[] args) { RunIt runIt = new RunIt(); // Properties props = System.getProperties(); // for (Entry entry : props.entrySet()) // { // System.out.println(entry.getKey() + ": " + entry.getValue()); // } } }