List of usage examples for java.io Serializable toString
public String toString()
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoDwsServiceHandler.java
/** * @see org.alfresco.module.vti.handler.DwsServiceHandler#getDwsData(java.lang.String, java.lang.String) *//*w w w .j a v a 2s . c o m*/ public DwsData getDwsData(String document, String lastUpdate) throws SiteDoesNotExistException { DwsData dwsData = new DwsData(); String dws = pathHelper.getDwsFromDocumentName(document, doGetModelType()); String host = pathHelper.getHostFromDocumentName(document); String context = pathHelper.getContextFromDocumentName(document); FileInfo dwsInfo = pathHelper.resolvePathFileInfo(dws); if (dwsInfo == null) { throw new SiteDoesNotExistException(dws); } // set the title of the currently opened document workspace site Serializable title = nodeService.getProperty(dwsInfo.getNodeRef(), ContentModel.PROP_TITLE); if (title == null) { dwsData.setTitle(nodeService.getProperty(dwsInfo.getNodeRef(), ContentModel.PROP_NAME).toString()); } else { dwsData.setTitle(title.toString()); } // set the description of the currently opened document workspace site dwsData.setDescription( nodeService.getProperty(dwsInfo.getNodeRef(), ContentModel.PROP_DESCRIPTION).toString()); // ALF-12784 fix, don't return list of documents if last update was not changed String currentLastUpdate = doGetLastUpdate(dwsInfo); if (!currentLastUpdate.equals(lastUpdate)) { // setting the Documents list for current document workspace site List<DocumentBean> dwsContent = doGetDwsDocuments(dwsInfo); dwsData.setDocumentsList(dwsContent); } // setting the Links list for current document workspace site List<LinkBean> linksList = doGetDwsLinks(dwsInfo); dwsData.setLinksList(linksList); dwsData.setDocLibUrl(host + context + dws + "/documentLibrary.vti"); dwsData.setLastUpdate(currentLastUpdate); // setting currently authenticated user UserBean user = getCurrentUser(); dwsData.setUser(user); // if current user has permission to view dws users then collect information about dws users if (permissionService.hasPermission(dwsInfo.getNodeRef(), PermissionService.READ_PERMISSIONS) == AccessStatus.ALLOWED) { List<MemberBean> members = doListDwsMembers(dwsInfo); dwsData.setMembers(members); List<AssigneeBean> assignees = new ArrayList<AssigneeBean>(); for (MemberBean member : members) { assignees.add(new AssigneeBean(member.getId(), member.getName(), member.getLoginName())); } dwsData.setAssignees(assignees); } if (logger.isDebugEnabled()) { logger.debug("Document workspace data was retrieved for '" + dwsInfo.getName() + "' site."); } return dwsData; }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCLogger.java
/** * Returns a loggable value using pseudo-SQL syntax. *//*from w w w.java2 s. c o m*/ @SuppressWarnings("boxing") public static String loggedValue(Serializable value) { if (value == null) { return "NULL"; } if (value instanceof String) { String v = (String) value; if (v.length() > DEBUG_MAX_STRING) { v = v.substring(0, DEBUG_MAX_STRING) + "...(" + v.length() + " chars)..."; } return "'" + v.replace("'", "''") + "'"; } if (value instanceof Calendar) { Calendar cal = (Calendar) value; char sign; int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()) / 60000; if (offset < 0) { offset = -offset; sign = '-'; } else { sign = '+'; } return String.format("TIMESTAMP '%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d'", cal.get(Calendar.YEAR), // cal.get(Calendar.MONTH) + 1, // cal.get(Calendar.DAY_OF_MONTH), // cal.get(Calendar.HOUR_OF_DAY), // cal.get(Calendar.MINUTE), // cal.get(Calendar.SECOND), // cal.get(Calendar.MILLISECOND), // sign, offset / 60, offset % 60); } if (value instanceof Binary) { return "'" + ((Binary) value).getDigest() + "'"; } if (value.getClass().isArray()) { Serializable[] v = (Serializable[]) value; StringBuilder b = new StringBuilder(); b.append('['); for (int i = 0; i < v.length; i++) { if (i > 0) { b.append(','); if (i > DEBUG_MAX_ARRAY) { b.append("...(" + v.length + " items)..."); break; } } b.append(loggedValue(v[i])); } b.append(']'); return b.toString(); } return value.toString(); }
From source file:org.rhq.plugins.mobicents.servlet.sip.jboss5.ApplicationServerComponent.java
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) { for (MeasurementScheduleRequest request : requests) { String metricName = request.getName(); try {//from w w w. j a va 2 s.c om // Metric names are expected to have the following syntax: // "<componentType>|<componentSubType>|<componentName>|<propertyName>" Matcher matcher = METRIC_NAME_PATTERN.matcher(metricName); if (!matcher.matches()) { log.error("Metric name '" + metricName + "' does not match pattern '" + METRIC_NAME_PATTERN + "'."); continue; } String componentCategory = matcher.group(1); String componentSubType = matcher.group(2); String componentName = matcher.group(3); String propertyName = matcher.group(4); ComponentType componentType = new ComponentType(componentCategory, componentSubType); ManagedComponent component; if (componentName.equals("*")) { component = ManagedComponentUtils.getSingletonManagedComponent(componentType); } else { component = ManagedComponentUtils.getManagedComponent(componentType, componentName); } Serializable value = ManagedComponentUtils.getSimplePropertyValue(component, propertyName); if (value == null) { log.debug("Null value returned for metric '" + metricName + "'."); continue; } if (request.getDataType() == DataType.MEASUREMENT) { Number number = (Number) value; report.addData(new MeasurementDataNumeric(request, number.doubleValue())); } else if (request.getDataType() == DataType.TRAIT) { report.addData(new MeasurementDataTrait(request, value.toString())); } } catch (RuntimeException e) { log.error("Failed to obtain metric '" + metricName + "'.", e); } } }
From source file:org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper.java
/** * @since 5.5, signature changed on 5.6 to include parameters widgetType and widgetMode. *//*from w w w . ja va 2 s .co m*/ public List<TagAttribute> getTagAttributes(Map<String, Serializable> properties, List<String> excludedProperties, boolean useReferenceProperties, String widgetType, String widgetTypeCategory, String widgetMode) { WebLayoutManager service = Framework.getService(WebLayoutManager.class); List<TagAttribute> attrs = new ArrayList<TagAttribute>(); if (properties != null) { for (Map.Entry<String, Serializable> prop : properties.entrySet()) { TagAttribute attr; String key = prop.getKey(); if (excludedProperties != null && excludedProperties.contains(key)) { continue; } Serializable valueInstance = prop.getValue(); if (!useReferenceProperties || !service.referencePropertyAsExpression(key, valueInstance, widgetType, widgetTypeCategory, widgetMode, null)) { if (valueInstance == null || valueInstance instanceof String) { // FIXME: this will not be updated correctly using ajax attr = createAttribute(key, (String) valueInstance); } else { attr = createAttribute(key, valueInstance.toString()); } } else { // create a reference so that it's a real expression // and it's not kept (cached) in a component value on // ajax refresh attr = createAttribute(key, "#{" + RenderVariables.widgetVariables.widget.name() + ".properties." + key + "}"); } attrs.add(attr); } } return attrs; }
From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtil.java
/** * Add a single property to a property map * /* w w w. ja v a 2s . com*/ * @param properties * @param key * @param value */ private void addProperty(final Map<QName, Serializable> properties, final QName key, Serializable value) { // if no text, just exit if (value == null) { return; } // if no text, just exit if (!StringUtils.hasText(value.toString())) { return; } // trim all trailing spaces for strings if (value instanceof String) { value = StringUtils.trimTrailingWhitespace(value.toString()); } properties.put(key, value); }
From source file:gov.pnnl.goss.gridappsd.testmanager.TestManagerImpl.java
private void requestSimOld(Client client, Serializable message, DataResponse event) { statusReporter.reportStatus(String.format("Got new message in %s", getClass().getName())); //TODO: create registry mapping between request topics and request handlers. switch (event.getDestination().replace("/queue/", "")) { case topic_requestTest: { log.debug("Received test request: " + event.getData()); //generate simulation id and reply to event's reply destination. // int simulationId = generateSimulationId(); int testId = 1234; client.publish(event.getReplyDestination(), testId); try {//from w ww . j a va 2 s. co m // TODO: validate simulation request json and create PowerSystemConfig and SimulationConfig dto objects to work with internally. Gson gson = new Gson(); RequestSimulation config = gson.fromJson(message.toString(), RequestSimulation.class); log.info("Parsed config " + config); if (config == null || config.getPower_system_config() == null || config.getSimulation_config() == null) { throw new RuntimeException("Invalid configuration received"); } //make request to configuration Manager to get power grid model file locations and names log.debug("Creating simulation and power grid model files for simulation Id " + testId); File simulationFile = configurationManager.getSimulationFile(testId, config); if (simulationFile == null) { throw new Exception("No simulation file returned for request " + config); } log.debug("Simulation and power grid model files generated for simulation Id " + testId); //start simulation log.debug("Starting simulation for id " + testId); simulationManager.startSimulation(testId, simulationFile, config.getSimulation_config()); log.debug("Starting simulation for id " + testId); // new ProcessSimulationRequest().process(event, client, configurationManager, simulationManager); break; } catch (Exception e) { e.printStackTrace(); try { statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog + testId, "Test Initialization error: " + e.getMessage()); log.error("Test Initialization error", e); } catch (Exception e1) { e1.printStackTrace(); } } } //case GridAppsDConstants.topic_requestData : processDataRequest(); break; //case GridAppsDConstants.topic_requestSimulationStatus : processSimulationStatusRequest(); break; } }
From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java
@Override public ResourceResponse retrieveResource(URI uri, Map<String, Serializable> requestProperties) throws ResourceNotFoundException, ResourceNotSupportedException, IOException { final String methodName = "retrieveResource"; LOGGER.trace("ENTRY: {}", methodName); if (requestProperties == null) { throw new ResourceNotFoundException("Could not retrieve resource with null properties."); }/*from w ww. j a v a 2 s .c o m*/ Serializable serializableId = requestProperties.get(Metacard.ID); if (serializableId != null) { String metacardId = serializableId.toString(); WebClient restClient = newRestClient(null, metacardId, true, null); if (StringUtils.isNotBlank(username)) { requestProperties.put(USERNAME_PROPERTY, username); requestProperties.put(PASSWORD_PROPERTY, password); } return resourceReader.retrieveResource(restClient.getCurrentURI(), requestProperties); } LOGGER.trace("EXIT: {}", methodName); throw new ResourceNotFoundException(COULD_NOT_RETRIEVE_RESOURCE_MESSAGE); }
From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.nodeService.NodeServiceImpl.java
private String getSQLFormatFromSerializable(Serializable property, PropertyDefinition propertyDefinition) { String value = null;/*from w ww .j av a2 s. c om*/ QName dataTypeName = propertyDefinition.getDataType().getName(); if (property == null) { value = "NULL"; } else if (dataTypeName.equals(DataTypeDefinition.DATE)) { DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); value = String.format("{d '%1$s'}", dateformat.format((Date) property)); } else if (dataTypeName.equals(DataTypeDefinition.DATETIME)) { DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); value = String.format("{ts '%1$s'}", dateformat.format((Date) property)); } else { value = property.toString(); /* escape string values */ if (dataTypeName.equals(DataTypeDefinition.TEXT) || dataTypeName.equals(DataTypeDefinition.PATH) || dataTypeName.equals(DataTypeDefinition.NODE_REF)) { value = synchronizationDialect.quoteString(synchronizationDialect.escape(value)); } else if ("".equals(value)) { /* * not a string quoted value and does not have a value implies a NULL value */ value = "NULL"; } } return value; }
From source file:org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer.java
/** * Corresponds to <element name="javaExecutable"> * *//*from w ww .ja va 2 s .c om*/ private Element createJavaExecutableElement(Document doc, JavaTask t) { Element executableE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.JAVA_EXECUTABLE.getXMLName()); setAttribute(executableE, XMLAttributes.TASK_CLASS_NAME, t.getExecutableClassName(), true); // <ref name="javaParameters"/> try { Map<String, Serializable> args = t.getArguments(); if ((args != null) && (args.size() > 0)) { // <element name="parameter"> Element paramsE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_PARAMETERS.getXMLName()); for (String name : args.keySet()) { Serializable val = args.get(name); Element paramE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_PARAMETER.getXMLName()); setAttribute(paramE, XMLAttributes.COMMON_NAME, name, true); setAttribute(paramE, XMLAttributes.COMMON_VALUE, val.toString(), true); paramsE.appendChild(paramE); } executableE.appendChild(paramsE); } } catch (Exception e) { logger.error("Could not add arguments for Java Executable element of task " + t.getName(), e); } return executableE; }
From source file:org.openiot.gsn.storage.StorageManager.java
public void executeInsert(CharSequence tableName, DataField[] fields, StreamElement streamElement, Connection connection) throws SQLException { PreparedStatement ps = null;//from w w w .ja v a 2s .co m String query = getStatementInsert(tableName, fields).toString(); try { ps = connection.prepareStatement(query); int counter = 1; for (DataField dataField : fields) { if (dataField.getName().equalsIgnoreCase("timed")) continue; Serializable value = streamElement.getData(dataField.getName()); switch (dataField.getDataTypeID()) { case DataTypes.VARCHAR: if (value == null) ps.setNull(counter, Types.VARCHAR); else ps.setString(counter, value.toString()); break; case DataTypes.CHAR: if (value == null) ps.setNull(counter, Types.CHAR); else ps.setString(counter, value.toString()); break; case DataTypes.INTEGER: if (value == null) ps.setNull(counter, Types.INTEGER); else ps.setInt(counter, ((Number) value).intValue()); break; case DataTypes.SMALLINT: if (value == null) ps.setNull(counter, Types.SMALLINT); else ps.setShort(counter, ((Number) value).shortValue()); break; case DataTypes.TINYINT: if (value == null) ps.setNull(counter, Types.TINYINT); else ps.setByte(counter, ((Number) value).byteValue()); break; case DataTypes.DOUBLE: if (value == null) ps.setNull(counter, Types.DOUBLE); else ps.setDouble(counter, ((Number) value).doubleValue()); break; case DataTypes.BIGINT: if (value == null) ps.setNull(counter, Types.BIGINT); else ps.setLong(counter, ((Number) value).longValue()); break; case DataTypes.BINARY: if (value == null) ps.setNull(counter, Types.BINARY); else ps.setBytes(counter, (byte[]) value); break; default: logger.error("The type conversion is not supported for : " + dataField.getName() + "(" + dataField.getDataTypeID() + ") : "); } counter++; } ps.setLong(counter, streamElement.getTimeStamp()); ps.execute(); } catch (GSNRuntimeException e) { //if (e.getType() == GSNRuntimeException.UNEXPECTED_VIRTUAL_SENSOR_REMOVAL) { // if (logger.isDebugEnabled()) // logger.debug("An stream element dropped due to unexpected virtual sensor removal. (Stream element: " + streamElement.toString() + ")+ Query: " + query, e); //} else logger.warn("Inserting a stream element failed : " + streamElement.toString(), e); } catch (SQLException e) { if (e.getMessage().toLowerCase().contains("duplicate entry")) logger.info("Error occurred on inserting data to the database, an stream element dropped due to: " + e.getMessage() + ". (Stream element: " + streamElement.toString() + ")+ Query: " + query); else logger.warn("Error occurred on inserting data to the database, an stream element dropped due to: " + e.getMessage() + ". (Stream element: " + streamElement.toString() + ")+ Query: " + query); throw e; } finally { close(ps); } }