You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by David Blevins <da...@visi.com> on 2009/09/01 00:56:39 UTC

Re: JNDI Names: lower case interfaceType.annotationName?

On Aug 31, 2009, at 2:44 PM, Jonathan Gallimore wrote:

> This seems to work well, although I did break the JndiNameTest. I've  
> fixed
> this by using the StringTemplate that is used normally, and grabbing  
> the
> format string from there. This seems a bit nasty but all the openejb- 
> core
> tests pass now (and I'll run the rest tonight).


That does seem a bit nasty.  What if we created a complete replacement  
StringTemplate class, something like this (refactored version of the  
code from your patch):

   public class StringTemplate {

       private static final Pattern PATTERN = Pattern.compile("(\\{)((\ 
\.|\\w)+)(})");

       private Matcher matcher;

       public StringTemplate(String template) {
           matcher = PATTERN.matcher(template);
       }

       public String format(Map<String, String> map) {
           StringBuffer buf = new StringBuffer();

           while (matcher.find()) {
               String key = matcher.group(2);
               String value = map.get(key);

               if (key.toLowerCase().endsWith(".lc")) {
                   value = map.get(key.substring(0, key.length() -  
3)).toLowerCase();
               } else if (key.toLowerCase().endsWith(".uc")) {
                   value = map.get(key.substring(0, key.length() -  
3)).toUpperCase();
               } else if (key.toLowerCase().endsWith(".cc")) {
                   value = Strings.camelCase(map.get(key.substring(0,  
key.length() - 3)));
               }

               matcher.appendReplacement(buf, value);
           }

           matcher.appendTail(buf);
           return buf.toString();
       }

   }


We could throw that in the util package then just do a find/replace on  
org.codehaus.swizzle.stream.StringTemplate ->  
org.apache.openejb.util.StringTemplate

Thoughts?

On a side note we should use StringBuilder instead of StringBuffer.

-David


Re: JNDI Names: lower case interfaceType.annotationName?

Posted by Jonathan Gallimore <jo...@gmail.com>.
Its in. I didn't change to StringBuilder in the end as
Matcher.appendReplacement() doesn't support it.

Cheers

Jon

On Tue, Sep 1, 2009 at 11:39 PM, David Blevins <da...@visi.com>wrote:

> Go ahead and commit it.
>
>
> On Sep 1, 2009, at 3:14 PM, Jonathan Gallimore wrote:
>
>  Thanks again David. I've made those changes and attached them to the
>> issue.
>> All tests pass and it seems to work ok.
>>
>> I've just remembered that I forgot to swap to use StringBuilder - I'll do
>> that before committing. Let me know if there's any other comments!
>>
>> Cheers
>>
>> Jon
>>
>> On Mon, Aug 31, 2009 at 11:56 PM, David Blevins <david.blevins@visi.com
>> >wrote:
>>
>>
>>> On Aug 31, 2009, at 2:44 PM, Jonathan Gallimore wrote:
>>>
>>> This seems to work well, although I did break the JndiNameTest. I've
>>> fixed
>>>
>>>> this by using the StringTemplate that is used normally, and grabbing the
>>>> format string from there. This seems a bit nasty but all the
>>>> openejb-core
>>>> tests pass now (and I'll run the rest tonight).
>>>>
>>>>
>>>
>>> That does seem a bit nasty.  What if we created a complete replacement
>>> StringTemplate class, something like this (refactored version of the code
>>> from your patch):
>>>
>>> public class StringTemplate {
>>>
>>>    private static final Pattern PATTERN =
>>> Pattern.compile("(\\{)((\\.|\\w)+)(})");
>>>
>>>    private Matcher matcher;
>>>
>>>    public StringTemplate(String template) {
>>>        matcher = PATTERN.matcher(template);
>>>    }
>>>
>>>    public String format(Map<String, String> map) {
>>>        StringBuffer buf = new StringBuffer();
>>>
>>>        while (matcher.find()) {
>>>            String key = matcher.group(2);
>>>            String value = map.get(key);
>>>
>>>            if (key.toLowerCase().endsWith(".lc")) {
>>>                value = map.get(key.substring(0, key.length() -
>>> 3)).toLowerCase();
>>>            } else if (key.toLowerCase().endsWith(".uc")) {
>>>                value = map.get(key.substring(0, key.length() -
>>> 3)).toUpperCase();
>>>            } else if (key.toLowerCase().endsWith(".cc")) {
>>>                value = Strings.camelCase(map.get(key.substring(0,
>>> key.length() - 3)));
>>>            }
>>>
>>>            matcher.appendReplacement(buf, value);
>>>        }
>>>
>>>        matcher.appendTail(buf);
>>>        return buf.toString();
>>>    }
>>>
>>> }
>>>
>>>
>>> We could throw that in the util package then just do a find/replace on
>>> org.codehaus.swizzle.stream.StringTemplate ->
>>> org.apache.openejb.util.StringTemplate
>>>
>>> Thoughts?
>>>
>>> On a side note we should use StringBuilder instead of StringBuffer.
>>>
>>> -David
>>>
>>>
>>>
>

Re: JNDI Names: lower case interfaceType.annotationName?

Posted by David Blevins <da...@visi.com>.
Go ahead and commit it.

On Sep 1, 2009, at 3:14 PM, Jonathan Gallimore wrote:

> Thanks again David. I've made those changes and attached them to the  
> issue.
> All tests pass and it seems to work ok.
>
> I've just remembered that I forgot to swap to use StringBuilder -  
> I'll do
> that before committing. Let me know if there's any other comments!
>
> Cheers
>
> Jon
>
> On Mon, Aug 31, 2009 at 11:56 PM, David Blevins <david.blevins@visi.com 
> >wrote:
>
>>
>> On Aug 31, 2009, at 2:44 PM, Jonathan Gallimore wrote:
>>
>> This seems to work well, although I did break the JndiNameTest.  
>> I've fixed
>>> this by using the StringTemplate that is used normally, and  
>>> grabbing the
>>> format string from there. This seems a bit nasty but all the  
>>> openejb-core
>>> tests pass now (and I'll run the rest tonight).
>>>
>>
>>
>> That does seem a bit nasty.  What if we created a complete  
>> replacement
>> StringTemplate class, something like this (refactored version of  
>> the code
>> from your patch):
>>
>> public class StringTemplate {
>>
>>     private static final Pattern PATTERN =
>> Pattern.compile("(\\{)((\\.|\\w)+)(})");
>>
>>     private Matcher matcher;
>>
>>     public StringTemplate(String template) {
>>         matcher = PATTERN.matcher(template);
>>     }
>>
>>     public String format(Map<String, String> map) {
>>         StringBuffer buf = new StringBuffer();
>>
>>         while (matcher.find()) {
>>             String key = matcher.group(2);
>>             String value = map.get(key);
>>
>>             if (key.toLowerCase().endsWith(".lc")) {
>>                 value = map.get(key.substring(0, key.length() -
>> 3)).toLowerCase();
>>             } else if (key.toLowerCase().endsWith(".uc")) {
>>                 value = map.get(key.substring(0, key.length() -
>> 3)).toUpperCase();
>>             } else if (key.toLowerCase().endsWith(".cc")) {
>>                 value = Strings.camelCase(map.get(key.substring(0,
>> key.length() - 3)));
>>             }
>>
>>             matcher.appendReplacement(buf, value);
>>         }
>>
>>         matcher.appendTail(buf);
>>         return buf.toString();
>>     }
>>
>> }
>>
>>
>> We could throw that in the util package then just do a find/replace  
>> on
>> org.codehaus.swizzle.stream.StringTemplate ->
>> org.apache.openejb.util.StringTemplate
>>
>> Thoughts?
>>
>> On a side note we should use StringBuilder instead of StringBuffer.
>>
>> -David
>>
>>


Re: JNDI Names: lower case interfaceType.annotationName?

Posted by Jonathan Gallimore <jo...@gmail.com>.
Thanks again David. I've made those changes and attached them to the issue.
All tests pass and it seems to work ok.

I've just remembered that I forgot to swap to use StringBuilder - I'll do
that before committing. Let me know if there's any other comments!

Cheers

Jon

On Mon, Aug 31, 2009 at 11:56 PM, David Blevins <da...@visi.com>wrote:

>
> On Aug 31, 2009, at 2:44 PM, Jonathan Gallimore wrote:
>
>  This seems to work well, although I did break the JndiNameTest. I've fixed
>> this by using the StringTemplate that is used normally, and grabbing the
>> format string from there. This seems a bit nasty but all the openejb-core
>> tests pass now (and I'll run the rest tonight).
>>
>
>
> That does seem a bit nasty.  What if we created a complete replacement
> StringTemplate class, something like this (refactored version of the code
> from your patch):
>
>  public class StringTemplate {
>
>      private static final Pattern PATTERN =
> Pattern.compile("(\\{)((\\.|\\w)+)(})");
>
>      private Matcher matcher;
>
>      public StringTemplate(String template) {
>          matcher = PATTERN.matcher(template);
>      }
>
>      public String format(Map<String, String> map) {
>          StringBuffer buf = new StringBuffer();
>
>          while (matcher.find()) {
>              String key = matcher.group(2);
>              String value = map.get(key);
>
>              if (key.toLowerCase().endsWith(".lc")) {
>                  value = map.get(key.substring(0, key.length() -
> 3)).toLowerCase();
>              } else if (key.toLowerCase().endsWith(".uc")) {
>                  value = map.get(key.substring(0, key.length() -
> 3)).toUpperCase();
>              } else if (key.toLowerCase().endsWith(".cc")) {
>                  value = Strings.camelCase(map.get(key.substring(0,
> key.length() - 3)));
>              }
>
>              matcher.appendReplacement(buf, value);
>          }
>
>          matcher.appendTail(buf);
>          return buf.toString();
>      }
>
>  }
>
>
> We could throw that in the util package then just do a find/replace on
> org.codehaus.swizzle.stream.StringTemplate ->
> org.apache.openejb.util.StringTemplate
>
> Thoughts?
>
> On a side note we should use StringBuilder instead of StringBuffer.
>
> -David
>
>