Search in sources :

Example 1 with Tag

use of org.jsmpp.bean.OptionalParameter.Tag in project camel by apache.

the class AbstractSmppCommand method createOptionalParametersByName.

/**
     * @deprecated will be removed in Camel 2.13.0/3.0.0 - use createOptionalParametersByCode instead
     * @param optinalParamaters
     * @return
     */
@Deprecated
@SuppressWarnings({ "rawtypes", "unchecked" })
protected List<OptionalParameter> createOptionalParametersByName(Map<String, String> optinalParamaters) {
    List<OptionalParameter> optParams = new ArrayList<OptionalParameter>();
    for (Entry<String, String> entry : optinalParamaters.entrySet()) {
        OptionalParameter optParam = null;
        String value = entry.getValue();
        try {
            Tag tag = Tag.valueOf(entry.getKey());
            Class type = determineTypeClass(tag);
            Set<Class> ancestorClasses = new HashSet<Class>(2);
            Class superclass = type.getSuperclass();
            ancestorClasses.add(superclass);
            if (superclass != Object.class) {
                ancestorClasses.add(superclass.getSuperclass());
            }
            if (ancestorClasses.contains(OctetString.class)) {
                optParam = (OptionalParameter) type.getConstructor(byte[].class).newInstance(value.getBytes());
            } else if (ancestorClasses.contains(OptionalParameter.Byte.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Byte byteValue = (value == null) ? 0 : Byte.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(byte.class).newInstance(byteValue);
            } else if (ancestorClasses.contains(OptionalParameter.Int.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Integer intValue = (value == null) ? 0 : Integer.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(int.class).newInstance(intValue);
            } else if (ancestorClasses.contains(OptionalParameter.Short.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Short shortValue = (value == null) ? 0 : Short.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(short.class).newInstance(shortValue);
            }
            optParams.add(optParam);
        } catch (Exception e) {
            log.info("Couldn't determine optional parameter for key {} and value {}. Skip this one.", entry.getKey(), value);
        }
    }
    return optParams;
}
Also used : ArrayList(java.util.ArrayList) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) Tag(org.jsmpp.bean.OptionalParameter.Tag) HashSet(java.util.HashSet)

Example 2 with Tag

use of org.jsmpp.bean.OptionalParameter.Tag in project camel by apache.

the class SmppBinding method createOptionalParameterByName.

private Map<String, Object> createOptionalParameterByName(DeliverSm deliverSm) {
    List<OptionalParameter> oplist = Arrays.asList(deliverSm.getOptionalParameters());
    Map<String, Object> optParams = new HashMap<String, Object>();
    for (OptionalParameter optPara : oplist) {
        try {
            Tag valueOfTag = OptionalParameter.Tag.valueOf(optPara.tag);
            if (valueOfTag != null) {
                if (COctetString.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), ((COctetString) optPara).getValueAsString());
                } else if (org.jsmpp.bean.OptionalParameter.OctetString.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), ((OctetString) optPara).getValueAsString());
                } else if (org.jsmpp.bean.OptionalParameter.Byte.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Byte.valueOf(((org.jsmpp.bean.OptionalParameter.Byte) optPara).getValue()));
                } else if (org.jsmpp.bean.OptionalParameter.Short.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Short.valueOf(((org.jsmpp.bean.OptionalParameter.Short) optPara).getValue()));
                } else if (org.jsmpp.bean.OptionalParameter.Int.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Integer.valueOf(((org.jsmpp.bean.OptionalParameter.Int) optPara).getValue()));
                } else if (Null.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), null);
                }
            } else {
                LOG.debug("Skipping optional parameter with tag {} because it was not recogized", optPara.tag);
            }
        } catch (IllegalArgumentException e) {
            LOG.debug("Skipping optional parameter with tag {} due " + e.getMessage(), optPara.tag);
        }
    }
    return optParams;
}
Also used : COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Null(org.jsmpp.bean.OptionalParameter.Null) HashMap(java.util.HashMap) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) Tag(org.jsmpp.bean.OptionalParameter.Tag)

Aggregations

OptionalParameter (org.jsmpp.bean.OptionalParameter)2 OctetString (org.jsmpp.bean.OptionalParameter.OctetString)2 Tag (org.jsmpp.bean.OptionalParameter.Tag)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 COctetString (org.jsmpp.bean.OptionalParameter.COctetString)1 Null (org.jsmpp.bean.OptionalParameter.Null)1