package org.jboss.as.quickstarts.login;

import java.util.List;
import java.util.logging.Logger;

import javax.ejb.Stateful;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

@Named("userManager")
@RequestScoped
@Alternative
@Stateful
public class EJBUserManager implements UserManager {

	@Inject
	private transient Logger logger;

	@Inject
	private EntityManager userDatabase;

	private User newUser = new User();

	@SuppressWarnings("unchecked")
	@Produces
	@Named
	@RequestScoped
	public List<User> getUsers() throws Exception {
		return userDatabase.createQuery("select u from User u").getResultList();
	}

	public String addUser() throws Exception {
		userDatabase.persist(newUser);
		logger.info("Added " + newUser);
		return "userAdded";
	}

	public User findUser(String username, String password) throws Exception {
		@SuppressWarnings("unchecked")
		List<User> results = userDatabase
				.createQuery(
						"select u from User u where u.username=:username and u.password=:password")
				.setParameter("username", username)
				.setParameter("password", password).getResultList();
		if (results.isEmpty()) {
			return null;
		} else if (results.size() > 1) {
			throw new IllegalStateException(
					"Cannot have more than one user with the same username!");
		} else {
			return results.get(0);
		}
	}

	@Produces
	@RequestScoped
	@Named
	public User getNewUser() {
		return newUser;
	}

}

@@ -655,16 +655,30 @@
 tScoped%0A
+%09@Alternative%0A
 %09public 
@@ -1534,16 +1534,30 @@
 %09@Named%0A
+%09@Alternative%0A
 %09public 

Make producers alternatives explicitly