List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:org.hibernate.ogm.datastore.redis.impl.RedisDatastoreProvider.java
private synchronized JedisPool setupJedis() { String host = props.getProperty(Environment.REDIS_HOST, Environment.REDIS_DEFAULT_HOST); String port = props.getProperty(Environment.REDIS_PORT, Environment.REDIS_DEFAULT_PORT); String timeout = props.getProperty(Environment.REDIS_TIMEOUT, Environment.REDIS_DEFAULT_TIMEOUT); String password = props.getProperty(Environment.REDIS_PASSWORD, Environment.REDIS_DEFAULT_PASSWORD); String database = props.getProperty(Environment.REDIS_DATABASE, Environment.REDIS_DEFAULT_DATABASE); if (log.isDebugEnabled()) log.debug("Create JedisPool... host=[{}], port=[{}], timeout=[{}], password=[{}], database=[{}]", host, port, timeout, password, database); return new JedisPool(getPoolConfig(), host, Integer.decode(port), Integer.decode(timeout), password, Integer.decode(database)); }
From source file:com.mirth.connect.connectors.mllp.MllpMessageReceiver.java
public MllpMessageReceiver(UMOConnector connector, UMOComponent component, UMOEndpoint endpoint) throws InitialisationException { super(connector, component, endpoint); MllpConnector tcpConnector = (MllpConnector) connector; this.connector = tcpConnector; if (tcpConnector.getCharEncoding().equals("hex")) { START_MESSAGE = (char) Integer.decode(tcpConnector.getMessageStart()).intValue(); END_MESSAGE = (char) Integer.decode(tcpConnector.getMessageEnd()).intValue(); END_OF_RECORD = (char) Integer.decode(tcpConnector.getRecordSeparator()).intValue(); END_OF_SEGMENT = (char) Integer.decode(tcpConnector.getSegmentEnd()).intValue(); } else {//from ww w. jav a 2 s .co m // TODO: Ensure this is unit-tested START_MESSAGE = tcpConnector.getMessageStart().charAt(0); END_MESSAGE = tcpConnector.getMessageEnd().charAt(0); END_OF_RECORD = tcpConnector.getRecordSeparator().charAt(0); END_OF_SEGMENT = tcpConnector.getSegmentEnd().charAt(0); } }
From source file:org.rti.zcore.dar.struts.action.ListAction.java
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); Principal user = request.getUserPrincipal(); String username = user.getName(); Form encounterForm;/* w w w . j a v a 2s .co m*/ BaseEncounter encounter = null; Map encMap = null; Long formId = null; Long patientId = null; Long eventId = null; String constraintClause = null; Long constraintLong = null; String detailName = null; BaseSessionSubject sessionPatient = null; Integer maxRows = 0; Integer offset = 0; Integer prevRows = 0; Integer nextRows = 0; Connection conn = null; String className = null; try { conn = DatabaseUtils.getZEPRSConnection(username); if (request.getParameter("formId") != null) { formId = Long.decode(request.getParameter("formId")); } else if (request.getAttribute("formId") != null) { formId = Long.decode(request.getAttribute("formId").toString()); } if (request.getParameter("className") != null) { className = request.getParameter("className"); formId = (Long) DynaSiteObjects.getFormNameMap().get(className); } else if (request.getAttribute("className") != null) { className = (String) request.getAttribute("className"); formId = (Long) DynaSiteObjects.getFormNameMap().get(className); } if (request.getParameter("constraintClause") != null) { constraintClause = request.getParameter("constraintClause"); } else if (request.getAttribute("constraintClause") != null) { constraintClause = request.getAttribute("constraintClause").toString(); } if (request.getParameter("constraintLong") != null) { constraintLong = Long.decode(request.getParameter("constraintLong")); } else if (request.getAttribute("constraintLong") != null) { constraintLong = Long.decode(request.getAttribute("constraintLong").toString()); } if (request.getParameter("maxRows") != null) { maxRows = Integer.decode(request.getParameter("maxRows")); } else if (request.getAttribute("maxRows") != null) { maxRows = Integer.decode(request.getAttribute("maxRows").toString()); } else { if (formId != null) { switch (formId.intValue()) { case 128: maxRows = 0; break; case 129: maxRows = 0; break; case 130: maxRows = 0; break; case 131: maxRows = 0; break; case 181: maxRows = 0; break; default: maxRows = 20; break; } } else { maxRows = 20; } } if (request.getParameter("offset") != null) { offset = Integer.decode(request.getParameter("offset")); } else if (request.getAttribute("offset") != null) { offset = Integer.decode(request.getAttribute("offset").toString()); } if (request.getParameter("prevRows") != null) { prevRows = Integer.decode(request.getParameter("prevRows")); offset = prevRows; } else if (request.getAttribute("prevRows") != null) { prevRows = Integer.decode(request.getAttribute("prevRows").toString()); offset = prevRows; } if (request.getParameter("nextRows") != null) { nextRows = Integer.decode(request.getParameter("nextRows")); } else if (request.getAttribute("nextRows") != null) { nextRows = Integer.decode(request.getAttribute("nextRows").toString()); } if (mapping.getParameter() != null && !mapping.getParameter().equals("")) { String formName = mapping.getParameter(); formId = (Long) DynaSiteObjects.getFormNameMap().get(formName); } // Admin pages usually do not have a sessionPatient. This is a hack to use code that uses sessionPatient. sessionPatient = new TimsSessionSubject(); SessionUtil.getInstance(session).setSessionPatient(sessionPatient); encounterForm = ((Form) DynaSiteObjects.getForms().get(new Long(formId))); Long formTypeId = encounterForm.getFormTypeId(); // populate the records for this class List items = null; if (className != null && className.equals("MenuItem")) { items = DynaSiteObjects.getMenuItemList(); //must be sorted } else { String classname = StringManipulation.fixClassname(encounterForm.getName()); Class clazz = null; try { clazz = Class.forName(Constants.getDynasiteFormsPackage() + "." + classname); } catch (ClassNotFoundException e1) { if (classname.equals("UserInfo")) { clazz = Class.forName("org.rti.zcore." + classname); } } try { String orderBy = "id DESC"; switch (formTypeId.intValue()) { case 5: // admin if (constraintLong != null) { /*if (formId == 161) { // stock // Get the item - form 131 Class clazz = Class.forName(DynaSiteObjects.getDynasiteFormsPackage() + ".Item"); Item stockItem = (Item) EncountersDAO.getOne(conn, constraintLong, "SQL_RETRIEVE_ONE_ADMIN131", clazz); detailName = stockItem.getField2153(); request.setAttribute("detailName", detailName); }*/ //String orderBy = "id DESC"; items = EncountersDAO.getAllConstraintOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, constraintClause, constraintLong, orderBy); } else { if (formId == 161) { // stock //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, maxRows, offset, "id DESC"); if (maxRows == 0) { items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, orderBy); } } else if (formId == 128) { // regimen groups //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name "); if (maxRows == 0) { items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "name "); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name "); } } else if (formId == 129) { // regimen //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "code "); if (maxRows == 0) { items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "code "); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "code "); } } else if (formId == 130) { // item groups //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name "); if (maxRows == 0) { items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "name "); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name "); } } else { if (className != null && className.equals("MenuItem")) { items = DynaSiteObjects.getMenuItemList(); //must be sorted } else { if (formId == 181) { orderBy = "regimen_id DESC"; if (maxRows == 0) { //items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy); String sql = "SELECT rb.id, rb.regimen_id AS regimen_id, item_id AS item_id, r.code " + "FROM regimen_item_bridge rb, regimen r " + "WHERE rb.regimen_id = r.id ORDER BY r.code ASC"; ArrayList values = new ArrayList(); items = DatabaseUtils.getList(conn, clazz, sql, values); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, orderBy); } } else { if (maxRows == 0) { items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy); } else { items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, orderBy); } } } } } break; case 8: // list - for patients items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVEALL" + formId, clazz, maxRows, offset); break; default: items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL" + formId, clazz, maxRows, offset); break; } } catch (IOException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (ServletException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (SQLException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } } if (maxRows == 0) { request.setAttribute("noNavigationWidget", "1"); } else { request.setAttribute("maxRows", maxRows); nextRows = offset + maxRows; if (items.size() < maxRows) { if (offset == 0) { request.setAttribute("noNavigationWidget", "1"); } } else { request.setAttribute("offset", nextRows); } if (offset - maxRows >= 0) { prevRows = offset - maxRows; request.setAttribute("prevRows", prevRows); } request.setAttribute("nextRows", nextRows); } // Attach a map of encounter values that has enumerations already resolved. Form encForm = (Form) DynaSiteObjects.getForms().get(encounterForm.getId()); for (int i = 0; i < items.size(); i++) { encounter = (EncounterData) items.get(i); // Form encForm = (Form) DynaSiteObjects.getForms().get(encounter.getFormId()); encMap = PatientRecordUtils.getEncounterMap(encForm, encounter, "fieldId"); encounter.setEncounterMap(encMap); } if (items.size() > 0) { request.setAttribute("chartItems", items); request.setAttribute("formId", encounterForm.getId()); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } // Process the dynamic dropdown lists. HashMap listMap = new HashMap(); Form inlineForm = null; HashMap<Long, StockReport> balanceMap = null; if (DynaSiteObjects.getStatusMap().get("balanceMap") != null) { balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects.getStatusMap().get("balanceMap"); } for (Iterator iterator = encounterForm.getPageItems().iterator(); iterator.hasNext();) { PageItem pageItem = (PageItem) iterator.next(); FormField formField = pageItem.getForm_field(); String identifier = formField.getIdentifier(); if (pageItem.getInputType().equals("dropdown") || pageItem.getInputType().equals("dropdown-add-one") || pageItem.getInputType().equals("dropdown_site")) { String dropdownConstraint = null; String pageItemDropdownConstraint = pageItem.getDropdownConstraint(); if (pageItemDropdownConstraint != null && pageItemDropdownConstraint.endsWith("'siteAbbrev'")) { String siteAbbrev = SessionUtil.getInstance(session).getClientSettings().getSite() .getAbbreviation(); dropdownConstraint = pageItemDropdownConstraint.replace("'siteAbbrev'", "'" + siteAbbrev + "'"); } else { dropdownConstraint = pageItemDropdownConstraint; } List<DropdownItem> list = WidgetUtils.getList(conn, pageItem.getDropdownTable(), pageItem.getDropdownColumn(), dropdownConstraint, pageItem.getDropdownOrderByClause(), DropdownItem.class, pageItem.getFkIdentifier()); String formName = encForm.getClassname(); if (formName.equals("StockControl")) { for (DropdownItem dropdownItem : list) { if (balanceMap != null) { String itemIdStr = dropdownItem.getDropdownId(); Long itemId = Long.valueOf(itemIdStr); StockReport stockReport = balanceMap.get(itemId); Integer balance = 0; if (stockReport != null) { balance = stockReport.getBalanceBF(); String label = dropdownItem.getDropdownValue(); if (balance <= 0) { String value = dropdownItem.getDropdownValue(); dropdownItem .setDropdownValue(value + " ** Out of Stock ** Bal: " + balance); } else { dropdownItem.setDropdownValue(label + " Bal: " + balance); } } } } } listMap.put(pageItem.getId(), list); if (pageItem.getInputType().equals("dropdown-add-one")) { String classNameString = StringManipulation.fixClassname(pageItem.getDropdownTable()); Long inlineFormId = (Long) DynaSiteObjects.getFormNameMap().get(classNameString); inlineForm = ((Form) DynaSiteObjects.getForms().get(new Long(inlineFormId))); // Create a list of fieldnames for inline forms. ArrayList<String> inlineFields = new ArrayList<String>(); for (Iterator iterator2 = inlineForm.getPageItems().iterator(); iterator2.hasNext();) { PageItem pageItem2 = (PageItem) iterator2.next(); if (pageItem2.getForm_field().isEnabled() == true && !pageItem2.getForm_field().getType().equals("Display")) { inlineFields.add(pageItem2.getForm_field().getIdentifier()); } } request.setAttribute("inlineForm_" + identifier, inlineForm); request.setAttribute("inlineFields_" + identifier, inlineFields); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } } } request.setAttribute("listMap", listMap); request.setAttribute("encounterForm", encounterForm); List sites = DynaSiteObjects.getClinics(); request.setAttribute("sites", sites); if (Constants.STOCK_PROBLEMS_ENABLED != null && Constants.STOCK_PROBLEMS_ENABLED.equals("true")) { //List<Task> stockAlertList = PatientRecordUtils.getStockAlerts(); List<Task> stockAlertList = null; if (DynaSiteObjects.getStatusMap().get("stockAlertList") != null) { stockAlertList = (List<Task>) DynaSiteObjects.getStatusMap().get("stockAlertList"); } request.setAttribute("activeProblems", stockAlertList); } } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } return mapping.findForward("success"); }
From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForCorrelationer.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();// w ww . j a va 2 s . c om /* Assigning parameter descriptions to each parameter ID */ addParameterInfo(); /* need a Object parser of PosixParser class for the function parse of CommandLine class */ PosixParser parser = new PosixParser(); /* print out help information */ HelpParam help = new HelpParam(parameter, parameterMap); /* check each parameter for assignment */ try { long input_limit = -1; int threads = Runtime.getRuntime().availableProcessors(); /* Set Object cl of CommandLine class for Parameter storage */ CommandLine cl = parser.parse(parameter, arguments, true); if (cl.hasOption(HELP)) { help.printStatisticerHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printStatisticerHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(COLUMN)) != null) { param.columns = value; param.columnStart = Integer.decode(value.split("-")[0]); param.columnEnd = Integer.decode(value.split("-")[1]); } else { param.columnStart = Integer.decode(param.columns.split("-")[0]); param.columnEnd = Integer.decode(param.columns.split("-")[1]); } if (cl.hasOption(CACHE)) { param.cache = true; } if ((value = cl.getOptionValue(INPUT_VCF)) != null) { param.inputFqPath = value; } else if ((value = cl.getOptionValue(INPUT_TAB)) != null) { param.inputFqPath = value; } else { help.printStatisticerHelp(); System.exit(0); // throw new IOException("Input file not specified.\nUse -help for list of options"); } /* not applicable for HDFS and S3 */ /* using TextFileBufferInput for such purpose */ // File inputFastq = new File(param.inputFqPath).getAbsoluteFile(); // if (!inputFastq.exists()){ // err.println("Input query file not found."); // return; //i } if ((value = cl.getOptionValue(OUTPUT_LINE)) != null) { param.outputPath = value; } else { help.printStatisticerHelp(); info.readMessage("Output file not set with -outfile options"); info.screenDump(); System.exit(0); } File outfile = new File(param.outputPath).getAbsoluteFile(); if (outfile.exists()) { info.readParagraphedMessages( "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite."); info.screenDump(); Runtime.getRuntime().exec("rm -rf " + param.outputPath); } } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this. info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (RuntimeException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (ParseException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } return param; }
From source file:org.forgerock.openidm.shell.impl.RemoteCommandScope.java
private void processOptions(final String userPass, final String idmUrl, final String idmPort) { String username = ""; String password = ""; if (StringUtils.isNotBlank(userPass)) { int passwordIdx = userPass.indexOf(":") + 1; if (passwordIdx > 0) { username = userPass.substring(0, passwordIdx - 1); password = userPass.substring(passwordIdx); } else {/* www .j a v a2 s .c o m*/ username = userPass; password = new String(System.console().readPassword("Password:")); } resource.setUsername(username); resource.setPassword(password); } if (StringUtils.isNotBlank(idmUrl)) { resource.setBaseUri(idmUrl.endsWith("/") ? idmUrl : idmUrl + "/"); } if (StringUtils.isNotBlank(idmPort)) { if (NumberUtils.isDigits(idmPort)) { resource.setPort(Integer.decode(idmPort)); } else { throw new IllegalArgumentException("Port must be a number"); } } }
From source file:net.malisis.advert.advert.ServerAdvert.java
public static void readListing() { File listing = new File(packDir, advertListing); if (!listing.exists()) return;/* w w w . jav a2s. c om*/ try (BufferedReader br = new BufferedReader(new FileReader(listing))) { for (String line; (line = br.readLine()) != null;) { String[] parts = line.split(";"); if (parts.length == 3 || parts.length == 4) { int id = Integer.decode(parts[0]); ServerAdvert advert = new ServerAdvert(id); advert.setInfos(parts[1], parts[2]); if (parts.length == 4) advert.setHash(parts[3]); adverts.put(id, advert); if (id >= globalId) globalId = id + 1; } } } catch (IOException e) { MalisisAdvert.log.error("Could not read advert listing file : ", e); } }
From source file:org.jbpm.formModeler.components.renderer.FormRenderingComponent.java
public CommandResponse actionDoResize(CommandRequest request) { String ctxUID = request.getRequestObject().getParameter("ctxUID"); if (ctx == null || ctx.getUID().equals(ctxUID)) ctx = formRenderContextManager.getFormRenderContext(ctxUID); if (ctx != null) { String width = request.getRequestObject().getParameter("width"); String height = request.getRequestObject().getParameter("height"); if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { ResizeFormcontainerEvent event = new ResizeFormcontainerEvent(); event.setContext(new FormRenderContextTO(ctx)); event.setWidth(Integer.decode(width)); event.setHeight(Integer.decode(height)); formRenderContextManager.fireContextFormResize(event); }//from ww w . ja v a 2 s . co m } return new DoNothingResponse(); }
From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForReporter.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();/*w ww.j a va2s.co m*/ /* Assigning parameter descriptions to each parameter ID */ addParameterInfo(); /* need a Object parser of PosixParser class for the function parse of CommandLine class */ PosixParser parser = new PosixParser(); /* print out help information */ HelpParam help = new HelpParam(parameter, parameterMap); /* check each parameter for assignment */ try { long input_limit = -1; int threads = Runtime.getRuntime().availableProcessors(); /* Set Object cl of CommandLine class for Parameter storage */ CommandLine cl = parser.parse(parameter, arguments, true); if (cl.hasOption(HELP)) { help.printReporterHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printReporterHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(INPUT_KEY)) != null) { param.word = value; } if ((value = cl.getOptionValue(INPUT_VALUE)) != null) { param.count = Integer.decode(value); } if ((value = cl.getOptionValue(INPUT_HIT)) != null) { param.inputResultPath = value; } else { help.printReporterHelp(); System.exit(0); // throw new IOException("Input file not specified.\nUse -help for list of options"); } /* not applicable for HDFS and S3 */ /* using TextFileBufferInput for such purpose */ // File inputFastq = new File(param.inputFqPath).getAbsoluteFile(); // if (!inputFastq.exists()){ // err.println("Input query file not found."); // return; //i } if ((value = cl.getOptionValue(OUTPUT_REPORT)) != null) { param.outputPath = value; } else { info.readMessage("Output file not set of -outfile options"); info.screenDump(); } File outfile = new File(param.outputPath).getAbsoluteFile(); if (outfile.exists()) { info.readParagraphedMessages( "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite."); info.screenDump(); Runtime.getRuntime().exec("rm -rf " + param.outputPath); } // param.bestNas = (param.alignLength * param.readIdentity) / 100; // param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3; } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this. info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (RuntimeException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (ParseException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } return param; }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Converts an object to a JDBC type. This has just been started * and does not do much at the moment.// w ww . j a va 2s. co m * */ public static Object convert(Object value, String jType) { Object object = null; if (jType.equalsIgnoreCase("string")) { if (value instanceof String) { object = value; } else { object = value.toString(); } } else if (jType.equalsIgnoreCase("int")) { if (value instanceof String) { object = Integer.decode((String) value); } else if (value instanceof Integer) { object = value; } else { // } } else if (jType.equalsIgnoreCase("long")) { if (value instanceof String) { object = Long.decode((String) value); } else if (value instanceof Long) { object = value; } else { // } } else { // other types need parsing & creation // } return object; }
From source file:mil.jpeojtrs.sca.util.AnyUtils.java
/** * Attempts to convert the string value to the appropriate Java type. * // w w w. j ava 2s. c o m * @param stringValue the string form of the value * @param type the string form of the TypeCode * @return A Java object of theString corresponding to the typecode */ private static Object primitiveConvertString(final String stringValue, final String type) { if (stringValue == null) { return null; } if ("string".equals(type)) { return stringValue; } else if ("wstring".equals(type)) { return stringValue; } else if ("boolean".equals(type)) { if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) { return Boolean.parseBoolean(stringValue); } throw new IllegalArgumentException(stringValue + " is not a valid boolean value"); } else if ("char".equals(type)) { switch (stringValue.length()) { case 1: return stringValue.charAt(0); case 0: return null; default: throw new IllegalArgumentException(stringValue + " is not a valid char value"); } } else if ("wchar".equals(type)) { return stringValue.charAt(0); } else if ("double".equals(type)) { return Double.parseDouble(stringValue); } else if ("float".equals(type)) { return Float.parseFloat(stringValue); } else if ("short".equals(type)) { return Short.decode(stringValue); } else if ("long".equals(type)) { return Integer.decode(stringValue); } else if ("longlong".equals(type)) { return Long.decode(stringValue); } else if ("ulong".equals(type)) { final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L; final Long retVal = Long.decode(stringValue); if (retVal < 0 || retVal > MAX_UINT) { throw new IllegalArgumentException( "ulong value must be greater than '0' and less than " + MAX_UINT); } return retVal; } else if ("ushort".equals(type)) { final int MAX_USHORT = 2 * Short.MAX_VALUE + 1; final Integer retVal = Integer.decode(stringValue); if (retVal < 0 || retVal > MAX_USHORT) { throw new IllegalArgumentException( "ushort value must be greater than '0' and less than " + MAX_USHORT); } return retVal; } else if ("ulonglong".equals(type)) { final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)) .add(BigInteger.ONE); final BigInteger retVal = AnyUtils.bigIntegerDecode(stringValue); if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) { throw new IllegalArgumentException( "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString()); } return retVal; } else if ("objref".equals(type)) { if ("".equals(stringValue)) { return null; } final List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:"); for (final String prefix : objrefPrefix) { if (stringValue.startsWith(prefix)) { return stringValue; } } throw new IllegalArgumentException(stringValue + " is not a valid objref value"); } else if ("octet".equals(type)) { final short MIN_OCTET = 0; final short MAX_OCTET = 0xFF; final short val = Short.decode(stringValue); if (val <= MAX_OCTET && val >= MIN_OCTET) { return Short.valueOf(val); } throw new IllegalArgumentException(stringValue + " is not a valid octet value"); } else { throw new IllegalArgumentException("Unknown CORBA Type: " + type); } }