List of usage examples for java.lang Short Short
@Deprecated(since = "9") public Short(String s) throws NumberFormatException
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a value to the given primitive number class *///from w w w . java 2s. c o m public static Number coerceToPrimitiveNumber(Object pValue, Class pClass) throws ElException { if (pValue == null || "".equals(pValue)) { return coerceToPrimitiveNumber(ZERO, pClass); } else if (pValue instanceof Character) { char val = ((Character) pValue).charValue(); return coerceToPrimitiveNumber(new Short((short) val), pClass); } else if (pValue instanceof Boolean) { if (log.isErrorEnabled()) { String message = MessageUtil.getMessageWithArgs(Constants.BOOLEAN_TO_NUMBER, pValue, pClass.getName()); log.error(message); throw new ElException(message); } return coerceToPrimitiveNumber(ZERO, pClass); } else if (pValue.getClass() == pClass) { return (Number) pValue; } else if (pValue instanceof Number) { return coerceToPrimitiveNumber((Number) pValue, pClass); } else if (pValue instanceof String) { try { return coerceToPrimitiveNumber((String) pValue, pClass); } catch (Exception exc) { if (log.isErrorEnabled()) { String message = MessageUtil.getMessageWithArgs(Constants.STRING_TO_NUMBER_EXCEPTION, (String) pValue, pClass.getName()); log.error(message); throw new ElException(message); } return coerceToPrimitiveNumber(ZERO, pClass); } } else { if (log.isErrorEnabled()) { String message = MessageUtil.getMessageWithArgs(Constants.COERCE_TO_NUMBER, pValue.getClass().getName(), pClass.getName()); log.error(message); throw new ElException(message); } return coerceToPrimitiveNumber(0, pClass); } }
From source file:javadz.beanutils.converters.NumberConverter.java
/** * Default String to Number conversion./*from w w w . j a v a 2 s. c om*/ * <p> * This method handles conversion from a String to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The String value to convert. * * @return The converted Number value. */ private Number toNumber(Class sourceType, Class targetType, String value) { // Byte if (targetType.equals(Byte.class)) { return new Byte(value); } // Short if (targetType.equals(Short.class)) { return new Short(value); } // Integer if (targetType.equals(Integer.class)) { return new Integer(value); } // Long if (targetType.equals(Long.class)) { return new Long(value); } // Float if (targetType.equals(Float.class)) { return new Float(value); } // Double if (targetType.equals(Double.class)) { return new Double(value); } // BigDecimal if (targetType.equals(BigDecimal.class)) { return new BigDecimal(value); } // BigInteger if (targetType.equals(BigInteger.class)) { return new BigInteger(value); } String msg = toString(getClass()) + " cannot handle conversion from '" + toString(sourceType) + "' to '" + toString(targetType) + "'"; if (log().isWarnEnabled()) { log().warn(" " + msg); } throw new ConversionException(msg); }
From source file:com.cognitect.transit.TransitTest.java
public void testWriteInteger() throws Exception { assertEquals(scalarVerbose("42"), writeJsonVerbose(42)); assertEquals(scalarVerbose("42"), writeJsonVerbose(42L)); assertEquals(scalarVerbose("42"), writeJsonVerbose(new Byte("42"))); assertEquals(scalarVerbose("42"), writeJsonVerbose(new Short("42"))); assertEquals(scalarVerbose("42"), writeJsonVerbose(new Integer("42"))); assertEquals(scalarVerbose("42"), writeJsonVerbose(new Long("42"))); assertEquals(scalarVerbose("\"~n42\""), writeJsonVerbose(new BigInteger("42"))); assertEquals(scalarVerbose("\"~n4256768765123454321897654321234567\""), writeJsonVerbose(new BigInteger("4256768765123454321897654321234567"))); }
From source file:com.tc.object.ApplicatorDNAEncodingTest.java
public void testBasic() throws Exception { final TCByteBufferOutputStream output = new TCByteBufferOutputStream(); final List<Object> data = new ArrayList<Object>(); data.add(new ObjectID(1)); data.add("one"); data.add(new Boolean(true)); data.add("two"); data.add(new Byte((byte) 42)); data.add("three"); data.add(new Character('\t')); data.add("four"); data.add(new Double(Math.PI)); data.add("five"); data.add(new Float(Math.E)); data.add("six"); data.add(new Integer(Integer.MAX_VALUE)); data.add("seven"); data.add(new Long(System.currentTimeMillis() % 17)); data.add("eight"); data.add(new Short((short) -1)); final DNAEncoding encoding = getApplicatorEncoding(); for (Object d : data) { encoding.encode(d, output);/*w w w . jav a2 s . c om*/ } final TCByteBufferInputStream input = new TCByteBufferInputStream(output.toArray()); for (Object orig : data) { final Object decoded = encoding.decode(input); assertEquals(orig, decoded); } assertEquals(0, input.available()); }
From source file:javadz.beanutils.ConvertUtilsBean.java
/** * Sets the default value for Short conversions. * @param newDefaultShort The default Short value * @deprecated Register replacement converters for Short.TYPE and * Short.class instead//from w w w .jav a 2s .c o m */ public void setDefaultShort(short newDefaultShort) { defaultShort = new Short(newDefaultShort); register(new ShortConverter(defaultShort), Short.TYPE); register(new ShortConverter(defaultShort), Short.class); }
From source file:com.znsx.cms.web.controller.UserController.java
@InterfaceDescription(logon = true, method = "Create_User", cmd = "2002") @RequestMapping("/create_user.json") public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception { String standardNumber = request.getParameter("standardNumber"); String ccsId = request.getParameter("ccsId"); if (StringUtils.isBlank(ccsId)) { throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [ccsId]"); }//from w w w . jav a 2s . c o m String logonName = request.getParameter("logonName"); if (StringUtils.isBlank(logonName)) { throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [logonName]"); } String name = request.getParameter("name"); if (StringUtils.isBlank(name)) { throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [name]"); } String password = request.getParameter("password"); if (StringUtils.isBlank(password)) { throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [password]"); } Short sex = new Short("0"); String sexString = request.getParameter("sex"); if (StringUtils.isNotBlank(sexString)) { try { sex = Short.parseShort(sexString); } catch (NumberFormatException e) { e.printStackTrace(); throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Parameter sex[" + sexString + "] invalid !"); } } String email = request.getParameter("email"); String phone = request.getParameter("phone"); String address = request.getParameter("address"); String organId = request.getParameter("organId"); if (StringUtils.isBlank(organId)) { throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [organId]"); } Short priority = new Short("0"); String priorityString = request.getParameter("priority"); if (StringUtils.isNotBlank(priorityString)) { try { priority = Short.parseShort(priorityString); } catch (NumberFormatException e) { e.printStackTrace(); throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Parameter priority[" + priorityString + "] invalid !"); } } String note = request.getParameter("note"); Integer maxConnect = 1; String maxConnectString = request.getParameter("maxConnect"); if (StringUtils.isNotBlank(maxConnectString)) { try { maxConnect = Integer.parseInt(maxConnectString); } catch (NumberFormatException e) { e.printStackTrace(); throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Parameter maxConnect[" + maxConnectString + "] invalid !"); } } // ?License??,? License license = licenseManager.getLicense(); int userCount = userManager.countUser(); if (userCount >= Integer.parseInt(license.getUserAmount())) { throw new BusinessException(ErrorCode.USER_AMOUNT_LIMIT, "User amount over license limit !"); } // ?? if (StringUtils.isBlank(standardNumber)) { standardNumber = userManager.generateStandardNum("User", organId); } // String userId = userManager.createUser(name, standardNumber, ccsId, logonName, password, sex, email, phone, address, organId, priority, note, maxConnect); BaseDTO dto = new BaseDTO(); dto.setCmd("2002"); dto.setMethod("Create_User"); dto.setMessage(userId); writePage(response, dto); }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstGenFileCreateHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {/* w w w . jav a2 s. c om*/ // Common XML Attributes String attrId = null; String attrRevision = null; // GenItem Attributes String attrTenantId = null; String attrCartridgeId = null; String attrItemId = null; String attrRuleTypeId = null; String attrName = null; String attrToolSetId = null; String attrScopeDefId = null; String attrGenDefId = null; String attrGelExecutableId = null; // GenRule Attributes String attrBody = null; // GenFile Attributes String attrSourceBundle = null; String attrBasePackageName = null; String attrSubPackageName = null; String attrExpansionClassName = null; String attrExpansionKeyName = null; String attrExpansionFileName = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstGenFileCreate"); 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()"); } // Instantiate an edit buffer for the parsed information ICFGenKbGenFileEditObj editBuff = (ICFGenKbGenFileEditObj) schemaObj.getGenFileTableObj().newInstance() .beginEdit(); CFGenKbGenFileBuff dataBuff = editBuff.getGenFileBuff(); // 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("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CartridgeId")) { if (attrCartridgeId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCartridgeId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ItemId")) { if (attrItemId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrItemId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("RuleTypeId")) { if (attrRuleTypeId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRuleTypeId = 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("ToolSetId")) { if (attrToolSetId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolSetId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ScopeDefId")) { if (attrScopeDefId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrScopeDefId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("GenDefId")) { if (attrGenDefId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrGenDefId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("GelExecutableId")) { if (attrGelExecutableId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrGelExecutableId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Body")) { if (attrBody != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBody = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SourceBundle")) { if (attrSourceBundle != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSourceBundle = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BasePackageName")) { if (attrBasePackageName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBasePackageName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SubPackageName")) { if (attrSubPackageName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSubPackageName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ExpansionClassName")) { if (attrExpansionClassName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrExpansionClassName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ExpansionKeyName")) { if (attrExpansionKeyName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrExpansionKeyName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ExpansionFileName")) { if (attrExpansionFileName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrExpansionFileName = 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 ((attrCartridgeId == null) || (attrCartridgeId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "CartridgeId"); } if ((attrItemId == null) || (attrItemId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ItemId"); } if ((attrRuleTypeId == null) || (attrRuleTypeId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "RuleTypeId"); } if (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrToolSetId == null) || (attrToolSetId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ToolSetId"); } if ((attrGenDefId == null) || (attrGenDefId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "GenDefId"); } if (attrBody == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Body"); } // 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 natCartridgeId = Long.parseLong(attrCartridgeId); dataBuff.setRequiredCartridgeId(natCartridgeId); short natRuleTypeId = Short.parseShort(attrRuleTypeId); dataBuff.setRequiredRuleTypeId(natRuleTypeId); String natName = attrName; dataBuff.setRequiredName(natName); short natToolSetId = Short.parseShort(attrToolSetId); dataBuff.setRequiredToolSetId(natToolSetId); Short natScopeDefId; if ((attrScopeDefId == null) || (attrScopeDefId.length() <= 0)) { natScopeDefId = null; } else { natScopeDefId = new Short(Short.parseShort(attrScopeDefId)); } dataBuff.setOptionalScopeDefId(natScopeDefId); short natGenDefId = Short.parseShort(attrGenDefId); dataBuff.setRequiredGenDefId(natGenDefId); Integer natGelExecutableId; if ((attrGelExecutableId == null) || (attrGelExecutableId.length() <= 0)) { natGelExecutableId = null; } else { natGelExecutableId = new Integer(Integer.parseInt(attrGelExecutableId)); } dataBuff.setOptionalGelExecutableId(natGelExecutableId); String natBody = attrBody; dataBuff.setRequiredBody(natBody); String natSourceBundle = attrSourceBundle; dataBuff.setOptionalSourceBundle(natSourceBundle); String natBasePackageName = attrBasePackageName; dataBuff.setOptionalBasePackageName(natBasePackageName); String natSubPackageName = attrSubPackageName; dataBuff.setOptionalSubPackageName(natSubPackageName); String natExpansionClassName = attrExpansionClassName; dataBuff.setOptionalExpansionClassName(natExpansionClassName); String natExpansionKeyName = attrExpansionKeyName; dataBuff.setOptionalExpansionKeyName(natExpansionKeyName); String natExpansionFileName = attrExpansionFileName; dataBuff.setOptionalExpansionFileName(natExpansionFileName); // Attempt the create editBuff.copyBuffToPKey(); // Allow for predefined ids ICFGenKbGenFileObj created = (ICFGenKbGenFileObj) editBuff.create(); editBuff.endEdit(); String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFGenKbXMsgGenFileMessageFormatter.formatGenFileRspnCreated("\n\t\t\t", created.getGenFileBuff()) + "\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:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstAddressUpdateHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//from w ww . j a v a2s . c om // Common XML Attributes String attrId = null; String attrRevision = null; // Address Attributes String attrTenantId = null; String attrAddressId = null; String attrContactId = null; String attrDescription = null; String attrAddrLine1 = null; String attrAddrLine2 = null; String attrCity = null; String attrState = null; String attrCountryId = null; String attrZip = 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("RqstAddressUpdate"); 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("AddressId")) { if (attrAddressId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAddressId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ContactId")) { if (attrContactId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrContactId = 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("AddrLine1")) { if (attrAddrLine1 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAddrLine1 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AddrLine2")) { if (attrAddrLine2 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAddrLine2 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("City")) { if (attrCity != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCity = attrs.getValue(idxAttr); } else if (attrLocalName.equals("State")) { if (attrState != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrState = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CountryId")) { if (attrCountryId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCountryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Zip")) { if (attrZip != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrZip = 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 ((attrAddressId == null) || (attrAddressId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AddressId"); } if ((attrContactId == null) || (attrContactId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ContactId"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } 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 CFAccAddressPKey pkey = schemaObj.getBackingStore().getFactoryAddress().newPKey(); long natTenantId; natTenantId = Long.parseLong(attrTenantId); pkey.setRequiredTenantId(natTenantId); long natAddressId; natAddressId = Long.parseLong(attrAddressId); pkey.setRequiredAddressId(natAddressId); // Read the instance ICFAccAddressObj origBuff = schemaObj.getAddressTableObj().readAddress(pkey); if (origBuff == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getAddressTableObj().readAddress()"); } else { // Edit the instance ICFAccAddressEditObj editBuff = (ICFAccAddressEditObj) origBuff.beginEdit(); CFAccAddressBuff dataBuff = editBuff.getAddressBuff(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. long natContactId = Long.parseLong(attrContactId); dataBuff.setRequiredContactId(natContactId); String natDescription = attrDescription; dataBuff.setRequiredDescription(natDescription); String natAddrLine1 = attrAddrLine1; dataBuff.setOptionalAddrLine1(natAddrLine1); String natAddrLine2 = attrAddrLine2; dataBuff.setOptionalAddrLine2(natAddrLine2); String natCity = attrCity; dataBuff.setOptionalCity(natCity); String natState = attrState; dataBuff.setOptionalState(natState); Short natCountryId; if ((attrCountryId == null) || (attrCountryId.length() <= 0)) { natCountryId = null; } else { natCountryId = new Short(Short.parseShort(attrCountryId)); } dataBuff.setOptionalCountryId(natCountryId); String natZip = attrZip; dataBuff.setOptionalZip(natZip); 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" + CFAccXMsgAddressMessageFormatter.formatAddressRspnUpdated("\n\t\t\t", origBuff.getAddressBuff()) + "\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.github.xbn.array.helper.NewPrimitiveArrayHelper.java
public Short getWrapper(Object obj_thatIsPrimArr, int index, String array_name) { try {/*from w ww. j av a 2s . c o m*/ return (new Short(getPrimitiveArray(obj_thatIsPrimArr, NullContainer.BAD, array_name)[index])); } catch (RuntimeException rx) { ciObjNullUnexpectedTypeOrBadIndex(obj_thatIsPrimArr, index, array_name); throw rx; } }
From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java
/** * {@inheritDoc}//from w ww .j a v a 2 s . com * */ @Override protected void selectLogsImpl(Timestamp start, Timestamp end, Integer loglevel, String category, String msg, List<Pair<String, String>> logAttributes, final int startRow, final int maxRow, List<OrderBy> orderBy, final boolean masterOnly, final LogEntryCallback callback) throws EndOfSearch { final StopWatch sw = new StopWatch(); sw.start(); final StringBuilder queryStringBuilder = new StringBuilder( "select lm from " + getMasterClass().getName() + " as lm"); if (masterOnly == false) { queryStringBuilder.append(" left outer join fetch lm.attributes"); } boolean firstWhere = true; // final List<Object> args = new ArrayList<Object>(); Map<String, Object> argmap = new HashMap<>(); if (start != null) { firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt >= :createdAtMin"); argmap.put("createdAtMin", start); } if (end != null) { firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt <= :createdAtMax"); argmap.put("createdAtMax", end); } if (loglevel != null) { firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.loglevel >= :logLevelMin"); argmap.put("logLevelMin", new Short(loglevel.shortValue())); } if (StringUtils.isNotBlank(category) == true) { firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.category = :category"); argmap.put("category", category); } if (StringUtils.isNotBlank(msg) == true) { firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.shortmessage like :message"); argmap.put("message", msg + "%"); } if (logAttributes != null) { int attrNum = 0; for (Pair<String, String> pat : logAttributes) { ++attrNum; LogAttributeType at = getAttributeTypeByString(pat.getFirst()); if (at == null) { GLog.warn(GenomeLogCategory.Configuration, "SelLogs; Cannot find LogAttribute: " + pat.getFirst()); continue; } if (at.isSearchKey() == false) { GLog.warn(GenomeLogCategory.Configuration, "SelLogs; LogAttribute not searchable: " + pat.getFirst()); continue; } if (StringUtils.contains(pat.getSecond(), "%") == false) { firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " = :attr" + attrNum); } else { firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " like :attr" + attrNum); } argmap.put("attr" + attrNum, pat.getSecond()); } } if (CollectionUtils.isEmpty(orderBy) == false) { queryStringBuilder.append(" order by "); boolean first = true; for (OrderBy order : orderBy) { if (first == true) { first = false; } else { queryStringBuilder.append(", "); } String propertyName = convertColumnNameToPropertyName(order.getColumn()); queryStringBuilder.append("lm.").append((propertyName != null) ? propertyName : order.getColumn()); // eventually // requires // translation // to // propertynames queryStringBuilder.append(order.isDescending() ? " desc" : " asc"); } } EmgrFactory<DefaultEmgr> mgrfac = getEmgrFactory(); mgrfac.runInTrans(new EmgrCallable<Void, DefaultEmgr>() { @Override public Void call(DefaultEmgr mgr) { Query query = mgr.createQuery(queryStringBuilder.toString()); for (Map.Entry<String, Object> arg : argmap.entrySet()) { query.setParameter(arg.getKey(), arg.getValue()); } query.setFirstResult(startRow); if (masterOnly == true) { query.setMaxResults(maxRow); } else { query.setMaxResults(maxRow * 10); // pessimistic assumption: // 10 attributes per // master entry } List<M> res = query.getResultList(); for (M lmDo : res) { LogEntry le = new LogEntry(); copyMasterFields(le, lmDo, masterOnly); try { callback.onRow(le); } catch (EndOfSearch eos) { break; } } return null; } }); }