PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/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
23package org.mobicents.ss7.hardware.dahdi.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>dahdi</tt> based {@link Linkset}
32 * </p>
33 * 
34 * @author amit bhayani
35 * 
36 */
37public class DahdiLinksetFactory extends LinksetFactory {
38
39    private static final String NAME = "dahdi";
40
41    public DahdiLinksetFactory() {
42    }
43
44    @Override
45    public String getName() {
46        return NAME;
47    }
48
49    @Override
50    public Linkset createLinkset(String[] options) throws Exception {
51
52        // the expected command is "linkset create dahdi opc 1 apc 2 ni 3
53        // linkset1". We know length is 10
54        if (options.length != 10) {
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        String name = options[9];
80
81        if (name == null) {
82            throw new Exception(LinkOAMMessages.INVALID_COMMAND);
83        }
84
85        return new DahdiLinkset(name, opc, dpc, ni);
86    }
87
88}