List of usage examples for java.lang Short Short
@Deprecated(since = "9") public Short(String s) throws NumberFormatException
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
private Object morphToShort(String str) { try {//from ww w .ja v a 2s . co m return new Short(str); } catch (Exception e) { throw new ConvertErrorException(str, this.type); } }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnToolLockedHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//www . j a v a 2s .c o m // Common XML Attributes String attrId = null; String attrRevision = null; // Tool Attributes String attrName = null; String attrReplacesId = null; String attrIsSupported = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RspnToolLocked"); CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj 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("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ReplacesId")) { if (attrReplacesId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrReplacesId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("IsSupported")) { if (attrIsSupported != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrIsSupported = 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 (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrIsSupported == null) || (attrIsSupported.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "IsSupported"); } 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 natName = attrName; Short natReplacesId; if ((attrReplacesId == null) || (attrReplacesId.length() <= 0)) { natReplacesId = null; } else { natReplacesId = new Short(Short.parseShort(attrReplacesId)); } boolean natIsSupported; if (attrIsSupported.equals("true") || attrIsSupported.equals("yes") || attrIsSupported.equals("1")) { natIsSupported = true; } else if (attrIsSupported.equals("false") || attrIsSupported.equals("no") || attrIsSupported.equals("0")) { natIsSupported = false; } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Unexpected IsSupported value, must be one of true, false, yes, no, 1, or 0, not \"" + attrIsSupported + "\""); } int natRevision = Integer.parseInt(attrRevision); // Instantiate a buffer for the parsed information ICFGenKbToolObj obj = schemaObj.getToolTableObj().newInstance(); CFGenKbToolBuff dataBuff = obj.getToolBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredName(natName); dataBuff.setOptionalReplacesId(natReplacesId); dataBuff.setRequiredIsSupported(natIsSupported); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); ICFGenKbToolObj realized = (ICFGenKbToolObj) 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:com.edmunds.autotest.AutoTestGetterSetter.java
private static Map<Class<?>, Object> createValueMap() { Map<Class<?>, Object> valueMap = new HashMap<Class<?>, Object>(); valueMap.put(byte.class, new Byte((byte) 40)); valueMap.put(short.class, new Short((short) 41)); valueMap.put(int.class, new Integer(42)); valueMap.put(long.class, new Long(43)); valueMap.put(float.class, new Float(44)); valueMap.put(double.class, new Double(45)); valueMap.put(boolean.class, Boolean.TRUE); valueMap.put(char.class, new Character((char) 46)); valueMap.put(Byte.class, new Byte((byte) 40)); valueMap.put(Short.class, new Short((short) 41)); valueMap.put(Integer.class, new Integer(42)); valueMap.put(Long.class, new Long(43)); valueMap.put(Float.class, new Float(44)); valueMap.put(Double.class, new Double(45)); valueMap.put(Boolean.class, Boolean.TRUE); valueMap.put(Character.class, new Character((char) 46)); return valueMap; }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnToolCreatedHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//from w ww . j a v a2s. c o m // Common XML Attributes String attrId = null; String attrRevision = null; // Tool Attributes String attrName = null; String attrReplacesId = null; String attrIsSupported = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RspnToolCreated"); CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj 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("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ReplacesId")) { if (attrReplacesId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrReplacesId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("IsSupported")) { if (attrIsSupported != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrIsSupported = 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 (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrIsSupported == null) || (attrIsSupported.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "IsSupported"); } 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 natName = attrName; Short natReplacesId; if ((attrReplacesId == null) || (attrReplacesId.length() <= 0)) { natReplacesId = null; } else { natReplacesId = new Short(Short.parseShort(attrReplacesId)); } boolean natIsSupported; if (attrIsSupported.equals("true") || attrIsSupported.equals("yes") || attrIsSupported.equals("1")) { natIsSupported = true; } else if (attrIsSupported.equals("false") || attrIsSupported.equals("no") || attrIsSupported.equals("0")) { natIsSupported = false; } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Unexpected IsSupported value, must be one of true, false, yes, no, 1, or 0, not \"" + attrIsSupported + "\""); } int natRevision = Integer.parseInt(attrRevision); // Instantiate a buffer for the parsed information ICFGenKbToolObj obj = schemaObj.getToolTableObj().newInstance(); CFGenKbToolBuff dataBuff = obj.getToolBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredName(natName); dataBuff.setOptionalReplacesId(natReplacesId); dataBuff.setRequiredIsSupported(natIsSupported); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); ICFGenKbToolObj realized = (ICFGenKbToolObj) 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:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnToolUpdatedHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//from www . j a v a 2 s . c o m // Common XML Attributes String attrId = null; String attrRevision = null; // Tool Attributes String attrName = null; String attrReplacesId = null; String attrIsSupported = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RspnToolUpdated"); CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj 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("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ReplacesId")) { if (attrReplacesId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrReplacesId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("IsSupported")) { if (attrIsSupported != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrIsSupported = 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 (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrIsSupported == null) || (attrIsSupported.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "IsSupported"); } 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 natName = attrName; Short natReplacesId; if ((attrReplacesId == null) || (attrReplacesId.length() <= 0)) { natReplacesId = null; } else { natReplacesId = new Short(Short.parseShort(attrReplacesId)); } boolean natIsSupported; if (attrIsSupported.equals("true") || attrIsSupported.equals("yes") || attrIsSupported.equals("1")) { natIsSupported = true; } else if (attrIsSupported.equals("false") || attrIsSupported.equals("no") || attrIsSupported.equals("0")) { natIsSupported = false; } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Unexpected IsSupported value, must be one of true, false, yes, no, 1, or 0, not \"" + attrIsSupported + "\""); } int natRevision = Integer.parseInt(attrRevision); // Instantiate a buffer for the parsed information ICFGenKbToolObj obj = schemaObj.getToolTableObj().newInstance(); CFGenKbToolBuff dataBuff = obj.getToolBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredName(natName); dataBuff.setOptionalReplacesId(natReplacesId); dataBuff.setRequiredIsSupported(natIsSupported); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); ICFGenKbToolObj realized = (ICFGenKbToolObj) 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:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstDefClassUpdateHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {// www. j a v a2 s .co m // Common XML Attributes String attrId = null; String attrRevision = null; // DefClass Attributes String attrName = null; String attrBaseId = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstDefClassUpdate"); CFGenKbXMsgRqstHandler xmsgRqstHandler = (CFGenKbXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj 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("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BaseId")) { if (attrBaseId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBaseId = 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 (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrRevision == null) || (attrRevision.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Revision"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Instantiate a PKey buffer for the parsed information CFGenKbDefClassPKey pkey = schemaObj.getBackingStore().getFactoryDefClass().newPKey(); short natId; natId = Short.parseShort(attrId); pkey.setRequiredId(natId); // Read the instance ICFGenKbDefClassObj origBuff = schemaObj.getDefClassTableObj().readDefClass(pkey); if (origBuff == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getDefClassTableObj().readDefClass()"); } else { // Edit the instance ICFGenKbDefClassEditObj editBuff = (ICFGenKbDefClassEditObj) origBuff.beginEdit(); CFGenKbDefClassBuff dataBuff = editBuff.getDefClassBuff(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. String natName = attrName; dataBuff.setRequiredName(natName); Short natBaseId; if ((attrBaseId == null) || (attrBaseId.length() <= 0)) { natBaseId = null; } else { natBaseId = new Short(Short.parseShort(attrBaseId)); } dataBuff.setOptionalBaseId(natBaseId); int natRevision = Integer.parseInt(attrRevision); dataBuff.setRequiredRevision(natRevision); // Attempt the update editBuff.update(); editBuff.endEdit(); String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFGenKbXMsgDefClassMessageFormatter.formatDefClassRspnUpdated("\n\t\t\t", origBuff.getDefClassBuff()) + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); ((CFGenKbXMsgRqstHandler) getParser()).appendResponse(response); } } catch (RuntimeException e) { String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }
From source file:com.github.xbn.array.primitive.ObjectArrayFromPrimitive.java
/** <p>Get a {@code java.lang.Object} array from an array of {@code short}-s.</p> //w w w. j a v a2s . c o m * @return If {@code prmtv_array} is<ul> <li>{@code null}: {@code null}</li> <li>non-{@code null} and has no elements: <code>org.apache.commons.lang3.{@link org.apache.commons.lang3.ArrayUtils ArrayUtils}.{@link org.apache.commons.lang3.ArrayUtils#EMPTY_OBJECT_ARRAY EMPTY_OBJECT_ARRAY}</code></li> <li>Otherwise: A new {@code Object} array containing all elements in {@code prmtv_array}.</li> </ul> * @see #get(boolean[], NullContainer, String) get(b[]) */ public static final Object[] get(short[] prmtv_array, NullContainer nnull, String cntrName_forNullBad) { if (prmtv_array == null) { IndexableUtil.crashIfContainerIsNullAndThatIsBad(nnull, cntrName_forNullBad); return null; } if (prmtv_array.length == 0) { return ArrayUtils.EMPTY_OBJECT_ARRAY; } Short[] ao = new Short[prmtv_array.length]; for (int i = 0; i < prmtv_array.length; i++) { ao[i] = new Short(prmtv_array[i]); } return ao; }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
public void testPrimitive() throws Exception { assertEquals(Boolean.TRUE, ParseUtils.parse(boolean.class, "true")); assertEquals(Boolean.FALSE, ParseUtils.parse(boolean.class, "false")); assertEquals(new Character((char) 10), ParseUtils.parse(char.class, "\n")); assertEquals(new Byte((byte) 10), ParseUtils.parse(byte.class, "10")); assertEquals(new Short((short) 10), ParseUtils.parse(short.class, "10")); assertEquals(new Integer(10), ParseUtils.parse(int.class, "10")); assertEquals(new Long(10), ParseUtils.parse(long.class, "10")); assertEquals(new Float(10), ParseUtils.parse(float.class, "10")); assertEquals(new Double(10), ParseUtils.parse(double.class, "10")); }/*w w w. ja v a 2s . co m*/
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbSaxLoader.CFGenKbSaxLoaderISOLanguageHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {/* w w w.java2 s . 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"); CFGenKbSaxLoader saxLoader = (CFGenKbSaxLoader) getParser(); if (saxLoader == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj schemaObj = saxLoader.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFGenKbISOLanguageEditObj editBuff = (ICFGenKbISOLanguageEditObj) 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; } CFGenKbSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOLanguageLoaderBehaviour(); ICFGenKbISOLanguageEditObj editISOLanguage = null; ICFGenKbISOLanguageObj 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 = (ICFGenKbISOLanguageEditObj) origISOLanguage.beginEdit(); editISOLanguage.setRequiredISOCode(editBuff.getRequiredISOCode()); editISOLanguage.setRequiredBaseLanguageCode(editBuff.getRequiredBaseLanguageCode()); editISOLanguage.setOptionalISOCountryId(editBuff.getOptionalISOCountryId()); break; case Replace: editISOLanguage = (ICFGenKbISOLanguageEditObj) origISOLanguage.beginEdit(); editISOLanguage.delete(); editISOLanguage.endEdit(); origISOLanguage = null; editISOLanguage = editBuff; break; } } if (editISOLanguage != null) { if (origISOLanguage != null) { editISOLanguage.update(); } else { origISOLanguage = (ICFGenKbISOLanguageObj) 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.jaspersoft.jasperserver.ws.axis2.RepositoryHelper.java
/** * This method get a string and tries to convert the string into the requested object. * Valid classes are:/*from w w w . j a va 2 s . c om*/ * java.util.Date (the string is supposed to represent a number of milliseconds) * Number * BigDecimal * Byte * Short * Integer * Long * Float * Double * Boolean * String * java.util.Locale * * The default returned object is of type String * @param str the string representing the value * @param clazz The class of the result (not garanteed) * @return return an Object hopefully of the requested class (or a String) * */ public Object stringToValue(String str, Class clazz) { Object value = str; if (value == null) { return value; } if (java.util.Date.class.getName().equals(clazz.getName())) { value = new java.util.Date(Long.valueOf(value.toString()).longValue()); } else if (java.sql.Date.class.getName().equals(clazz.getName())) { value = new java.sql.Date(Long.valueOf(value.toString()).longValue()); } else if (java.sql.Timestamp.class.getName().equals(clazz.getName())) { value = new java.sql.Timestamp(Long.valueOf(value.toString()).longValue()); } else if (Number.class.isAssignableFrom(clazz)) { value = new java.math.BigDecimal(value.toString()); if (Byte.class.getName().equals(clazz.getName())) { value = new Byte(((Number) value).byteValue()); } else if (Short.class.getName().equals(clazz.getName())) { value = new Short(((Number) value).shortValue()); } else if (Integer.class.getName().equals(clazz.getName())) { value = new Integer(((Number) value).intValue()); } else if (Long.class.getName().equals(clazz.getName())) { value = new Long(((Number) value).longValue()); } else if (Float.class.getName().equals(clazz.getName())) { value = new Float(((Number) value).floatValue()); } else if (Double.class.getName().equals(clazz.getName())) { value = new Double(((Number) value).doubleValue()); } } else if (Boolean.class.getName().equals(clazz.getName())) { value = Boolean.valueOf(value.toString()); } else if (Locale.class.getName().equals(clazz.getName())) { value = LocaleHelper.getInstance().getLocale(str); } else if (DateRange.class.equals(clazz)) { try { value = DateRangeFactory.getInstance(str, Date.class); } catch (InvalidDateRangeExpressionException e) { //if DateRange passed as string with milliseconds we need to parse it Date dateValue = (Date) stringToValue(str, Date.class); value = DateRangeFactory.getInstance(dateValue); } } else if (TimestampRange.class.equals(clazz)) { try { value = DateRangeFactory.getInstance(str, Timestamp.class); } catch (InvalidDateRangeExpressionException e) { //if TimestampRange passed as string with milliseconds we need to parse it Timestamp timestamp = (Timestamp) stringToValue(str, Timestamp.class); value = DateRangeFactory.getInstance(timestamp); } } return value; }