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:com.fluidops.iwb.api.APIImpl.java

public void setConfigOption(String key, String value) throws Exception {
    Method found = null;//from  w w  w .ja  va 2  s  .c  o m
    // fbase Config
    for (Method m : Config.class.getMethods()) {
        ConfigDoc cfd = m.getAnnotation(ConfigDoc.class);
        if (cfd != null)
            if (cfd.name().equals(key))
                found = m;
    }

    // check if prop exists
    if (found == null)
        throw new Exception("Config property does not exist: " + key);

    // check type
    if (found.getReturnType().equals(boolean.class))
        Boolean.valueOf(value);
    else if (found.getReturnType().equals(int.class))
        new Integer(value);
    else if (found.getReturnType().equals(long.class))
        new Long(value);
    else if (found.getReturnType().equals(byte.class))
        new Byte(value);
    else if (found.getReturnType().equals(short.class))
        new Short(value);
    else if (found.getReturnType().equals(float.class))
        new Float(value);
    else if (found.getReturnType().equals(double.class))
        new Double(value);
    else if (found.getReturnType().equals(char.class))
        Character.valueOf(value.charAt(0));
    else if (found.getReturnType().equals(Character.class))
        Character.valueOf(value.charAt(0));
    else
        found.getReturnType().getConstructor(String.class).newInstance(value);

    com.fluidops.config.Config.getConfig().set(key, value);
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSaxLoader.CFAccSaxLoaderISOLanguageHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from   w w w .j  a v a 2 s .c om*/
        // Common XML Attributes
        String attrId = null;
        // Primary Key Attributes for Constant Enum support
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = null;
        // ISOLanguage References
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ISOLanguage");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFAccISOLanguageEditObj editBuff = (ICFAccISOLanguageEditObj) schemaObj.getISOLanguageTableObj()
                .newInstance().beginEdit();

        // 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = 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
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("ISOCode", attrISOCode);
        curContext.putNamedValue("BaseLanguageCode", attrBaseLanguageCode);
        curContext.putNamedValue("ISOCountryId", attrISOCountryId);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natId;
        natId = Short.parseShort(attrId);
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);

        String natISOCode = attrISOCode;
        editBuff.setRequiredISOCode(natISOCode);

        String natBaseLanguageCode = attrBaseLanguageCode;
        editBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);

        Short natISOCountryId;
        if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
            natISOCountryId = null;
        } else {
            natISOCountryId = new Short(Short.parseShort(attrISOCountryId));
        }
        editBuff.setOptionalISOCountryId(natISOCountryId);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        CFAccSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOLanguageLoaderBehaviour();
        ICFAccISOLanguageEditObj editISOLanguage = null;
        ICFAccISOLanguageObj origISOLanguage = schemaObj.getISOLanguageTableObj()
                .readISOLanguageByCodeIdx(editBuff.getRequiredISOCode());
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);
        if (origISOLanguage == null) {
            editISOLanguage = editBuff;
        } else {
            switch (loaderBehaviour) {
            case Insert:
                break;
            case Update:
                editISOLanguage = (ICFAccISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.setRequiredISOCode(editBuff.getRequiredISOCode());
                editISOLanguage.setRequiredBaseLanguageCode(editBuff.getRequiredBaseLanguageCode());
                editISOLanguage.setOptionalISOCountryId(editBuff.getOptionalISOCountryId());
                break;
            case Replace:
                editISOLanguage = (ICFAccISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.delete();
                editISOLanguage.endEdit();
                origISOLanguage = null;
                editISOLanguage = editBuff;
                break;
            }
        }

        if (editISOLanguage != null) {
            if (origISOLanguage != null) {
                editISOLanguage.update();
            } else {
                origISOLanguage = (ICFAccISOLanguageObj) editISOLanguage.create();
            }
            editISOLanguage.endEdit();
        }

        curContext.putNamedValue("Object", origISOLanguage);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstSaxLoader.CFAstSaxLoaderISOLanguageHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from  w w w .j  a va  2s  .co m
        // Common XML Attributes
        String attrId = null;
        // Primary Key Attributes for Constant Enum support
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = null;
        // ISOLanguage References
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ISOLanguage");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFAstISOLanguageEditObj editBuff = (ICFAstISOLanguageEditObj) schemaObj.getISOLanguageTableObj()
                .newInstance().beginEdit();

        // 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = 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
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("ISOCode", attrISOCode);
        curContext.putNamedValue("BaseLanguageCode", attrBaseLanguageCode);
        curContext.putNamedValue("ISOCountryId", attrISOCountryId);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natId;
        natId = Short.parseShort(attrId);
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);

        String natISOCode = attrISOCode;
        editBuff.setRequiredISOCode(natISOCode);

        String natBaseLanguageCode = attrBaseLanguageCode;
        editBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);

        Short natISOCountryId;
        if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
            natISOCountryId = null;
        } else {
            natISOCountryId = new Short(Short.parseShort(attrISOCountryId));
        }
        editBuff.setOptionalISOCountryId(natISOCountryId);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        CFAstSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOLanguageLoaderBehaviour();
        ICFAstISOLanguageEditObj editISOLanguage = null;
        ICFAstISOLanguageObj origISOLanguage = schemaObj.getISOLanguageTableObj()
                .readISOLanguageByCodeIdx(editBuff.getRequiredISOCode());
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);
        if (origISOLanguage == null) {
            editISOLanguage = editBuff;
        } else {
            switch (loaderBehaviour) {
            case Insert:
                break;
            case Update:
                editISOLanguage = (ICFAstISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.setRequiredISOCode(editBuff.getRequiredISOCode());
                editISOLanguage.setRequiredBaseLanguageCode(editBuff.getRequiredBaseLanguageCode());
                editISOLanguage.setOptionalISOCountryId(editBuff.getOptionalISOCountryId());
                break;
            case Replace:
                editISOLanguage = (ICFAstISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.delete();
                editISOLanguage.endEdit();
                origISOLanguage = null;
                editISOLanguage = editBuff;
                break;
            }
        }

        if (editISOLanguage != null) {
            if (origISOLanguage != null) {
                editISOLanguage.update();
            } else {
                origISOLanguage = (ICFAstISOLanguageObj) editISOLanguage.create();
            }
            editISOLanguage.endEdit();
        }

        curContext.putNamedValue("Object", origISOLanguage);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_0.CFFswSaxLoader.CFFswSaxLoaderISOLanguageHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*w  ww . ja  v a2s  . co m*/
        // Common XML Attributes
        String attrId = null;
        // Primary Key Attributes for Constant Enum support
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = null;
        // ISOLanguage References
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ISOLanguage");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFFswISOLanguageEditObj editBuff = (ICFFswISOLanguageEditObj) schemaObj.getISOLanguageTableObj()
                .newInstance().beginEdit();

        // 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = 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
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("ISOCode", attrISOCode);
        curContext.putNamedValue("BaseLanguageCode", attrBaseLanguageCode);
        curContext.putNamedValue("ISOCountryId", attrISOCountryId);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natId;
        natId = Short.parseShort(attrId);
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);

        String natISOCode = attrISOCode;
        editBuff.setRequiredISOCode(natISOCode);

        String natBaseLanguageCode = attrBaseLanguageCode;
        editBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);

        Short natISOCountryId;
        if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
            natISOCountryId = null;
        } else {
            natISOCountryId = new Short(Short.parseShort(attrISOCountryId));
        }
        editBuff.setOptionalISOCountryId(natISOCountryId);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        CFFswSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOLanguageLoaderBehaviour();
        ICFFswISOLanguageEditObj editISOLanguage = null;
        ICFFswISOLanguageObj origISOLanguage = schemaObj.getISOLanguageTableObj()
                .readISOLanguageByCodeIdx(editBuff.getRequiredISOCode());
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOLanguageBuff().setRequiredId(natId);
        if (origISOLanguage == null) {
            editISOLanguage = editBuff;
        } else {
            switch (loaderBehaviour) {
            case Insert:
                break;
            case Update:
                editISOLanguage = (ICFFswISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.setRequiredISOCode(editBuff.getRequiredISOCode());
                editISOLanguage.setRequiredBaseLanguageCode(editBuff.getRequiredBaseLanguageCode());
                editISOLanguage.setOptionalISOCountryId(editBuff.getOptionalISOCountryId());
                break;
            case Replace:
                editISOLanguage = (ICFFswISOLanguageEditObj) origISOLanguage.beginEdit();
                editISOLanguage.delete();
                editISOLanguage.endEdit();
                origISOLanguage = null;
                editISOLanguage = editBuff;
                break;
            }
        }

        if (editISOLanguage != null) {
            if (origISOLanguage != null) {
                editISOLanguage.update();
            } else {
                origISOLanguage = (ICFFswISOLanguageObj) editISOLanguage.create();
            }
            editISOLanguage.endEdit();
        }

        curContext.putNamedValue("Object", origISOLanguage);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java

/**
 * Retrieve a JDBC column value from a ResultSet, using the specified value
 * type./*from   w w w  .j  a  v a  2  s.c  o m*/
 * <p>
 * Uses the specifically typed ResultSet accessor methods, falling back to
 * {@link #getResultSetValue(java.sql.ResultSet, int)} for unknown types.
 * <p>
 * Note that the returned value may not be assignable to the specified
 * required type, in case of an unknown type. Calling code needs to deal
 * with this case appropriately, e.g. throwing a corresponding exception.
 * 
 * @param rs is the ResultSet holding the data
 * @param index is the column index
 * @param requiredType the required value type (may be <code>null</code>)
 * @return the value object
 * @throws SQLException if thrown by the JDBC API
 */
private static String getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException {
    if (requiredType == null) {
        return getResultSetValue(rs, index);
    }

    Object value = null;
    boolean wasNullCheck = false;

    // Explicitly extract typed value, as far as possible.
    if (String.class.equals(requiredType)) {
        value = rs.getString(index);
    } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) {
        value = Boolean.valueOf(rs.getBoolean(index));
        wasNullCheck = true;
    } else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) {
        value = new Byte(rs.getByte(index));
        wasNullCheck = true;
    } else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) {
        value = new Short(rs.getShort(index));
        wasNullCheck = true;
    } else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) {
        value = new Long(rs.getLong(index));
        wasNullCheck = true;
    } else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) {
        value = rs.getBigDecimal(index);
        wasNullCheck = true;
    } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) {
        value = new Float(rs.getFloat(index));
        wasNullCheck = true;
    } else if (double.class.equals(requiredType) || Double.class.equals(requiredType)
            || Number.class.equals(requiredType)) {
        value = new Double(rs.getDouble(index));
        wasNullCheck = true;
    } else if (java.sql.Time.class.equals(requiredType)) {
        // try {
        // value = rs.getTime(index);
        // } catch (SQLException e) {
        value = rs.getString(index);// ?string0000Time
        // if (value == null && !rs.wasNull()) {
        // value = "00:00:00"; //
        // mysqlzeroDateTimeBehavior=convertToNull0null
        // }
        // }
    } else if (java.sql.Timestamp.class.equals(requiredType) || java.sql.Date.class.equals(requiredType)) {
        // try {
        // value = convertTimestamp(rs.getTimestamp(index));
        // } catch (SQLException e) {
        // ?string0000-00-00 00:00:00Timestamp 
        value = rs.getString(index);
        // if (value == null && !rs.wasNull()) {
        // value = "0000:00:00 00:00:00"; //
        // mysqlzeroDateTimeBehavior=convertToNull0null
        // }
        // }
    } else if (BigDecimal.class.equals(requiredType)) {
        value = rs.getBigDecimal(index);
    } else if (BigInteger.class.equals(requiredType)) {
        value = rs.getBigDecimal(index);
    } else if (Blob.class.equals(requiredType)) {
        value = rs.getBlob(index);
    } else if (Clob.class.equals(requiredType)) {
        value = rs.getClob(index);
    } else if (byte[].class.equals(requiredType)) {
        try {
            byte[] bytes = rs.getBytes(index);
            if (bytes == null) {
                value = null;
            } else {
                value = new String(bytes, "ISO-8859-1");// binaryiso-8859-1
            }
        } catch (UnsupportedEncodingException e) {
            throw new SQLException(e);
        }
    } else {
        // Some unknown type desired -> rely on getObject.
        value = getResultSetValue(rs, index);
    }

    // Perform was-null check if demanded (for results that the
    // JDBC driver returns as primitives).
    if (wasNullCheck && (value != null) && rs.wasNull()) {
        value = null;
    }

    return (value == null) ? null : convertUtilsBean.convert(value);
}

From source file:com.tesora.dve.db.mysql.DBTypeBasedUtilsTest.java

@Test
public void mysqlConvertTest() throws Exception {
    ByteBuf cb;//from   ww w  .ja  va2  s. c o m

    ListOfPairs<MyFieldType, Object> expValuesConvMysql = new ListOfPairs<MyFieldType, Object>();
    expValuesConvMysql.add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_LONG, new Integer(8765432)));
    expValuesConvMysql.add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_LONGLONG, new Long(8765432)));
    expValuesConvMysql
            .add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_SHORT, new Short((short) 5678)));
    expValuesConvMysql.add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_TINY, new Integer(100)));
    expValuesConvMysql.add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_TINY, new Byte((byte) 1)));
    //      expValuesConvMysql.add(new Pair<MyFieldType, Object>(MyFieldType.FIELD_TYPE_BIT, new Boolean(true)));

    int len;
    for (Pair<MyFieldType, Object> expValue : expValuesConvMysql) {
        len = 0;
        if (expValue.getSecond() instanceof Byte)
            len = 1;

        cb = Unpooled.buffer(100).order(ByteOrder.LITTLE_ENDIAN);
        DataTypeValueFunc dtvf = DBTypeBasedUtils.getMysqlTypeFunc(expValue.getFirst(), len, 0);
        dtvf.writeObject(cb, expValue.getSecond());
        assertEquals(expValue.getSecond(), dtvf.readObject(cb));
    }

}

From source file:javadz.beanutils.locale.converters.ShortLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type. This method will return values of type Short.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value//w w w  .j  a  va2 s  .c o  m
 *
 * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 * @since 1.8.0
 */
protected Object parse(Object value, String pattern) throws ParseException {

    Object result = super.parse(value, pattern);

    if (result == null || result instanceof Short) {
        return result;
    }

    Number parsed = (Number) result;
    if (parsed.longValue() != parsed.shortValue()) {
        throw new ConversionException("Supplied number is not of type Short: " + parsed.longValue());
    }

    // now returns property Short
    return new Short(parsed.shortValue());
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRspnHandler.CFAsteriskXMsgRspnISOLanguageRecHandler.java

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

        assert qName.equals("ISOLanguage");

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

        ICFAsteriskSchemaObj schemaObj = xmsgRspnHandler.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("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = 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
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        short natId = Short.parseShort(attrId);

        String natISOCode = attrISOCode;

        String natBaseLanguageCode = attrBaseLanguageCode;

        Short natISOCountryId;
        if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
            natISOCountryId = null;
        } else {
            natISOCountryId = new Short(Short.parseShort(attrISOCountryId));
        }

        int natRevision = Integer.parseInt(attrRevision);
        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAsteriskISOLanguageObj obj = (ICFAsteriskISOLanguageObj) (schemaObj.getISOLanguageTableObj()
                .newInstance());
        CFSecurityISOLanguageBuff dataBuff = obj.getISOLanguageBuff();
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredISOCode(natISOCode);
        dataBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);
        dataBuff.setOptionalISOCountryId(natISOCountryId);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        @SuppressWarnings("unchecked")
        List<ICFSecurityISOLanguageObj> list = (List<ICFSecurityISOLanguageObj>) xmsgRspnHandler
                .getListOfObjects();
        ICFSecurityISOLanguageObj realized = (ICFSecurityISOLanguageObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (list != null) {
            list.add(realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmXMsgRspnHandler.CFCrmXMsgRspnISOLanguageLockedHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {// w  w  w . j  a  va 2s .  co  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RspnISOLanguageLocked");

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

        ICFCrmSchemaObj schemaObj = xmsgRspnHandler.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("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = 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
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }
        if ((attrRevision == null) || (attrRevision.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Revision");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Convert string attributes to native Java types

        short natId = Short.parseShort(attrId);

        String natISOCode = attrISOCode;

        String natBaseLanguageCode = attrBaseLanguageCode;

        Short natISOCountryId;
        if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
            natISOCountryId = null;
        } else {
            natISOCountryId = new Short(Short.parseShort(attrISOCountryId));
        }

        int natRevision = Integer.parseInt(attrRevision);
        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        // Instantiate a buffer for the parsed information
        ICFCrmISOLanguageObj obj = schemaObj.getISOLanguageTableObj().newInstance();
        CFCrmISOLanguageBuff dataBuff = obj.getISOLanguageBuff();
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredISOCode(natISOCode);
        dataBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);
        dataBuff.setOptionalISOCountryId(natISOCountryId);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        ICFCrmISOLanguageObj realized = (ICFCrmISOLanguageObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:demo.config.PropertyConverter.java

/**
 * Convert the specified object into a Short.
 * //from  www .  java2 s. co m
 * @param value
 *            the value to convert
 * @return the converted value
 * @throws ConversionException
 *             thrown if the value cannot be converted to a short
 */
public static Short toShort(Object value) throws ConversionException {
    Number n = toNumber(value, Short.class);
    if (n instanceof Short) {
        return (Short) n;
    } else {
        return new Short(n.shortValue());
    }
}