Example usage for java.lang Short Short

List of usage examples for java.lang Short Short

Introduction

In this page you can find the example usage for java.lang Short Short.

Prototype

@Deprecated(since = "9")
public Short(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Usage

From source file:net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmXMsgRqstHandler.CFCrmXMsgRqstISOLanguageDeleteByCountryIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//w w  w .  j  a va  2  s .c om
        // Common XML Attributes
        String attrId = null;
        String attrISOCountryId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOLanguageDeleteByCountryIdx");

        CFCrmXMsgRqstHandler xmsgRqstHandler = (CFCrmXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFCrmSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values$implRqstTableDeleteByHandlerCheckReqKeyAttrs$

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Delete the objects
        schemaObj.getISOLanguageTableObj().deleteISOLanguageByCountryIdx(natISOCountryId);
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDeleted() + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFCrmXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:com.judoscript.jamaica.MyUtils.java

public static Object value2object(Object val, String typeHint) {
    if (typeHint == null)
        return val;

    if (typeHint.equals("boolean") || val instanceof Boolean)
        return val; // leave type check to caller.

    double v;/*  w w w  .j  a v  a  2  s  .  c o m*/
    if (val instanceof Character)
        v = ((Character) val).charValue();
    else if (val instanceof Number)
        v = ((Number) val).doubleValue();
    else
        return val; // leave type check to caller.

    if (typeHint.equals("int"))
        return new Integer((int) v);
    if (typeHint.equals("long"))
        return new Long((long) v);
    if (typeHint.equals("short"))
        return new Short((short) v);
    if (typeHint.equals("char"))
        return new Character((char) v);
    if (typeHint.equals("byte"))
        return new Byte((byte) v);
    if (typeHint.equals("float"))
        return new Float((float) v);
    //  if (typeHint.equals("double"))
    return new Double(v);
}

From source file:com.krawler.br.nodes.Activity.java

/**
 * converts the given object value to the given primitive type's wrapper class
 * if possible (if it is a <tt>Number</tt>)
 *
 * @param type the premitive type name, may be:
 * <ul>//from  w  w  w.  ja  v a  2 s  .  c o m
 * <li><tt>byte</tt>
 * <li><tt>char</tt>
 * <li><tt>short</tt>
 * <li><tt>int</tt>
 * <li><tt>long</tt>
 * <li><tt>float</tt>
 * <li><tt>double</tt>
 * </ul>
 * @param value the original value
 * @return the converted value
 */
private Object convert(String type, Object value) {
    Object val = value;

    if (value instanceof Number) {
        Number num = (Number) value;

        if (Byte.class.getCanonicalName().equals(type))
            val = new Byte(num.byteValue());
        else if (Character.class.getCanonicalName().equals(type))
            val = new Character((char) num.intValue());
        else if (Short.class.getCanonicalName().equals(type))
            val = new Short(num.shortValue());
        else if (Integer.class.getCanonicalName().equals(type))
            val = new Integer(num.intValue());
        else if (Long.class.getCanonicalName().equals(type))
            val = new Long(num.longValue());
        else if (Float.class.getCanonicalName().equals(type))
            val = new Float(num.floatValue());
        else if (Double.class.getCanonicalName().equals(type))
            val = new Double(num.doubleValue());
    }
    return val;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstISOLanguageDeleteByCountryIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFAsteriskXMsgSchemaMessageFormatter schemaFormatter = null;
    try {//from  ww  w .  j  a  va  2 s .c om
        // Common XML Attributes
        String attrId = null;
        String attrISOCountryId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOLanguageDeleteByCountryIdx");

        CFAsteriskXMsgRqstHandler xmsgRqstHandler = (CFAsteriskXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFAsteriskSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Delete the objects
        schemaObj.getISOLanguageTableObj().deleteISOLanguageByCountryIdx(natISOCountryId);
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDeleted() + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        ((CFAsteriskXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstISOLanguageDeleteByCountryIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/* w  w  w  . ja  v  a  2  s.c  o m*/
        // Common XML Attributes
        String attrId = null;
        String attrISOCountryId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOLanguageDeleteByCountryIdx");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Delete the objects
        schemaObj.getISOLanguageTableObj().deleteISOLanguageByCountryIdx(natISOCountryId);
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDeleted() + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        ((CFFreeSwitchXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:co.sip.dmesmobile.bs.ScStopDao.java

@Override
public ScStopMachine getStopMachine(String idMachine, String state) throws Exception {
    entityManager = Factory.getEntityManagerFactory().createEntityManager();
    ScStopMachine result = null;/*from  w  w  w  .  ja  v a  2s .c o  m*/
    String stringQuery = "SELECT * FROM (SELECT sm.id_stop_machine, sm.id_maintenance, "
            + "sm.reason, sm.state, sm.password, g.type AS type_group, ROW_NUMBER() OVER "
            + "(ORDER BY sm.id_stop_machine DESC) AS item\n"
            + "FROM dmes.sc_stop_machine sm, dmes.sc_notification n, dmes.sc_group g WHERE " + "sm.state = "
            + state + " AND n.id_stop_machine = sm.id_stop_machine\n" + "AND n.id_group = g.id_group\n"
            + "AND n.id_machine = " + idMachine + ") AS STOP_MACHINE WHERE item = 1";
    Query query = entityManager.createNativeQuery(stringQuery);
    Object object = query.getSingleResult();
    if (object != null) {
        result = new ScStopMachine();

        result.setIdStopMachine(new Long(((Object[]) object)[0].toString())); //Extraigo el id
        result.setReason(((Object[]) object)[2].toString()); //Extraigo la razn
        result.setState(new Short(((Object[]) object)[3].toString()));
        result.setPassword(((Object[]) object)[4].toString());
        if (((Object[]) object)[1] != null) {
            result.setIdMaintenance(new Long(((Object[]) object)[1].toString()));
        } else if (((Object[]) object)[5].toString().equals("1")) {
            result.setIdMaintenance(-1L);
        }
    }
    return result;
}

From source file:NumberUtils.java

/**
 * Converts the given number to a <code>Short</code> (by using <code>shortValue()</code>).
 *
 * @param number/*www .  j  a v  a 2  s  .  c o m*/
 * @return java.lang.Short
 * @throws IllegalArgumentException The given number is 'not a number' or infinite.
 */
public static Short toShort(Number number) throws IllegalArgumentException {
    if (number == null || number instanceof Short)
        return (Short) number;
    if (isNaN(number) || isInfinite(number))
        throw new IllegalArgumentException("Argument must not be NaN or infinite.");
    return new Short(number.shortValue());
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstISOLanguageReadByCountryIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFAsteriskXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/*from w  w  w .  j a  v  a  2s.c  o m*/
        // Common XML Attributes
        String attrId = null;
        String attrISOCountryId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOLanguageReadByCountryIdx");

        CFAsteriskXMsgRqstHandler xmsgRqstHandler = (CFAsteriskXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFAsteriskSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Read the objects
        List<ICFSecurityISOLanguageObj> list = schemaObj.getISOLanguageTableObj()
                .readISOLanguageByCountryIdx(natISOCountryId);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgISOLanguageMessageFormatter.formatISOLanguageRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecurityISOLanguageObj> iter = list.iterator();
        ICFSecurityISOLanguageObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFAsteriskXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDerivedRec("\n\t\t",
                    cur.getISOLanguageBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFAsteriskXMsgISOLanguageMessageFormatter.formatISOLanguageRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstISOLanguageReadByCountryIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {//from  w ww. j  av a 2s.  co  m
        // Common XML Attributes
        String attrId = null;
        String attrISOCountryId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOLanguageReadByCountryIdx");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Read the objects
        List<ICFSecurityISOLanguageObj> list = schemaObj.getISOLanguageTableObj()
                .readISOLanguageByCountryIdx(natISOCountryId);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgISOLanguageMessageFormatter.formatISOLanguageRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecurityISOLanguageObj> iter = list.iterator();
        ICFSecurityISOLanguageObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFFreeSwitchXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDerivedRec("\n\t\t",
                    cur.getISOLanguageBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFFreeSwitchXMsgISOLanguageMessageFormatter.formatISOLanguageRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:com.scit.sling.test.MockValueMap.java

@SuppressWarnings("unchecked")
private <T> T convertType(Object o, Class<T> type) {
    if (o == null) {
        return null;
    }//from  ww w. j  a v  a 2s .c  om
    if (o.getClass().isArray() && type.isArray()) {
        if (type.getComponentType().isAssignableFrom(o.getClass().getComponentType())) {
            return (T) o;
        } else {
            // we need to convert the elements in the array
            Object array = Array.newInstance(type.getComponentType(), Array.getLength(o));
            for (int i = 0; i < Array.getLength(o); i++) {
                Array.set(array, i, convertType(Array.get(o, i), type.getComponentType()));
            }
            return (T) array;
        }
    }
    if (o.getClass().isAssignableFrom(type)) {
        return (T) o;
    }
    if (String.class.isAssignableFrom(type)) {
        // Format dates
        if (o instanceof Calendar) {
            return (T) formatDate((Calendar) o);
        } else if (o instanceof Date) {
            return (T) formatDate((Date) o);
        } else if (o instanceof DateTime) {
            return (T) formatDate((DateTime) o);
        }
        return (T) String.valueOf(o);
    } else if (o instanceof DateTime) {
        DateTime dt = (DateTime) o;
        if (Calendar.class.isAssignableFrom(type)) {
            return (T) dt.toCalendar(Locale.getDefault());
        } else if (Date.class.isAssignableFrom(type)) {
            return (T) dt.toDate();
        } else if (Number.class.isAssignableFrom(type)) {
            return convertType(dt.getMillis(), type);
        }
    } else if (o instanceof Number && Number.class.isAssignableFrom(type)) {
        if (Byte.class.isAssignableFrom(type)) {
            return (T) (Byte) ((Number) o).byteValue();
        } else if (Double.class.isAssignableFrom(type)) {
            return (T) (Double) ((Number) o).doubleValue();
        } else if (Float.class.isAssignableFrom(type)) {
            return (T) (Float) ((Number) o).floatValue();
        } else if (Integer.class.isAssignableFrom(type)) {
            return (T) (Integer) ((Number) o).intValue();
        } else if (Long.class.isAssignableFrom(type)) {
            return (T) (Long) ((Number) o).longValue();
        } else if (Short.class.isAssignableFrom(type)) {
            return (T) (Short) ((Number) o).shortValue();
        } else if (BigDecimal.class.isAssignableFrom(type)) {
            return (T) new BigDecimal(o.toString());
        }
    } else if (o instanceof Number && type.isPrimitive()) {
        final Number num = (Number) o;
        if (type == byte.class) {
            return (T) new Byte(num.byteValue());
        } else if (type == double.class) {
            return (T) new Double(num.doubleValue());
        } else if (type == float.class) {
            return (T) new Float(num.floatValue());
        } else if (type == int.class) {
            return (T) new Integer(num.intValue());
        } else if (type == long.class) {
            return (T) new Long(num.longValue());
        } else if (type == short.class) {
            return (T) new Short(num.shortValue());
        }
    } else if (o instanceof String && Number.class.isAssignableFrom(type)) {
        if (Byte.class.isAssignableFrom(type)) {
            return (T) new Byte((String) o);
        } else if (Double.class.isAssignableFrom(type)) {
            return (T) new Double((String) o);
        } else if (Float.class.isAssignableFrom(type)) {
            return (T) new Float((String) o);
        } else if (Integer.class.isAssignableFrom(type)) {
            return (T) new Integer((String) o);
        } else if (Long.class.isAssignableFrom(type)) {
            return (T) new Long((String) o);
        } else if (Short.class.isAssignableFrom(type)) {
            return (T) new Short((String) o);
        } else if (BigDecimal.class.isAssignableFrom(type)) {
            return (T) new BigDecimal((String) o);
        }
    }
    throw new NotImplementedException(
            "Can't handle conversion from " + o.getClass().getName() + " to " + type.getName());
}