/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/sg/RemAsTransInactToInact.java

http://mobicents.googlecode.com/ · Java · 83 lines · 46 code · 16 blank · 21 comment · 4 complexity · e862b59fc0a1010d3a8f918b0b368185 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.ss7.m3ua.impl.sg;
  23. import org.apache.log4j.Logger;
  24. import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
  25. import org.mobicents.protocols.ss7.m3ua.impl.fsm.State;
  26. import org.mobicents.protocols.ss7.m3ua.impl.fsm.TransitionHandler;
  27. import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
  28. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  29. import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
  30. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  31. public class RemAsTransInactToInact implements TransitionHandler {
  32. private static final Logger logger = Logger.getLogger(RemAsTransInactToInact.class);
  33. private RemAsImpl as = null;
  34. private FSM fsm;
  35. public RemAsTransInactToInact(RemAsImpl as, FSM fsm) {
  36. this.as = as;
  37. this.fsm = fsm;
  38. }
  39. public boolean process(State state) {
  40. try {
  41. RemAspImpl remAsp = (RemAspImpl) this.fsm.getAttribute(RemAsImpl.ATTRIBUTE_ASP);
  42. if (remAsp == null) {
  43. logger.error(String.format("No ASP found. %s", this.fsm.toString()));
  44. return false;
  45. }
  46. Notify msg = createNotify(remAsp);
  47. remAsp.getAspFactory().write(msg);
  48. return true;
  49. } catch (Exception e) {
  50. logger.error(String.format("Error while translating Rem AS to INACTIVE message. %s", this.fsm.toString()),
  51. e);
  52. }
  53. return false;
  54. }
  55. private Notify createNotify(RemAspImpl remAsp) {
  56. Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory().createMessage(MessageClass.MANAGEMENT,
  57. MessageType.NOTIFY);
  58. Status status = this.as.getM3UAProvider().getParameterFactory().createStatus(Status.STATUS_AS_State_Change,
  59. Status.INFO_AS_INACTIVE);
  60. msg.setStatus(status);
  61. if (remAsp.getASPIdentifier() != null) {
  62. msg.setASPIdentifier(remAsp.getASPIdentifier());
  63. }
  64. msg.setRoutingContext(this.as.getRoutingContext());
  65. return msg;
  66. }
  67. }