List of usage examples for java.lang Short Short
@Deprecated(since = "9") public Short(String s) throws NumberFormatException
From source file:net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashXMsgRspnHandler.CFGCashXMsgRspnAccountEntryUpdatedHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {// ww w. ja v a2s . c o m // Common XML Attributes String attrId = null; String attrRevision = null; // AccountEntry Attributes String attrTenantId = null; String attrAccountId = null; String attrEntryId = null; String attrSplitEntryId = null; String attrEntryStamp = null; String attrDescription = null; String attrTransferTenantId = null; String attrTransferAccountId = null; String attrDebitCurrencyId = null; String attrDebit = null; String attrCreditCurrencyId = null; String attrCredit = null; String attrConvertedCurrencyId = null; String attrConvertedAmount = null; String attrBalanceCurrencyId = null; String attrBalance = 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("RspnAccountEntryUpdated"); CFGCashXMsgRspnHandler xmsgRspnHandler = (CFGCashXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGCashSchemaObj 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("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AccountId")) { if (attrAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryId")) { if (attrEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SplitEntryId")) { if (attrSplitEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSplitEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryStamp")) { if (attrEntryStamp != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryStamp = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferTenantId")) { if (attrTransferTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferAccountId")) { if (attrTransferAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("DebitCurrencyId")) { if (attrDebitCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebitCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Debit")) { if (attrDebit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreditCurrencyId")) { if (attrCreditCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreditCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Credit")) { if (attrCredit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCredit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedCurrencyId")) { if (attrConvertedCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedAmount")) { if (attrConvertedAmount != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedAmount = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BalanceCurrencyId")) { if (attrBalanceCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalanceCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Balance")) { if (attrBalance != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalance = 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 ((attrTenantId == null) || (attrTenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "TenantId"); } if ((attrAccountId == null) || (attrAccountId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AccountId"); } if ((attrEntryId == null) || (attrEntryId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryId"); } if ((attrEntryStamp == null) || (attrEntryStamp.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryStamp"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } if ((attrConvertedCurrencyId == null) || (attrConvertedCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedCurrencyId"); } if ((attrConvertedAmount == null) || (attrConvertedAmount.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedAmount"); } if ((attrBalanceCurrencyId == null) || (attrBalanceCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "BalanceCurrencyId"); } if ((attrBalance == null) || (attrBalance.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Balance"); } 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 long natTenantId = Long.parseLong(attrTenantId); long natAccountId = Long.parseLong(attrAccountId); UUID natEntryId = UUID.fromString(attrEntryId); UUID natSplitEntryId; if ((attrSplitEntryId == null) || (attrSplitEntryId.length() <= 0)) { natSplitEntryId = null; } else { natSplitEntryId = UUID.fromString(attrSplitEntryId); } Calendar natEntryStamp; try { natEntryStamp = CFLibXmlUtil.parseTimestamp(attrEntryStamp); } catch (RuntimeException e) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, 0, "EntryStamp", attrEntryStamp, e); } String natDescription = attrDescription; Long natTransferTenantId; if ((attrTransferTenantId == null) || (attrTransferTenantId.length() <= 0)) { natTransferTenantId = null; } else { natTransferTenantId = new Long(Long.parseLong(attrTransferTenantId)); } Long natTransferAccountId; if ((attrTransferAccountId == null) || (attrTransferAccountId.length() <= 0)) { natTransferAccountId = null; } else { natTransferAccountId = new Long(Long.parseLong(attrTransferAccountId)); } Short natDebitCurrencyId; if ((attrDebitCurrencyId == null) || (attrDebitCurrencyId.length() <= 0)) { natDebitCurrencyId = null; } else { natDebitCurrencyId = new Short(Short.parseShort(attrDebitCurrencyId)); } BigDecimal natDebit; if ((attrDebit == null) || (attrDebit.length() <= 0)) { natDebit = null; } else { natDebit = new BigDecimal(attrDebit); } Short natCreditCurrencyId; if ((attrCreditCurrencyId == null) || (attrCreditCurrencyId.length() <= 0)) { natCreditCurrencyId = null; } else { natCreditCurrencyId = new Short(Short.parseShort(attrCreditCurrencyId)); } BigDecimal natCredit; if ((attrCredit == null) || (attrCredit.length() <= 0)) { natCredit = null; } else { natCredit = new BigDecimal(attrCredit); } short natConvertedCurrencyId = Short.parseShort(attrConvertedCurrencyId); BigDecimal natConvertedAmount = new BigDecimal(attrConvertedAmount); short natBalanceCurrencyId = Short.parseShort(attrBalanceCurrencyId); BigDecimal natBalance = new BigDecimal(attrBalance); 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 ICFGCashAccountEntryObj obj = schemaObj.getAccountEntryTableObj().newInstance(); CFGCashAccountEntryBuff dataBuff = obj.getAccountEntryBuff(); dataBuff.setRequiredTenantId(natTenantId); dataBuff.setRequiredAccountId(natAccountId); dataBuff.setRequiredEntryId(natEntryId); dataBuff.setOptionalSplitEntryId(natSplitEntryId); dataBuff.setRequiredEntryStamp(natEntryStamp); dataBuff.setRequiredDescription(natDescription); dataBuff.setOptionalTransferTenantId(natTransferTenantId); dataBuff.setOptionalTransferAccountId(natTransferAccountId); dataBuff.setOptionalDebitCurrencyId(natDebitCurrencyId); dataBuff.setOptionalDebit(natDebit); dataBuff.setOptionalCreditCurrencyId(natCreditCurrencyId); dataBuff.setOptionalCredit(natCredit); dataBuff.setRequiredConvertedCurrencyId(natConvertedCurrencyId); dataBuff.setRequiredConvertedAmount(natConvertedAmount); dataBuff.setRequiredBalanceCurrencyId(natBalanceCurrencyId); dataBuff.setRequiredBalance(natBalance); 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(); ICFGCashAccountEntryObj realized = (ICFGCashAccountEntryObj) 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.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testNumberCoercion() { NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new JuffrouSpringBeanWrapper(tb); try {//from www. j a va 2 s. c om bw.setPropertyValue("short2", new Integer(2)); bw.setPropertyValue("int2", new Long(8)); bw.setPropertyValue("long2", new BigInteger("6")); bw.setPropertyValue("bigInteger", new Integer(3)); bw.setPropertyValue("float2", new Double(8.1)); bw.setPropertyValue("double2", new BigDecimal(6.1)); bw.setPropertyValue("bigDecimal", new Float(4.0)); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(tb.getBigDecimal())); }
From source file:com.germinus.easyconf.ComponentProperties.java
public short getShort(String key, Filter filter, short defaultValue) { return getShort(key, filter, new Short(defaultValue)).shortValue(); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstAccountEntryCreateHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {/*from w ww. j a v a2 s . c om*/ // Common XML Attributes String attrId = null; String attrRevision = null; // AccountEntry Attributes String attrTenantId = null; String attrAccountId = null; String attrEntryId = null; String attrSplitEntryId = null; String attrEntryStamp = null; String attrDescription = null; String attrTransferTenantId = null; String attrTransferAccountId = null; String attrDebitCurrencyId = null; String attrDebit = null; String attrCreditCurrencyId = null; String attrCredit = null; String attrConvertedCurrencyId = null; String attrConvertedAmount = null; String attrBalanceCurrencyId = null; String attrBalance = 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("RqstAccountEntryCreate"); CFAccXMsgRqstHandler xmsgRqstHandler = (CFAccXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFAccSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFAccAccountEntryEditObj editBuff = (ICFAccAccountEntryEditObj) schemaObj.getAccountEntryTableObj() .newInstance().beginEdit(); CFAccAccountEntryBuff dataBuff = editBuff.getAccountEntryBuff(); // 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("schemaLocation")) { // ignored } 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("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AccountId")) { if (attrAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryId")) { if (attrEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SplitEntryId")) { if (attrSplitEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSplitEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryStamp")) { if (attrEntryStamp != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryStamp = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferTenantId")) { if (attrTransferTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferAccountId")) { if (attrTransferAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("DebitCurrencyId")) { if (attrDebitCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebitCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Debit")) { if (attrDebit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreditCurrencyId")) { if (attrCreditCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreditCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Credit")) { if (attrCredit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCredit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedCurrencyId")) { if (attrConvertedCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedAmount")) { if (attrConvertedAmount != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedAmount = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BalanceCurrencyId")) { if (attrBalanceCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalanceCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Balance")) { if (attrBalance != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalance = attrs.getValue(idxAttr); } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrTenantId == null) || (attrTenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "TenantId"); } if ((attrAccountId == null) || (attrAccountId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AccountId"); } if ((attrEntryId == null) || (attrEntryId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryId"); } if ((attrEntryStamp == null) || (attrEntryStamp.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryStamp"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } if ((attrConvertedCurrencyId == null) || (attrConvertedCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedCurrencyId"); } if ((attrConvertedAmount == null) || (attrConvertedAmount.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedAmount"); } if ((attrBalanceCurrencyId == null) || (attrBalanceCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "BalanceCurrencyId"); } if ((attrBalance == null) || (attrBalance.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Balance"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. long natTenantId = Long.parseLong(attrTenantId); dataBuff.setRequiredTenantId(natTenantId); long natAccountId = Long.parseLong(attrAccountId); dataBuff.setRequiredAccountId(natAccountId); UUID natSplitEntryId; if ((attrSplitEntryId == null) || (attrSplitEntryId.length() <= 0)) { natSplitEntryId = null; } else { natSplitEntryId = UUID.fromString(attrSplitEntryId); } dataBuff.setOptionalSplitEntryId(natSplitEntryId); Calendar natEntryStamp; try { natEntryStamp = CFLibXmlUtil.parseTimestamp(attrEntryStamp); } catch (RuntimeException e) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, 0, "EntryStamp", attrEntryStamp, e); } dataBuff.setRequiredEntryStamp(natEntryStamp); String natDescription = attrDescription; dataBuff.setRequiredDescription(natDescription); Long natTransferTenantId; if ((attrTransferTenantId == null) || (attrTransferTenantId.length() <= 0)) { natTransferTenantId = null; } else { natTransferTenantId = new Long(Long.parseLong(attrTransferTenantId)); } dataBuff.setOptionalTransferTenantId(natTransferTenantId); Long natTransferAccountId; if ((attrTransferAccountId == null) || (attrTransferAccountId.length() <= 0)) { natTransferAccountId = null; } else { natTransferAccountId = new Long(Long.parseLong(attrTransferAccountId)); } dataBuff.setOptionalTransferAccountId(natTransferAccountId); Short natDebitCurrencyId; if ((attrDebitCurrencyId == null) || (attrDebitCurrencyId.length() <= 0)) { natDebitCurrencyId = null; } else { natDebitCurrencyId = new Short(Short.parseShort(attrDebitCurrencyId)); } dataBuff.setOptionalDebitCurrencyId(natDebitCurrencyId); BigDecimal natDebit; if ((attrDebit == null) || (attrDebit.length() <= 0)) { natDebit = null; } else { natDebit = new BigDecimal(attrDebit); } dataBuff.setOptionalDebit(natDebit); Short natCreditCurrencyId; if ((attrCreditCurrencyId == null) || (attrCreditCurrencyId.length() <= 0)) { natCreditCurrencyId = null; } else { natCreditCurrencyId = new Short(Short.parseShort(attrCreditCurrencyId)); } dataBuff.setOptionalCreditCurrencyId(natCreditCurrencyId); BigDecimal natCredit; if ((attrCredit == null) || (attrCredit.length() <= 0)) { natCredit = null; } else { natCredit = new BigDecimal(attrCredit); } dataBuff.setOptionalCredit(natCredit); short natConvertedCurrencyId = Short.parseShort(attrConvertedCurrencyId); dataBuff.setRequiredConvertedCurrencyId(natConvertedCurrencyId); BigDecimal natConvertedAmount = new BigDecimal(attrConvertedAmount); dataBuff.setRequiredConvertedAmount(natConvertedAmount); short natBalanceCurrencyId = Short.parseShort(attrBalanceCurrencyId); dataBuff.setRequiredBalanceCurrencyId(natBalanceCurrencyId); BigDecimal natBalance = new BigDecimal(attrBalance); dataBuff.setRequiredBalance(natBalance); 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); } if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } // Attempt the create editBuff.copyBuffToPKey(); // Allow for predefined ids ICFAccAccountEntryObj created = (ICFAccAccountEntryObj) editBuff.create(); editBuff.endEdit(); String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgAccountEntryMessageFormatter.formatAccountEntryRspnCreated("\n\t\t\t", created.getAccountEntryBuff()) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); ((CFAccXMsgRqstHandler) getParser()).appendResponse(response); } catch (RuntimeException e) { String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }
From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java
public static Object readObjectFromXml(Element node) throws Exception { String nodeName = node.getNodeName(); String nodeValue = ((Element) node).getAttribute("value"); if (nodeName.equals("java.lang.Boolean")) { return new Boolean(nodeValue); } else if (nodeName.equals("java.lang.Byte")) { return new Byte(nodeValue); } else if (nodeName.equals("java.lang.Character")) { return new Character(nodeValue.charAt(0)); } else if (nodeName.equals("java.lang.Integer")) { return new Integer(nodeValue); } else if (nodeName.equals("java.lang.Double")) { return new Double(nodeValue); } else if (nodeName.equals("java.lang.Float")) { return new Float(nodeValue); } else if (nodeName.equals("java.lang.Long")) { return new Long(nodeValue); } else if (nodeName.equals("java.lang.Short")) { return new Short(nodeValue); } else if (nodeName.equals("java.lang.String")) { return nodeValue; } else if (nodeName.equals("array")) { String className = node.getAttribute("classname"); String length = node.getAttribute("length"); int len = (new Integer(length)).intValue(); Object array;// w w w . j ava2 s . c o m if (className.equals("byte")) { array = new byte[len]; } else if (className.equals("boolean")) { array = new boolean[len]; } else if (className.equals("char")) { array = new char[len]; } else if (className.equals("double")) { array = new double[len]; } else if (className.equals("float")) { array = new float[len]; } else if (className.equals("int")) { array = new int[len]; } else if (className.equals("long")) { array = new long[len]; } else if (className.equals("short")) { array = new short[len]; } else { array = Array.newInstance(Class.forName(className), len); } Node xmlNode = null; NodeList nl = node.getChildNodes(); int len_nl = nl.getLength(); int i = 0; for (int j = 0; j < len_nl; j++) { xmlNode = nl.item(j); if (xmlNode.getNodeType() == Node.ELEMENT_NODE) { Object o = XMLUtils.readObjectFromXml((Element) xmlNode); Array.set(array, i, o); i++; } } return array; } // XMLization else if (nodeName.equals("xmlizable")) { String className = node.getAttribute("classname"); Node xmlNode = findChildNode(node, Node.ELEMENT_NODE); Object xmlizable = Class.forName(className).newInstance(); ((XMLizable) xmlizable).readXml(xmlNode); return xmlizable; } // Serialization else if (nodeName.equals("serializable")) { Node cdata = findChildNode(node, Node.CDATA_SECTION_NODE); String objectSerializationData = cdata.getNodeValue(); Engine.logEngine.debug("Object serialization data:\n" + objectSerializationData); byte[] objectBytes = org.apache.commons.codec.binary.Base64.decodeBase64(objectSerializationData); // We read the object to a bytes array ByteArrayInputStream inputStream = new ByteArrayInputStream(objectBytes); ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); Object object = objectInputStream.readObject(); inputStream.close(); return object; } return null; }
From source file:edu.hawaii.soest.hioos.isus.ISUSFrame.java
public int getChannelWavelengthCounts(int wavelength) { int position = (wavelength * 2) - 2; short counts = this.channelWavelengths.getShort(position); return new Short(counts).intValue(); }
From source file:net.sf.json.TestJSONObject.java
public void testFromBean_use_wrappers() { JSONObject json = JSONObject.fromObject(Boolean.TRUE); assertTrue(json.isEmpty());// w ww .j a va 2 s . c om json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Short(Short.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Long(Long.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Float(Float.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Double(Double.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Character('A')); assertTrue(json.isEmpty()); }
From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java
/** * Adds a calendar. If necessary, a new ID is generated and set in the * CalendarWrapper.// w w w .j a v a 2 s . c o m * * @param c as a CalendarWrapper object, usually without an ID set. * @throws DAOException * * @see CalendarWrapper */ public void addItem(CalendarWrapper cw) throws DAOException { if (log.isTraceEnabled()) { log.trace("PIMCalendarDAO addItem begin"); } Connection con = null; PreparedStatement ps = null; long id = 0; String allDay = null; String body = null; Short busyStatus = null; String categories = null; String companies = null; int duration = 0; Date dend = null; short importance = 0; String location = null; Short meetingStatus = null; String mileage = null; Date replyTime = null; short sensitivity = 0; Date dstart = null; String subject = null; int interval = 0; short monthOfYear = 0; short dayOfMonth = 0; String dayOfWeekMask = null; short instance = 0; String startDatePattern = null; String endDatePattern = null; Reminder reminder = null; RecurrencePattern rp = null; short recurrenceType = -1; String sId = null; int occurrences = -1; String folder = null; String dstartTimeZone = null; String dendTimeZone = null; String reminderTimeZone = null; Date completed = null; short percentComplete = -1; Timestamp lastUpdate = cw.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } try { sId = cw.getId(); if (sId == null || sId.length() == 0) { // ...as it should be sId = getNextID(); cw.setId(sId); } id = Long.parseLong(sId); CalendarContent c = cw.getCalendar().getCalendarContent(); rp = c.getRecurrencePattern(); boolean allDayB; if (c.getAllDay() != null && c.getAllDay().booleanValue()) { allDayB = true; allDay = "1"; } else { allDayB = false; allDay = "0"; } String sd = null; if (c.getDtStart() != null) { sd = c.getDtStart().getPropertyValueAsString(); dstart = getDateFromString(allDayB, sd, "000000"); } String ed = null; if ((sd != null && sd.length() > 0) || c.getDtEnd() != null) { ed = c.getDtEnd().getPropertyValueAsString(); // // Fix for Siemens S56 end date issue only for event // @todo: verify if is really need to do this // if (c instanceof Event) { if (ed == null || ed.length() == 0) { ed = sd; } } dend = getDateFromString(allDayB, ed, "235900"); } body = Property.stringFrom(c.getDescription()); if (c.getBusyStatus() != null) { busyStatus = new Short(c.getBusyStatus().shortValue()); } categories = Property.stringFrom(c.getCategories()); companies = Property.stringFrom(c.getOrganizer()); location = Property.stringFrom(c.getLocation()); folder = Property.stringFrom(c.getFolder()); dstartTimeZone = timeZoneFrom(c.getDtStart()); dendTimeZone = timeZoneFrom(c.getDtEnd()); reminderTimeZone = timeZoneFrom(c.getReminder()); meetingStatus = c.getMeetingStatus(); Integer mileageInteger = c.getMileage(); // NB: not an int... if (mileageInteger != null) { // ...therefore it may be null mileage = String.valueOf(mileageInteger); } if (c instanceof Event) { replyTime = getDateFromString(allDayB, // @todo or false? Property.stringFrom(((Event) c).getReplyTime()), "000000"); } try { sensitivity = Short.parseShort(Property.stringFrom(c.getAccessClass())); } catch (NumberFormatException nfe) { sensitivity = 0; // The short must go on } if ((subject = Property.stringFrom(c.getSummary())) == null && body != null) { int endOfSentence = body.indexOf('.'); if (endOfSentence == -1) { endOfSentence = body.length(); } if (endOfSentence > SQL_SUBJECT_DIM) { endOfSentence = SQL_SUBJECT_DIM; } subject = body.substring(0, endOfSentence); } String isInfinite = "0"; if (rp != null) { interval = rp.getInterval(); recurrenceType = rp.getTypeId(); monthOfYear = rp.getMonthOfYear(); dayOfMonth = rp.getDayOfMonth(); dayOfWeekMask = String.valueOf(rp.getDayOfWeekMask()); instance = rp.getInstance(); startDatePattern = rp.getStartDatePattern(); endDatePattern = rp.getEndDatePattern(); if (rp.isNoEndDate()) { isInfinite = "1"; } occurrences = rp.getOccurrences(); } if (c instanceof Task) { Task t = (Task) c; if (t.getDateCompleted() != null) { completed = getDateFromString(allDayB, ((Task) c).getDateCompleted().getPropertyValueAsString(), "000000"); } try { String complete = Property.stringFrom(t.getComplete()); if (complete != null && complete.equals("1")) { percentComplete = 100; } else { percentComplete = Short.parseShort(Property.stringFrom(t.getPercentComplete())); } if (percentComplete < 0 || percentComplete > 100) { throw new NumberFormatException("A percentage can't be " + percentComplete); } } catch (NumberFormatException nfe) { percentComplete = -1; // the short must go on } meetingStatus = getTaskStatus(t); } con = getUserDataSource().getRoutedConnection(userId); ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR); ps.setLong(1, id); ps.setString(2, userId); ps.setLong(3, lastUpdate.getTime()); ps.setString(4, String.valueOf(Def.PIM_STATE_NEW)); ps.setString(5, allDay); ps.setString(6, StringUtils.left(body, SQL_BODY_DIM)); if (busyStatus != null) { ps.setShort(7, busyStatus.shortValue()); } else { ps.setNull(7, Types.SMALLINT); } ps.setString(8, StringUtils.left(categories, SQL_CATEGORIES_DIM)); ps.setString(9, StringUtils.left(companies, SQL_COMPANIES_DIM)); ps.setInt(10, duration); if (dend != null) { ps.setTimestamp(11, new Timestamp(dend.getTime())); } else { ps.setNull(11, Types.TIMESTAMP); } if (c.getPriority() != null) { String priority = c.getPriority().getPropertyValueAsString(); if (priority != null && priority.length() > 0) { importance = Short.parseShort(priority); ps.setShort(12, importance); } else { ps.setNull(12, Types.SMALLINT); } } else { ps.setNull(12, Types.SMALLINT); } ps.setString(13, StringUtils.left(location, SQL_LOCATION_DIM)); if (meetingStatus != null) { ps.setShort(14, meetingStatus.shortValue()); } else { ps.setNull(14, Types.SMALLINT); } ps.setString(15, mileage); reminder = c.getReminder(); if (reminder != null && reminder.isActive()) { Timestamp reminderTime = getReminderTime(dstart, reminder); if (reminderTime == null) { ps.setNull(16, Types.TIMESTAMP); } else { ps.setTimestamp(16, reminderTime); } ps.setInt(17, reminder.getRepeatCount()); ps.setString(18, (reminder.isActive()) ? "1" : "0"); String soundFileValue = reminder.getSoundFile(); ps.setString(19, StringUtils.left(soundFileValue, SQL_SOUNDFILE_DIM)); ps.setInt(20, reminder.getOptions()); } else { ps.setNull(16, Types.TIMESTAMP); ps.setInt(17, 0); ps.setString(18, "0"); ps.setString(19, null); ps.setInt(20, 0); } if (replyTime != null) { ps.setTimestamp(21, new Timestamp(replyTime.getTime())); } else { ps.setNull(21, Types.TIMESTAMP); } ps.setShort(22, sensitivity); if (dstart != null) { ps.setTimestamp(23, new Timestamp(dstart.getTime())); } else { ps.setNull(23, Types.TIMESTAMP); } ps.setString(24, StringUtils.left(subject, SQL_SUBJECT_DIM)); ps.setShort(25, recurrenceType); ps.setInt(26, interval); ps.setShort(27, monthOfYear); ps.setShort(28, dayOfMonth); ps.setString(29, StringUtils.left(dayOfWeekMask, SQL_DAYOFWEEKMASK_DIM)); ps.setShort(30, instance); ps.setString(31, StringUtils.left(startDatePattern, SQL_STARTDATEPATTERN_DIM)); ps.setString(32, isInfinite); ps.setString(33, StringUtils.left(endDatePattern, SQL_ENDDATEPATTERN_DIM)); ps.setInt(34, occurrences); if (c instanceof Event) { ps.setInt(35, CALENDAR_EVENT_TYPE); ps.setNull(36, Types.TIMESTAMP); // completed ps.setNull(37, Types.SMALLINT); // percent_complete } else { ps.setInt(35, CALENDAR_TASK_TYPE); if (completed != null) { ps.setTimestamp(36, new Timestamp(completed.getTime())); } else { ps.setNull(36, Types.TIMESTAMP); } if (percentComplete != -1) { ps.setShort(37, percentComplete); } else { ps.setNull(37, Types.SMALLINT); } } ps.setString(38, StringUtils.left(folder, SQL_FOLDER_DIM)); ps.setString(39, StringUtils.left(dstartTimeZone, SQL_TIME_ZONE_DIM)); ps.setString(40, StringUtils.left(dendTimeZone, SQL_TIME_ZONE_DIM)); ps.setString(41, StringUtils.left(reminderTimeZone, SQL_TIME_ZONE_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); if (recurrenceType != -1) { List<ExceptionToRecurrenceRule> exceptions = rp.getExceptions(); for (ExceptionToRecurrenceRule etrr : exceptions) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR_EXCEPTION); ps.setLong(1, id); ps.setString(2, (etrr.isAddition() ? "1" : "0")); ps.setTimestamp(3, new Timestamp(getDateFromString(allDayB, etrr.getDate(), "000000").getTime())); ps.executeUpdate(); DBTools.close(null, ps, null); } } } catch (Exception e) { throw new DAOException("Error adding a calendar item: " + e.getMessage(), e); } finally { DBTools.close(con, ps, null); } }
From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
/** * Extract the OUT parameter values from the callable statment and * assign them to the value of the parameter. *///from ww w . jav a2 s. c o m public void extract(ConnectionContext cc, CallableStatement stmt) throws SQLException { if (getType().getValueIndex() == StoredProcedureParameter.Type.IN) return; int index = this.getIndex(); QueryParameterType paramType = getSqlType(); int jdbcType = paramType.getJdbcType(); String identifier = paramType.getIdentifier(); // result sets are special if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER)) { ResultSet rs = (ResultSet) stmt.getObject(index); QueryResultSet qrs = new QueryResultSet(getParent().getProcedure(), cc, rs); value.getValue(cc).setValue(qrs); return; } switch (jdbcType) { case Types.VARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case Types.INTEGER: value.getValue(cc).setValue(new Integer(stmt.getInt(index))); break; case Types.DOUBLE: value.getValue(cc).setValue(new Double(stmt.getDouble(index))); break; case Types.CLOB: Clob clob = stmt.getClob(index); value.getValue(cc).setTextValue(clob.getSubString(1, (int) clob.length())); break; case java.sql.Types.ARRAY: Array array = stmt.getArray(index); value.getValue(cc).setValue(array); break; case java.sql.Types.BIGINT: long bigint = stmt.getLong(index); value.getValue(cc).setValue(new Long(bigint)); break; case java.sql.Types.BINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.BIT: boolean bit = stmt.getBoolean(index); value.getValue(cc).setValue(new Boolean(bit)); case java.sql.Types.BLOB: value.getValue(cc).setValue(stmt.getBlob(index)); break; case java.sql.Types.CHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case java.sql.Types.DATE: value.getValue(cc).setValue(stmt.getDate(index)); break; case java.sql.Types.DECIMAL: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.DISTINCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.FLOAT: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; case java.sql.Types.JAVA_OBJECT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.LONGVARBINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.LONGVARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; //case java.sql.Types.NULL: // value.getValue(cc).setValue(null); // break; case java.sql.Types.NUMERIC: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.OTHER: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.REAL: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; //case java.sql.Types.REF: // Ref ref = stmt.getRef(index); // break; case java.sql.Types.SMALLINT: short sh = stmt.getShort(index); value.getValue(cc).setValue(new Short(sh)); break; case java.sql.Types.STRUCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.TIME: value.getValue(cc).setValue(stmt.getTime(index)); break; case java.sql.Types.TIMESTAMP: value.getValue(cc).setValue(stmt.getTimestamp(index)); break; case java.sql.Types.TINYINT: byte b = stmt.getByte(index); value.getValue(cc).setValue(new Byte(b)); break; case java.sql.Types.VARBINARY: value.getValue(cc).setValue(stmt.getBytes(index)); break; default: throw new RuntimeException( "Unknown JDBC Type set for stored procedure parameter '" + this.getName() + "'."); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstAccountEntryUpdateHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {// ww w. j a v a2 s.com // Common XML Attributes String attrId = null; String attrRevision = null; // AccountEntry Attributes String attrTenantId = null; String attrAccountId = null; String attrEntryId = null; String attrSplitEntryId = null; String attrEntryStamp = null; String attrDescription = null; String attrTransferTenantId = null; String attrTransferAccountId = null; String attrDebitCurrencyId = null; String attrDebit = null; String attrCreditCurrencyId = null; String attrCredit = null; String attrConvertedCurrencyId = null; String attrConvertedAmount = null; String attrBalanceCurrencyId = null; String attrBalance = 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("RqstAccountEntryUpdate"); CFAccXMsgRqstHandler xmsgRqstHandler = (CFAccXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFAccSchemaObj 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("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("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AccountId")) { if (attrAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryId")) { if (attrEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SplitEntryId")) { if (attrSplitEntryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSplitEntryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("EntryStamp")) { if (attrEntryStamp != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrEntryStamp = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferTenantId")) { if (attrTransferTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TransferAccountId")) { if (attrTransferAccountId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTransferAccountId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("DebitCurrencyId")) { if (attrDebitCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebitCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Debit")) { if (attrDebit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDebit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreditCurrencyId")) { if (attrCreditCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreditCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Credit")) { if (attrCredit != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCredit = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedCurrencyId")) { if (attrConvertedCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ConvertedAmount")) { if (attrConvertedAmount != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrConvertedAmount = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BalanceCurrencyId")) { if (attrBalanceCurrencyId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalanceCurrencyId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Balance")) { if (attrBalance != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBalance = 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 ((attrTenantId == null) || (attrTenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "TenantId"); } if ((attrAccountId == null) || (attrAccountId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AccountId"); } if ((attrEntryId == null) || (attrEntryId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryId"); } if ((attrEntryStamp == null) || (attrEntryStamp.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "EntryStamp"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } if ((attrConvertedCurrencyId == null) || (attrConvertedCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedCurrencyId"); } if ((attrConvertedAmount == null) || (attrConvertedAmount.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ConvertedAmount"); } if ((attrBalanceCurrencyId == null) || (attrBalanceCurrencyId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "BalanceCurrencyId"); } if ((attrBalance == null) || (attrBalance.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Balance"); } if ((attrRevision == null) || (attrRevision.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Revision"); } if ((attrCreatedAt == null) || (attrCreatedAt.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "CreatedAt"); } if ((attrCreatedBy == null) || (attrCreatedBy.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "CreatedBy"); } if ((attrUpdatedAt == null) || (attrUpdatedAt.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "UpdatedAt"); } if ((attrUpdatedBy == null) || (attrUpdatedBy.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "UpdatedBy"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Instantiate a PKey buffer for the parsed information CFAccAccountEntryPKey pkey = schemaObj.getBackingStore().getFactoryAccountEntry().newPKey(); long natTenantId; natTenantId = Long.parseLong(attrTenantId); pkey.setRequiredTenantId(natTenantId); long natAccountId; natAccountId = Long.parseLong(attrAccountId); pkey.setRequiredAccountId(natAccountId); UUID natEntryId; natEntryId = UUID.fromString(attrEntryId); pkey.setRequiredEntryId(natEntryId); // Read the instance ICFAccAccountEntryObj origBuff = schemaObj.getAccountEntryTableObj().readAccountEntry(pkey); if (origBuff == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getAccountEntryTableObj().readAccountEntry()"); } else { // Edit the instance ICFAccAccountEntryEditObj editBuff = (ICFAccAccountEntryEditObj) origBuff.beginEdit(); CFAccAccountEntryBuff dataBuff = editBuff.getAccountEntryBuff(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. UUID natSplitEntryId; if ((attrSplitEntryId == null) || (attrSplitEntryId.length() <= 0)) { natSplitEntryId = null; } else { natSplitEntryId = UUID.fromString(attrSplitEntryId); } dataBuff.setOptionalSplitEntryId(natSplitEntryId); Calendar natEntryStamp; try { natEntryStamp = CFLibXmlUtil.parseTimestamp(attrEntryStamp); } catch (RuntimeException e) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, 0, "EntryStamp", attrEntryStamp, e); } dataBuff.setRequiredEntryStamp(natEntryStamp); String natDescription = attrDescription; dataBuff.setRequiredDescription(natDescription); Long natTransferTenantId; if ((attrTransferTenantId == null) || (attrTransferTenantId.length() <= 0)) { natTransferTenantId = null; } else { natTransferTenantId = new Long(Long.parseLong(attrTransferTenantId)); } dataBuff.setOptionalTransferTenantId(natTransferTenantId); Long natTransferAccountId; if ((attrTransferAccountId == null) || (attrTransferAccountId.length() <= 0)) { natTransferAccountId = null; } else { natTransferAccountId = new Long(Long.parseLong(attrTransferAccountId)); } dataBuff.setOptionalTransferAccountId(natTransferAccountId); Short natDebitCurrencyId; if ((attrDebitCurrencyId == null) || (attrDebitCurrencyId.length() <= 0)) { natDebitCurrencyId = null; } else { natDebitCurrencyId = new Short(Short.parseShort(attrDebitCurrencyId)); } dataBuff.setOptionalDebitCurrencyId(natDebitCurrencyId); BigDecimal natDebit; if ((attrDebit == null) || (attrDebit.length() <= 0)) { natDebit = null; } else { natDebit = new BigDecimal(attrDebit); } dataBuff.setOptionalDebit(natDebit); Short natCreditCurrencyId; if ((attrCreditCurrencyId == null) || (attrCreditCurrencyId.length() <= 0)) { natCreditCurrencyId = null; } else { natCreditCurrencyId = new Short(Short.parseShort(attrCreditCurrencyId)); } dataBuff.setOptionalCreditCurrencyId(natCreditCurrencyId); BigDecimal natCredit; if ((attrCredit == null) || (attrCredit.length() <= 0)) { natCredit = null; } else { natCredit = new BigDecimal(attrCredit); } dataBuff.setOptionalCredit(natCredit); short natConvertedCurrencyId = Short.parseShort(attrConvertedCurrencyId); dataBuff.setRequiredConvertedCurrencyId(natConvertedCurrencyId); BigDecimal natConvertedAmount = new BigDecimal(attrConvertedAmount); dataBuff.setRequiredConvertedAmount(natConvertedAmount); short natBalanceCurrencyId = Short.parseShort(attrBalanceCurrencyId); dataBuff.setRequiredBalanceCurrencyId(natBalanceCurrencyId); BigDecimal natBalance = new BigDecimal(attrBalance); dataBuff.setRequiredBalance(natBalance); int natRevision = Integer.parseInt(attrRevision); dataBuff.setRequiredRevision(natRevision); 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); } if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } // Attempt the update editBuff.update(); editBuff.endEdit(); String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgAccountEntryMessageFormatter.formatAccountEntryRspnUpdated("\n\t\t\t", origBuff.getAccountEntryBuff()) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); ((CFAccXMsgRqstHandler) getParser()).appendResponse(response); } } catch (RuntimeException e) { String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble(); CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser()); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }