List of usage examples for java.io Serializable toString
public String toString()
From source file:com.reactivetechnologies.platform.datagrid.HazelcastKeyValueAdapterBean.java
@Override public Object delete(Serializable id, Serializable keyspace) { if (!hz.isStarted()) throw new IllegalStateException("Hazelcast service not started!"); Assert.notNull(id, "Cannot delete item with null id."); Assert.notNull(keyspace, "Cannot delete item for null collection."); return hz.removeNow(id, keyspace.toString()); }
From source file:com.clarionmedia.infinitum.orm.rest.impl.RestfulSession.java
@Override public boolean delete(Object model) { OrmPreconditions.checkForOpenSession(mIsOpen); OrmPreconditions.checkPersistenceForModify(model, mPersistencePolicy); mLogger.debug("Sending DELETE request to delete entity"); Serializable pk = mPersistencePolicy.getPrimaryKey(model); String uri = mHost + mPersistencePolicy.getRestEndpoint(model.getClass()) + "/" + pk.toString(); Map<String, String> headers = new HashMap<String, String>(); RestResponse response = mRestClient.executeDelete(uri, headers); if (response == null) return false; switch (response.getStatusCode()) { case HttpStatus.SC_OK: case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_NO_CONTENT: return true; default:/* ww w. j a v a 2 s . c om*/ return false; } }
From source file:ddf.catalog.transformer.xml.MetacardMarshallerImpl.java
private String getStringValue(XmlPullParser parser, Attribute attribute, AttributeType.AttributeFormat format, Serializable value) throws IOException, CatalogTransformerException { switch (format) { case STRING:// w w w . ja v a2 s. c o m case BOOLEAN: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return value.toString(); case DATE: Date date = (Date) value; return DateFormatUtils.formatUTC(date, DF_PATTERN); case GEOMETRY: return geoToXml(geometryTransformer.transform(attribute), parser); case OBJECT: ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutput output = new ObjectOutputStream(bos)) { output.writeObject(attribute.getValue()); return Base64.getEncoder().encodeToString(bos.toByteArray()); } case BINARY: return Base64.getEncoder().encodeToString((byte[]) value); case XML: return value.toString().replaceAll("[<][?]xml.*[?][>]", ""); default: LOGGER.warn("Unsupported attribute: {}", format); return value.toString(); } }
From source file:com.clarionmedia.infinitum.http.rest.impl.RestfulSession.java
@Override public boolean delete(Object model) { Preconditions.checkPersistenceForModify(model, mPersistencePolicy); mLogger.debug("Sending DELETE request to delete entity"); Serializable pk = mPersistencePolicy.getPrimaryKey(model); String uri = mHost + mPersistencePolicy.getRestEndpoint(model.getClass()) + "/" + pk.toString(); Map<String, String> headers = new HashMap<String, String>(); RestResponse response = mRestClient.executeDelete(uri, headers); if (response == null) return false; switch (response.getStatusCode()) { case HttpStatus.SC_OK: case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_NO_CONTENT: return true; default:// w w w .j a va2s . com return false; } }
From source file:com.codecrate.shard.search.ObjectIndexer.java
public void save(Serializable id, Object entity) { removeDocuments(id);//w w w .j av a2 s . c o m IndexWriter writer = null; try { writer = new IndexWriter(directory, analyzer, DO_NOT_CREATE_INDEX); Document document = new Document(); document.add(Field.Keyword(HibernateObjectSearcher.FIELD_CLASS, entity.getClass().getName())); document.add(Field.Keyword(HibernateObjectSearcher.FIELD_ID, id.toString())); document.add(Field.Text(HibernateObjectSearcher.FIELD_TEXT, entity.toString())); LOG.debug("saving " + document); writer.addDocument(document); } catch (IOException e) { LOG.error("Error updating index for object " + entity, e); } finally { closeWriter(writer); } }
From source file:com.splunk.logging.HttpEventCollectorSender.java
@SuppressWarnings("unchecked") private String serializeEventInfo(HttpEventCollectorEventInfo eventInfo) { // create event json content ////from w ww . j a v a 2 s . c o m // cf: http://dev.splunk.com/view/event-collector/SP-CAAAE6P // JSONObject event = new JSONObject(); // event timestamp and metadata putIfPresent(event, MetadataTimeTag, String.format(Locale.US, "%.3f", eventInfo.getTime())); putIfPresent(event, MetadataHostTag, metadata.get(MetadataHostTag)); putIfPresent(event, MetadataIndexTag, metadata.get(MetadataIndexTag)); putIfPresent(event, MetadataSourceTag, metadata.get(MetadataSourceTag)); putIfPresent(event, MetadataSourceTypeTag, metadata.get(MetadataSourceTypeTag)); // event body JSONObject body = new JSONObject(); putIfPresent(body, "severity", eventInfo.getSeverity()); putIfPresent(body, "message", eventInfo.getMessage()); putIfPresent(body, "logger", eventInfo.getLoggerName()); putIfPresent(body, "thread", eventInfo.getThreadName()); // add an exception record if and only if there is one // in practice, the message also has the exception information attached if (eventInfo.getExceptionMessage() != null) { putIfPresent(body, "exception", eventInfo.getExceptionMessage()); } final JSONObject throwableJson = writeThrowableInfoToJson(eventInfo.getThrowableInfo()); if (throwableJson != null) { body.put("throwable", throwableJson); } // add properties if and only if there are any final Map<String, String> props = eventInfo.getProperties(); if (props != null && !props.isEmpty()) { body.put("properties", props); } // add marker if and only if there is one final Serializable marker = eventInfo.getMarker(); if (marker != null) { putIfPresent(body, "marker", marker.toString()); } // join event and body event.put("event", body); return event.toString(); }
From source file:org.alfresco.repo.action.executer.ContentMetadataExtracter.java
/** * Iterates the values of the taggable property which the metadata * extractor should have already attempted to convert values to {@link NodeRef}s. * <p>//from ww w . j av a 2s.c o m * If conversion by the metadata extracter failed due to a MalformedNodeRefException * the taggable property should still contain raw string values. * <p> * Mixing of NodeRefs and string values is permitted so each raw value is * checked for a valid NodeRef representation and if so, converts to a NodeRef, * if not, adds as a tag via the {@link TaggingService}. * * @param actionedUponNodeRef The NodeRef being actioned upon * @param propertyDef the PropertyDefinition of the taggable property * @param rawValue the raw value from the metadata extracter */ @SuppressWarnings("unchecked") protected void addTags(NodeRef actionedUponNodeRef, PropertyDefinition propertyDef, Serializable rawValue) { List<String> tags = new ArrayList<String>(); if (logger.isDebugEnabled()) { logger.debug("converting " + rawValue.toString() + " of type " + rawValue.getClass().getCanonicalName() + " to tags"); } if (rawValue instanceof Collection<?>) { for (Object singleValue : (Collection<?>) rawValue) { if (singleValue instanceof String) { if (NodeRef.isNodeRef((String) singleValue)) { // Convert to a NodeRef Serializable convertedPropertyValue = (Serializable) DefaultTypeConverter.INSTANCE .convert(propertyDef.getDataType(), (String) singleValue); try { String tagName = (String) nodeService.getProperty((NodeRef) convertedPropertyValue, ContentModel.PROP_NAME); if (logger.isTraceEnabled()) { logger.trace("found tag '" + tagName + "' from tag nodeRef '" + (String) singleValue + "', " + "adding to " + actionedUponNodeRef.toString()); } if (tagName != null && !tagName.equals("")) { tags.add(tagName); } } catch (InvalidNodeRefException e) { if (logger.isWarnEnabled()) { logger.warn("tag nodeRef Invalid: " + e.getMessage()); } } } else { // Must be a simple string if (logger.isTraceEnabled()) { logger.trace("adding string tag '" + (String) singleValue + "' to " + actionedUponNodeRef.toString()); } tags.add((String) singleValue); } } else if (singleValue instanceof NodeRef) { String tagName = (String) nodeService.getProperty((NodeRef) singleValue, ContentModel.PROP_NAME); tags.add(tagName); } } } else if (rawValue instanceof String) { if (logger.isTraceEnabled()) { logger.trace("adding tag '" + (String) rawValue + "' to " + actionedUponNodeRef.toString()); } tags.add((String) rawValue); } taggingService.addTags(actionedUponNodeRef, tags); }
From source file:org.projectforge.framework.persistence.utils.ReflectionToString.java
private String myToString(final Object obj) { if (obj == null) { return "<null>"; } else if (ShortDisplayNameCapable.class.isAssignableFrom(obj.getClass()) == true) { if (BaseDO.class.isAssignableFrom(obj.getClass()) == true) { final Serializable id = HibernateUtils.getIdentifier((BaseDO<?>) obj); return id + ":" + ((ShortDisplayNameCapable) obj).getShortDisplayName(); }/*from ww w .j av a 2 s . c o m*/ return ((ShortDisplayNameCapable) obj).getShortDisplayName(); } else if (BaseDO.class.isAssignableFrom(obj.getClass()) == true) { final Serializable id = HibernateUtils.getIdentifier((BaseDO<?>) obj); return id != null ? id.toString() : "<id>"; } return obj.toString(); }
From source file:ddf.catalog.transformer.metacard.propertyjson.PropertyJsonMetacardTransformer.java
@Nullable private static Object convertValue(String name, Serializable value, AttributeType.AttributeFormat format) throws CatalogTransformerException { if (value == null) { return null; }//ww w . j ava 2s. c om switch (format) { case DATE: if (!(value instanceof Date)) { LOGGER.debug("Dropping attribute date value {} for {} because it isn't a Date object.", value, name); return null; } // Creating date format instance each time is inefficient, however // it is not a threadsafe class so we are not able to put it in a static // class variable. If this proves to be a slowdown this class should be refactored // such that we don't need this method to be static. SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_8601_DATE_FORMAT); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format((Date) value); case BINARY: byte[] bytes = (byte[]) value; return DatatypeConverter.printBase64Binary(bytes); case BOOLEAN: case DOUBLE: case LONG: case INTEGER: case SHORT: return value; case STRING: case XML: case FLOAT: case GEOMETRY: return value.toString(); case OBJECT: default: return null; } }
From source file:net.refractions.udig.catalog.IService.java
/** * Retrieves the title from the IService cache, or from the ServiceInfo * object iff it is present. Returns null if either of these are not * available. If the title is fetched from ServiceInfo, it is added to the * cache before returning.// www .j a va 2s.c o m * * @returns the service title or null if non is readily available */ public String getTitle() { String title = null; if (info != null) { // we are connected and can use the real title title = info.getTitle(); // cache title for when we are next offline getPersistentProperties().put("title", title); //$NON-NLS-1$ } if (title == null) { Serializable s = properties.get("title"); //$NON-NLS-1$ title = (s != null ? s.toString() : null); } return title; }