/protocols/ss7/hardware/dahdi/java/src/main/java/org/mobicents/ss7/hardware/dahdi/oam/DahdiLinksetFactory.java

http://mobicents.googlecode.com/ · Java · 88 lines · 37 code · 19 blank · 32 comment · 10 complexity · 16c9528ab367c57dd3c3d1f986055fc0 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.ss7.hardware.dahdi.oam;
  23. import org.mobicents.ss7.linkset.oam.LinkOAMMessages;
  24. import org.mobicents.ss7.linkset.oam.Linkset;
  25. import org.mobicents.ss7.linkset.oam.LinksetFactory;
  26. /**
  27. * <p>
  28. * Factory for creating <tt>dahdi</tt> based {@link Linkset}
  29. * </p>
  30. *
  31. * @author amit bhayani
  32. *
  33. */
  34. public class DahdiLinksetFactory extends LinksetFactory {
  35. private static final String NAME = "dahdi";
  36. public DahdiLinksetFactory() {
  37. }
  38. @Override
  39. public String getName() {
  40. return NAME;
  41. }
  42. @Override
  43. public Linkset createLinkset(String[] options) throws Exception {
  44. // the expected command is "linkset create dahdi opc 1 apc 2 ni 3
  45. // linkset1". We know length is 10
  46. if (options.length != 10) {
  47. throw new Exception(LinkOAMMessages.INVALID_COMMAND);
  48. }
  49. String option = options[3];
  50. // If first option is not OPC
  51. if (option.compareTo("opc") != 0) {
  52. return null;
  53. }
  54. int opc = Integer.parseInt(options[4]);
  55. if (options[5].compareTo("apc") != 0) {
  56. throw new Exception(LinkOAMMessages.INVALID_COMMAND);
  57. }
  58. int dpc = Integer.parseInt(options[6]);
  59. if (options[7].compareTo("ni") != 0) {
  60. throw new Exception(LinkOAMMessages.INVALID_COMMAND);
  61. }
  62. int ni = Integer.parseInt(options[8]);
  63. String name = options[9];
  64. if (name == null) {
  65. throw new Exception(LinkOAMMessages.INVALID_COMMAND);
  66. }
  67. return new DahdiLinkset(name, opc, dpc, ni);
  68. }
  69. }