[Ejtools-cvs] applications/jndi.browser/src/main/org/ejtools/jndi/browser/model JNDIContext.java,1.2
Brought to you by:
letiemble
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model In directory sc8-pr-cvs1:/tmp/cvs-serv17169/jndi.browser/src/main/org/ejtools/jndi/browser/model Modified Files: JNDIContext.java JNDIEntry.java JNDIEnvEntry.java JNDILinkRef.java Proxy.java Server.java Log Message: Address Todo #755528 Address Todo #800902 Index: JNDIContext.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/JNDIContext.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JNDIContext.java 12 Feb 2003 21:24:36 -0000 1.2 --- JNDIContext.java 27 Nov 2003 01:30:29 -0000 1.3 *************** *** 1,134 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import java.awt.Component; ! import java.beans.Customizer; ! import java.beans.beancontext.BeanContextChildComponentProxy; ! import java.util.Iterator; ! ! import org.apache.log4j.Logger; ! import org.ejtools.adwt.GenericCustomizer; ! import org.ejtools.beans.Sort; ! import org.ejtools.beans.beancontext.CustomBeanContextServicesSupport; ! ! /** ! * Ancestor of all element in the JNDI tree. Represents a JNDI Context and can contains other context. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Context" ! * shortDescription="JNDI Context" ! * @javabean:icons color16="/toolbarButtonGraphics/general/Folder16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the context" ! */ ! public class JNDIContext extends CustomBeanContextServicesSupport implements BeanContextChildComponentProxy ! { ! /** Customizer of the JavaBean */ ! protected transient Customizer c = null; ! /** Class name of the context */ ! protected String className = ""; ! /** Name of the context */ ! protected String name = ""; ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(JNDIContext.class); ! ! ! /** Constructor for the JndiServer object */ ! public JNDIContext() ! { ! super(); ! } ! ! ! /** ! * Gets the class name of the context ! * ! * @return The class name string ! */ ! public String getClassName() ! { ! return this.className; ! } ! ! ! /** ! * Gets the JavaBean customizer of the context ! * ! * @return The customizer ! */ ! public Component getComponent() ! { ! // Lazy creation ! if (c == null) ! { ! c = new GenericCustomizer(true, this); ! } ! return (Component) c; ! } ! ! ! /** ! * Gets the name of the context ! * ! * @return The name string ! */ ! public String getName() ! { ! return this.name; ! } ! ! ! /** ! * Return the children of this context as an iterator ! * ! * @return The sorted iterator by class and by name ! */ ! public Iterator iterator() ! { ! return Sort.sortByName(super.iterator()); ! } ! ! ! /** ! * Implementation of toString() method ! * ! * @return The name of the context ! */ ! public String toString() ! { ! return name == null ? "Undefined" : name; ! } ! ! ! /** ! * Sets the class name of this context ! * ! * @param className The class name ! */ ! protected void setClassName(String className) ! { ! this.className = className; ! } ! ! ! /** ! * Sets the name of this context ! * ! * @param name The name ! */ ! protected void setName(String name) ! { ! String old = this.name; ! this.name = name; ! this.firePropertyChange("name", old, this.name); ! } ! } --- 1,131 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import java.awt.Component; ! import java.beans.Customizer; ! import java.beans.beancontext.BeanContextChildComponentProxy; ! import java.util.Iterator; ! ! import org.ejtools.adwt.GenericCustomizer; ! import org.ejtools.beans.Sort; ! import org.ejtools.beans.beancontext.CustomBeanContextServicesSupport; ! ! /** ! * Ancestor of all element in the JNDI tree. Represents a JNDI Context and can contains other context. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Context" ! * shortDescription="JNDI Context" ! * @javabean:icons color16="/toolbarButtonGraphics/general/Folder16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the context" ! */ ! public class JNDIContext extends CustomBeanContextServicesSupport implements BeanContextChildComponentProxy ! { ! /** Customizer of the JavaBean */ ! protected transient Customizer c = null; ! /** Class name of the context */ ! protected String className = ""; ! /** Name of the context */ ! protected String name = ""; ! ! ! /** Constructor for the JndiServer object */ ! public JNDIContext() ! { ! super(); ! } ! ! ! /** ! * Gets the class name of the context ! * ! * @return The class name string ! */ ! public String getClassName() ! { ! return this.className; ! } ! ! ! /** ! * Gets the JavaBean customizer of the context ! * ! * @return The customizer ! */ ! public Component getComponent() ! { ! // Lazy creation ! if (c == null) ! { ! c = new GenericCustomizer(true, this); ! } ! return (Component) c; ! } ! ! ! /** ! * Gets the name of the context ! * ! * @return The name string ! */ ! public String getName() ! { ! return this.name; ! } ! ! ! /** ! * Return the children of this context as an iterator ! * ! * @return The sorted iterator by class and by name ! */ ! public Iterator iterator() ! { ! return Sort.sortByName(super.iterator()); ! } ! ! ! /** ! * Implementation of toString() method ! * ! * @return The name of the context ! */ ! public String toString() ! { ! return name == null ? "Undefined" : name; ! } ! ! ! /** ! * Sets the class name of this context ! * ! * @param className The class name ! */ ! protected void setClassName(String className) ! { ! this.className = className; ! } ! ! ! /** ! * Sets the name of this context ! * ! * @param name The name ! */ ! protected void setName(String name) ! { ! String old = this.name; ! this.name = name; ! this.firePropertyChange("name", old, this.name); ! } ! } Index: JNDIEntry.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/JNDIEntry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JNDIEntry.java 10 Feb 2003 21:17:23 -0000 1.1 --- JNDIEntry.java 27 Nov 2003 01:30:29 -0000 1.2 *************** *** 1,30 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! ! /** ! * Describe a simple JNDI entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Entry" ! * shortDescription="JNDI Entry" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! */ ! public class JNDIEntry extends JNDIContext ! { ! } --- 1,30 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! ! /** ! * Describe a simple JNDI entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Entry" ! * shortDescription="JNDI Entry" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! */ ! public class JNDIEntry extends JNDIContext ! { ! } Index: JNDIEnvEntry.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/JNDIEnvEntry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JNDIEnvEntry.java 10 Feb 2003 21:17:23 -0000 1.1 --- JNDIEnvEntry.java 27 Nov 2003 01:30:29 -0000 1.2 *************** *** 1,79 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! ! ! /** ! * Describe a environment entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Entry" ! * shortDescription="JNDI Entry" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="value" ! * class="java.lang.String" ! * displayName="Value" ! * shortDescription="Value of the environment entry" ! */ ! public class JNDIEnvEntry extends JNDIContext ! { ! /** Description of the Field */ ! protected Object value = null; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public JNDIEnvEntry(Context context, String jndiName) ! throws Exception ! { ! Object o = context.lookup(jndiName); ! ! Class clazz = o.getClass(); ! if (clazz.getName().startsWith("java.lang.")) ! { ! this.value = o; ! } ! if (clazz.equals(java.net.URL.class)) ! { ! this.value = o; ! } ! if (this.value == null) ! { ! throw new Exception("This object is not a valid environment entry"); ! } ! this.setName(jndiName); ! this.setClassName(clazz.getName()); ! } ! ! ! /** ! * Gets the value attribute of the JNDIEnvEntry object ! * ! * @return The value value ! */ ! public String getValue() ! { ! return this.value.toString(); ! } ! } --- 1,79 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! ! ! /** ! * Describe a environment entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @javabean:class displayName="JNDI Entry" ! * shortDescription="JNDI Entry" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="value" ! * class="java.lang.String" ! * displayName="Value" ! * shortDescription="Value of the environment entry" ! */ ! public class JNDIEnvEntry extends JNDIContext ! { ! /** Description of the Field */ ! protected Object value = null; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public JNDIEnvEntry(Context context, String jndiName) ! throws Exception ! { ! Object o = context.lookup(jndiName); ! ! Class clazz = o.getClass(); ! if (clazz.getName().startsWith("java.lang.")) ! { ! this.value = o; ! } ! if (clazz.equals(java.net.URL.class)) ! { ! this.value = o; ! } ! if (this.value == null) ! { ! throw new Exception("This object is not a valid environment entry"); ! } ! this.setName(jndiName); ! this.setClassName(clazz.getName()); ! } ! ! ! /** ! * Gets the value attribute of the JNDIEnvEntry object ! * ! * @return The value value ! */ ! public String getValue() ! { ! return this.value.toString(); ! } ! } Index: JNDILinkRef.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/JNDILinkRef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JNDILinkRef.java 24 Feb 2003 22:32:12 -0000 1.2 --- JNDILinkRef.java 27 Nov 2003 01:30:29 -0000 1.3 *************** *** 1,84 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! import javax.naming.LinkRef; ! ! ! /** ! * Describe a simple JNDI Link Reference. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @javabean:class displayName="JNDI LinkRef" ! * shortDescription="JNDI Link Reference" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="linkName" ! * class="java.lang.String" ! * displayName="Link Reference" ! * shortDescription="Link Reference" ! */ ! public class JNDILinkRef extends JNDIEntry ! { ! /** Class name of the context */ ! protected String linkName = ""; ! /** Description of the Field */ ! protected LinkRef ref; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public JNDILinkRef(Context context, String jndiName) ! throws Exception ! { ! this.setName(jndiName); ! ! Object o = context.lookupLink(jndiName); ! this.setClassName(o.getClass().getName()); ! ! ref = (LinkRef) o; ! this.setLinkName(ref.getLinkName()); ! } ! ! ! /** ! * Gets the linkName attribute of the JNDILinkRef object ! * ! * @return The linkName value ! */ ! public String getLinkName() ! { ! return this.linkName; ! } ! ! ! /** ! * Sets the linkName attribute of the JNDILinkRef object ! * ! * @param linkName The new linkName value ! */ ! protected void setLinkName(String linkName) ! { ! this.linkName = linkName; ! } ! } --- 1,84 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! import javax.naming.LinkRef; ! ! ! /** ! * Describe a simple JNDI Link Reference. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @javabean:class displayName="JNDI LinkRef" ! * shortDescription="JNDI Link Reference" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="linkName" ! * class="java.lang.String" ! * displayName="Link Reference" ! * shortDescription="Link Reference" ! */ ! public class JNDILinkRef extends JNDIEntry ! { ! /** Class name of the context */ ! protected String linkName = ""; ! /** Description of the Field */ ! protected LinkRef ref; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public JNDILinkRef(Context context, String jndiName) ! throws Exception ! { ! this.setName(jndiName); ! ! Object o = context.lookupLink(jndiName); ! this.setClassName(o.getClass().getName()); ! ! ref = (LinkRef) o; ! this.setLinkName(ref.getLinkName()); ! } ! ! ! /** ! * Gets the linkName attribute of the JNDILinkRef object ! * ! * @return The linkName value ! */ ! public String getLinkName() ! { ! return this.linkName; ! } ! ! ! /** ! * Sets the linkName attribute of the JNDILinkRef object ! * ! * @param linkName The new linkName value ! */ ! protected void setLinkName(String linkName) ! { ! this.linkName = linkName; ! } ! } Index: Proxy.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/Proxy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Proxy.java 24 Feb 2003 22:32:12 -0000 1.2 --- Proxy.java 27 Nov 2003 01:30:29 -0000 1.3 *************** *** 1,85 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! ! ! /** ! * Describe a Proyx entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @javabean:class displayName="Proxy Class" ! * shortDescription="Proxy Class" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="interfaces" ! * class="java.lang.Class" ! * displayName="Interfaces" ! * shortDescription="Interfaces implemented by this proxy" ! */ ! public class Proxy extends JNDIEntry ! { ! /** Description of the Field */ ! protected Object proxy = null; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public Proxy(Context context, String jndiName) ! throws Exception ! { ! Object o = context.lookup(jndiName); ! Class clazz = o.getClass(); ! ! if (java.lang.reflect.Proxy.isProxyClass(clazz)) ! { ! proxy = o; ! } ! else ! { ! if (clazz.getName().startsWith("$Proxy")) ! { ! proxy = o; ! } ! } ! ! if (proxy == null) ! { ! throw new Exception("This object is not a proxy"); ! } ! ! this.setName(jndiName); ! this.setClassName(clazz.getName()); ! } ! ! ! /** ! * Gets the linkName attribute of the JNDILinkRef object ! * ! * @return The linkName value ! */ ! public Class[] getInterfaces() ! { ! return proxy.getClass().getInterfaces(); ! } ! } --- 1,85 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import javax.naming.Context; ! ! ! /** ! * Describe a Proyx entry. ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @javabean:class displayName="Proxy Class" ! * shortDescription="Proxy Class" ! * @javabean:icons color16="/toolbarButtonGraphics/general/File16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Name" ! * shortDescription="Name of the entry" ! * @javabean:property name="className" ! * class="java.lang.String" ! * displayName="Class" ! * shortDescription="Class of the entry" ! * @javabean:property name="interfaces" ! * class="java.lang.Class" ! * displayName="Interfaces" ! * shortDescription="Interfaces implemented by this proxy" ! */ ! public class Proxy extends JNDIEntry ! { ! /** Description of the Field */ ! protected Object proxy = null; ! ! ! /** ! * Constructor for the JNDILinkRef object ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @exception Exception Description of the Exception ! */ ! public Proxy(Context context, String jndiName) ! throws Exception ! { ! Object o = context.lookup(jndiName); ! Class clazz = o.getClass(); ! ! if (java.lang.reflect.Proxy.isProxyClass(clazz)) ! { ! proxy = o; ! } ! else ! { ! if (clazz.getName().startsWith("$Proxy")) ! { ! proxy = o; ! } ! } ! ! if (proxy == null) ! { ! throw new Exception("This object is not a proxy"); ! } ! ! this.setName(jndiName); ! this.setClassName(clazz.getName()); ! } ! ! ! /** ! * Gets the linkName attribute of the JNDILinkRef object ! * ! * @return The linkName value ! */ ! public Class[] getInterfaces() ! { ! return proxy.getClass().getInterfaces(); ! } ! } Index: Server.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/model/Server.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Server.java 3 Mar 2003 20:34:32 -0000 1.2 --- Server.java 27 Nov 2003 01:30:29 -0000 1.3 *************** *** 1,444 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import java.lang.reflect.Constructor; ! import java.util.Collection; ! import java.util.Iterator; ! import java.util.Properties; ! import java.util.ResourceBundle; ! import java.util.Vector; ! ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.naming.LinkRef; ! import javax.naming.NameClassPair; ! import javax.naming.NamingEnumeration; ! import javax.naming.NamingException; ! ! import org.apache.log4j.Logger; ! import org.ejtools.jndi.browser.model.service.ConnectionMetaData; ! import org.ejtools.util.service.Profile; ! ! /** ! * Description of the Class ! * ! * @author letiemble ! * @created 13 décembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @todo Add log4j logs ! * @javabean:class displayName="JNDI Server" ! * shortDescription="JNDI Server" ! * @javabean:icons color16="/toolbarButtonGraphics/development/Server16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Connection" ! * shortDescription="Connection Name" ! * @javabean:property name="factory" ! * class="java.lang.String" ! * displayName="Factory" ! * shortDescription="JNDI context factory" ! * @javabean:property name="packages" ! * class="java.lang.String" ! * displayName="Packages" ! * shortDescription="Packages for context" ! * @javabean:property name="url" ! * class="java.lang.String" ! * displayName="URL" ! * shortDescription="JNDI Server URL" ! * @javabean:property name="context" ! * class="java.lang.String" ! * displayName="Context" ! * shortDescription="Initial JNDI context" ! * @javabean:property name="principal" ! * class="java.lang.String" ! * displayName="Principal" ! * shortDescription="Principal to connect" ! * @javabean:property name="credentials" ! * class="java.lang.String" ! * displayName="Credentials" ! * shortDescription="Credentials to connect" ! */ ! public class Server extends JNDIContext ! { ! /** Description of the Field */ ! protected Profile profile = new Profile(); ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(Server.class); ! /** Description of the Field */ ! private static Vector proxies = new Vector(); ! /** Bundle for I18N */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources"); ! ! ! /** ! * Constructor for the JndiServer object ! * ! * @todo I18N to complete ! */ ! public Server() ! { ! super(); ! this.setName(resources.getString("connection.text.untitled")); ! } ! ! ! /** ! * Gets the context attribute of the JNDIServer object ! * ! * @return The context value ! */ ! public String getContext() ! { ! return this.profile.getProperty(ConnectionMetaData.CONTEXT); ! } ! ! ! /** ! * Returns the credentials. ! * ! * @return String ! */ ! public String getCredentials() ! { ! return this.profile.getProperty(ConnectionMetaData.CREDENTIALS); ! } ! ! ! /** ! * Gets the provider attribute of the JndiServer object ! * ! * @return The provider value ! */ ! public String getFactory() ! { ! return this.profile.getProperty(ConnectionMetaData.FACTORY); ! } ! ! ! /** ! * Gets the packages attribute of the JndiServer object ! * ! * @return The packages value ! */ ! public String getPackages() ! { ! return this.profile.getProperty(ConnectionMetaData.PACKAGES); ! } ! ! ! ! /** ! * Returns the principal. ! * ! * @return String ! */ ! public String getPrincipal() ! { ! return this.profile.getProperty(ConnectionMetaData.PRINCIPAL); ! } ! ! ! /** ! * Gets the url attribute of the JndiServer object ! * ! * @return The url value ! */ ! public String getUrl() ! { ! return this.profile.getProperty(ConnectionMetaData.URL); ! } ! ! ! /** ! * Description of the Method ! * ! * @javabean:method name="refresh" displayName="Refresh" shortDescription="Refresh the JNDI tree" ! */ ! public void refresh() ! { ! logger.debug("Cleaning JNDI tree..."); ! Iterator iterator = iterator(); ! while (iterator.hasNext()) ! { ! remove(iterator.next()); ! } ! ! try ! { ! Context context = null; ! if (this.getFactory() != null) ! { ! Properties props = new Properties(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.getFactory()); ! props.put(Context.URL_PKG_PREFIXES, this.getPackages()); ! props.put(Context.PROVIDER_URL, this.getUrl()); ! logger.debug("Initial context with " + props); ! context = new InitialContext(props); ! } ! else ! { ! context = new InitialContext(); ! } ! ! if (!("".equals(this.getContext()))) ! { ! logger.debug("Context =<" + this.getContext() + ">"); ! context = (Context) context.lookup(this.getContext()); ! } ! ! logger.debug("Populating JNDI tree..."); ! this.list(context, this); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! logger.error("Exception " + e.getMessage()); ! } ! } ! ! ! /** ! * Sets the context attribute of the JNDIServer object ! * ! * @param context The new context value ! */ ! public void setContext(String context) ! { ! this.profile.setProperty(ConnectionMetaData.CONTEXT, context); ! } ! ! ! ! /** ! * Sets the credentials. ! * ! * @param credentials The credentials to set ! */ ! public void setCredentials(String credentials) ! { ! this.profile.setProperty(ConnectionMetaData.CREDENTIALS, credentials); ! } ! ! ! /** ! * Sets the provider attribute of the JndiServer object ! * ! * @param factory The new factory value ! */ ! public void setFactory(String factory) ! { ! this.profile.setProperty(ConnectionMetaData.FACTORY, factory); ! } ! ! ! /** ! * Sets the name of this server ! * ! * @param name The name ! */ ! public void setName(String name) ! { ! super.setName(name); ! } ! ! ! /** ! * Sets the packages attribute of the JndiServer object ! * ! * @param packages The new packages value ! */ ! public void setPackages(String packages) ! { ! this.profile.setProperty(ConnectionMetaData.PACKAGES, packages); ! } ! ! ! ! /** ! * Sets the principal. ! * ! * @param principal The principal to set ! */ ! public void setPrincipal(String principal) ! { ! this.profile.setProperty(ConnectionMetaData.PRINCIPAL, principal); ! } ! ! ! /** ! * Sets the profile. ! * ! * @param profile The profile to set ! */ ! public void setProfile(Profile profile) ! { ! this.profile = profile; ! } ! ! ! /** ! * Sets the url attribute of the JndiServer object ! * ! * @param url The new url value ! */ ! public void setUrl(String url) ! { ! this.profile.setProperty(ConnectionMetaData.URL, url); ! } ! ! ! /** ! * Description of the Method ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @return Description of the Return Value ! */ ! protected JNDIContext createNode(Context context, String jndiName) ! { ! for (int i = 0; i < proxies.size(); i++) ! { ! Class clazz = (Class) proxies.elementAt(i); ! ! try ! { ! Constructor c = clazz.getConstructor(new Class[]{javax.naming.Context.class, java.lang.String.class}); ! JNDIContext node = (JNDIContext) c.newInstance(new Object[]{context, jndiName}); ! if (node != null) ! { ! return node; ! } ! } ! catch (Exception e) ! { ! } ! } ! ! return null; ! } ! ! ! /** ! * Description of the Method ! * ! * @param ctx Description of the Parameter ! * @param node Description of the Parameter ! */ ! protected void list(Context ctx, Collection node) ! { ! ClassLoader loader = Thread.currentThread().getContextClassLoader(); ! try ! { ! NamingEnumeration ne = ctx.list(""); ! while (ne.hasMore()) ! { ! JNDIContext newNode = null; ! ! NameClassPair pair = (NameClassPair) ne.next(); ! ! String name = pair.getName(); ! String className = pair.getClassName(); ! boolean recursive = false; ! boolean isLinkRef = false; ! ! Class c = null; ! try ! { ! c = loader.loadClass(className); ! ! if (Context.class.isAssignableFrom(c)) ! { ! recursive = true; ! } ! if (LinkRef.class.isAssignableFrom(c)) ! { ! isLinkRef = true; ! } ! } ! catch (ClassNotFoundException cnfe) ! { ! logger.warn("ClassNotFoundException " + cnfe.getMessage()); ! } ! catch (Exception e) ! { ! logger.warn("Exception " + e.getMessage()); ! } ! ! if (isLinkRef) ! { ! try ! { ! newNode = new JNDILinkRef(ctx, name); ! node.add(newNode); ! } ! catch (Exception e) ! { ! } ! } ! ! if (recursive) ! { ! newNode = new JNDIContext(); ! newNode.setName(name); ! newNode.setClassName(className); ! ! try ! { ! Object value = ctx.lookup(name); ! ! if (value instanceof Context) ! { ! Context subctx = (Context) value; ! list(subctx, newNode); ! } ! } ! catch (Throwable t) ! { ! logger.warn("Throwable " + t); ! } ! } ! ! // Try to cast to a predefined object ! if (newNode == null) ! { ! newNode = createNode(ctx, name); ! } ! ! // If no match, create a JNDIEntry ! if (newNode == null) ! { ! newNode = new JNDIEntry(); ! newNode.setName(name); ! newNode.setClassName(className); ! } ! ! node.add(newNode); ! } ! ne.close(); ! } ! catch (NamingException ne) ! { ! logger.error("error while listing context " + ctx.toString() + ": " + ne.toString(true)); ! } ! } ! ! /** Proxies to load */ ! static ! { ! proxies.add(org.ejtools.jndi.browser.model.JNDIEnvEntry.class); ! proxies.add(org.ejtools.jndi.browser.model.ejb.EJBHomeProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.ejb.EJBLocalHomeProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.QueueProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.TopicProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.ConnectionFactoryProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.mail.SessionProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.sql.DataSourceProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.Proxy.class); ! } ! } --- 1,445 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.model; ! ! import java.lang.reflect.Constructor; ! import java.util.Collection; ! import java.util.Iterator; ! import java.util.Properties; ! import java.util.ResourceBundle; ! import java.util.Vector; ! ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.naming.LinkRef; ! import javax.naming.NameClassPair; ! import javax.naming.NamingEnumeration; ! import javax.naming.NamingException; ! ! import org.apache.log4j.Logger; ! import org.ejtools.jndi.browser.model.service.ConnectionMetaData; ! import org.ejtools.util.service.Profile; ! import org.ejtools.util.service.ProfileHolder; ! ! /** ! * Description of the Class ! * ! * @author letiemble ! * @created 13 d?cembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! * @todo Add log4j logs ! * @javabean:class displayName="JNDI Server" ! * shortDescription="JNDI Server" ! * @javabean:icons color16="/toolbarButtonGraphics/development/Server16.gif" ! * @javabean:property name="name" ! * class="java.lang.String" ! * displayName="Connection" ! * shortDescription="Connection Name" ! * @javabean:property name="factory" ! * class="java.lang.String" ! * displayName="Factory" ! * shortDescription="JNDI context factory" ! * @javabean:property name="packages" ! * class="java.lang.String" ! * displayName="Packages" ! * shortDescription="Packages for context" ! * @javabean:property name="url" ! * class="java.lang.String" ! * displayName="URL" ! * shortDescription="JNDI Server URL" ! * @javabean:property name="context" ! * class="java.lang.String" ! * displayName="Context" ! * shortDescription="Initial JNDI context" ! * @javabean:property name="principal" ! * class="java.lang.String" ! * displayName="Principal" ! * shortDescription="Principal to connect" ! * @javabean:property name="credentials" ! * class="java.lang.String" ! * displayName="Credentials" ! * shortDescription="Credentials to connect" ! */ ! public class Server extends JNDIContext implements ProfileHolder ! { ! /** Description of the Field */ ! protected Profile profile = new Profile(); ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(Server.class); ! /** Description of the Field */ ! private static Vector proxies = new Vector(); ! /** Bundle for I18N */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources"); ! ! ! /** ! * Constructor for the JndiServer object ! * ! * @todo I18N to complete ! */ ! public Server() ! { ! super(); ! this.setName(resources.getString("connection.text.untitled")); ! } ! ! ! /** ! * Gets the context attribute of the JNDIServer object ! * ! * @return The context value ! */ ! public String getContext() ! { ! return this.profile.getProperty(ConnectionMetaData.CONTEXT); ! } ! ! ! /** ! * Returns the credentials. ! * ! * @return String ! */ ! public String getCredentials() ! { ! return this.profile.getProperty(ConnectionMetaData.CREDENTIALS); ! } ! ! ! /** ! * Gets the provider attribute of the JndiServer object ! * ! * @return The provider value ! */ ! public String getFactory() ! { ! return this.profile.getProperty(ConnectionMetaData.FACTORY); ! } ! ! ! /** ! * Gets the packages attribute of the JndiServer object ! * ! * @return The packages value ! */ ! public String getPackages() ! { ! return this.profile.getProperty(ConnectionMetaData.PACKAGES); ! } ! ! ! ! /** ! * Returns the principal. ! * ! * @return String ! */ ! public String getPrincipal() ! { ! return this.profile.getProperty(ConnectionMetaData.PRINCIPAL); ! } ! ! ! /** ! * Gets the url attribute of the JndiServer object ! * ! * @return The url value ! */ ! public String getUrl() ! { ! return this.profile.getProperty(ConnectionMetaData.URL); ! } ! ! ! /** ! * Description of the Method ! * ! * @javabean:method name="refresh" displayName="Refresh" shortDescription="Refresh the JNDI tree" ! */ ! public void refresh() ! { ! logger.debug("Cleaning JNDI tree..."); ! Iterator iterator = iterator(); ! while (iterator.hasNext()) ! { ! remove(iterator.next()); ! } ! ! try ! { ! Context context = null; ! if (this.getFactory() != null) ! { ! Properties props = new Properties(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.getFactory()); ! props.put(Context.URL_PKG_PREFIXES, this.getPackages()); ! props.put(Context.PROVIDER_URL, this.getUrl()); ! logger.debug("Initial context with " + props); ! context = new InitialContext(props); ! } ! else ! { ! context = new InitialContext(); ! } ! ! if (!("".equals(this.getContext()))) ! { ! logger.debug("Context =<" + this.getContext() + ">"); ! context = (Context) context.lookup(this.getContext()); ! } ! ! logger.debug("Populating JNDI tree..."); ! this.list(context, this); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! logger.error("Exception " + e.getMessage()); ! } ! } ! ! ! /** ! * Sets the context attribute of the JNDIServer object ! * ! * @param context The new context value ! */ ! public void setContext(String context) ! { ! this.profile.setProperty(ConnectionMetaData.CONTEXT, context); ! } ! ! ! ! /** ! * Sets the credentials. ! * ! * @param credentials The credentials to set ! */ ! public void setCredentials(String credentials) ! { ! this.profile.setProperty(ConnectionMetaData.CREDENTIALS, credentials); ! } ! ! ! /** ! * Sets the provider attribute of the JndiServer object ! * ! * @param factory The new factory value ! */ ! public void setFactory(String factory) ! { ! this.profile.setProperty(ConnectionMetaData.FACTORY, factory); ! } ! ! ! /** ! * Sets the name of this server ! * ! * @param name The name ! */ ! public void setName(String name) ! { ! super.setName(name); ! } ! ! ! /** ! * Sets the packages attribute of the JndiServer object ! * ! * @param packages The new packages value ! */ ! public void setPackages(String packages) ! { ! this.profile.setProperty(ConnectionMetaData.PACKAGES, packages); ! } ! ! ! ! /** ! * Sets the principal. ! * ! * @param principal The principal to set ! */ ! public void setPrincipal(String principal) ! { ! this.profile.setProperty(ConnectionMetaData.PRINCIPAL, principal); ! } ! ! ! /** ! * Sets the profile. ! * ! * @param profile The profile to set ! */ ! public void setProfile(Profile profile) ! { ! this.profile = profile; ! } ! ! ! /** ! * Sets the url attribute of the JndiServer object ! * ! * @param url The new url value ! */ ! public void setUrl(String url) ! { ! this.profile.setProperty(ConnectionMetaData.URL, url); ! } ! ! ! /** ! * Description of the Method ! * ! * @param context Description of the Parameter ! * @param jndiName Description of the Parameter ! * @return Description of the Return Value ! */ ! protected JNDIContext createNode(Context context, String jndiName) ! { ! for (int i = 0; i < proxies.size(); i++) ! { ! Class clazz = (Class) proxies.elementAt(i); ! ! try ! { ! Constructor c = clazz.getConstructor(new Class[]{javax.naming.Context.class, java.lang.String.class}); ! JNDIContext node = (JNDIContext) c.newInstance(new Object[]{context, jndiName}); ! if (node != null) ! { ! return node; ! } ! } ! catch (Exception e) ! { ! } ! } ! ! return null; ! } ! ! ! /** ! * Description of the Method ! * ! * @param ctx Description of the Parameter ! * @param node Description of the Parameter ! */ ! protected void list(Context ctx, Collection node) ! { ! ClassLoader loader = Thread.currentThread().getContextClassLoader(); ! try ! { ! NamingEnumeration ne = ctx.list(""); ! while (ne.hasMore()) ! { ! JNDIContext newNode = null; ! ! NameClassPair pair = (NameClassPair) ne.next(); ! ! String name = pair.getName(); ! String className = pair.getClassName(); ! boolean recursive = false; ! boolean isLinkRef = false; ! ! Class c = null; ! try ! { ! c = loader.loadClass(className); ! ! if (Context.class.isAssignableFrom(c)) ! { ! recursive = true; ! } ! if (LinkRef.class.isAssignableFrom(c)) ! { ! isLinkRef = true; ! } ! } ! catch (ClassNotFoundException cnfe) ! { ! logger.warn("ClassNotFoundException " + cnfe.getMessage()); ! } ! catch (Exception e) ! { ! logger.warn("Exception " + e.getMessage()); ! } ! ! if (isLinkRef) ! { ! try ! { ! newNode = new JNDILinkRef(ctx, name); ! node.add(newNode); ! } ! catch (Exception e) ! { ! } ! } ! ! if (recursive) ! { ! newNode = new JNDIContext(); ! newNode.setName(name); ! newNode.setClassName(className); ! ! try ! { ! Object value = ctx.lookup(name); ! ! if (value instanceof Context) ! { ! Context subctx = (Context) value; ! list(subctx, newNode); ! } ! } ! catch (Throwable t) ! { ! logger.warn("Throwable " + t); ! } ! } ! ! // Try to cast to a predefined object ! if (newNode == null) ! { ! newNode = createNode(ctx, name); ! } ! ! // If no match, create a JNDIEntry ! if (newNode == null) ! { ! newNode = new JNDIEntry(); ! newNode.setName(name); ! newNode.setClassName(className); ! } ! ! node.add(newNode); ! } ! ne.close(); ! } ! catch (NamingException ne) ! { ! logger.error("error while listing context " + ctx.toString() + ": " + ne.toString(true)); ! } ! } ! ! /** Proxies to load */ ! static ! { ! proxies.add(org.ejtools.jndi.browser.model.JNDIEnvEntry.class); ! proxies.add(org.ejtools.jndi.browser.model.ejb.EJBHomeProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.ejb.EJBLocalHomeProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.QueueProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.TopicProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.jms.ConnectionFactoryProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.mail.SessionProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.sql.DataSourceProxy.class); ! proxies.add(org.ejtools.jndi.browser.model.Proxy.class); ! } ! } |