Author: akarasulu Date: Tue Dec 14 16:46:06 2004 New Revision: 111903 URL: http://svn.apache.org/viewcvs?view=rev&rev=111903 Log: Changes ...
o cleared out Sytem.out or System.err lines replacing them where appropriate with a call to a monitor o added and using a ProviderMonitor This resolves the following issue: http://nagoya.apache.org/jira/browse/DIRLDAP-22 Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/ProviderMonitor.java Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java (original) +++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifIterator.java Tue Dec 14 16:46:06 2004 @@ -209,15 +209,7 @@ */ private void error( String msg, Throwable throwable ) { - if ( null == monitor ) - { - System.err.println( msg ) ; - throwable.printStackTrace( System.err ) ; - } - else - { - monitor.fatalFailure( msg, throwable ) ; - } + monitor.fatalFailure( msg, throwable ) ; } @@ -229,20 +221,7 @@ */ private void debug( String msg ) { - if ( !DEBUG ) - { - return ; - } - - - if ( null == monitor ) - { - System.out.println( msg ) ; - } - else - { - monitor.infoAvailable( msg ) ; - } + monitor.infoAvailable( msg ) ; } Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java (original) +++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/Provider.java Tue Dec 14 16:46:06 2004 @@ -236,7 +236,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a> * @author $Author: akarasulu $ - * @version $Revision: 1.9 $ + * @version $Revision$ */ public abstract class Provider { @@ -249,9 +249,74 @@ "asn.1.berlib.provider" ; /** The default file searched for on CP to load default provider props. */ - public static final String BERLIB_PROPFILE = + public static final String BERLIB_PROPFILE = "berlib.properties" ; + /** A provider monitor key. */ + public static final String PROVIDER_MONITOR_KEY = + "asn.1.berlib.provider.monitor" ; + + /** Message to use when using defaults */ + public static final String USING_DEFAULTS_MSG = + "Could not find the ASN.1 berlib provider properties file: " + + "berlib.properties.\nFile is not present on the classpath " + + "or in $JAVA_HOME/lib:\n\tjava.home = " + + System.getProperty( "java.home" ) + "\n\tjava.class.path = " + + System.getProperty( "java.class.path" ); + + /** Use the no-op monitor by default unless we find something else */ + private static ProviderMonitor monitor = null; + + + static + { + findMonitor( System.getProperties() ); + } + + + /* + * Checks to see if the provider monitor has been set as a system + * property. If it has try to instantiate it and use it. + */ + private static void findMonitor( Properties props ) + { + if ( props.containsKey( PROVIDER_MONITOR_KEY ) ) + { + String fqcn = System.getProperties().getProperty( PROVIDER_MONITOR_KEY ); + + if ( fqcn != null ) + { + Class mc = null; + + try + { + mc = Class.forName( fqcn ); + monitor = ( ProviderMonitor ) mc.newInstance(); + } + catch ( ClassNotFoundException e ) + { + System.err.println( "provider monitor class " + fqcn + " not found" ); + } + catch ( IllegalAccessException e ) + { + System.err.println( "provider monitor class " + fqcn + + " does not expose a public default constructor" ); + } + catch ( InstantiationException e ) + { + System.err.println( "provider monitor class " + fqcn + + " failed during instantiation" ); + } + } + } + + if ( monitor == null ) + { + monitor = ProviderMonitor.NOOP_MONITOR; + } + } + + // ------------------------------------------------------------------------ // Provider Properties // ------------------------------------------------------------------------ @@ -262,6 +327,7 @@ /** The Provider's vendor name */ private final String vendor; + // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @@ -369,8 +435,7 @@ * @return a singleton instance of the ASN.1 BER Library Provider * @throws ProviderException if the provider cannot be found */ - public static Provider getProvider( Hashtable a_env ) - throws ProviderException + public static Provider getProvider( Hashtable a_env ) throws ProviderException { Provider provider = null ; String className = ( String ) a_env.get( BERLIB_PROVIDER ) ; @@ -418,15 +483,14 @@ } catch ( InvocationTargetException ite ) { - ProviderException l_pe = new ProviderException( null, + ProviderException pe = new ProviderException( null, "Call to Provider's factory method: " + className + ".getProvider() threw the following exception:\n" + ite.getTargetException() ) ; - l_pe.addThrowable( ite.getTargetException() ) ; - throw l_pe ; + pe.addThrowable( ite.getTargetException() ) ; + throw pe ; } - return provider ; } @@ -487,6 +551,8 @@ pe.addThrowable( ioe ); } + findMonitor( env ); + monitor.propsFound( propFile.getAbsolutePath(), env ); break ; } @@ -532,34 +598,29 @@ "Failed to load " + propFile.getAbsolutePath() ) ; pe.addThrowable( ioe ); } + + findMonitor( env ); + monitor.propsFound( propFile.getAbsolutePath(), env ); } } - // Prop file not on classpath so we complain and use the default! - if ( env == null ) + // Attempt to override or add values off of JVM command-line parameter. + if ( System.getProperties().containsKey( BERLIB_PROVIDER ) + && ( System.getProperty( BERLIB_PROVIDER ) != null ) ) { - System.err.println( - "Could not find the ASN.1 berlib provider properties file: " - + "berlib.properties.\nFile is not present on the classpath " - + "or in $JAVA_HOME/lib:\n\tjava.home = " - + System.getProperty( "java.home" ) + "\n\tjava.class.path = " - + System.getProperty( "java.class.path" ) ); - System.err.println( "Using default provider class: " - + DEFAULT_PROVIDER ); env = new Properties(); - env.setProperty( BERLIB_PROVIDER, DEFAULT_PROVIDER ); + env.setProperty( BERLIB_PROVIDER, System.getProperty( BERLIB_PROVIDER ) ); } - // Attempt to override or add values off of JVM command-line parameter. - if ( System.getProperties().containsKey( BERLIB_PROVIDER ) - && ( System.getProperty( BERLIB_PROVIDER ) != null ) ) + // Prop file not on classpath so we complain and use the default! + if ( env == null ) { - env.setProperty( BERLIB_PROVIDER, - System.getProperty( BERLIB_PROVIDER ) ); + env = new Properties(); + env.setProperty( BERLIB_PROVIDER, DEFAULT_PROVIDER ); + monitor.usingDefaults( USING_DEFAULTS_MSG, env ); } - return env; } Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/ProviderMonitor.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/ProviderMonitor.java?view=auto&rev=111903 ============================================================================== --- (empty file) +++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/spi/ProviderMonitor.java Tue Dec 14 16:46:06 2004 @@ -0,0 +1,54 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.ldap.common.message.spi; + + +import java.util.Properties; + + +/** + * A Provider monitor's callback interface. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public interface ProviderMonitor +{ + /** A do nothing monitor to use if none is provided */ + public static ProviderMonitor NOOP_MONITOR = new ProviderMonitor() + { + public final void propsFound( final String msg, final Properties props ) {} + public final void usingDefaults( final String msg, final Properties props ) {} + }; + + + /** + * Callback used to monitor the discovered properties for the provider. + * + * @param msg a message about where the properties were found or null + * @param props the properties discovered + */ + void propsFound( String msg, Properties props ); + + /** + * Callback used to monitor if and what set of defaults are being used. + * + * @param msg a descriptive message about this event or null + * @param props the properties that constitute the defaults + */ + void usingDefaults( String msg, Properties props ); +} Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java (original) +++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/BooleanUtils.java Tue Dec 14 16:46:06 2004 @@ -616,16 +616,6 @@ return false; } -// public static void main(String[] args) { -// long start = System.currentTimeMillis(); -// boolean flag = true; -// int count = 0; -// for (int i = 0; i < 100000000; i++) { -// flag = toBoolean("YES"); -// } -// long end = System.currentTimeMillis(); -// System.out.println((end - start) + " " + flag + " " + count); -// } /** * <p>Converts a String to a Boolean throwing an exception if no match found.</p> Modified: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java (original) +++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java Tue Dec 14 16:46:06 2004 @@ -77,11 +77,8 @@ StringBuffer oriBuf = new StringBuffer(); ori.printToBuffer( oriBuf ); - System.out.println( "ori: " + oriBuf.toString() ); StringBuffer alteredBuf = new StringBuffer(); altered.printToBuffer( alteredBuf ); - System.out.println( "altered: " + alteredBuf.toString() ); - assertFalse( oriBuf.toString().equals( alteredBuf.toString() ) ); } @@ -98,11 +95,8 @@ StringBuffer oriBuf = new StringBuffer(); ori.printToBuffer( oriBuf ); - System.out.println( "ori: " + oriBuf.toString() ); StringBuffer alteredBuf = new StringBuffer(); altered.printToBuffer( alteredBuf ); - System.out.println( "altered: " + alteredBuf.toString() ); - assertTrue( oriBuf.toString().equals( alteredBuf.toString() ) ); } } Modified: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java (original) +++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java Tue Dec 14 16:46:06 2004 @@ -681,36 +681,7 @@ DirContext l_dirCtx = ( DirContext ) l_binding.getObject() ; NameParser l_parser = l_dirCtx.getNameParser( "" ) ; Name l_namex = l_parser.parse( l_dirCtx.getNameInNamespace() ) ; - System.out.println( "l_namex = " + l_namex.toString() ) ; - - System.out.println( "l_namex.endsWith( " - + "ou=Special Users,dc=example,dc=com ) = " - + l_namex.endsWith( l_name0 ) ) ; - - System.out.println( "l_namex.endsWith( " - + "dc=example,dc=com ) = " - + l_namex.endsWith( l_name1 ) ) ; - - System.out.println( "l_namex.endsWith( " - + "dc=com ) = " - + l_namex.endsWith( l_name2 ) ) ; - - System.out.println( "l_namex.endsWith( " - + "ou=Special Users ) = " - + l_namex.endsWith( l_name3 ) ) ; - - System.out.println( "l_namex.endsWith( " - + "ou=Special Users,dc=example ) = " - + l_namex.endsWith( l_name4 ) ) ; - - System.out.println( "l_namex.endsWith( " - + "\"\" ) = " - + l_namex.endsWith( l_name5 ) ) ; - - // DirContext l_dirCtx = ( DirContext ) l_enum.next() ; - // System.out.println( l_dirCtx.getNameInNamespace() ) ; - // System.out.println( l_enum.next().getClass() ) ; } */ } Modified: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java?view=diff&rev=111903&p1=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java&r1=111902&p2=incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java&r2=111903 ============================================================================== --- incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java (original) +++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java Tue Dec 14 16:46:06 2004 @@ -36,7 +36,6 @@ "All generalized time lengths with g-differential option for the " + "time zone should be a length of 19 characters but we got:\n"; - /** * Tests to make sure the format and time correspond with the returned * String from the [EMAIL PROTECTED] DateUtils#getGeneralizedTime(long)} method.
