http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-request-scope/README.md ---------------------------------------------------------------------- diff --git a/examples/cdi-request-scope/README.md b/examples/cdi-request-scope/README.md index 4658c45..1b2aa49 100644 --- a/examples/cdi-request-scope/README.md +++ b/examples/cdi-request-scope/README.md @@ -1,150 +1,150 @@ -Title: CDI @RequestScoped - -This example show the use of `@RequestScoped` annotation for injected objects. An object -which is defined as `@RequestScoped` is created once for every request and is shared by all the -bean that inject it throughout a request. - -# Example - -This example depicts a similar scenario to cdi-application-scope. A restaurant guest orders -a soup from the waiter. The order is passed to the chef who prepares it and passes it back -the waiter who in turn delivers it to the guest. - -## Waiter - -The `Waiter` session bean receives a request from the test class via the `orderSoup()` method. -A `Soup` insance will be created in this method and will be shared throughout the request with -the `Chef` bean. The method passes the request to the `Chef` bean. It then returns the name of -the soup to the test class. - - @Stateless - public class Waiter { - - @Inject - private Soup soup; - - @EJB - private Chef chef; - - public String orderSoup(String name){ - soup.setName(name); - return chef.prepareSoup().getName(); - } - } - -## Soup - -The `Soup` class is an injectable POJO, defined as `@RequestScoped`. This means that an instance -will be created only once for every request and will be shared by all the beans injecting it. - - @RequestScoped - public class Soup { - - private String name = "Soup of the day"; - - @PostConstruct - public void afterCreate() { - System.out.println("Soup created"); - } - - public String getName() { - return name; - } - - public void setName(String name){ - this.name = name; - } - } - -## Chef - -The `Chef` class is a simple session bean with an injected `Soup` field. Normally, the soup -parameter would be passed as a `prepareSoup()` argument, but for the need of this example -it's passed by the request context. - - @Stateless - public class Chef { - - @Inject - private Soup soup; - - public Soup prepareSoup() { - return soup; - } - } - -# Test Case - -This is the entry class for this example. - - public class RestaurantTest { - - private static String TOMATO_SOUP = "Tomato Soup"; - private EJBContainer container; - - @EJB - private Waiter joe; - - @Before - public void startContainer() throws Exception { - container = EJBContainer.createEJBContainer(); - container.getContext().bind("inject", this); - } - - @Test - public void orderSoup(){ - String soup = joe.orderSoup(TOMATO_SOUP); - assertEquals(TOMATO_SOUP, soup); - soup = joe.orderSoup(POTATO_SOUP); - assertEquals(POTATO_SOUP, soup); - } - - @After - public void closeContainer() throws Exception { - container.close(); - } - } - -# Running - -In the output you can see that there were two `Soup` instances created - one for -each request. - - ------------------------------------------------------- - T E S T S - ------------------------------------------------------- - Running org.superbiz.cdi.requestscope.RestaurantTest - Apache OpenEJB 7.0.0-SNAPSHOT build: 20111224-11:09 - http://tomee.apache.org/ - INFO - openejb.home = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope - INFO - openejb.base = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope - INFO - Using 'javax.ejb.embeddable.EJBContainer=true' - INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) - INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) - INFO - Found EjbModule in classpath: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes - INFO - Beginning load: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes - INFO - Configuring enterprise application: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope - INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) - INFO - Auto-creating a container for bean cdi-request-scope.Comp: Container(type=MANAGED, id=Default Managed Container) - INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) - INFO - Auto-creating a container for bean Chef: Container(type=STATELESS, id=Default Stateless Container) - INFO - Enterprise application "c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope" loaded. - INFO - Assembling app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope - INFO - Jndi(name="java:global/cdi-request-scope/Chef!org.superbiz.cdi.requestscope.Chef") - INFO - Jndi(name="java:global/cdi-request-scope/Chef") - INFO - Jndi(name="java:global/cdi-request-scope/Waiter!org.superbiz.cdi.requestscope.Waiter") - INFO - Jndi(name="java:global/cdi-request-scope/Waiter") - INFO - Created Ejb(deployment-id=Chef, ejb-name=Chef, container=Default Stateless Container) - INFO - Created Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container) - INFO - Started Ejb(deployment-id=Chef, ejb-name=Chef, container=Default Stateless Container) - INFO - Started Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container) - INFO - Deployed Application(path=c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope) - Soup created - Soup created - INFO - Undeploying app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope - Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.412 sec - - Results : - - Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 - +Title: CDI @RequestScoped + +This example show the use of `@RequestScoped` annotation for injected objects. An object +which is defined as `@RequestScoped` is created once for every request and is shared by all the +bean that inject it throughout a request. + +# Example + +This example depicts a similar scenario to cdi-application-scope. A restaurant guest orders +a soup from the waiter. The order is passed to the chef who prepares it and passes it back +the waiter who in turn delivers it to the guest. + +## Waiter + +The `Waiter` session bean receives a request from the test class via the `orderSoup()` method. +A `Soup` insance will be created in this method and will be shared throughout the request with +the `Chef` bean. The method passes the request to the `Chef` bean. It then returns the name of +the soup to the test class. + + @Stateless + public class Waiter { + + @Inject + private Soup soup; + + @EJB + private Chef chef; + + public String orderSoup(String name){ + soup.setName(name); + return chef.prepareSoup().getName(); + } + } + +## Soup + +The `Soup` class is an injectable POJO, defined as `@RequestScoped`. This means that an instance +will be created only once for every request and will be shared by all the beans injecting it. + + @RequestScoped + public class Soup { + + private String name = "Soup of the day"; + + @PostConstruct + public void afterCreate() { + System.out.println("Soup created"); + } + + public String getName() { + return name; + } + + public void setName(String name){ + this.name = name; + } + } + +## Chef + +The `Chef` class is a simple session bean with an injected `Soup` field. Normally, the soup +parameter would be passed as a `prepareSoup()` argument, but for the need of this example +it's passed by the request context. + + @Stateless + public class Chef { + + @Inject + private Soup soup; + + public Soup prepareSoup() { + return soup; + } + } + +# Test Case + +This is the entry class for this example. + + public class RestaurantTest { + + private static String TOMATO_SOUP = "Tomato Soup"; + private EJBContainer container; + + @EJB + private Waiter joe; + + @Before + public void startContainer() throws Exception { + container = EJBContainer.createEJBContainer(); + container.getContext().bind("inject", this); + } + + @Test + public void orderSoup(){ + String soup = joe.orderSoup(TOMATO_SOUP); + assertEquals(TOMATO_SOUP, soup); + soup = joe.orderSoup(POTATO_SOUP); + assertEquals(POTATO_SOUP, soup); + } + + @After + public void closeContainer() throws Exception { + container.close(); + } + } + +# Running + +In the output you can see that there were two `Soup` instances created - one for +each request. + + ------------------------------------------------------- + T E S T S + ------------------------------------------------------- + Running org.superbiz.cdi.requestscope.RestaurantTest + Apache OpenEJB 7.0.0-SNAPSHOT build: 20111224-11:09 + http://tomee.apache.org/ + INFO - openejb.home = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope + INFO - openejb.base = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope + INFO - Using 'javax.ejb.embeddable.EJBContainer=true' + INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) + INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) + INFO - Found EjbModule in classpath: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes + INFO - Beginning load: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes + INFO - Configuring enterprise application: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope + INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) + INFO - Auto-creating a container for bean cdi-request-scope.Comp: Container(type=MANAGED, id=Default Managed Container) + INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) + INFO - Auto-creating a container for bean Chef: Container(type=STATELESS, id=Default Stateless Container) + INFO - Enterprise application "c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope" loaded. + INFO - Assembling app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope + INFO - Jndi(name="java:global/cdi-request-scope/Chef!org.superbiz.cdi.requestscope.Chef") + INFO - Jndi(name="java:global/cdi-request-scope/Chef") + INFO - Jndi(name="java:global/cdi-request-scope/Waiter!org.superbiz.cdi.requestscope.Waiter") + INFO - Jndi(name="java:global/cdi-request-scope/Waiter") + INFO - Created Ejb(deployment-id=Chef, ejb-name=Chef, container=Default Stateless Container) + INFO - Created Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container) + INFO - Started Ejb(deployment-id=Chef, ejb-name=Chef, container=Default Stateless Container) + INFO - Started Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container) + INFO - Deployed Application(path=c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope) + Soup created + Soup created + INFO - Undeploying app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope + Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.412 sec + + Results : + + Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Chef.java ---------------------------------------------------------------------- diff --git a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Chef.java b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Chef.java index 7185113..c795bea 100644 --- a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Chef.java +++ b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Chef.java @@ -1,31 +1,31 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.requestscope; - -import javax.ejb.Stateless; -import javax.inject.Inject; - -@Stateless -public class Chef { - - @Inject - private Soup soup; - - public Soup prepareSoup() { - return soup; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.requestscope; + +import javax.ejb.Stateless; +import javax.inject.Inject; + +@Stateless +public class Chef { + + @Inject + private Soup soup; + + public Soup prepareSoup() { + return soup; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Soup.java ---------------------------------------------------------------------- diff --git a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Soup.java b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Soup.java index 3bce620..d86a608 100644 --- a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Soup.java +++ b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Soup.java @@ -1,39 +1,39 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.requestscope; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; - -@RequestScoped -public class Soup { - - private String name = "Soup of the day"; - - @PostConstruct - public void afterCreate() { - System.out.println("Soup created"); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.requestscope; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class Soup { + + private String name = "Soup of the day"; + + @PostConstruct + public void afterCreate() { + System.out.println("Soup created"); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Waiter.java ---------------------------------------------------------------------- diff --git a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Waiter.java b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Waiter.java index 53559a7..f14e4d9 100644 --- a/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Waiter.java +++ b/examples/cdi-request-scope/src/main/java/org/superbiz/cdi/requestscope/Waiter.java @@ -1,37 +1,37 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.requestscope; - -import javax.ejb.EJB; -import javax.ejb.Stateless; -import javax.inject.Inject; - -@Stateless -public class Waiter { - - @Inject - private Soup soup; - - @EJB - private Chef chef; - - public String orderSoup(String name) { - soup.setName(name); - return chef.prepareSoup().getName(); - } - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.requestscope; + +import javax.ejb.EJB; +import javax.ejb.Stateless; +import javax.inject.Inject; + +@Stateless +public class Waiter { + + @Inject + private Soup soup; + + @EJB + private Chef chef; + + public String orderSoup(String name) { + soup.setName(name); + return chef.prepareSoup().getName(); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-request-scope/src/test/java/org/superbiz/cdi/requestscope/RestaurantTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-request-scope/src/test/java/org/superbiz/cdi/requestscope/RestaurantTest.java b/examples/cdi-request-scope/src/test/java/org/superbiz/cdi/requestscope/RestaurantTest.java index fa64175..4a811ea 100644 --- a/examples/cdi-request-scope/src/test/java/org/superbiz/cdi/requestscope/RestaurantTest.java +++ b/examples/cdi-request-scope/src/test/java/org/superbiz/cdi/requestscope/RestaurantTest.java @@ -1,55 +1,55 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.requestscope; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; - -import static org.junit.Assert.assertEquals; - -public class RestaurantTest { - - private static final String TOMATO_SOUP = "Tomato Soup"; - private static final String POTATO_SOUP = "Potato Soup"; - private EJBContainer container; - - @EJB - private Waiter joe; - - @Before - public void startContainer() throws Exception { - container = EJBContainer.createEJBContainer(); - container.getContext().bind("inject", this); - } - - @Test - public void orderSoup() { - String soup = joe.orderSoup(TOMATO_SOUP); - assertEquals(TOMATO_SOUP, soup); - soup = joe.orderSoup(POTATO_SOUP); - assertEquals(POTATO_SOUP, soup); - } - - @After - public void closeContainer() throws Exception { - container.close(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.requestscope; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; + +import static org.junit.Assert.assertEquals; + +public class RestaurantTest { + + private static final String TOMATO_SOUP = "Tomato Soup"; + private static final String POTATO_SOUP = "Potato Soup"; + private EJBContainer container; + + @EJB + private Waiter joe; + + @Before + public void startContainer() throws Exception { + container = EJBContainer.createEJBContainer(); + container.getContext().bind("inject", this); + } + + @Test + public void orderSoup() { + String soup = joe.orderSoup(TOMATO_SOUP); + assertEquals(TOMATO_SOUP, soup); + soup = joe.orderSoup(POTATO_SOUP); + assertEquals(POTATO_SOUP, soup); + } + + @After + public void closeContainer() throws Exception { + container.close(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/AnswerBean.java ---------------------------------------------------------------------- diff --git a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/AnswerBean.java b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/AnswerBean.java index 2ba85a7..37655dc 100644 --- a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/AnswerBean.java +++ b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/AnswerBean.java @@ -1,40 +1,40 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.session; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -// just to take care to refresh it, otherwise using postcontruct you can see kind of cache effect on session bean -@RequestScoped -public class AnswerBean { - - @Inject - private SessionBean bean; - - private String value; - - @PostConstruct - public void init() { - value = '{' + bean.getName() + '}'; - } - - public String value() { - return value; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.session; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +// just to take care to refresh it, otherwise using postcontruct you can see kind of cache effect on session bean +@RequestScoped +public class AnswerBean { + + @Inject + private SessionBean bean; + + private String value; + + @PostConstruct + public void init() { + value = '{' + bean.getName() + '}'; + } + + public String value() { + return value; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/InputServlet.java ---------------------------------------------------------------------- diff --git a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/InputServlet.java b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/InputServlet.java index 220408b..af5d614 100644 --- a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/InputServlet.java +++ b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/InputServlet.java @@ -1,44 +1,44 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.session; - -import javax.inject.Inject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@WebServlet(name = "input-servlet", urlPatterns = {"/set-name"}) -public class InputServlet extends HttpServlet { - - @Inject - private SessionBean bean; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - final String name = req.getParameter("name"); - if (name == null || name.isEmpty()) { - resp.getWriter().write("please add a parameter name=xxx"); - } else { - bean.setName(name); - resp.getWriter().write("done, go to /name servlet"); - } - - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.session; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(name = "input-servlet", urlPatterns = {"/set-name"}) +public class InputServlet extends HttpServlet { + + @Inject + private SessionBean bean; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String name = req.getParameter("name"); + if (name == null || name.isEmpty()) { + resp.getWriter().write("please add a parameter name=xxx"); + } else { + bean.setName(name); + resp.getWriter().write("done, go to /name servlet"); + } + + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/OutputServlet.java ---------------------------------------------------------------------- diff --git a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/OutputServlet.java b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/OutputServlet.java index 11f623d..78c64a6 100644 --- a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/OutputServlet.java +++ b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/OutputServlet.java @@ -1,42 +1,42 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.session; - -import javax.inject.Inject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@WebServlet(name = "output-servlet", urlPatterns = {"/name"}) -public class OutputServlet extends HttpServlet { - - @Inject - private AnswerBean bean; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - final String name = bean.value(); - if (name == null || name.isEmpty()) { - resp.getWriter().write("please go to servlet /set-name please"); - } else { - resp.getWriter().write("name = " + name); - } - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.session; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(name = "output-servlet", urlPatterns = {"/name"}) +public class OutputServlet extends HttpServlet { + + @Inject + private AnswerBean bean; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String name = bean.value(); + if (name == null || name.isEmpty()) { + resp.getWriter().write("please go to servlet /set-name please"); + } else { + resp.getWriter().write("name = " + name); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/SessionBean.java ---------------------------------------------------------------------- diff --git a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/SessionBean.java b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/SessionBean.java index 0381af1..cc48047 100644 --- a/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/SessionBean.java +++ b/examples/cdi-session-scope/src/main/java/org/superbiz/cdi/session/SessionBean.java @@ -1,34 +1,34 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.cdi.session; - -import javax.enterprise.context.SessionScoped; -import java.io.Serializable; - -@SessionScoped -public class SessionBean implements Serializable { - - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.cdi.session; + +import javax.enterprise.context.SessionScoped; +import java.io.Serializable; + +@SessionScoped +public class SessionBean implements Serializable { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/change-jaxws-url/src/test/java/org/superbiz/jaxws/Rot13Test.java ---------------------------------------------------------------------- diff --git a/examples/change-jaxws-url/src/test/java/org/superbiz/jaxws/Rot13Test.java b/examples/change-jaxws-url/src/test/java/org/superbiz/jaxws/Rot13Test.java index adace70..b6a537d 100644 --- a/examples/change-jaxws-url/src/test/java/org/superbiz/jaxws/Rot13Test.java +++ b/examples/change-jaxws-url/src/test/java/org/superbiz/jaxws/Rot13Test.java @@ -1,51 +1,51 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.superbiz.jaxws; - -import org.apache.ziplock.IO; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.net.URL; - -@RunWith(Arquillian.class) -public class Rot13Test { - - @ArquillianResource - private URL url; - - @Deployment(testable = false) - public static WebArchive war() { - return ShrinkWrap.create(WebArchive.class) - .addClass(Rot13.class) - .addAsWebInfResource(new ClassLoaderAsset("META-INF/openejb-jar.xml"), ArchivePaths.create("openejb-jar.xml")); - } - - @Test - public void checkWSDLIsDeployedWhereItIsConfigured() throws Exception { - final String wsdl = IO.slurp(new URL(url.toExternalForm() + "tool/rot13?wsdl")); - Assert.assertTrue(wsdl.contains("Rot13")); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.superbiz.jaxws; + +import org.apache.ziplock.IO; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; + +@RunWith(Arquillian.class) +public class Rot13Test { + + @ArquillianResource + private URL url; + + @Deployment(testable = false) + public static WebArchive war() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Rot13.class) + .addAsWebInfResource(new ClassLoaderAsset("META-INF/openejb-jar.xml"), ArchivePaths.create("openejb-jar.xml")); + } + + @Test + public void checkWSDLIsDeployedWhereItIsConfigured() throws Exception { + final String wsdl = IO.slurp(new URL(url.toExternalForm() + "tool/rot13?wsdl")); + Assert.assertTrue(wsdl.contains("Rot13")); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java ---------------------------------------------------------------------- diff --git a/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java b/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java index be1b6de..ae06449 100644 --- a/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java +++ b/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java @@ -1,55 +1,55 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.client; - -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.jms.ConnectionFactory; -import javax.jms.Queue; -import javax.naming.Context; -import javax.naming.InitialContext; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class SenderTest { - - @BeforeClass - public static void configureClientResources() { - // can be set this way or with the key Resource/<type> - // in fact we create on client side a mini jndi tree - // the key is the jndi name (the one used for the lookup) - System.setProperty("aConnectionFactory", "connectionfactory:org.apache.activemq.ActiveMQConnectionFactory:tcp://localhost:11616"); - System.setProperty("aQueue", "queue:org.apache.activemq.command.ActiveMQQueue:LISTENER"); - } - - @Test - public void send() throws Exception { - final Properties properties = new Properties(); - properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); - final Context context = new InitialContext(properties); - - final Queue destination = (Queue) context.lookup("java:aQueue"); - assertNotNull(destination); - assertEquals("LISTENER", destination.getQueueName()); - - final ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("java:aConnectionFactory"); - assertNotNull(connectionFactory); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.client; + +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.jms.ConnectionFactory; +import javax.jms.Queue; +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class SenderTest { + + @BeforeClass + public static void configureClientResources() { + // can be set this way or with the key Resource/<type> + // in fact we create on client side a mini jndi tree + // the key is the jndi name (the one used for the lookup) + System.setProperty("aConnectionFactory", "connectionfactory:org.apache.activemq.ActiveMQConnectionFactory:tcp://localhost:11616"); + System.setProperty("aQueue", "queue:org.apache.activemq.command.ActiveMQQueue:LISTENER"); + } + + @Test + public void send() throws Exception { + final Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); + final Context context = new InitialContext(properties); + + final Queue destination = (Queue) context.lookup("java:aQueue"); + assertNotNull(destination); + assertEquals("LISTENER", destination.getQueueName()); + + final ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("java:aConnectionFactory"); + assertNotNull(connectionFactory); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPerson.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPerson.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPerson.java index 3f2dfee..da55649 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPerson.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPerson.java @@ -1,126 +1,126 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -import javax.ejb.Init; -import javax.ejb.Local; -import javax.ejb.LocalHome; -import javax.ejb.Remote; -import javax.ejb.RemoteHome; -import javax.ejb.Remove; -import javax.ejb.Stateful; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Locale; -import java.util.Properties; - -/** - * This is an EJB 3 style pojo stateful session bean - * it does not need to implement javax.ejb.SessionBean - */ -//START SNIPPET: code - -// EJB 3.0 Style business interfaces -// Each of these interfaces are already annotated in the classes -// themselves with @Remote and @Local, so annotating them here -// in the bean class again is not really required. -@Remote({FriendlyPersonRemote.class}) -@Local({FriendlyPersonLocal.class}) - -// EJB 2.1 Style component interfaces -// These interfaces, however, must be annotated here in the bean class. -// Use of @RemoteHome in the FriendlyPersonEjbHome class itself is not allowed. -// Use of @LocalHome in the FriendlyPersonEjbLocalHome class itself is also not allowed. -@RemoteHome(FriendlyPersonEjbHome.class) -@LocalHome(FriendlyPersonEjbLocalHome.class) - -@Stateful -public class FriendlyPerson implements FriendlyPersonLocal, FriendlyPersonRemote { - - private final HashMap<String, MessageFormat> greetings; - private final Properties languagePreferences; - - private String defaultLanguage; - - public FriendlyPerson() { - greetings = new HashMap(); - languagePreferences = new Properties(); - defaultLanguage = Locale.getDefault().getLanguage(); - - addGreeting("en", "Hello {0}!"); - addGreeting("es", "Hola {0}!"); - addGreeting("fr", "Bonjour {0}!"); - addGreeting("pl", "Witaj {0}!"); - } - - /** - * This method corresponds to the FriendlyPersonEjbHome.create() method - * and the FriendlyPersonEjbLocalHome.create() - * <p/> - * If you do not have an EJBHome or EJBLocalHome interface, this method - * can be deleted. - */ - @Init - public void create() { - } - - /** - * This method corresponds to the following methods: - * - EJBObject.remove() - * - EJBHome.remove(ejbObject) - * - EJBLocalObject.remove() - * - EJBLocalHome.remove(ejbObject) - * <p/> - * If you do not have an EJBHome or EJBLocalHome interface, this method - * can be deleted. - */ - @Remove - public void remove() { - } - - public String greet(String friend) { - String language = languagePreferences.getProperty(friend, defaultLanguage); - return greet(language, friend); - } - - public String greet(String language, String friend) { - MessageFormat greeting = greetings.get(language); - if (greeting == null) { - Locale locale = new Locale(language); - return "Sorry, I don't speak " + locale.getDisplayLanguage() + "."; - } - - return greeting.format(new Object[]{friend}); - } - - public void addGreeting(String language, String message) { - greetings.put(language, new MessageFormat(message)); - } - - public void setLanguagePreferences(String friend, String language) { - languagePreferences.put(friend, language); - } - - public String getDefaultLanguage() { - return defaultLanguage; - } - - public void setDefaultLanguage(String defaultLanguage) { - this.defaultLanguage = defaultLanguage; - } -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +import javax.ejb.Init; +import javax.ejb.Local; +import javax.ejb.LocalHome; +import javax.ejb.Remote; +import javax.ejb.RemoteHome; +import javax.ejb.Remove; +import javax.ejb.Stateful; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Locale; +import java.util.Properties; + +/** + * This is an EJB 3 style pojo stateful session bean + * it does not need to implement javax.ejb.SessionBean + */ +//START SNIPPET: code + +// EJB 3.0 Style business interfaces +// Each of these interfaces are already annotated in the classes +// themselves with @Remote and @Local, so annotating them here +// in the bean class again is not really required. +@Remote({FriendlyPersonRemote.class}) +@Local({FriendlyPersonLocal.class}) + +// EJB 2.1 Style component interfaces +// These interfaces, however, must be annotated here in the bean class. +// Use of @RemoteHome in the FriendlyPersonEjbHome class itself is not allowed. +// Use of @LocalHome in the FriendlyPersonEjbLocalHome class itself is also not allowed. +@RemoteHome(FriendlyPersonEjbHome.class) +@LocalHome(FriendlyPersonEjbLocalHome.class) + +@Stateful +public class FriendlyPerson implements FriendlyPersonLocal, FriendlyPersonRemote { + + private final HashMap<String, MessageFormat> greetings; + private final Properties languagePreferences; + + private String defaultLanguage; + + public FriendlyPerson() { + greetings = new HashMap(); + languagePreferences = new Properties(); + defaultLanguage = Locale.getDefault().getLanguage(); + + addGreeting("en", "Hello {0}!"); + addGreeting("es", "Hola {0}!"); + addGreeting("fr", "Bonjour {0}!"); + addGreeting("pl", "Witaj {0}!"); + } + + /** + * This method corresponds to the FriendlyPersonEjbHome.create() method + * and the FriendlyPersonEjbLocalHome.create() + * <p/> + * If you do not have an EJBHome or EJBLocalHome interface, this method + * can be deleted. + */ + @Init + public void create() { + } + + /** + * This method corresponds to the following methods: + * - EJBObject.remove() + * - EJBHome.remove(ejbObject) + * - EJBLocalObject.remove() + * - EJBLocalHome.remove(ejbObject) + * <p/> + * If you do not have an EJBHome or EJBLocalHome interface, this method + * can be deleted. + */ + @Remove + public void remove() { + } + + public String greet(String friend) { + String language = languagePreferences.getProperty(friend, defaultLanguage); + return greet(language, friend); + } + + public String greet(String language, String friend) { + MessageFormat greeting = greetings.get(language); + if (greeting == null) { + Locale locale = new Locale(language); + return "Sorry, I don't speak " + locale.getDisplayLanguage() + "."; + } + + return greeting.format(new Object[]{friend}); + } + + public void addGreeting(String language, String message) { + greetings.put(language, new MessageFormat(message)); + } + + public void setLanguagePreferences(String friend, String language) { + languagePreferences.put(friend, language); + } + + public String getDefaultLanguage() { + return defaultLanguage; + } + + public void setDefaultLanguage(String defaultLanguage) { + this.defaultLanguage = defaultLanguage; + } +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbHome.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbHome.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbHome.java index ae301a4..31842e5 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbHome.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbHome.java @@ -1,29 +1,29 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -//START SNIPPET: code - -import javax.ejb.CreateException; -import javax.ejb.EJBHome; -import java.rmi.RemoteException; - -public interface FriendlyPersonEjbHome extends EJBHome { - - FriendlyPersonEjbObject create() throws CreateException, RemoteException; -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +//START SNIPPET: code + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import java.rmi.RemoteException; + +public interface FriendlyPersonEjbHome extends EJBHome { + + FriendlyPersonEjbObject create() throws CreateException, RemoteException; +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalHome.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalHome.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalHome.java index ac00b76..adb52af 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalHome.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalHome.java @@ -1,29 +1,29 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -//START SNIPPET: code - -import javax.ejb.CreateException; -import javax.ejb.EJBLocalHome; -import java.rmi.RemoteException; - -public interface FriendlyPersonEjbLocalHome extends EJBLocalHome { - - FriendlyPersonEjbLocalObject create() throws CreateException, RemoteException; -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +//START SNIPPET: code + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; +import java.rmi.RemoteException; + +public interface FriendlyPersonEjbLocalHome extends EJBLocalHome { + + FriendlyPersonEjbLocalObject create() throws CreateException, RemoteException; +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalObject.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalObject.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalObject.java index 7b11e8e..fd420cd 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalObject.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbLocalObject.java @@ -1,35 +1,35 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -import javax.ejb.EJBLocalObject; - -public interface FriendlyPersonEjbLocalObject extends EJBLocalObject { - - String greet(String friend); - - String greet(String language, String friend); - - void addGreeting(String language, String message); - - void setLanguagePreferences(String friend, String language); - - String getDefaultLanguage(); - - void setDefaultLanguage(String defaultLanguage); - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +import javax.ejb.EJBLocalObject; + +public interface FriendlyPersonEjbLocalObject extends EJBLocalObject { + + String greet(String friend); + + String greet(String language, String friend); + + void addGreeting(String language, String message); + + void setLanguagePreferences(String friend, String language); + + String getDefaultLanguage(); + + void setDefaultLanguage(String defaultLanguage); + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbObject.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbObject.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbObject.java index 277111d..d6ce4af 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbObject.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonEjbObject.java @@ -1,39 +1,39 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -//START SNIPPET: code - -import javax.ejb.EJBObject; -import java.rmi.RemoteException; - -public interface FriendlyPersonEjbObject extends EJBObject { - - String greet(String friend) throws RemoteException; - - String greet(String language, String friend) throws RemoteException; - - void addGreeting(String language, String message) throws RemoteException; - - void setLanguagePreferences(String friend, String language) throws RemoteException; - - String getDefaultLanguage() throws RemoteException; - - void setDefaultLanguage(String defaultLanguage) throws RemoteException; - -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +//START SNIPPET: code + +import javax.ejb.EJBObject; +import java.rmi.RemoteException; + +public interface FriendlyPersonEjbObject extends EJBObject { + + String greet(String friend) throws RemoteException; + + String greet(String language, String friend) throws RemoteException; + + void addGreeting(String language, String message) throws RemoteException; + + void setLanguagePreferences(String friend, String language) throws RemoteException; + + String getDefaultLanguage() throws RemoteException; + + void setDefaultLanguage(String defaultLanguage) throws RemoteException; + +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonLocal.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonLocal.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonLocal.java index 551bee3..6198708 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonLocal.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonLocal.java @@ -1,39 +1,39 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -//START SNIPPET: code - -import javax.ejb.Local; - -@Local -public interface FriendlyPersonLocal { - - String greet(String friend); - - String greet(String language, String friend); - - void addGreeting(String language, String message); - - void setLanguagePreferences(String friend, String language); - - String getDefaultLanguage(); - - void setDefaultLanguage(String defaultLanguage); - -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +//START SNIPPET: code + +import javax.ejb.Local; + +@Local +public interface FriendlyPersonLocal { + + String greet(String friend); + + String greet(String language, String friend); + + void addGreeting(String language, String message); + + void setLanguagePreferences(String friend, String language); + + String getDefaultLanguage(); + + void setDefaultLanguage(String defaultLanguage); + +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonRemote.java ---------------------------------------------------------------------- diff --git a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonRemote.java b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonRemote.java index 8b378d1..9444c90 100644 --- a/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonRemote.java +++ b/examples/component-interfaces/src/main/java/org/superbiz/FriendlyPersonRemote.java @@ -1,38 +1,38 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz; - -import javax.ejb.Remote; - -//START SNIPPET: code -@Remote -public interface FriendlyPersonRemote { - - String greet(String friend); - - String greet(String language, String friend); - - void addGreeting(String language, String message); - - void setLanguagePreferences(String friend, String language); - - String getDefaultLanguage(); - - void setDefaultLanguage(String defaultLanguage); - -} -//END SNIPPET: code +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz; + +import javax.ejb.Remote; + +//START SNIPPET: code +@Remote +public interface FriendlyPersonRemote { + + String greet(String friend); + + String greet(String language, String friend); + + void addGreeting(String language, String message); + + void setLanguagePreferences(String friend, String language); + + String getDefaultLanguage(); + + void setDefaultLanguage(String defaultLanguage); + +} +//END SNIPPET: code