List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:org.wurstworks.tools.pinto.AbstractPintoBean.java
/** * Converts a string to the type indicated by the <b>type</b> parameter. The ability of a pinto bean to convert * strings to any arbitrary type can be extended by overriding and extending this method. * * @param type Indicates the type to which the argument should be converted. * @param argument The argument to be converted. * @return An object of the indicated type from the given value. * @throws PintoException/* www .j a v a2 s . c o m*/ */ protected Object convertStringToType(final Class<?> type, final String argument) throws PintoException { Object object; if (type == String.class) { object = argument; } else if (type == Integer.class || type == int.class) { object = Integer.parseInt(argument); } else if (type == Long.class || type == long.class) { object = Long.parseLong(argument); } else if (type == Float.class || type == float.class) { object = Float.parseFloat(argument); } else if (type == Double.class || type == double.class) { object = Double.parseDouble(argument); } else if (type == Character.class || type == char.class) { object = argument.toCharArray()[0]; } else if (type == Byte.class || type == byte.class) { object = Byte.parseByte(argument); } else if (type == Short.class || type == short.class) { object = Short.parseShort(argument); } else if (type == Boolean.class || type == boolean.class) { object = Boolean.parseBoolean(argument); } else if (type == File.class) { object = new File(argument); } else if (type == URI.class) { try { object = new URI(argument); } catch (URISyntaxException exception) { throw new PintoException(PintoExceptionType.SyntaxFormat, "The value " + argument + " is not a valid URI.", exception); } } else { throw new PintoException(PintoExceptionType.UnknownParameterTypes, "I don't know how to convert to the type " + type.getName()); } return object; }
From source file:org.wso2.carbon.appmgt.keymgt.internal.AppMKeyMgtServiceComponent.java
/** * Get INetAddress by host name or IP Address * * @param host name or host IP String// w w w .j a va 2 s .com * @return InetAddress * @throws java.net.UnknownHostException */ private InetAddress getHostAddress(String host) throws UnknownHostException { String[] splittedString = host.split("\\."); boolean value = checkIfIP(splittedString); if (!value) { return InetAddress.getByName(host); } byte[] byteAddress = new byte[4]; for (int i = 0; i < splittedString.length; i++) { if (Integer.parseInt(splittedString[i]) > 127) { byteAddress[i] = new Integer(Integer.parseInt(splittedString[i]) - 256).byteValue(); } else { byteAddress[i] = Byte.parseByte(splittedString[i]); } } return InetAddress.getByAddress(byteAddress); }
From source file:net.agkn.field_stripe.record.reader.PGTextRecordReader.java
@Override public byte readByteField(final MutableBoolean isSet) throws IllegalStateException, InvalidDataException { final String fieldString = readStringField(); if ((fieldString == null) || (fieldString.length() == 0)) { isSet.setValue(false/*not set*/); return -1/*any value allowed*/; } /* else -- a non-null value */ try {//from w w w. j a v a2 s . co m isSet.setValue(true/*set*/); return Byte.parseByte(fieldString); } catch (final NumberFormatException nfe) { throw new InvalidDataException("Could not convert \"" + fieldString + "\" to a byte.", nfe); } }
From source file:com.ltmonitor.jt808.service.impl.CommandService.java
private T808Message ParseAreaConfig(TerminalCommand tc) { T808Message ts = new T808Message(); ts.setHeader(new T808MessageHeader()); ts.getHeader().setSimId("0" + tc.getSimNo()); ts.getHeader().setMessageSerialNo((short) T808Manager.getSerialNo()); ts.getHeader().setIsPackage(false);//from ww w . j av a 2 s.c o m ts.getHeader().setMessageType(tc.getCmdType()); // tc.setStatus(TerminalCommand.STATUS_PROCESSING); tc.setSN(ts.getHeader().getMessageSerialNo()); java.util.ArrayList<Enclosure> enclosureList = new java.util.ArrayList<Enclosure>(); ArrayList enclosureIds = new ArrayList(); if (Tools.isNullOrEmpty(tc.getCmdData()) == false) { String[] strEnclosureIds = tc.getCmdData().split("[;]", -1); for (String enclosureId : strEnclosureIds) { if (StringHelper.isNullOrEmpty(enclosureId) == false) { int enId = Integer.parseInt(enclosureId); Enclosure ec = (Enclosure) getBaseDao().load( Enclosure.class, enId); enclosureList.add(ec); enclosureIds.add(enId); } } } if (tc.getCmdType() == JT808Constants.CMD_CIRCLE_CONFIG) { JT_8600 cmdData = new JT_8600(); ts.setMessageContents(cmdData); cmdData.setAreasCount((byte) 1); byte settingType = Byte.parseByte(tc.getCmd()); cmdData.setSettingType(settingType); cmdData.setCircleAreas(new java.util.ArrayList<CircleAreaItem>()); for (Enclosure ec : enclosureList) { CircleAreaItem ci = new CircleAreaItem(); ci.setCircleAreaId((int) ec.getEntityId()); ci.setCircleAreaName(ec.getName()); ci.setCircleAreaNameLength((byte) StringHelper.getByteLength(ec .getName())); // ???byte ci.setCircleAreaProperty(ec.CreateAreaAttr()); ci.setStartTime(ec.getStartDate()); ci.setEndTime(ec.getEndDate()); ci.setRadius((int) ec.getRadius()); ci.setMaxSpeed((short) ec.getMaxSpeed()); ci.setOverSpeedLastTime((byte) ec.getDelay()); java.util.ArrayList<EnclosureNode> nodes = ec.GetNodes(); if (nodes.size() > 0) { EnclosureNode node = nodes.get(0); ci.setCenterLatitude((int) (node.getLat() * 1000000)); ci.setCenterLongitude((int) (node.getLng() * 1000000)); } cmdData.getCircleAreas().add(ci); } } else if (tc.getCmdType() == JT808Constants.CMD_RECT_CONFIG) { JT_8602 cmdData = new JT_8602(); ts.setMessageContents(cmdData); cmdData.setAreasCount((byte) 1); byte settingType = Byte.parseByte(tc.getCmd()); cmdData.setSettingType(settingType); cmdData.setRectangleAreas(new java.util.ArrayList<RectangleAreaItem>()); for (Enclosure ec : enclosureList) { RectangleAreaItem ci = new RectangleAreaItem(); ci.setRectangleAreaId((int) ec.getEntityId()); ci.setRectangleAreaName(ec.getName()); ci.setRectangleAreaNameLength((byte) StringHelper .getByteLength(ec.getName())); // ???byte ci.setRectangleAreaProperty(ec.CreateAreaAttr()); ci.setStartTime(ec.getStartDate()); ci.setEndTime(ec.getEndDate()); ci.setMaxSpeed((short) ec.getMaxSpeed()); ci.setOverSpeedLastTime((byte) ec.getDelay()); java.util.ArrayList<EnclosureNode> nodes = ec.GetNodes(); if (nodes.size() > 0) { EnclosureNode node = nodes.get(0); ci.setLeftTopLatitude((int) (node.getLat() * 1000000)); ci.setLeftTopLongitude((int) (node.getLng() * 1000000)); node = nodes.get(2); ci.setRightBottomLatitude((int) (node.getLat() * 1000000)); ci.setRightBottomLongitude((int) (node.getLng() * 1000000)); } cmdData.getRectangleAreas().add(ci); } } else if (tc.getCmdType() == JT808Constants.CMD_POLYGON_CONFIG) { JT_8604 ci = new JT_8604(); ts.setMessageContents(ci); Enclosure ec = enclosureList.get(0); ci.setPolygonAreaId((int) ec.getEntityId()); ci.setPolygonAreaName(ec.getName()); ci.setPolygonAreaNameLength((byte) StringHelper.getByteLength(ec .getName())); // ???byte ci.setPolygonAreaProperty(ec.CreateAreaAttr()); ci.setStartTime(ec.getStartDate()); ci.setEndTime(ec.getEndDate()); ci.setMaxSpeed((short) ec.getMaxSpeed()); ci.setOverSpeedLastTime((byte) ec.getDelay()); java.util.ArrayList<EnclosureNode> nodes = ec.GetNodes(); ci.setAreaNodesCount((short) nodes.size()); ci.setNodes(new java.util.ArrayList<PolygonNodeItem>()); for (EnclosureNode node : nodes) { PolygonNodeItem item = new PolygonNodeItem(); item.setLatitude((int) (node.getLat() * 1000000)); item.setLongitude((int) (node.getLng() * 1000000)); ci.getNodes().add(item); } } else if (tc.getCmdType() == JT808Constants.CMD_ROUTE_CONFIG) { JT_8606 ci = new JT_8606(); ts.setMessageContents(ci); Enclosure ec = enclosureList.get(0); ci.setRouteId((int) ec.getEntityId()); ci.setRouteName(ec.getName()); ci.setRouteNameLength((byte) StringHelper.getByteLength(ec .getName())); // ???byte ci.setRouteProperty(ec.CreateAreaAttr()); ci.setStartTime(ec.getStartDate()); ci.setEndTime(ec.getEndDate()); String hsql = "from LineSegment where EnclosureId = ? order by PointId"; java.util.List nodes = (java.util.ArrayList) getBaseDao().query( hsql, new Object[] { ec.getEntityId() }); ci.setRoutePointsCount((short) nodes.size()); ci.setTurnPoints(new java.util.ArrayList<RouteTurnPointItem>()); for (Object obj : nodes) { LineSegment node = (LineSegment) obj; // ????????wgs84?? PointLatLng pt = MapFixService.gcjToWgs(node.getLatitude1(), node.getLongitude1()); // pl.setLat(pt.getLat()); // pl.setLng(pt.getLng()); RouteTurnPointItem item = new RouteTurnPointItem(); item.setRoutePointId((int) node.getEntityId()); item.setRouteSegmentId((int) ec.getEntityId()); item.setRouteSegmentProperty(node.CreateAreaAttr()); item.setTurnPointLatitude((int) (pt.getLat() * 1000000)); item.setTurnPointLongitude((int) (pt.getLng() * 1000000)); item.setRouteSegmentWidth((byte) node.getLineWidth()); item.setMaxDriveTimeLimited((byte) node.getMaxTimeLimit()); item.setMinDriveTimeLimited((byte) node.getMinTimeLimit()); item.setMaxSpeedLimited((byte) node.getMaxSpeed()); item.setOverMaxSpeedLastTime((byte) node.getOverSpeedTime()); ci.getTurnPoints().add(item); } } else if (tc.getCmdType() == JT808Constants.CMD_DELETE_ROUTE) { JT_8607 ci = new JT_8607(); ci.setRoutesCount((byte) enclosureIds.size()); ci.setRouteIDs(enclosureIds); ts.setMessageContents(ci); } else if (tc.getCmdType() == JT808Constants.CMD_DELETE_CIRCLE) { JT_8601 ci = new JT_8601(); ci.setCircleAreasCount((byte) enclosureIds.size()); ci.setCircleAreaIDs(enclosureIds); ts.setMessageContents(ci); } else if (tc.getCmdType() == JT808Constants.CMD_DELETE_RECT) { JT_8603 ci = new JT_8603(); ci.setCircleAreasCount((byte) enclosureIds.size()); ci.setCircleAreaIDs(enclosureIds); ts.setMessageContents(ci); } else if (tc.getCmdType() == JT808Constants.CMD_DELETE_POLYGON) { JT_8605 ci = new JT_8605(); ci.setPolygonAreasCount((byte) enclosureIds.size()); ci.setPolygonAreaIDs(enclosureIds); ts.setMessageContents(ci); } return ts; }
From source file:org.openlegacy.db.mvc.rest.DefaultDbRestController.java
private static Object toObject(Class<?> clazz, String value) { if (Boolean.class == clazz || Boolean.TYPE == clazz) { return Boolean.parseBoolean(value); }//from ww w .ja v a2 s . com if (Byte.class == clazz || Byte.TYPE == clazz) { return Byte.parseByte(value); } if (Short.class == clazz || Short.TYPE == clazz) { return Short.parseShort(value); } if (Integer.class == clazz || Integer.TYPE == clazz) { return Integer.parseInt(value); } if (Long.class == clazz || Long.TYPE == clazz) { return Long.parseLong(value); } if (Float.class == clazz || Float.TYPE == clazz) { return Float.parseFloat(value); } if (Double.class == clazz || Double.TYPE == clazz) { return Double.parseDouble(value); } return value; }
From source file:net.ymate.platform.commons.lang.BlurObject.java
public byte toByteValue() { if (attr == null) { return 0; }//from ww w. j a va 2 s . co m if (attr instanceof Byte) { return (Byte) attr; } if (attr instanceof BlurObject) { return ((BlurObject) this.attr).toByteValue(); } return Byte.parseByte(toStringValue()); }
From source file:de.micromata.genome.util.strings.converter.StandardStringConverter.java
/** * Parses the byte.//from ww w. ja v a2 s. com * * @param s the s * @return the byte */ protected Byte parseByte(String s) { if (StringUtils.isBlank(s) == true) { return null; } try { return Byte.parseByte(s); } catch (NumberFormatException ex) { throw new IllegalArgumentException("StringConverter; Unexpected value format for BYTE: " + s, ex); } }
From source file:se.crafted.chrisb.ecoCreature.drops.chances.ItemChance.java
protected static Byte parseData(String dropString) { String[] dropParts = dropString.split(":"); String[] itemParts = dropParts[0].split(","); String[] itemSubParts = itemParts[0].split("\\."); return itemSubParts.length > 1 && !itemSubParts[1].isEmpty() ? Byte.parseByte(itemSubParts[1]) : null; }
From source file:org.ncbo.stanford.util.helper.BeanHelper.java
/** * Takes an OntologyBean object and populates it from Request object. * /*from w w w. ja v a 2s. c o m*/ * <ontology Id>, <internal_version_number> - will be determined at ontology * creation time * * The following attributes are only for System or Admin. <statusId>, * <codingScheme> - updated by Scheduler <isReviewed> - updated by Admin * * source: request, destination: ontologyBean * * @param Request */ public static void populateOntologyBeanFromRequest(OntologyBean bean, Request request) { List<Integer> categoryIds = new ArrayList<Integer>(0); List<Integer> groupIds = new ArrayList<Integer>(0); List<Integer> hasViewIds = new ArrayList<Integer>(0); List<Integer> userIds = new ArrayList<Integer>(0); HttpServletRequest httpServletRequest = RequestUtils.getHttpServletRequest(request); // first decide if it is a view or not String isView = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isView")); // for new version for existing ontology String ontologyId = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.ontologyId")); String isManual = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isManual")); String versionNumber = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.versionNumber")); String versionStatus = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.versionStatus")); String isRemote = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isRemote")); // only accessible by Admin String isReviewed = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isReviewed")); String dateCreated = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.dateCreated")); String dateReleased = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.dateReleased")); // only accessible by Scheduler (system) String statusId = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.statusId")); String displayLabel = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.displayLabel")); String description = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.description")); String abbreviation = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.abbreviation")); String format = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.format")); String contactName = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.contactName")); String contactEmail = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.contactEmail")); String homepage = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.homepage")); String documentation = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.documentation")); String publication = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.publication")); String urn = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.urn")); String codingScheme = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.codingScheme")); String downloadLocation = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.downloadLocation")); String isFlat = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isFlat")); String isFoundry = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.isFoundry")); String isMetadataOnly = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.isMetadataOnly")); String targetTerminologies = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.targetTerminologies")); String synonymSlot = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.synonymSlot")); String preferredNameSlot = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.preferredNameSlot")); String documentationSlot = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.documentationSlot")); String authorSlot = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.authorSlot")); String slotWithUniqueValue = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.slotWithUniqueValue")); String preferredMaximumSubclassLimit = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.preferredMaximumSubclassLimit")); String userAcl = httpServletRequest.getParameter(MessageUtils.getMessage("form.ontology.useracl")); String viewingRestriction = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.viewingRestriction")); String licenseInformation = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.licenseInformation")); String obsoleteParent = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.obsoleteParent")); String obsoleteProperty = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.obsoleteProperty")); boolean isViewBool = RequestUtils.parseBooleanParam(isView); if (!StringHelper.isNullOrNullString(isView)) { bean.setView(isViewBool); } if (!StringHelper.isNullOrNullString(ontologyId)) { bean.setOntologyId(Integer.parseInt(ontologyId)); } // bean.setVirtualViewIds(...) // we do not set here the virtualViewIds of the ontology bean // from the request, because that is only a read-only field, // calculated from the metadata ontology on a read operation // get userId from request String[] userIdValues = httpServletRequest .getParameterValues(MessageUtils.getMessage("form.ontology.userId")); if (userIdValues != null) { userIds = RequestUtils.parseIntegerListParam(userIdValues); bean.setUserIds(userIds); } if (!StringHelper.isNullOrNullString(viewingRestriction) && !isViewBool) { if (viewingRestriction.equalsIgnoreCase(ViewingRestrictionEnum.VIEWING_RESTRICTION_PUBLIC.getLabel())) { bean.emptyUserAcl(); bean.setLicenseInformation(null); bean.setViewingRestriction(null); } else { if (!StringHelper.isNullOrNullString(licenseInformation)) { bean.setLicenseInformation(licenseInformation); } bean.setViewingRestriction(ViewingRestrictionEnum.getFromLabel(viewingRestriction)); // set user ACL if passed in if (!StringHelper.isNullOrNullString(userAcl)) { bean.emptyUserAcl(); List<Integer> userAclIds = RequestUtils.parseIntegerListParam(userAcl); for (Integer usrAclId : userAclIds) { if (!userIds.contains(usrAclId)) { bean.addUserToAcl(usrAclId, false); } } } for (Integer userId : userIds) { // add admins as the owner bean.addUserToAcl(userId, true); } } } if (!StringHelper.isNullOrNullString(isManual)) { bean.setIsManual(Byte.parseByte(isManual)); } if (!StringHelper.isNullOrNullString(isRemote)) { bean.setIsRemote(Byte.parseByte(isRemote)); } if (!StringHelper.isNullOrNullString(isReviewed)) { bean.setIsReviewed(Byte.parseByte(isReviewed)); } if (!StringHelper.isNullOrNullString(dateCreated)) { bean.setDateCreated(DateHelper.getDateFrom(dateCreated)); } if (!StringHelper.isNullOrNullString(statusId)) { bean.setStatusId(Integer.parseInt(statusId)); } if (displayLabel != null) { bean.setDisplayLabel(displayLabel); } if (description != null) { bean.setDescription(description); } if (abbreviation != null) { bean.setAbbreviation(abbreviation); } if (format != null) { bean.setFormat(format.toUpperCase()); } if (versionNumber != null) { bean.setVersionNumber(versionNumber); } if (versionStatus != null) { bean.setVersionStatus(versionStatus); } if (dateReleased != null) { bean.setDateReleased(DateHelper.getDateFrom(dateReleased)); } if (preferredNameSlot != null) { bean.setPreferredNameSlot(preferredNameSlot); } if (synonymSlot != null) { bean.setSynonymSlot(synonymSlot); } if (documentationSlot != null) { bean.setDocumentationSlot(documentationSlot); } if (authorSlot != null) { bean.setAuthorSlot(authorSlot); } if (slotWithUniqueValue != null) { bean.setSlotWithUniqueValue(slotWithUniqueValue); } if (!StringHelper.isNullOrNullString(preferredMaximumSubclassLimit)) { bean.setPreferredMaximumSubclassLimit(Integer.parseInt(preferredMaximumSubclassLimit)); } if (!StringHelper.isNullOrNullString(obsoleteParent)) { bean.setObsoleteParent(obsoleteParent); } if (!StringHelper.isNullOrNullString(obsoleteProperty)) { bean.setObsoleteProperty(obsoleteProperty); } if (contactName != null) { bean.setContactName(contactName); } if (contactEmail != null) { bean.setContactEmail(contactEmail); } if (homepage != null) { bean.setHomepage(homepage); } if (documentation != null) { bean.setDocumentation(documentation); } if (publication != null) { bean.setPublication(publication); } if (urn != null) { bean.setUrn(urn); } if (codingScheme != null) { bean.setCodingScheme(codingScheme); } if (downloadLocation != null) { bean.setDownloadLocation(downloadLocation); } if (!StringHelper.isNullOrNullString(isFlat)) { bean.setIsFlat(Byte.parseByte(isFlat)); } if (!StringHelper.isNullOrNullString(isFoundry)) { bean.setIsFoundry(Byte.parseByte(isFoundry)); } if (!StringHelper.isNullOrNullString(isMetadataOnly)) { bean.setIsMetadataOnly(Byte.parseByte(isMetadataOnly)); } if (targetTerminologies != null) { bean.setTargetTerminologies(targetTerminologies); } String[] categoryIdValues = httpServletRequest .getParameterValues(MessageUtils.getMessage("form.ontology.categoryId")); if (categoryIdValues != null) { categoryIds = RequestUtils.parseIntegerListParam(categoryIdValues); bean.setCategoryIds(categoryIds); } String[] groupIdValues = httpServletRequest .getParameterValues(MessageUtils.getMessage("form.ontology.groupId")); if (groupIdValues != null) { groupIds = RequestUtils.parseIntegerListParam(groupIdValues); bean.setGroupIds(groupIds); } // set file attribute in ontologyBean FileItem fileItem = (FileItem) httpServletRequest .getAttribute(MessageUtils.getMessage("form.ontology.filePath")); if (fileItem != null) { bean.setFileItem(fileItem); } // specifying this in the request is optional. Views should be added to // a // version by specifying value for the "viewOnOntologyVersionId" // parameter // on a create/update view request String[] hasViewIdValues = httpServletRequest .getParameterValues(MessageUtils.getMessage("form.ontology.hasView")); if (hasViewIdValues != null) { hasViewIds = RequestUtils.parseIntegerListParam(hasViewIdValues); bean.setHasViews(hasViewIds); } // populate view specific values if (bean.isView()) { // for new version for existing ontology view String viewDefinition = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.viewDefinition")); String viewDefinitionLanguage = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.viewDefinitionLanguage")); String viewGenerationEngine = httpServletRequest .getParameter(MessageUtils.getMessage("form.ontology.viewGenerationEngine")); List<Integer> ontVerIds = new ArrayList<Integer>(); String[] ontVerIdsStr = httpServletRequest .getParameterValues(MessageUtils.getMessage("form.ontology.viewOnOntologyVersionId")); if (ontVerIdsStr != null) { ontVerIds = RequestUtils.parseIntegerListParam(ontVerIdsStr); if (ontVerIds.size() > 0) { bean.setViewOnOntologyVersionId(ontVerIds); } } // now populate the OntologyViewBean if (!StringHelper.isNullOrNullString(viewDefinition)) { bean.setViewDefinition(viewDefinition); } if (!StringHelper.isNullOrNullString(viewDefinitionLanguage)) { bean.setViewDefinitionLanguage(viewDefinitionLanguage); } if (!StringHelper.isNullOrNullString(viewGenerationEngine)) { bean.setViewGenerationEngine(viewGenerationEngine); } } }
From source file:org.apache.synapse.mediators.db.AbstractDBMediator.java
/** * Return a Prepared statement for the given Statement object, which is ready to be executed * * @param stmnt SQL stataement to be executed * @param con The connection to be used * @param msgCtx Current message context * @return a PreparedStatement/*from w w w.j a v a2s. c o m*/ * @throws SQLException on error */ protected PreparedStatement getPreparedStatement(Statement stmnt, Connection con, MessageContext msgCtx) throws SQLException { SynapseLog synLog = getLog(msgCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Getting a connection from DataSource " + getDSName() + " and preparing statement : " + stmnt.getRawStatement()); } if (con == null) { String msg = "Connection from DataSource " + getDSName() + " is null."; log.error(msg); throw new SynapseException(msg); } if (dataSource instanceof BasicDataSource) { BasicDataSource basicDataSource = (BasicDataSource) dataSource; int numActive = basicDataSource.getNumActive(); int numIdle = basicDataSource.getNumIdle(); String connectionId = Integer.toHexString(con.hashCode()); DBPoolView dbPoolView = getDbPoolView(); if (dbPoolView != null) { dbPoolView.setNumActive(numActive); dbPoolView.setNumIdle(numIdle); dbPoolView.updateConnectionUsage(connectionId); } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("[ DB Connection : " + con + " ]"); synLog.traceOrDebug("[ DB Connection instance identifier : " + connectionId + " ]"); synLog.traceOrDebug("[ Number of Active Connection : " + numActive + " ]"); synLog.traceOrDebug("[ Number of Idle Connection : " + numIdle + " ]"); } } PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement()); // set parameters if any List<Statement.Parameter> params = stmnt.getParameters(); int column = 1; for (Statement.Parameter param : params) { if (param == null) { continue; } String value = (param.getPropertyName() != null ? param.getPropertyName() : param.getXpath().stringValueOf(msgCtx)); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting as parameter : " + column + " value : " + value + " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid " + "types)"); } switch (param.getType()) { // according to J2SE 1.5 /docs/guide/jdbc/getstart/mapping.html case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { if (value != null && value.length() != 0) { ps.setString(column++, value); } else { ps.setString(column++, null); } break; } case Types.NUMERIC: case Types.DECIMAL: { if (value != null && value.length() != 0) { ps.setBigDecimal(column++, new BigDecimal(value)); } else { ps.setBigDecimal(column++, null); } break; } case Types.BIT: { if (value != null && value.length() != 0) { ps.setBoolean(column++, Boolean.parseBoolean(value)); } else { ps.setNull(column++, Types.BIT); } break; } case Types.TINYINT: { if (value != null && value.length() != 0) { ps.setByte(column++, Byte.parseByte(value)); } else { ps.setNull(column++, Types.TINYINT); } break; } case Types.SMALLINT: { if (value != null && value.length() != 0) { ps.setShort(column++, Short.parseShort(value)); } else { ps.setNull(column++, Types.SMALLINT); } break; } case Types.INTEGER: { if (value != null && value.length() != 0) { ps.setInt(column++, Integer.parseInt(value)); } else { ps.setNull(column++, Types.INTEGER); } break; } case Types.BIGINT: { if (value != null && value.length() != 0) { ps.setLong(column++, Long.parseLong(value)); } else { ps.setNull(column++, Types.BIGINT); } break; } case Types.REAL: { if (value != null && value.length() != 0) { ps.setFloat(column++, Float.parseFloat(value)); } else { ps.setNull(column++, Types.REAL); } break; } case Types.FLOAT: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.FLOAT); } break; } case Types.DOUBLE: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.DOUBLE); } break; } // skip BINARY, VARBINARY and LONGVARBINARY case Types.DATE: { if (value != null && value.length() != 0) { ps.setDate(column++, Date.valueOf(value)); } else { ps.setNull(column++, Types.DATE); } break; } case Types.TIME: { if (value != null && value.length() != 0) { ps.setTime(column++, Time.valueOf(value)); } else { ps.setNull(column++, Types.TIME); } break; } case Types.TIMESTAMP: { if (value != null && value.length() != 0) { ps.setTimestamp(column++, Timestamp.valueOf(value)); } else { ps.setNull(column++, Types.TIMESTAMP); } break; } // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT default: { String msg = "Trying to set an un-supported JDBC Type : " + param.getType() + " against column : " + column + " and statement : " + stmnt.getRawStatement() + " used by a DB mediator against DataSource : " + getDSName() + " (see java.sql.Types for valid type values)"; handleException(msg, msgCtx); } } } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Successfully prepared statement : " + stmnt.getRawStatement() + " against DataSource : " + getDSName()); } return ps; }