Bug with AnnotationScannerParser (DWR-3.0.RC3)

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug with AnnotationScannerParser (DWR-3.0.RC3)

ememisya
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}

Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}


Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

ememisya
I don't believe I have access, I don't see the CREATE button I usually see in Jira instances.  My username is ememisya

On 09/28/2015 05:51 PM, David Marginian wrote:
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}



Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
https://directwebremoting.atlassian.net/browse/DWR-651

On 09/28/2015 10:09 PM, John Doe wrote:
I don't believe I have access, I don't see the CREATE button I usually see in Jira instances.  My username is ememisya

On 09/28/2015 05:51 PM, David Marginian wrote:
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}




Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
In reply to this post by ememisya
I looked into this more and I closed the issue, the DWR code is correct.

By default, Spring uses the AnnotationBeanNameGenerator for component scanning:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator--

This name generator allows users to specify the bean name on the annotation.  If we do as you suggest (which isn't correct, you could simply use the DefaultBeanGenerator) we would be going against Spring's convention and potentially break other users. 

On 09/28/2015 10:09 PM, John Doe wrote:
I don't believe I have access, I don't see the CREATE button I usually see in Jira instances.  My username is ememisya

On 09/28/2015 05:51 PM, David Marginian wrote:
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}




Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

Mike Wilson
Administrator
Erdem,
Instead of setting the bean name on every RemoteProxy, Spring should allow you to make a global configuration specifying your preferred BeanNameGenerator for annotation scanning. Something like:
 
@ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
public class MySpringConfiguration {
/* dummy config holder class */ }
 
Best regards
Mike Wilson
 
David Marginian wrote:
I looked into this more and I closed the issue, the DWR code is correct.

By default, Spring uses the AnnotationBeanNameGenerator for component scanning:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator--

This name generator allows users to specify the bean name on the annotation.  If we do as you suggest (which isn't correct, you could simply use the DefaultBeanGenerator) we would be going against Spring's convention and potentially break other users. 

On 09/28/2015 10:09 PM, John Doe wrote:
I don't believe I have access, I don't see the CREATE button I usually see in Jira instances.  My username is ememisya

On 09/28/2015 05:51 PM, David Marginian wrote:
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}




Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

ememisya
However I'd rather not set a global configuration as I already have a naming scheme, how would I implement nameGenerator for <dwr:annotation-scan> element which ignores @Component?

In an out of the box simple web application where you implement Spring and DWR, it won't work if the classes have the same name in different packages and are annotated by @RemoteProxy.  It's broken out of the box, this would fix it.

If you could please look into it once more I would appreciate it.

On 09/29/2015 10:53 AM, Mike Wilson wrote:
Erdem,
Instead of setting the bean name on every RemoteProxy, Spring should allow you to make a global configuration specifying your preferred BeanNameGenerator for annotation scanning. Something like:
 
@ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
public class MySpringConfiguration {
/* dummy config holder class */ }
 
Best regards
Mike Wilson
 
David Marginian wrote:
I looked into this more and I closed the issue, the DWR code is correct.

By default, Spring uses the AnnotationBeanNameGenerator for component scanning:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator--

This name generator allows users to specify the bean name on the annotation.  If we do as you suggest (which isn't correct, you could simply use the DefaultBeanGenerator) we would be going against Spring's convention and potentially break other users. 

On 09/28/2015 10:09 PM, John Doe wrote:
I don't believe I have access, I don't see the CREATE button I usually see in Jira instances.  My username is ememisya

On 09/28/2015 05:51 PM, David Marginian wrote:
Can you create a Jira for this?

On 09/28/2015 10:20 AM, John Doe wrote:
I've come across an issue refactoring my code the other day.  It looks like DWR uses the class' simple name to name the beans, this becomes an issue when two classes with the same name exist on different packages and are annotated with @RemoteProxy.  Adding a BeanNameGenerator implementation which uses the full package name (like Spring does conventionally) would resolve this problem as shown below:

        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });

I have the below implementation in my project to continue developing, looking forward to hearing from you.

Sincerely,

--Erdem "Adam" Memisyazici
SETI Middleware (http://www.middleware.vt.edu)
Virginia Tech Polytechnic Institute and State University

AnnotationScannerParser.java

/*
 * Copyright 2010 original author or authors
 *
 * 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.directwebremoting.spring.namespace;

import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.GlobalFilter;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.w3c.dom.Element;

import static org.springframework.util.StringUtils.*;

/**
 * Register a new bean definition and a proxy for each class that is annotated with
 * {@link org.directwebremoting.annotations.RemoteProxy} and is detected scanning the
 * base-package directory. It will also scan for DTOs and global filters in the same way.
 *
 * @author Jose Noheda [[hidden email]]
 * @author Erdem Memisyazici [[hidden email]]
 */
public class AnnotationScannerParser implements BeanDefinitionParser
{

    private static final Log log = LogFactory.getLog(AnnotationScannerParser.class);

    private boolean scanFilters = true;
    private boolean scanProxies = true;
    private boolean scanConverters = true;

    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
        scanner.setBeanNameGenerator(new BeanNameGenerator() {
          public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
          {
           return beanDefinition.getBeanClassName();
          }
        });
        String basePackage = element.getAttribute("base-package");
        if (!hasText(basePackage))
        {
            if (log.isInfoEnabled())
            {
                log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
            }
        }
        String regex = element.getAttribute("regex");
        if (hasText(regex))
        {
            scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
        }
        String proxies = element.getAttribute("scanRemoteProxy");
        if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
        {
            scanProxies = Boolean.parseBoolean(proxies);
        }
        if (scanProxies)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        }
        String conv = element.getAttribute("scanDataTransferObject");
        if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
        {
            scanConverters = Boolean.parseBoolean(conv);
        }
        if (scanConverters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        }
        String filters = element.getAttribute("scanGlobalFilter");
        if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
        {
            scanFilters = Boolean.parseBoolean(filters);
        }
        if (scanFilters)
        {
            scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        }
        if (scanProxies | scanConverters | scanFilters)
        {
            scanner.scan(basePackage == null ? "" : basePackage);
        }
        else
        {
            log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
        }
        return null;
    }

}





Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
What you are asking us to do is change the default way Spring handles
creating beans from annotated components.  Spring has defaults in place
for a reason, I don't think it is our place to override their decisions.
  Your fix would fix things for you, it would break other people that use
and rely on the name generator that Spring uses by default -
AnnotationBeanNameGenerator.  There is a solution for you.  Specify your
bean name in the annotated component - problem solved.  It fixes your
issue and it doesn't break other users.

On 2015-09-29 10:47, John Doe wrote:

> However I'd rather not set a global configuration as I already have a
> naming scheme, how would I implement nameGenerator for
> <dwr:annotation-scan> element which ignores @Component?
>
>  In an out of the box simple web application where you implement
> Spring and DWR, it won't work if the classes have the same name in
> different packages and are annotated by @RemoteProxy.  It's broken
> out of the box, this would fix it.
>
>  If you could please look into it once more I would appreciate it.
>
> On 09/29/2015 10:53 AM, Mike Wilson wrote:
>
>> Erdem,
>> Instead of setting the bean name on every RemoteProxy, Spring
>> should allow you to make a global configuration specifying your
>> preferred BeanNameGenerator for annotation scanning. Something like:
>>
>>  
>> @ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
>> public class MySpringConfiguration { /* dummy config holder class
>> */ }
>>  
>> Best regards
>> Mike Wilson
>>  
>> David Marginian wrote:
>> I looked into this more and I closed the issue, the DWR code is
>> correct.
>>
>> By default, Spring uses the AnnotationBeanNameGenerator for
>> component scanning:
>>
> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator
>> [1]--
>>
>> This name generator allows users to specify the bean name on the
>> annotation.  If we do as you suggest (which isn't correct, you
>> could simply use the DefaultBeanGenerator) we would be going against
>> Spring's convention and potentially break other users. 
>>
>> On 09/28/2015 10:09 PM, John Doe wrote:
>> I don't believe I have access, I don't see the CREATE button I
>> usually see in Jira instances.  My username is ememisya
>>
>> On 09/28/2015 05:51 PM, David Marginian wrote:
>>
>> Can you create a Jira for this?
>>
>> On 09/28/2015 10:20 AM, John Doe wrote:
>>
>> I've come across an issue refactoring my code the other day.  It
>> looks like DWR uses the class' simple name to name the beans, this
>> becomes an issue when two classes with the same name exist on
>> different packages and are annotated with @RemoteProxy.  Adding a
>> BeanNameGenerator implementation which uses the full package name
>> (like Spring does conventionally) would resolve this problem as
>> shown below:
>>
>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>> {
>>           public String generateBeanName(BeanDefinition
>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>           {
>>            return beanDefinition.getBeanClassName();
>>           }
>>         });
>>
>> I have the below implementation in my project to continue
>> developing, looking forward to hearing from you.
>>
>> Sincerely,
>>
>> --Erdem "Adam" Memisyazici
>> SETI Middleware (http://www.middleware.vt.edu [2])
>> Virginia Tech Polytechnic Institute and State University
>>
>> AnnotationScannerParser.java
>>
>> /*
>>  * Copyright 2010 original author or authors
>>  *
>>  * 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 [3]
>>  *
>>  * 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.directwebremoting.spring.namespace;
>>
>> import java.util.regex.Pattern;
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> import org.directwebremoting.annotations.DataTransferObject;
>> import org.directwebremoting.annotations.GlobalFilter;
>> import org.directwebremoting.annotations.RemoteProxy;
>> import
>> org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
>> import org.springframework.beans.factory.config.BeanDefinition;
>> import
>> org.springframework.beans.factory.support.BeanDefinitionRegistry;
>> import org.springframework.beans.factory.support.BeanNameGenerator;
>> import org.springframework.beans.factory.xml.BeanDefinitionParser;
>> import org.springframework.beans.factory.xml.ParserContext;
>> import
>>
> org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
>> import org.springframework.core.type.filter.AnnotationTypeFilter;
>> import org.springframework.core.type.filter.RegexPatternTypeFilter;
>> import org.w3c.dom.Element;
>>
>> import static org.springframework.util.StringUtils.*;
>>
>> /**
>>  * Register a new bean definition and a proxy for each class that
>> is annotated with
>>  * {@link org.directwebremoting.annotations.RemoteProxy} and is
>> detected scanning the
>>  * base-package directory. It will also scan for DTOs and global
>> filters in the same way.
>>  *
>>  * @author Jose Noheda [[hidden email]]
>>
>>  * @author Erdem Memisyazici [[hidden email]]
>>
>>  */
>> public class AnnotationScannerParser implements
>> BeanDefinitionParser
>> {
>>
>>     private static final Log log =
>> LogFactory.getLog(AnnotationScannerParser.class);
>>
>>     private boolean scanFilters = true;
>>     private boolean scanProxies = true;
>>     private boolean scanConverters = true;
>>
>>     public BeanDefinition parse(Element element, ParserContext
>> parserContext)
>>     {
>>         ClassPathBeanDefinitionScanner scanner = new
>> DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>> {
>>           public String generateBeanName(BeanDefinition
>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>           {
>>            return beanDefinition.getBeanClassName();
>>           }
>>         });
>>         String basePackage =
>> element.getAttribute("base-package");
>>         if (!hasText(basePackage))
>>         {
>>             if (log.isInfoEnabled())
>>             {
>>                 log.info [4]("No base package
>> defined for classpath scanning. Traversing the whole JVM
>> classpath");
>>             }
>>         }
>>         String regex = element.getAttribute("regex");
>>         if (hasText(regex))
>>         {
>>             scanner.addIncludeFilter(new
>> RegexPatternTypeFilter(Pattern.compile(regex)));
>>         }
>>         String proxies =
>> element.getAttribute("scanRemoteProxy");
>>         if (hasText(proxies) &&
>> ("TRUE".equals(proxies.toUpperCase()) ||
>> "FALSE".equals(proxies.toUpperCase())))
>>         {
>>             scanProxies = Boolean.parseBoolean(proxies);
>>         }
>>         if (scanProxies)
>>         {
>>             scanner.addIncludeFilter(new
>> AnnotationTypeFilter(RemoteProxy.class));
>>         }
>>         String conv =
>> element.getAttribute("scanDataTransferObject");
>>         if (hasText(conv) &&
>> ("TRUE".equals(conv.toUpperCase()) ||
>> "FALSE".equals(conv.toUpperCase())))
>>         {
>>             scanConverters = Boolean.parseBoolean(conv);
>>         }
>>         if (scanConverters)
>>         {
>>             scanner.addIncludeFilter(new
>> AnnotationTypeFilter(DataTransferObject.class));
>>         }
>>         String filters =
>> element.getAttribute("scanGlobalFilter");
>>         if (hasText(filters) &&
>> ("TRUE".equals(filters.toUpperCase()) ||
>> "FALSE".equals(filters.toUpperCase())))
>>         {
>>             scanFilters = Boolean.parseBoolean(filters);
>>         }
>>         if (scanFilters)
>>         {
>>             scanner.addIncludeFilter(new
>> AnnotationTypeFilter(GlobalFilter.class));
>>         }
>>         if (scanProxies | scanConverters | scanFilters)
>>         {
>>             scanner.scan(basePackage == null ? "" :
>> basePackage);
>>         }
>>         else
>>         {
>>             log.warn("Scan is not required if all
>> @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled.
>> Skipping detection");
>>         }
>>         return null;
>>     }
>>
>> }
>
>
>
> Links:
> ------
> [1]
> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator
> [2] http://www.middleware.vt.edu
> [3] http://www.apache.org/licenses/LICENSE-2.0
> [4] http://log.info
Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

ememisya
It would be nice if I could use the features of the
AnnotationBeanNameGenerator, however I cannot since the scanner ignores
classes annotated with @Component

There is indeed a reason why there are defaults in place, and by default
DWR doesn't work.

http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/context/annotation/AnnotationBeanNameGenerator.html

If you have a chance, please feel free to look into this issue
independently.

Sincerely,

--Erdem "Adam" Memisyazici

On 09/29/2015 01:19 PM, [hidden email] wrote:

> What you are asking us to do is change the default way Spring handles
> creating beans from annotated components.  Spring has defaults in
> place for a reason, I don't think it is our place to override their
> decisions.  Your fix would fix things for you, it would break other
> people that use and rely on the name generator that Spring uses by
> default - AnnotationBeanNameGenerator.  There is a solution for you.
> Specify your bean name in the annotated component - problem solved.  
> It fixes your issue and it doesn't break other users.
>
> On 2015-09-29 10:47, John Doe wrote:
>> However I'd rather not set a global configuration as I already have a
>> naming scheme, how would I implement nameGenerator for
>> <dwr:annotation-scan> element which ignores @Component?
>>
>>  In an out of the box simple web application where you implement
>> Spring and DWR, it won't work if the classes have the same name in
>> different packages and are annotated by @RemoteProxy.  It's broken
>> out of the box, this would fix it.
>>
>>  If you could please look into it once more I would appreciate it.
>>
>> On 09/29/2015 10:53 AM, Mike Wilson wrote:
>>
>>> Erdem,
>>> Instead of setting the bean name on every RemoteProxy, Spring
>>> should allow you to make a global configuration specifying your
>>> preferred BeanNameGenerator for annotation scanning. Something like:
>>>
>>>
>>> @ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
>>> public class MySpringConfiguration { /* dummy config holder class
>>> */ }
>>>
>>> Best regards
>>> Mike Wilson
>>>
>>> David Marginian wrote:
>>> I looked into this more and I closed the issue, the DWR code is
>>> correct.
>>>
>>> By default, Spring uses the AnnotationBeanNameGenerator for
>>> component scanning:
>>>
>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator 
>>
>>> [1]--
>>>
>>> This name generator allows users to specify the bean name on the
>>> annotation.  If we do as you suggest (which isn't correct, you
>>> could simply use the DefaultBeanGenerator) we would be going against
>>> Spring's convention and potentially break other users.
>>>
>>> On 09/28/2015 10:09 PM, John Doe wrote:
>>> I don't believe I have access, I don't see the CREATE button I
>>> usually see in Jira instances.  My username is ememisya
>>>
>>> On 09/28/2015 05:51 PM, David Marginian wrote:
>>>
>>> Can you create a Jira for this?
>>>
>>> On 09/28/2015 10:20 AM, John Doe wrote:
>>>
>>> I've come across an issue refactoring my code the other day. It
>>> looks like DWR uses the class' simple name to name the beans, this
>>> becomes an issue when two classes with the same name exist on
>>> different packages and are annotated with @RemoteProxy. Adding a
>>> BeanNameGenerator implementation which uses the full package name
>>> (like Spring does conventionally) would resolve this problem as
>>> shown below:
>>>
>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>> {
>>>           public String generateBeanName(BeanDefinition
>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>           {
>>>            return beanDefinition.getBeanClassName();
>>>           }
>>>         });
>>>
>>> I have the below implementation in my project to continue
>>> developing, looking forward to hearing from you.
>>>
>>> Sincerely,
>>>
>>> --Erdem "Adam" Memisyazici
>>> SETI Middleware (http://www.middleware.vt.edu [2])
>>> Virginia Tech Polytechnic Institute and State University
>>>
>>> AnnotationScannerParser.java
>>>
>>> /*
>>>  * Copyright 2010 original author or authors
>>>  *
>>>  * 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 [3]
>>>  *
>>>  * 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.directwebremoting.spring.namespace;
>>>
>>> import java.util.regex.Pattern;
>>>
>>> import org.apache.commons.logging.Log;
>>> import org.apache.commons.logging.LogFactory;
>>> import org.directwebremoting.annotations.DataTransferObject;
>>> import org.directwebremoting.annotations.GlobalFilter;
>>> import org.directwebremoting.annotations.RemoteProxy;
>>> import
>>> org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
>>> import org.springframework.beans.factory.config.BeanDefinition;
>>> import
>>> org.springframework.beans.factory.support.BeanDefinitionRegistry;
>>> import org.springframework.beans.factory.support.BeanNameGenerator;
>>> import org.springframework.beans.factory.xml.BeanDefinitionParser;
>>> import org.springframework.beans.factory.xml.ParserContext;
>>> import
>>>
>> org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
>>> import org.springframework.core.type.filter.AnnotationTypeFilter;
>>> import org.springframework.core.type.filter.RegexPatternTypeFilter;
>>> import org.w3c.dom.Element;
>>>
>>> import static org.springframework.util.StringUtils.*;
>>>
>>> /**
>>>  * Register a new bean definition and a proxy for each class that
>>> is annotated with
>>>  * {@link org.directwebremoting.annotations.RemoteProxy} and is
>>> detected scanning the
>>>  * base-package directory. It will also scan for DTOs and global
>>> filters in the same way.
>>>  *
>>>  * @author Jose Noheda [[hidden email]]
>>>
>>>  * @author Erdem Memisyazici [[hidden email]]
>>>
>>>  */
>>> public class AnnotationScannerParser implements
>>> BeanDefinitionParser
>>> {
>>>
>>>     private static final Log log =
>>> LogFactory.getLog(AnnotationScannerParser.class);
>>>
>>>     private boolean scanFilters = true;
>>>     private boolean scanProxies = true;
>>>     private boolean scanConverters = true;
>>>
>>>     public BeanDefinition parse(Element element, ParserContext
>>> parserContext)
>>>     {
>>>         ClassPathBeanDefinitionScanner scanner = new
>>> DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>> {
>>>           public String generateBeanName(BeanDefinition
>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>           {
>>>            return beanDefinition.getBeanClassName();
>>>           }
>>>         });
>>>         String basePackage =
>>> element.getAttribute("base-package");
>>>         if (!hasText(basePackage))
>>>         {
>>>             if (log.isInfoEnabled())
>>>             {
>>>                 log.info [4]("No base package
>>> defined for classpath scanning. Traversing the whole JVM
>>> classpath");
>>>             }
>>>         }
>>>         String regex = element.getAttribute("regex");
>>>         if (hasText(regex))
>>>         {
>>>             scanner.addIncludeFilter(new
>>> RegexPatternTypeFilter(Pattern.compile(regex)));
>>>         }
>>>         String proxies =
>>> element.getAttribute("scanRemoteProxy");
>>>         if (hasText(proxies) &&
>>> ("TRUE".equals(proxies.toUpperCase()) ||
>>> "FALSE".equals(proxies.toUpperCase())))
>>>         {
>>>             scanProxies = Boolean.parseBoolean(proxies);
>>>         }
>>>         if (scanProxies)
>>>         {
>>>             scanner.addIncludeFilter(new
>>> AnnotationTypeFilter(RemoteProxy.class));
>>>         }
>>>         String conv =
>>> element.getAttribute("scanDataTransferObject");
>>>         if (hasText(conv) &&
>>> ("TRUE".equals(conv.toUpperCase()) ||
>>> "FALSE".equals(conv.toUpperCase())))
>>>         {
>>>             scanConverters = Boolean.parseBoolean(conv);
>>>         }
>>>         if (scanConverters)
>>>         {
>>>             scanner.addIncludeFilter(new
>>> AnnotationTypeFilter(DataTransferObject.class));
>>>         }
>>>         String filters =
>>> element.getAttribute("scanGlobalFilter");
>>>         if (hasText(filters) &&
>>> ("TRUE".equals(filters.toUpperCase()) ||
>>> "FALSE".equals(filters.toUpperCase())))
>>>         {
>>>             scanFilters = Boolean.parseBoolean(filters);
>>>         }
>>>         if (scanFilters)
>>>         {
>>>             scanner.addIncludeFilter(new
>>> AnnotationTypeFilter(GlobalFilter.class));
>>>         }
>>>         if (scanProxies | scanConverters | scanFilters)
>>>         {
>>>             scanner.scan(basePackage == null ? "" :
>>> basePackage);
>>>         }
>>>         else
>>>         {
>>>             log.warn("Scan is not required if all
>>> @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled.
>>> Skipping detection");
>>>         }
>>>         return null;
>>>     }
>>>
>>> }
>>
>>
>>
>> Links:
>> ------
>> [1]
>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator 
>>
>> [2] http://www.middleware.vt.edu
>> [3] http://www.apache.org/licenses/LICENSE-2.0
>> [4] http://log.info

Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
Thanks for the clarification.  If that is the case then there is a valid
issue here, that I will investigate.

On 2015-09-29 11:53, John Doe wrote:

> It would be nice if I could use the features of the
> AnnotationBeanNameGenerator, however I cannot since the scanner
> ignores classes annotated with @Component
>
> There is indeed a reason why there are defaults in place, and by
> default DWR doesn't work.
>
> http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/context/annotation/AnnotationBeanNameGenerator.html
>
> If you have a chance, please feel free to look into this issue
> independently.
>
> Sincerely,
>
> --Erdem "Adam" Memisyazici
>
> On 09/29/2015 01:19 PM, [hidden email] wrote:
>> What you are asking us to do is change the default way Spring handles
>> creating beans from annotated components.  Spring has defaults in
>> place for a reason, I don't think it is our place to override their
>> decisions.  Your fix would fix things for you, it would break other
>> people that use and rely on the name generator that Spring uses by
>> default - AnnotationBeanNameGenerator.  There is a solution for you.
>> Specify your bean name in the annotated component - problem solved.  
>> It fixes your issue and it doesn't break other users.
>>
>> On 2015-09-29 10:47, John Doe wrote:
>>> However I'd rather not set a global configuration as I already have a
>>> naming scheme, how would I implement nameGenerator for
>>> <dwr:annotation-scan> element which ignores @Component?
>>>
>>>  In an out of the box simple web application where you implement
>>> Spring and DWR, it won't work if the classes have the same name in
>>> different packages and are annotated by @RemoteProxy.  It's broken
>>> out of the box, this would fix it.
>>>
>>>  If you could please look into it once more I would appreciate it.
>>>
>>> On 09/29/2015 10:53 AM, Mike Wilson wrote:
>>>
>>>> Erdem,
>>>> Instead of setting the bean name on every RemoteProxy, Spring
>>>> should allow you to make a global configuration specifying your
>>>> preferred BeanNameGenerator for annotation scanning. Something like:
>>>>
>>>>
>>>> @ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
>>>> public class MySpringConfiguration { /* dummy config holder class
>>>> */ }
>>>>
>>>> Best regards
>>>> Mike Wilson
>>>>
>>>> David Marginian wrote:
>>>> I looked into this more and I closed the issue, the DWR code is
>>>> correct.
>>>>
>>>> By default, Spring uses the AnnotationBeanNameGenerator for
>>>> component scanning:
>>>>
>>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator
>>>> [1]--
>>>>
>>>> This name generator allows users to specify the bean name on the
>>>> annotation.  If we do as you suggest (which isn't correct, you
>>>> could simply use the DefaultBeanGenerator) we would be going against
>>>> Spring's convention and potentially break other users.
>>>>
>>>> On 09/28/2015 10:09 PM, John Doe wrote:
>>>> I don't believe I have access, I don't see the CREATE button I
>>>> usually see in Jira instances.  My username is ememisya
>>>>
>>>> On 09/28/2015 05:51 PM, David Marginian wrote:
>>>>
>>>> Can you create a Jira for this?
>>>>
>>>> On 09/28/2015 10:20 AM, John Doe wrote:
>>>>
>>>> I've come across an issue refactoring my code the other day. It
>>>> looks like DWR uses the class' simple name to name the beans, this
>>>> becomes an issue when two classes with the same name exist on
>>>> different packages and are annotated with @RemoteProxy. Adding a
>>>> BeanNameGenerator implementation which uses the full package name
>>>> (like Spring does conventionally) would resolve this problem as
>>>> shown below:
>>>>
>>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>>> {
>>>>           public String generateBeanName(BeanDefinition
>>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>>           {
>>>>            return beanDefinition.getBeanClassName();
>>>>           }
>>>>         });
>>>>
>>>> I have the below implementation in my project to continue
>>>> developing, looking forward to hearing from you.
>>>>
>>>> Sincerely,
>>>>
>>>> --Erdem "Adam" Memisyazici
>>>> SETI Middleware (http://www.middleware.vt.edu [2])
>>>> Virginia Tech Polytechnic Institute and State University
>>>>
>>>> AnnotationScannerParser.java
>>>>
>>>> /*
>>>>  * Copyright 2010 original author or authors
>>>>  *
>>>>  * 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 [3]
>>>>  *
>>>>  * 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.directwebremoting.spring.namespace;
>>>>
>>>> import java.util.regex.Pattern;
>>>>
>>>> import org.apache.commons.logging.Log;
>>>> import org.apache.commons.logging.LogFactory;
>>>> import org.directwebremoting.annotations.DataTransferObject;
>>>> import org.directwebremoting.annotations.GlobalFilter;
>>>> import org.directwebremoting.annotations.RemoteProxy;
>>>> import
>>>> org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
>>>> import org.springframework.beans.factory.config.BeanDefinition;
>>>> import
>>>> org.springframework.beans.factory.support.BeanDefinitionRegistry;
>>>> import org.springframework.beans.factory.support.BeanNameGenerator;
>>>> import org.springframework.beans.factory.xml.BeanDefinitionParser;
>>>> import org.springframework.beans.factory.xml.ParserContext;
>>>> import
>>>>
>>> org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
>>>> import org.springframework.core.type.filter.AnnotationTypeFilter;
>>>> import org.springframework.core.type.filter.RegexPatternTypeFilter;
>>>> import org.w3c.dom.Element;
>>>>
>>>> import static org.springframework.util.StringUtils.*;
>>>>
>>>> /**
>>>>  * Register a new bean definition and a proxy for each class that
>>>> is annotated with
>>>>  * {@link org.directwebremoting.annotations.RemoteProxy} and is
>>>> detected scanning the
>>>>  * base-package directory. It will also scan for DTOs and global
>>>> filters in the same way.
>>>>  *
>>>>  * @author Jose Noheda [[hidden email]]
>>>>
>>>>  * @author Erdem Memisyazici [[hidden email]]
>>>>
>>>>  */
>>>> public class AnnotationScannerParser implements
>>>> BeanDefinitionParser
>>>> {
>>>>
>>>>     private static final Log log =
>>>> LogFactory.getLog(AnnotationScannerParser.class);
>>>>
>>>>     private boolean scanFilters = true;
>>>>     private boolean scanProxies = true;
>>>>     private boolean scanConverters = true;
>>>>
>>>>     public BeanDefinition parse(Element element, ParserContext
>>>> parserContext)
>>>>     {
>>>>         ClassPathBeanDefinitionScanner scanner = new
>>>> DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
>>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>>> {
>>>>           public String generateBeanName(BeanDefinition
>>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>>           {
>>>>            return beanDefinition.getBeanClassName();
>>>>           }
>>>>         });
>>>>         String basePackage =
>>>> element.getAttribute("base-package");
>>>>         if (!hasText(basePackage))
>>>>         {
>>>>             if (log.isInfoEnabled())
>>>>             {
>>>>                 log.info [4]("No base package
>>>> defined for classpath scanning. Traversing the whole JVM
>>>> classpath");
>>>>             }
>>>>         }
>>>>         String regex = element.getAttribute("regex");
>>>>         if (hasText(regex))
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> RegexPatternTypeFilter(Pattern.compile(regex)));
>>>>         }
>>>>         String proxies =
>>>> element.getAttribute("scanRemoteProxy");
>>>>         if (hasText(proxies) &&
>>>> ("TRUE".equals(proxies.toUpperCase()) ||
>>>> "FALSE".equals(proxies.toUpperCase())))
>>>>         {
>>>>             scanProxies = Boolean.parseBoolean(proxies);
>>>>         }
>>>>         if (scanProxies)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(RemoteProxy.class));
>>>>         }
>>>>         String conv =
>>>> element.getAttribute("scanDataTransferObject");
>>>>         if (hasText(conv) &&
>>>> ("TRUE".equals(conv.toUpperCase()) ||
>>>> "FALSE".equals(conv.toUpperCase())))
>>>>         {
>>>>             scanConverters = Boolean.parseBoolean(conv);
>>>>         }
>>>>         if (scanConverters)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(DataTransferObject.class));
>>>>         }
>>>>         String filters =
>>>> element.getAttribute("scanGlobalFilter");
>>>>         if (hasText(filters) &&
>>>> ("TRUE".equals(filters.toUpperCase()) ||
>>>> "FALSE".equals(filters.toUpperCase())))
>>>>         {
>>>>             scanFilters = Boolean.parseBoolean(filters);
>>>>         }
>>>>         if (scanFilters)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(GlobalFilter.class));
>>>>         }
>>>>         if (scanProxies | scanConverters | scanFilters)
>>>>         {
>>>>             scanner.scan(basePackage == null ? "" :
>>>> basePackage);
>>>>         }
>>>>         else
>>>>         {
>>>>             log.warn("Scan is not required if all
>>>> @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled.
>>>> Skipping detection");
>>>>         }
>>>>         return null;
>>>>     }
>>>>
>>>> }
>>>
>>>
>>>
>>> Links:
>>> ------
>>> [1]
>>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator 
>>> [2] http://www.middleware.vt.edu
>>> [3] http://www.apache.org/licenses/LICENSE-2.0
>>> [4] http://log.info
Reply | Threaded
Open this post in threaded view
|

Re: Bug with AnnotationScannerParser (DWR-3.0.RC3)

david@butterdev.com
In reply to this post by ememisya
If you want a work-around until we fix this you should can use
annotation-config.  It scans @Component and will allow you to take
advantage of setting the name (value) on the component.  Example:

  <!-- Use annotation scan just for the DTOs -->
  <dwr:annotation-scan base-package="your.dto.package"
scanDataTransferObject="true" scanRemoteProxy="false"/>
  <!-- Use annotation-config to create DWR proxies -->
  <dwr:annotation-config id="dwrConfig"/>

Code:

package org.uk.ltd.dwr.dev.service;

@Component
@RemoteProxy(name="dwrService")
@Lazy(true)
public class DWRService {
     .... Code here
}

package org.uk.ltd.dwr.dev.dup;

@Component(value="dwrService2")
@RemoteProxy(name="dwrService2")
@Lazy(true)
public class DWRService {
     .... Code here
}

On 09/29/2015 11:53 AM, John Doe wrote:

> It would be nice if I could use the features of the
> AnnotationBeanNameGenerator, however I cannot since the scanner
> ignores classes annotated with @Component
>
> There is indeed a reason why there are defaults in place, and by
> default DWR doesn't work.
>
> http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/context/annotation/AnnotationBeanNameGenerator.html 
>
>
> If you have a chance, please feel free to look into this issue
> independently.
>
> Sincerely,
>
> --Erdem "Adam" Memisyazici
>
> On 09/29/2015 01:19 PM, [hidden email] wrote:
>> What you are asking us to do is change the default way Spring handles
>> creating beans from annotated components.  Spring has defaults in
>> place for a reason, I don't think it is our place to override their
>> decisions.  Your fix would fix things for you, it would break other
>> people that use and rely on the name generator that Spring uses by
>> default - AnnotationBeanNameGenerator.  There is a solution for you.
>> Specify your bean name in the annotated component - problem solved.  
>> It fixes your issue and it doesn't break other users.
>>
>> On 2015-09-29 10:47, John Doe wrote:
>>> However I'd rather not set a global configuration as I already have a
>>> naming scheme, how would I implement nameGenerator for
>>> <dwr:annotation-scan> element which ignores @Component?
>>>
>>>  In an out of the box simple web application where you implement
>>> Spring and DWR, it won't work if the classes have the same name in
>>> different packages and are annotated by @RemoteProxy.  It's broken
>>> out of the box, this would fix it.
>>>
>>>  If you could please look into it once more I would appreciate it.
>>>
>>> On 09/29/2015 10:53 AM, Mike Wilson wrote:
>>>
>>>> Erdem,
>>>> Instead of setting the bean name on every RemoteProxy, Spring
>>>> should allow you to make a global configuration specifying your
>>>> preferred BeanNameGenerator for annotation scanning. Something like:
>>>>
>>>>
>>>> @ComponentScan(nameGenerator = DefaultBeanNameGenerator.class)
>>>> public class MySpringConfiguration { /* dummy config holder class
>>>> */ }
>>>>
>>>> Best regards
>>>> Mike Wilson
>>>>
>>>> David Marginian wrote:
>>>> I looked into this more and I closed the issue, the DWR code is
>>>> correct.
>>>>
>>>> By default, Spring uses the AnnotationBeanNameGenerator for
>>>> component scanning:
>>>>
>>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator 
>>>
>>>> [1]--
>>>>
>>>> This name generator allows users to specify the bean name on the
>>>> annotation.  If we do as you suggest (which isn't correct, you
>>>> could simply use the DefaultBeanGenerator) we would be going against
>>>> Spring's convention and potentially break other users.
>>>>
>>>> On 09/28/2015 10:09 PM, John Doe wrote:
>>>> I don't believe I have access, I don't see the CREATE button I
>>>> usually see in Jira instances.  My username is ememisya
>>>>
>>>> On 09/28/2015 05:51 PM, David Marginian wrote:
>>>>
>>>> Can you create a Jira for this?
>>>>
>>>> On 09/28/2015 10:20 AM, John Doe wrote:
>>>>
>>>> I've come across an issue refactoring my code the other day. It
>>>> looks like DWR uses the class' simple name to name the beans, this
>>>> becomes an issue when two classes with the same name exist on
>>>> different packages and are annotated with @RemoteProxy. Adding a
>>>> BeanNameGenerator implementation which uses the full package name
>>>> (like Spring does conventionally) would resolve this problem as
>>>> shown below:
>>>>
>>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>>> {
>>>>           public String generateBeanName(BeanDefinition
>>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>>           {
>>>>            return beanDefinition.getBeanClassName();
>>>>           }
>>>>         });
>>>>
>>>> I have the below implementation in my project to continue
>>>> developing, looking forward to hearing from you.
>>>>
>>>> Sincerely,
>>>>
>>>> --Erdem "Adam" Memisyazici
>>>> SETI Middleware (http://www.middleware.vt.edu [2])
>>>> Virginia Tech Polytechnic Institute and State University
>>>>
>>>> AnnotationScannerParser.java
>>>>
>>>> /*
>>>>  * Copyright 2010 original author or authors
>>>>  *
>>>>  * 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 [3]
>>>>  *
>>>>  * 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.directwebremoting.spring.namespace;
>>>>
>>>> import java.util.regex.Pattern;
>>>>
>>>> import org.apache.commons.logging.Log;
>>>> import org.apache.commons.logging.LogFactory;
>>>> import org.directwebremoting.annotations.DataTransferObject;
>>>> import org.directwebremoting.annotations.GlobalFilter;
>>>> import org.directwebremoting.annotations.RemoteProxy;
>>>> import
>>>> org.directwebremoting.spring.DwrClassPathBeanDefinitionScanner;
>>>> import org.springframework.beans.factory.config.BeanDefinition;
>>>> import
>>>> org.springframework.beans.factory.support.BeanDefinitionRegistry;
>>>> import org.springframework.beans.factory.support.BeanNameGenerator;
>>>> import org.springframework.beans.factory.xml.BeanDefinitionParser;
>>>> import org.springframework.beans.factory.xml.ParserContext;
>>>> import
>>>>
>>> org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
>>>> import org.springframework.core.type.filter.AnnotationTypeFilter;
>>>> import org.springframework.core.type.filter.RegexPatternTypeFilter;
>>>> import org.w3c.dom.Element;
>>>>
>>>> import static org.springframework.util.StringUtils.*;
>>>>
>>>> /**
>>>>  * Register a new bean definition and a proxy for each class that
>>>> is annotated with
>>>>  * {@link org.directwebremoting.annotations.RemoteProxy} and is
>>>> detected scanning the
>>>>  * base-package directory. It will also scan for DTOs and global
>>>> filters in the same way.
>>>>  *
>>>>  * @author Jose Noheda [[hidden email]]
>>>>
>>>>  * @author Erdem Memisyazici [[hidden email]]
>>>>
>>>>  */
>>>> public class AnnotationScannerParser implements
>>>> BeanDefinitionParser
>>>> {
>>>>
>>>>     private static final Log log =
>>>> LogFactory.getLog(AnnotationScannerParser.class);
>>>>
>>>>     private boolean scanFilters = true;
>>>>     private boolean scanProxies = true;
>>>>     private boolean scanConverters = true;
>>>>
>>>>     public BeanDefinition parse(Element element, ParserContext
>>>> parserContext)
>>>>     {
>>>>         ClassPathBeanDefinitionScanner scanner = new
>>>> DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
>>>>         scanner.setBeanNameGenerator(new BeanNameGenerator()
>>>> {
>>>>           public String generateBeanName(BeanDefinition
>>>> beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry)
>>>>           {
>>>>            return beanDefinition.getBeanClassName();
>>>>           }
>>>>         });
>>>>         String basePackage =
>>>> element.getAttribute("base-package");
>>>>         if (!hasText(basePackage))
>>>>         {
>>>>             if (log.isInfoEnabled())
>>>>             {
>>>>                 log.info [4]("No base package
>>>> defined for classpath scanning. Traversing the whole JVM
>>>> classpath");
>>>>             }
>>>>         }
>>>>         String regex = element.getAttribute("regex");
>>>>         if (hasText(regex))
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> RegexPatternTypeFilter(Pattern.compile(regex)));
>>>>         }
>>>>         String proxies =
>>>> element.getAttribute("scanRemoteProxy");
>>>>         if (hasText(proxies) &&
>>>> ("TRUE".equals(proxies.toUpperCase()) ||
>>>> "FALSE".equals(proxies.toUpperCase())))
>>>>         {
>>>>             scanProxies = Boolean.parseBoolean(proxies);
>>>>         }
>>>>         if (scanProxies)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(RemoteProxy.class));
>>>>         }
>>>>         String conv =
>>>> element.getAttribute("scanDataTransferObject");
>>>>         if (hasText(conv) &&
>>>> ("TRUE".equals(conv.toUpperCase()) ||
>>>> "FALSE".equals(conv.toUpperCase())))
>>>>         {
>>>>             scanConverters = Boolean.parseBoolean(conv);
>>>>         }
>>>>         if (scanConverters)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(DataTransferObject.class));
>>>>         }
>>>>         String filters =
>>>> element.getAttribute("scanGlobalFilter");
>>>>         if (hasText(filters) &&
>>>> ("TRUE".equals(filters.toUpperCase()) ||
>>>> "FALSE".equals(filters.toUpperCase())))
>>>>         {
>>>>             scanFilters = Boolean.parseBoolean(filters);
>>>>         }
>>>>         if (scanFilters)
>>>>         {
>>>>             scanner.addIncludeFilter(new
>>>> AnnotationTypeFilter(GlobalFilter.class));
>>>>         }
>>>>         if (scanProxies | scanConverters | scanFilters)
>>>>         {
>>>>             scanner.scan(basePackage == null ? "" :
>>>> basePackage);
>>>>         }
>>>>         else
>>>>         {
>>>>             log.warn("Scan is not required if all
>>>> @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled.
>>>> Skipping detection");
>>>>         }
>>>>         return null;
>>>>     }
>>>>
>>>> }
>>>
>>>
>>>
>>> Links:
>>> ------
>>> [1]
>>> http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html#nameGenerator 
>>>
>>> [2] http://www.middleware.vt.edu
>>> [3] http://www.apache.org/licenses/LICENSE-2.0
>>> [4] http://log.info
>
>