User: pathoss Date: 02/04/05 06:12:25 Modified: core/resources/xdoclet/ejb Messages.properties util.j Log: - improved performance so that the construction of the initial context only happens when not cached before - i18n Revision Changes Path 1.10 +9 -0 xdoclet/core/resources/xdoclet/ejb/Messages.properties Index: Messages.properties =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/core/resources/xdoclet/ejb/Messages.properties,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -r1.9 -r1.10 --- Messages.properties 28 Mar 2002 00:00:57 -0000 1.9 +++ Messages.properties 5 Apr 2002 14:12:25 -0000 1.10 @@ -35,6 +35,8 @@ dd_findbypk_perm=Permission for findByPK method description_not_supported=description not supported yet by ejbdoclet entity_dataholder_version="Wrong version. Had " + getVersion() + ", got " + dataHolder.getVersion() +util_cached_remote=Cached remote home (EJBHome). Uses lazy loading to obtain its value (loaded by getHome() methods). +util_cached_local=Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). util_localhome_not_narrowed=Local homes shouldn''t be narrowed, as there is no RMI involved. util_obtain_localhome_def_ic=Obtain local home interface from default initial context util_obtain_home_param_ic=Obtain remote home interface from parameterised initial context @@ -42,6 +44,13 @@ util_ic_parameters=Parameters to use for creating initial context util_home_lookups=Home interface lookup methods util_obtain_ic=Obtain initial context +util_guid_1=A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT</strong> be seen by the user, +util_guid_2=not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs. +util_guid_usage=<p>Usage: Add an <code>id</code> field (type java.lang.String) to your EJB, and add <code>setId(XXXUtil.generateGUID(this));</code> to the <code>ejbCreate</code> method. +util_guid_ip=Cached per JVM server IP. +util_guid_securerandom=initialise the secure random instance +util_guid_localinetaddress=get the inet address +util_guid_unknownhost=Could not get the local IP address using InetAddress.getLocalHost()! interface_invalid_type=getComponentInterface can only take type=remote|local - received type={0} tag_missing_interface_parameter=Error in template file. {0} must contain the interface parameter. Allowed values are remote (default) or local. interface_not_found=The interface ''{0}'' not found! 1.18 +55 -41 xdoclet/core/resources/xdoclet/ejb/util.j Index: util.j =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/core/resources/xdoclet/ejb/util.j,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -r1.17 -r1.18 --- util.j 5 Apr 2002 10:26:16 -0000 1.17 +++ util.j 5 Apr 2002 14:12:25 -0000 1.18 @@ -23,9 +23,12 @@ { <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true"> <XDtEjbIntf:ifRemoteEjb> + /** <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_cached_remote"/> */ static <XDtEjbHome:homeInterface type="remote"/> cachedRemoteHome = null; </XDtEjbIntf:ifRemoteEjb> <XDtEjbIntf:ifLocalEjb> + + /** <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_cached_local"/> */ static <XDtEjbHome:homeInterface type="local"/> cachedLocalHome = null; </XDtEjbIntf:ifLocalEjb> </XDtConfig:ifConfigParamEquals> @@ -39,23 +42,29 @@ */ public static <XDtEjbHome:homeInterface type="remote"/> getHome() throws NamingException { - InitialContext initialContext = new InitialContext(); - try { <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true"> if (cachedRemoteHome == null) { + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_obtain_ic"/> + InitialContext initialContext = new InitialContext(); + try { java.lang.Object objRef = initialContext.lookup(<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>); cachedRemoteHome = (<XDtEjbHome:homeInterface type="remote"/>)PortableRemoteObject.narrow(objRef, <XDtEjbHome:homeInterface type="remote"/>.class); + } finally { + initialContext.close(); + } } return cachedRemoteHome; </XDtConfig:ifConfigParamEquals> - <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true"> + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_obtain_ic"/> + InitialContext initialContext = new InitialContext(); + try { java.lang.Object objRef = initialContext.lookup(<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>); return (<XDtEjbHome:homeInterface type="remote"/>)PortableRemoteObject.narrow(objRef, <XDtEjbHome:homeInterface type="remote"/>.class); - </XDtConfig:ifConfigParamNotEquals> } finally { initialContext.close(); } + </XDtConfig:ifConfigParamNotEquals> } /** @@ -65,6 +74,7 @@ */ public static <XDtEjbHome:homeInterface type="remote"/> getHome( Hashtable environment ) throws NamingException { + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_obtain_ic"/> InitialContext initialContext = new InitialContext(environment); try { java.lang.Object objRef = initialContext.lookup(<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>); @@ -82,21 +92,28 @@ */ public static <XDtEjbHome:homeInterface type="local"/> getLocalHome() throws NamingException { - InitialContext initialContext = new InitialContext(); - try { // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_localhome_not_narrowed"/> <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true"> - if (cachedLocalHome == null) + if (cachedLocalHome == null) { + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_obtain_ic"/> + InitialContext initialContext = new InitialContext(); + try { cachedLocalHome = (<XDtEjbHome:homeInterface type="local"/>) initialContext.lookup(<XDtEjbHome:homeInterface type="local"/>.<XDtEjbUtilObj:lookupKind/>); + } finally { + initialContext.close(); + } + } return cachedLocalHome; </XDtConfig:ifConfigParamEquals> - <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true"> + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_obtain_ic"/> + InitialContext initialContext = new InitialContext(); + try { return (<XDtEjbHome:homeInterface type="local"/>) initialContext.lookup(<XDtEjbHome:homeInterface type="local"/>.<XDtEjbUtilObj:lookupKind/>); - </XDtConfig:ifConfigParamNotEquals> } finally { initialContext.close(); } + </XDtConfig:ifConfigParamNotEquals> } </XDtEjbIntf:ifLocalEjb> @@ -104,29 +121,28 @@ </XDtMerge:merge> <XDtConfig:ifConfigParamEquals paramName="includeGUID" value="true"> - /** Cached per JVM server IP. */ + /** <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_ip"/> */ private static String hexServerIP = null; - // initialise the secure random instance + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_securerandom"/> private static final SecureRandom seeder = new SecureRandom(); /** - * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT</strong> be seen by the user, - * not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs. + * <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_1"/> + * <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_2"/> * - * <p>Usage: Add an <code>id</code> field (type java.lang.String) to your EJB, and add <code>setId(XXXUtil.generateGUID(this));</code> - * to the <code>ejbCreate</code> method. + * <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_usage"/> */ public static final String generateGUID(Object o) { StringBuffer tmpBuffer = new StringBuffer(16); if (hexServerIP == null) { InetAddress localInetAddress = null; try { - // get the inet address + // <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_localinetaddress"/> localInetAddress = InetAddress.getLocalHost(); } catch (java.net.UnknownHostException uhe) { - System.err.println("<XDtClass:classOf><XDtEjbUtilObj:utilClass/></XDtClass:classOf>: could not get the local IP address using InetAddress.getLocalHost()!"); + System.err.println("<XDtClass:classOf><XDtEjbUtilObj:utilClass/></XDtClass:classOf>: <XDtI18n:getString bundle="xdoclet.ejb.Messages" resource="util_guid_unknownhost"/>"); // todo: find better way to get around this... uhe.printStackTrace(); return null; @@ -134,16 +150,14 @@ byte serverIP[] = localInetAddress.getAddress(); hexServerIP = hexFormat(getInt(serverIP), 8); } - // get the hashcode String hashcode = hexFormat(System.identityHashCode(o), 8); - // set up a middle value as this is the same per method - // call as is object specific and is the ...-xxxx-xxxx-xxxx-xxxx.. - // mid part of the sequence tmpBuffer.append(hexServerIP); tmpBuffer.append(hashcode); + long timeNow = System.currentTimeMillis(); int timeLow = (int)timeNow & 0xFFFFFFFF; int node = seeder.nextInt(); + StringBuffer guid = new StringBuffer(32); guid.append(hexFormat(timeLow, 8)); guid.append(tmpBuffer.toString());
_______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel