/protocols/ss7/hardware/dialogic/java/src/main/java/org/mobicents/ss7/hardware/dialogic/oam/DialogicLinksetFactory.java
Java | 100 lines | 46 code | 22 blank | 32 comment | 14 complexity | 141ff1e4542e995d1f13ae7f66296ad8 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 23package org.mobicents.ss7.hardware.dialogic.oam; 24 25import org.mobicents.ss7.linkset.oam.LinkOAMMessages; 26import org.mobicents.ss7.linkset.oam.Linkset; 27import org.mobicents.ss7.linkset.oam.LinksetFactory; 28 29/** 30 * <p> 31 * Factory for creating <tt>dialogic</tt> based {@link Linkset} 32 * </p> 33 * 34 * @author amit bhayani 35 * 36 */ 37public class DialogicLinksetFactory extends LinksetFactory { 38 39 private static final String NAME = "dialogic"; 40 41 public DialogicLinksetFactory() { 42 super(); 43 } 44 45 @Override 46 public String getName() { 47 return NAME; 48 } 49 50 @Override 51 public Linkset createLinkset(String[] options) throws Exception { 52 // the expected command is "linkset create dialogic opc 1 apc 2 ni 3 53 // srcmod 61 dstmod 34 linkset1". We know length is 14 54 if (options.length != 14) { 55 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 56 } 57 58 String option = options[3]; 59 60 // If first option is not OPC 61 if (option.compareTo("opc") != 0) { 62 return null; 63 } 64 65 int opc = Integer.parseInt(options[4]); 66 67 if (options[5].compareTo("apc") != 0) { 68 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 69 } 70 71 int dpc = Integer.parseInt(options[6]); 72 73 if (options[7].compareTo("ni") != 0) { 74 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 75 } 76 77 int ni = Integer.parseInt(options[8]); 78 79 if (options[9].compareTo("srcmod") != 0) { 80 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 81 } 82 83 int srcmod = Integer.parseInt(options[10]); 84 85 if (options[11].compareTo("dstmod") != 0) { 86 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 87 } 88 89 int dstmod = Integer.parseInt(options[12]); 90 91 String name = options[13]; 92 93 if (name == null) { 94 throw new Exception(LinkOAMMessages.INVALID_COMMAND); 95 } 96 97 return new DialogicLinkset(name, opc, dpc, ni, srcmod, dstmod); 98 } 99 100}