List of usage examples for java.io Serializable toString
public String toString()
From source file:org.hippoecm.frontend.model.properties.JcrPropertyValueModel.java
public void setObject(final Serializable object) { load();//from ww w .j a v a2 s. c om if (object == null) { if (value != null) { setValue(null); } return; } Value value; try { ValueFactory factory = UserSession.get().getJcrSession().getValueFactory(); int type = getType(); switch (type) { case PropertyType.BOOLEAN: value = factory.createValue((Boolean) object); break; case PropertyType.DATE: Calendar calendar = Calendar.getInstance(); calendar.setTime((Date) object); value = factory.createValue(calendar); break; case PropertyType.DOUBLE: value = factory.createValue((Double) object); break; case PropertyType.LONG: value = factory.createValue((Long) object); break; default: String string = object.toString(); value = factory.createValue(string, (type == PropertyType.UNDEFINED ? PropertyType.STRING : type)); } } catch (ValueFormatException ex) { log.info("invalid value " + object + ": " + ex.getMessage()); return; } catch (UnsupportedRepositoryOperationException e) { log.error("repository is read-only", e); return; } catch (RepositoryException e) { log.error("repository error when setting value", e); return; } setValue(value); }
From source file:org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter.java
private void writeAttributeToXml(Attribute attribute, QName qname, AttributeFormat format, MarshallingContext context, HierarchicalStreamWriter writer) { // Loop to handle multi-valued attributes String name = qname.getPrefix() + ":" + attribute.getName(); for (Serializable value : attribute.getValues()) { String xmlValue = null;/*from w w w . j a v a 2s.c om*/ switch (format) { case XML: String cdata = (String) value; if (cdata != null && (writer.underlyingWriter() instanceof EnhancedStaxWriter)) { writer.startNode(name); EnhancedStaxWriter eWriter = (EnhancedStaxWriter) writer.underlyingWriter(); eWriter.writeCdata(cdata); writer.endNode(); } break; case GEOMETRY: XmlNode.writeGeometry(name, context, writer, XmlNode.readGeometry((String) value)); break; case BINARY: xmlValue = Base64.getEncoder().encodeToString((byte[]) value); break; case DATE: Date date = (Date) value; xmlValue = DateFormatUtils.formatUTC(date, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); break; case OBJECT: // Probably won't translate at all. break; default: xmlValue = value.toString(); break; } // Write the node if we were able to convert it. if (xmlValue != null) { writer.startNode(name); writer.setValue(xmlValue); writer.endNode(); } } }
From source file:org.craftercms.cstudio.alfresco.dm.script.DmWorkflowServiceScript.java
/** * get a submitted item from a JSON item * * @param site/*from www . java2 s. c om*/ * @param item * @param format * @return * @throws net.sf.json.JSONException */ protected DmDependencyTO getSubmittedItem(String site, JSONObject item, SimpleDateFormat format, String globalSchDate) throws JSONException { PersistenceManagerService persistenceManagerService = getServicesManager() .getService(PersistenceManagerService.class); DmDependencyTO submittedItem = new DmDependencyTO(); String uri = item.getString(JSON_KEY_URI); submittedItem.setUri(uri); boolean deleted = (item.containsKey(JSON_KEY_DELETED)) ? item.getBoolean(JSON_KEY_DELETED) : false; submittedItem.setDeleted(deleted); boolean isNow = (item.containsKey(JSON_KEY_IS_NOW)) ? item.getBoolean(JSON_KEY_IS_NOW) : false; submittedItem.setNow(isNow); boolean submittedForDeletion = (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ? item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false; boolean submitted = (item.containsKey(JSON_KEY_SUBMITTED)) ? item.getBoolean(JSON_KEY_SUBMITTED) : false; boolean inProgress = (item.containsKey(JSON_KEY_IN_PROGRESS)) ? item.getBoolean(JSON_KEY_IN_PROGRESS) : false; boolean isReference = (item.containsKey(JSON_KEY_IN_REFERENCE)) ? item.getBoolean(JSON_KEY_IN_REFERENCE) : false; submittedItem.setReference(isReference); // boolean submittedForDeletion = // (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ? // item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false; submittedItem.setSubmittedForDeletion(submittedForDeletion); submittedItem.setSubmitted(submitted); submittedItem.setInProgress(inProgress); // TODO: check scheduled date to make sure it is not null when isNow = // true and also it is not past Date scheduledDate = null; if (globalSchDate != null && !StringUtils.isEmpty(globalSchDate)) { scheduledDate = getScheduledDate(site, format, globalSchDate); } else { if (item.containsKey(JSON_KEY_SCHEDULED_DATE)) { String dateStr = item.getString(JSON_KEY_SCHEDULED_DATE); if (!StringUtils.isEmpty(dateStr)) { scheduledDate = getScheduledDate(site, format, dateStr); } } } if (scheduledDate == null && isNow == false) { submittedItem.setNow(true); } submittedItem.setScheduledDate(scheduledDate); JSONArray components = (item.containsKey(JSON_KEY_COMPONENTS)) ? item.getJSONArray(JSON_KEY_COMPONENTS) : null; List<DmDependencyTO> submittedComponents = getSubmittedItems(site, components, format, globalSchDate); submittedItem.setComponents(submittedComponents); JSONArray documents = (item.containsKey(JSON_KEY_DOCUMENTS)) ? item.getJSONArray(JSON_KEY_DOCUMENTS) : null; List<DmDependencyTO> submittedDocuments = getSubmittedItems(site, documents, format, globalSchDate); submittedItem.setDocuments(submittedDocuments); JSONArray assets = (item.containsKey(JSON_KEY_ASSETS)) ? item.getJSONArray(JSON_KEY_ASSETS) : null; List<DmDependencyTO> submittedAssets = getSubmittedItems(site, assets, format, globalSchDate); submittedItem.setAssets(submittedAssets); JSONArray templates = (item.containsKey(JSON_KEY_RENDERING_TEMPLATES)) ? item.getJSONArray(JSON_KEY_RENDERING_TEMPLATES) : null; List<DmDependencyTO> submittedTemplates = getSubmittedItems(site, templates, format, globalSchDate); submittedItem.setRenderingTemplates(submittedTemplates); JSONArray deletedItems = (item.containsKey(JSON_KEY_DELETED_ITEMS)) ? item.getJSONArray(JSON_KEY_DELETED_ITEMS) : null; List<DmDependencyTO> deletes = getSubmittedItems(site, deletedItems, format, globalSchDate); submittedItem.setDeletedItems(deletes); JSONArray children = (item.containsKey(JSON_KEY_CHILDREN)) ? item.getJSONArray(JSON_KEY_CHILDREN) : null; List<DmDependencyTO> submittedChidren = getSubmittedItems(site, children, format, globalSchDate); submittedItem.setChildren(submittedChidren); DmDependencyService dmDependencyService = getServicesManager().getService(DmDependencyService.class); if (uri.endsWith(DmConstants.XML_PATTERN)) { /** * Get dependent pages */ DmDependencyTO dmDependencyTo = dmDependencyService.getDependencies(site, null, item.getString(JSON_KEY_URI), false, true); List<DmDependencyTO> dependentPages = dmDependencyTo.getPages(); submittedItem.setPages(dependentPages); /** * Get Dependent Documents */ if (submittedItem.getDocuments() == null) { List<DmDependencyTO> dependentDocuments = dmDependencyTo.getDocuments(); submittedItem.setDocuments(dependentDocuments); } /** * get sendEmail property if it is there */ try { String fullPath = getFullPath(site, submittedItem); // PropertyValue sendEmailValue = // _avmService.getNodeProperty(-1, fullPath, // CStudioContentModel.PROP_WEB_WF_SEND_EMAIL); Serializable sendEmailValue = persistenceManagerService.getProperty( persistenceManagerService.getNodeRef(fullPath), CStudioContentModel.PROP_WEB_WF_SEND_EMAIL); boolean sendEmail = (sendEmailValue != null) ? Boolean.getBoolean(sendEmailValue.toString()) : false; submittedItem.setSendEmail(sendEmail); String user = item.getString(JSON_KEY_USER); submittedItem.setSubmittedBy(user); } catch (Exception e) { e.printStackTrace(); // To change body of catch statement use // File | Settings | File Templates. } } return submittedItem; }
From source file:org.alfresco.repo.jscript.People.java
private List<NodeRef> getSortedPeopleObjects(List<NodeRef> peopleRefs, final String sortBy, Boolean sortAsc) { if (sortBy == null) { return peopleRefs; }/*from w w w .j a v a2s .c o m*/ //make copy of peopleRefs because it can be unmodifiable list. List<NodeRef> sortedPeopleRefs = new ArrayList<NodeRef>(peopleRefs); final Collator col = Collator.getInstance(I18NUtil.getLocale()); final NodeService nodeService = services.getNodeService(); final int orderMultiplicator = ((sortAsc == null) || sortAsc) ? 1 : -1; Collections.sort(sortedPeopleRefs, new Comparator<NodeRef>() { @Override public int compare(NodeRef n1, NodeRef n2) { Serializable p1 = getProperty(n1); Serializable p2 = getProperty(n2); if ((p1 instanceof Long) && (p2 instanceof Long)) { return Long.compare((Long) p1, (Long) p2) * orderMultiplicator; } return col.compare(p1.toString(), p2) * orderMultiplicator; } public Serializable getProperty(NodeRef nodeRef) { Serializable result; if ("fullName".equalsIgnoreCase(sortBy)) { String firstName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_FIRSTNAME); String lastName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LASTNAME); String fullName = firstName; if (lastName != null && lastName.length() > 0) { fullName = fullName + " " + lastName; } result = fullName; } else if ("jobtitle".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_JOBTITLE); } else if ("email".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_EMAIL); } else if ("usage".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_CURRENT); } else if ("quota".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_QUOTA); } else { // Default result = nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME); } if (result == null) { result = ""; } return result; } }); return sortedPeopleRefs; }
From source file:org.ejbca.ui.web.admin.keybind.InternalKeyBindingMBean.java
/** @return the current multi-valued property's possible values as JSF friendly SelectItems. */ @SuppressWarnings("unchecked") public List<SelectItem/*<String,String>*/> getPropertyPossibleValues() { final List<SelectItem> propertyPossibleValues = new ArrayList<SelectItem>(); if (internalKeyBindingPropertyList != null) { final InternalKeyBindingProperty<? extends Serializable> property = (InternalKeyBindingProperty<? extends Serializable>) internalKeyBindingPropertyList .getRowData();/* w w w .j a v a 2 s . c o m*/ for (final Serializable possibleValue : property.getPossibleValues()) { propertyPossibleValues .add(new SelectItem(property.getAsEncodedValue(property.getType().cast(possibleValue)), possibleValue.toString())); } } return propertyPossibleValues; }
From source file:org.opoo.oqs.core.AbstractQuery.java
/** * ResultSetID//ww w . ja va2 s . co m * @param rs ResultSet * @return Serializable * @throws QueryException * @throws SQLException */ private Serializable getGeneratedIdentity(ResultSet rs) throws QueryException, SQLException { if (!rs.next()) { throw new QueryException("The database returned no natively generated identity value"); } //final Serializable id = IdentifierGeneratorFactory.get( rs, type ); Serializable id = (Serializable) rs.getObject(1); if (id != null) { if (id instanceof String) { return id.toString(); } if (id instanceof Number) { return id; } //Number return null; } if (log.isDebugEnabled()) { log.debug("Natively generated identity: " + id); } return id; }
From source file:org.ovirt.engine.core.bll.CommandBase.java
/** * Run the default compensation logic (inside a new transaction):<br> * <ol>/* ww w . j a v a2s. co m*/ * <li>Get all the entity snapshots that this command has created.</li> * <li>For each snapshot:</li> * <ol> * <li>Deserialize the entity.</li> * <li>Using the entity DAO:</li> * <ul> * <li>If the entity was added by the command, remove it.</li> * <li>Otherwise, If the entity is not in DB anymore, restore it.</li> * <li>Otherwise, update it.</li> * </ul> * </ol> * <li>Remove all the snapshots for this command, since we handled them.</li> </ol> */ @SuppressWarnings("unchecked") protected void compensate() { TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() { @Override public Object runInTransaction() { Deserializer deserializer = SerializationFactory.getFactory().createDeserializer(); List<BusinessEntitySnapshot> entitySnapshots = getBusinessEntitySnapshotDAO() .getAllForCommandId(commandId); log.debugFormat("Command [id={0}]: {1} compensation data.", commandId, entitySnapshots.isEmpty() ? "No" : "Going over"); for (BusinessEntitySnapshot snapshot : entitySnapshots) { Class<Serializable> snapshotClass = (Class<Serializable>) ReflectionUtils .getClassFor(snapshot.getSnapshotClass()); Serializable snapshotData = deserializer.deserialize(snapshot.getEntitySnapshot(), snapshotClass); log.infoFormat("Command [id={0}]: Compensating {1} of {2}; snapshot: {3}.", commandId, snapshot.getSnapshotType(), snapshot.getEntityType(), (snapshot.getSnapshotType() == SnapshotType.CHANGED_ENTITY ? "id=" + snapshot.getEntityId() : snapshotData.toString())); Class<BusinessEntity<Serializable>> entityClass = (Class<BusinessEntity<Serializable>>) ReflectionUtils .getClassFor(snapshot.getEntityType()); GenericDao<BusinessEntity<Serializable>, Serializable> daoForEntity = DbFacade.getInstance() .getDaoForEntity(entityClass); switch (snapshot.getSnapshotType()) { case CHANGED_STATUS_ONLY: EntityStatusSnapshot entityStatusSnapshot = (EntityStatusSnapshot) snapshotData; ((StatusAwareDao<Serializable, Enum<?>>) daoForEntity) .updateStatus(entityStatusSnapshot.getId(), entityStatusSnapshot.getStatus()); break; case CHANGED_ENTITY: BusinessEntity<Serializable> entitySnapshot = (BusinessEntity<Serializable>) snapshotData; if (daoForEntity.get(entitySnapshot.getId()) == null) { daoForEntity.save(entitySnapshot); } else { daoForEntity.update(entitySnapshot); } break; case NEW_ENTITY_ID: daoForEntity.remove(snapshotData); break; } } cleanUpCompensationData(); return null; } }); }
From source file:org.guzz.service.core.impl.SuperSlowUpdateServiceImpl.java
public void updateCount(String dbGroup, String tableName, String columnToUpdate, String pkColName, Serializable pkValue, int countToInc) { if (!isAvailable()) { throw new GuzzException("superSlowUpdateService is not available. use the config server's [" + FAMOUSE_SERVICE.SLOW_UPDATE + "] to active this service."); }/*www . j a va2 s . c o m*/ //key StringBuffer sb = new StringBuffer(32); sb.append(pkValue).append(columnToUpdate).append(tableName).append(dbGroup); String key = sb.toString(); IncUpdateBusiness ut = (IncUpdateBusiness) this.updateOperations.get(key); if (ut != null) { ut.incCount(countToInc); } else { synchronized (insertLock) { //read again ut = (IncUpdateBusiness) this.updateOperations.get(key); if (ut != null) {//already created while waiting for the lock //do nothing } else { ut = new IncUpdateBusiness(dbGroup); //put it into the map as soon as possible. this.updateOperations.put(key, ut); } } //release lock as soon as possible. ut.setTableName(tableName); ut.setPkColunName(pkColName); ut.setColumnToUpdate(columnToUpdate); ut.setPkValue(pkValue.toString()); //use thread safe method to inc count. Other threads may have already changed the count. ut.incCount(countToInc); } //just let it sleep. The delay is fine, a big batch is preferred. // if(this.updateThread.isSleeping()){ // synchronized (updateThread) { // try{ // this.updateThread.notify() ; // }catch(Exception e){} // } // } }
From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCache.java
/** * Queries the database for the value. If it gets a result, the value is * deserialized.//from ww w . j a v a2s . co m * <p> * @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doGet(java.io.Serializable) */ public ICacheElement doGet(Serializable key) { incrementGetCount(); if (log.isDebugEnabled()) { log.debug("Getting " + key + " from disk"); } if (!alive) { return null; } ICacheElement obj = null; byte[] data = null; try { // region, key String selectString = "select ELEMENT from " + getJdbcDiskCacheAttributes().getTableName() + " where REGION = ? and CACHE_KEY = ?"; Connection con = poolAccess.getConnection(); try { PreparedStatement psSelect = null; try { psSelect = con.prepareStatement(selectString); psSelect.setString(1, this.getCacheName()); psSelect.setString(2, key.toString()); ResultSet rs = psSelect.executeQuery(); try { if (rs.next()) { data = rs.getBytes(1); } if (data != null) { try { // USE THE SERIALIZER obj = (ICacheElement) getElementSerializer().deSerialize(data); } catch (IOException ioe) { log.error(ioe); } catch (Exception e) { log.error("Problem getting item.", e); } } } finally { if (rs != null) { rs.close(); } rs.close(); } } finally { if (psSelect != null) { psSelect.close(); } psSelect.close(); } } finally { if (con != null) { con.close(); } } } catch (SQLException sqle) { log.error(sqle); } if (log.isInfoEnabled()) { if (getCount % LOG_INTERVAL == 0) { // TODO make a log stats method log.info("Get Count [" + getCount + "]"); } } return obj; }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java
/** * {@inheritDoc}/*from ww w.j a va2 s .c o m*/ */ @Override public boolean canUnlockFile(final Serializable fileId) { return (Boolean) jcrTemplate.execute(new JcrCallback() { @Override public Object doInJcr(final Session session) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node fileNode = session.getNodeByIdentifier(fileId.toString()); Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath()); return lockHelper.canUnlock(session, pentahoJcrConstants, lock); } }); }