Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.sample » bean » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.sample.bean;
   15   
   16   import javax.enterprise.context.RequestScoped;
   17   import javax.enterprise.inject.Default;
   18   import javax.inject.Inject;
   19   import javax.inject.Named;
   20   import javax.enterprise.inject.Produces;
   21   import javax.enterprise.inject.spi.Bean;
   22   import javax.persistence.EntityManagerFactory;
   23   import javax.persistence.PersistenceUnit;
   24   
   25   import org.apache.webbeans.container.BeanManagerImpl;
   26   import org.apache.webbeans.sample.ejb.Echo;
   27   import org.apache.webbeans.sample.injection.InjectionTargetBean;
   28   
   29   
   30   @RequestScoped
   31   @Named("echo")
   32   public class EchoManaged
   33   {
   34       private @Inject @Default Echo echo;
   35           
   36       private String text;
   37       
   38       private String name;
   39       
   40       private @Produces @Default @PersistenceUnit(unitName="myDataBase") EntityManagerFactory emf;
   41       
   42       public String getName()
   43       {
   44           return name;
   45       }
   46   
   47       public void setName(String name)
   48       {
   49           this.name = name;
   50       }
   51   
   52       public String echo()
   53       {
   54           BeanManagerImpl manager = BeanManagerImpl.getManager();
   55           Bean<?> b = manager.getBeans("injected").iterator().next();
   56           InjectionTargetBean bean = (InjectionTargetBean)manager.getReference(b, InjectionTargetBean.class, manager.createCreationalContext(b)); 
   57           
   58           System.out.println("EMF --> " + bean.getFactory().equals(this.emf));
   59           
   60           this.text = echo.echo(name);
   61           
   62           return null;
   63       }
   64   
   65       public String getText()
   66       {
   67           return text;
   68       }
   69   
   70       public void setText(String text)
   71       {
   72           this.text = text;
   73       }
   74       
   75       
   76   }

Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.sample » bean » [javadoc | source]