Thread: [Ejtools-cvs] CVS: applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model Serv
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-22 17:59:41
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model In directory usw-pr-cvs1:/tmp/cvs-serv30601/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model Added Files: Server.java Log Message: Initial Import --- NEW FILE: Server.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.jndibrowser.model; // Standard Imports import java.util.Collection; import java.util.Iterator; import java.util.Properties; import java.util.Vector; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.NotContextException; // Other Imports import net.sourceforge.ejtools.jndibrowser.model.ejb.EJBHomeProxy; import net.sourceforge.ejtools.jndibrowser.model.jms.ConnectionFactoryProxy; import net.sourceforge.ejtools.jndibrowser.model.jms.QueueProxy; import net.sourceforge.ejtools.jndibrowser.model.jms.TopicProxy; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 13 décembre 2001 * @todo Javadoc to complete * @todo Add log4j logs */ public class Server extends JNDIContext { /** Description of the Field */ protected String factory = "org.jnp.interfaces.NamingContextFactory"; /** Description of the Field */ protected String initialContext = "/"; /** Description of the Field */ protected String pkgs = "org.jboss.naming:org.jnp.interfaces"; /** Description of the Field */ protected int searchType = Server.SHALLOW_SEARCH; /** Description of the Field */ protected String url = "localhost:1099"; /** Description of the Field */ public final static int DEEP_SEARCH = 0; /** Description of the Field */ public final static int SHALLOW_SEARCH = 1; /** Constructor for the JndiServer object */ public Server() { super(); this.name = "JNDI Server"; } /** * Gets the context attribute of the JNDIServer object * * @return The context value */ public String getContext() { return this.initialContext; } /** * Gets the provider attribute of the JndiServer object * * @return The provider value */ public String getFactory() { return this.factory; } /** * Gets the packages attribute of the JndiServer object * * @return The packages value */ public String getPackages() { return this.pkgs; } /** * Getter for the searchType attribute * * @return The value */ public int getSearchType() { return searchType; } /** * Gets the types attribute of the Server object * * @return The types value */ public String[] getTypes() { return new String[]{"aze", "qsd", "wxc"}; } /** * Gets the url attribute of the JndiServer object * * @return The url value */ public String getUrl() { return this.url; } /** Description of the Method */ public void refresh() { Iterator iterator = iterator(); while (iterator.hasNext()) { remove(iterator.next()); } try { Properties props = new Properties(); // To change props.put("java.naming.factory.initial", this.getFactory()); // To change props.put("java.naming.factory.url.pkgs", this.getPackages()); props.put(Context.PROVIDER_URL, this.getUrl()); InitialContext context = new InitialContext(props); Vector content = new Vector(); this.iterateContext(context, this.getContext(), content); Iterator it = content.iterator(); while (it.hasNext()) { add(it.next()); } } catch (Exception e) { System.err.println("Exception " + e.getMessage()); } } /** * Sets the context attribute of the JNDIServer object * * @param context The new context value */ public void setContext(String context) { this.initialContext = context; } /** * Sets the provider attribute of the JndiServer object * * @param factory The new factory value */ public void setFactory(String factory) { this.factory = factory; } /** * Sets the packages attribute of the JndiServer object * * @param pkgs The new packages value */ public void setPackages(String pkgs) { this.pkgs = pkgs; } /** * Setter for the searchType attribute * * @param searchType The new value */ public void setSearchType(int searchType) { this.searchType = searchType; } /** * Sets the url attribute of the JndiServer object * * @param url The new url value */ public void setUrl(String url) { this.url = url; } /** * Gets the context attribute of the JndiServer object * * @param context Description of Parameter * @param s Description of Parameter * @return The context value * @exception NamingException Description of Exception */ private boolean isContext(Context context, String s) throws NamingException { try { context.list(s); } catch (NotContextException notcontextexception) { return false; } return true; } /** * Description of the Method * * @param context Description of Parameter * @param s Description of Parameter * @param node Description of Parameter * @return Description of the Returned Value */ private boolean iterateContext(Context context, String s, Collection node) { try { for (NamingEnumeration namingenumeration = context.list(s); namingenumeration.hasMore(); ) { NameClassPair nc = (NameClassPair) namingenumeration.next(); if (isContext(context, nc.getName())) { Context context1 = (Context) context.lookup(nc.getName()); String s1 = context1.composeName(nc.getName(), s); JNDIContext newNode = new JNDIContext(); newNode.name = nc.getName(); newNode.className = nc.getClassName(); node.add(newNode); iterateContext(context1, s1, newNode); } else { JNDIContext newNode; newNode = new JNDIEntry(); newNode.name = nc.getName(); newNode.className = nc.getClassName(); if (this.searchType == Server.DEEP_SEARCH) { try { System.out.println("Name :" + nc.getName()); System.out.println("ClassName :" + nc.getClassName()); Object o = null; try { o = context.lookup(nc.getName()); } catch (Exception e1) { } try { newNode = new EJBHomeProxy(o); newNode.name = nc.getName(); } catch (Exception e1) { } try { newNode = new QueueProxy(o); newNode.name = nc.getName(); newNode.className = nc.getClassName(); } catch (Exception e2) { } try { newNode = new TopicProxy(o); newNode.name = nc.getName(); newNode.className = nc.getClassName(); } catch (Exception e3) { } try { newNode = new ConnectionFactoryProxy(o); newNode.name = nc.getName(); newNode.className = nc.getClassName(); } catch (Exception e4) { } } catch (Exception e1) { } } node.add(newNode); } } } catch (Exception namingexception) { System.err.println("iterateContext Exception " + namingexception.getMessage()); return false; } return true; } } |