2 Replies Latest reply on Aug 8, 2011 7:13 PM by Tim Evers

    Static inner class, duplicate components

    Ronaldo Rigoni Newbie

      Hello all,
      We have a Seam component and an inner class as follow, when Seam starts,try to setup the component twice.


      The basic problem is the enum inside the class, if I remove the enum and put in a separate file, all works fine!
      Why this problem occurs?


      The class is as follows:




      /**
       * 
       */
      package br.com.humanoweb.siheb.informacoespessoais.entity;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      
      import org.hibernate.envers.Audited;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Role;
      
      import br.com.humanoweb.arquitetura.framework.entity.BaseEntity;
      import br.com.humanoweb.arquitetura.framework.entity.EnumerableId;
      
      /**
       * @author Ronaldo
       * @date 03/08/2011
       */
      @Audited
      @Entity
      @Table(name = "tipo_situacao_pessoa", schema = "informacao_paciente")
      @Role(name = "situacaoPessoa")
      @AutoCreate
      @Name("situacaoPessoa")
      public class SituacaoPessoa extends BaseEntity {
      
          /**
           * serialVersionUID utilizado para interoperabilidade.
           */
          private static final long serialVersionUID = -1283781264136921L;
      
          /**
           * Enum para indicar a situação de uma pessoa.
           * 
           * @x: Ativo, Inativo ou Removido
           * @author ronaldo.rigoni
           * @date 04/08/2011
           */
          public static enum SituacaoPessoaEnum implements EnumerableId<SituacaoPessoa> {
              /**
               * Indica que a {@link Pessoa} está ativa.
               */
              ATIVO(1L),
              /**
               * Indica que a {@link Pessoa} está inativa.
               */
              INATIVO(2L),
              /**
               * Indica que a {@link Pessoa} foi removida do sistema.
               */
              REMOVIDO(3L);
      
              /**
               * Identificador do enum que será usado para comparações com a entidade {@link SituacaoPessoa}.
               */
              private Long id;
      
              /**
               * Inicializa a instância de {@link SituacaoPessoaEnum}.
               * 
               * @param id O identificador.
               */
              private SituacaoPessoaEnum(Long id) {
                  this.id = id;
              }
      
              /**
               * Recupera o identificador deste tipo do enum.
               */
              @Override
              public Long getId() {
                  return id;
              }
      
              /**
               * Compara uma {@link SituacaoPessoa} verificando se a mesma possui o mesmo identificador que este enum.
               * 
               * @param entity entidade do tipo {@link SituacaoPessoa}.
               */
              @Override
              public boolean compare(SituacaoPessoa entity) {
                  return this.id.equals(entity.getId());
              }
      
              /**
               * serialVersionUID utilizado para interoperabilidade.
               */
              private static final long serialVersionUID = -1283781297152634921L;
          }
      
          /**
           * Identificador de {@link SituacaoPessoa}.
           */
          @Id
          @Column(name = "id")
          private Long id;
          /**
           * Nome da {@link SituacaoPessoa}.
           */
          @Column(name = "nome")
          private String nome;
      
          /**
           * Construtor default.
           */
          public SituacaoPessoa() {
          }
      
          /**
           * Constrói uma nova instância de {@link SituacaoPessoa}.
           * 
           * @param situacaoPessoaEnum id correspondente.
           */
          public SituacaoPessoa(SituacaoPessoaEnum situacaoPessoaEnum) {
              this.id = situacaoPessoaEnum.getId();
          }
      
          /**
           * Recupera o identificador de {@link SituacaoPessoa}.
           */
          public Long getId() {
              return this.id;
          }
      
          /**
           * Define o identificador de {@link SituacaoPessoa}.
           * 
           * @param id o identificador.
           */
          public void setId(Long id) {
              this.id = id;
          }
      
          /**
           * Recupera o nome de {@link SituacaoPessoa}.
           * 
           * @return o nome.
           */
          public String getNome() {
              return this.nome;
          }
      
          /**
           * Define o nome de {@link SituacaoPessoa}.
           * 
           * @param nome o nome de {@link SituacaoPessoa}.
           */
          public void setNome(String nome) {
              this.nome = nome;
          }
      
      }
      



        • 1. Re: Static inner class, duplicate components
          Ronaldo Rigoni Newbie

          The complete error log is as follow:




          14:19:51,508 INFO  [STDOUT] INFO SeamListener - Welcome to Seam 2.2.0.GA
          14:19:55,987 INFO  [STDOUT] INFO Initialization - reading /WEB-INF/components.xml
          14:19:56,026 INFO  [STDOUT] INFO Initialization - reading properties from: /seam.properties
          14:19:56,028 INFO  [STDOUT] INFO Initialization - reading properties from: /jndi.properties
          14:19:56,055 INFO  [STDOUT] INFO Component - Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init
          14:19:56,066 INFO  [STDOUT] INFO Initialization - two components with same name, higher precedence wins: org.jboss.seam.core.expressions
          14:19:56,067 INFO  [STDOUT] INFO Initialization - two components with same name, higher precedence wins: situacaoPessoa
          14:19:56,067 ERROR [[/sih]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
          java.lang.IllegalStateException: Two components with the same name and precedence - component name: situacaoPessoa, component classes: br.com.humanoweb.siheb.informacoespessoais.entity.SituacaoPessoa, br.com.humanoweb.siheb.informacoespessoais.entity.SituacaoPessoa
               at org.jboss.seam.init.Initialization.addComponentDescriptor(Initialization.java:601)
               at org.jboss.seam.init.Initialization.installRole(Initialization.java:976)
               at org.jboss.seam.init.Initialization.installScannedComponentAndRoles(Initialization.java:958)
               at org.jboss.seam.init.Initialization.scanForComponents(Initialization.java:894)
               at org.jboss.seam.init.Initialization.init(Initialization.java:706)
               at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
               at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
               at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
               at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
               at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
               at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
               at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
               at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
               at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
               at $Proxy38.start(Unknown Source)
               at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
               at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
               at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
               at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
               at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
               at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
               at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
               at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
               at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
               at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
               at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
               at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
               at org.jboss.system.ServiceController.start(ServiceController.java:460)
               at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
               at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
               at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
               at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
               at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
               at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
               at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
               at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
               at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
               at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
               at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
               at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
               at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
               at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
               at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
               at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
               at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
               at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
               at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
               at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
               at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
               at java.lang.Thread.run(Unknown Source)



          • 2. Re: Static inner class, duplicate components
            Tim Evers Master

            Well, putting an inner enum class inside a Seam bean works fine for us.


            @Name(ArrearsExclusionActionBean.SEAM_ID)
            @Scope(ScopeType.CONVERSATION)
            public class ArrearsExclusionActionBean extends
                SortableTableBackingBean<ArrearsExclusionDisplayBean>
            {
            
                public static final String SEAM_ID = "ArrearsExclusionActionBean";
            
                //...bunch of methods etc
                //One of these methods is:
                public FilterType[] getFilterTypes() {
                    return FilterType.values();
                }
             
                private enum FilterType {
                    ALL, AVAILABLE, REMOVED
                }
            }
            



            Seam boots up fine with many of the above classes in our codebase. So, the problem must lie in the finer details.


            I guess I'm a little bit confused as to why you have a public enum as an inner class. If it's public then why make it an inner class? If it's not used by anything else then make it private. If you've only made it public so yo can access it on your xhtml page then use my example and make it private and just provide a public method that returns all the enum values.


            By the way...what does the static do for you? I actually have never really come across someone declaring their enums as static so, I'm genuinely interested in what that actually does. :S


            At the end of the day though there must be something else going on that is causing Seam to detect multiple beans of the same name. Make sure you are cleaning your classes directory properly. Make sure your superclasses aren't the cause of your problem. Try simplifying your code with just a simple inner enum class first and then expand it to what you want and see when the problem happens.


            Inner class enums work fine. So, start simple and build up to the point that exposes your problem.