View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.payment.handler;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.logging.Logger;
23  
24  import javax.enterprise.context.SessionScoped;
25  import javax.enterprise.event.Observes;
26  import javax.enterprise.inject.Produces;
27  import javax.inject.Inject;
28  import javax.inject.Named;
29  
30  import org.jboss.as.quickstarts.payment.events.PaymentEvent;
31  import org.jboss.as.quickstarts.payment.qualifiers.Credit;
32  import org.jboss.as.quickstarts.payment.qualifiers.Debit;
33  
34  @SessionScoped
35  public class PaymentHandler implements Serializable, ICreditEventObserver, IDebitEventObserver {
36  
37      /**
38       * 
39       */
40      private static final long serialVersionUID = 1L;
41  
42      @Inject
43      private Logger logger;
44  
45      List<PaymentEvent> payments = new ArrayList<PaymentEvent>();
46  
47      @Produces
48      @Named
49      public List<PaymentEvent> getPayments() {
50          return payments;
51      }
52  
53      public void onCreditPaymentEvent(@Observes @Credit PaymentEvent event) {
54  
55          logger.info("Processing the credit operation " + event);
56          payments.add(event);
57      }
58  
59      @Override
60      public void onDebitPaymentEvent(@Observes @Debit PaymentEvent event) {
61          logger.info("Processing the debit operation " + event);
62          payments.add(event);
63  
64      }
65  
66  }