Example usage for java.io Serializable toString

List of usage examples for java.io Serializable toString

Introduction

In this page you can find the example usage for java.io Serializable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.pentaho.platform.repository2.unified.fs.FileSystemRepositoryFileDao.java

public void setFileMetadata(final Serializable fileId, Map<String, Serializable> metadataMap) {
    final File targetFile = new File(fileId.toString());
    if (targetFile.exists()) {
        FileOutputStream fos = null;
        try {/*from  w  w  w. j  a  v  a  2s.c o m*/
            final File metadataDir = new File(targetFile.getParent() + File.separatorChar + ".metadata");
            if (!metadataDir.exists()) {
                metadataDir.mkdir();
            }
            final File metadataFile = new File(metadataDir, targetFile.getName());
            if (!metadataFile.exists()) {
                metadataFile.createNewFile();
            }

            final StringBuilder data = new StringBuilder();
            for (String key : metadataMap.keySet()) {
                data.append(key).append('=');
                if (metadataMap.get(key) != null) {
                    data.append(metadataMap.get(key).toString());
                }
                data.append('\n');
            }
            fos = new FileOutputStream(metadataFile);
            fos.write(data.toString().getBytes());
        } catch (FileNotFoundException e) {
            throw new UnifiedRepositoryException("Error writing file metadata [" + fileId + "]", e);
        } catch (IOException e) {
            throw new UnifiedRepositoryException("Error writing file metadata [" + fileId + "]", e);
        } finally {
            IOUtils.closeQuietly(fos);
        }
    }
}

From source file:uk.ac.diamond.scisoft.analysis.rpc.flattening.helpers.GuiBeanHelper.java

/**
 * We know the intended type, so in many cases we can upgrade from flattened to the expected type e.g. Object[] to
 * List<Object>./*w w w  .jav a 2  s. c o m*/
 * 
 * @param params
 * @param valueObj
 * @return upgraded valueObj, or the original if it matches
 */
private Serializable unflattenParam(GuiParameters params, Serializable valueObj) {
    Class<?> clazz = params.getStorageClass();
    if (clazz.isInstance(valueObj)) {
        return valueObj;
    } else if (clazz.equals(List.class)) {
        return new ArrayList<Object>(Arrays.asList((Object[]) valueObj));
    } else if (clazz.equals(Integer[].class)) {
        return ArrayUtils.toObject((int[]) valueObj);
    } else if (clazz.equals(GuiPlotMode.class)) {
        return GuiPlotMode.valueOf((String) valueObj);
    } else if (clazz.equals(UUID.class)) {
        return UUID.fromString(valueObj.toString());
    }
    return valueObj;
}

From source file:no.uka.findmyapp.android.rest.client.RestProcessor.java

private Serializable parseListFromJson(String response, Type t1) throws JSONException {
    Serializable s;
    Log.v(debug, "executeAndParse: Is list");
    JSONArray array = new JSONArray(response);
    List<Serializable> list = new ArrayList<Serializable>();
    for (int i = 0; i < array.length(); i++) {
        list.add((Serializable) mGson.fromJson(array.get(i).toString(), t1));
    }// w w w  . ja v  a 2s  .c o m
    s = (Serializable) list;
    Log.v(debug, "executeAndParse: Serializable " + s.toString());
    return s;
}

From source file:org.grails.orm.hibernate.HibernateDatastore.java

protected HibernateGormEnhancer initialize() {
    final HibernateConnectionSource defaultConnectionSource = (HibernateConnectionSource) getConnectionSources()
            .getDefaultConnectionSource();
    if (multiTenantMode == MultiTenancySettings.MultiTenancyMode.SCHEMA) {
        return new HibernateGormEnhancer(this, transactionManager, defaultConnectionSource.getSettings()) {
            @Override/*from  ww  w .  ja v a2  s.  co  m*/
            public List<String> allQualifiers(Datastore datastore, PersistentEntity entity) {
                List<String> allQualifiers = super.allQualifiers(datastore, entity);
                if (MultiTenant.class.isAssignableFrom(entity.getJavaClass())) {
                    if (tenantResolver instanceof AllTenantsResolver) {
                        Iterable<Serializable> tenantIds = ((AllTenantsResolver) tenantResolver)
                                .resolveTenantIds();
                        for (Serializable id : tenantIds) {
                            allQualifiers.add(id.toString());
                        }
                    } else {
                        Collection<String> schemaNames = schemaHandler
                                .resolveSchemaNames(defaultConnectionSource.getDataSource());
                        for (String schemaName : schemaNames) {
                            // skip common internal schemas
                            if (schemaName.equals("INFORMATION_SCHEMA") || schemaName.equals("PUBLIC"))
                                continue;
                            for (String connectionName : datastoresByConnectionSource.keySet()) {
                                if (schemaName.equalsIgnoreCase(connectionName)) {
                                    allQualifiers.add(connectionName);
                                }
                            }
                        }
                    }
                }

                return allQualifiers;
            }
        };
    } else {
        return new HibernateGormEnhancer(this, transactionManager, defaultConnectionSource.getSettings());
    }
}

From source file:org.pentaho.di.trans.steps.annotation.BaseAnnotationMeta.java

@Override
public void saveRep(final Repository rep, final IMetaStore metaStore, final ObjectId id_transformation,
        final ObjectId id_step) throws KettleException {

    try {/*  w w  w.  j a v a  2s . c om*/

        rep.saveStepAttribute(id_transformation, id_step, "CATEGORY_NAME", getModelAnnotationCategory());
        rep.saveStepAttribute(id_transformation, id_step, "TARGET_OUTPUT_STEP", getTargetOutputStep());

        // Save model annotations
        if (getModelAnnotations() != null) {

            for (int i = 0; i < getModelAnnotations().size(); i++) {

                final ModelAnnotation<?> modelAnnotation = getModelAnnotations().get(i);

                // Add default name
                if (StringUtils.isBlank(modelAnnotation.getName())) {
                    modelAnnotation.setName(UUID.randomUUID().toString()); // backwards compatibility
                }

                rep.saveStepAttribute(id_transformation, id_step, i, "ANNOTATION_NAME",
                        modelAnnotation.getName());
                rep.saveStepAttribute(id_transformation, id_step, i, "ANNOTATION_FIELD_NAME",
                        modelAnnotation.getAnnotation().getField());

                if (modelAnnotation.getType() != null) {
                    rep.saveStepAttribute(id_transformation, id_step, i, "ANNOTATION_TYPE",
                            modelAnnotation.getType().toString());

                    final int INDEX = i; // trap index so we can use in inner class
                    modelAnnotation.iterateProperties(new KeyValueClosure() {
                        @Override
                        public void execute(String key, Serializable serializable) {
                            try {
                                if (serializable != null && StringUtils.isNotBlank(serializable.toString())) {
                                    rep.saveStepAttribute(id_transformation, id_step, INDEX,
                                            "PROPERTY_VALUE_" + key, serializable.toString());
                                }
                            } catch (KettleException e) {
                                logError(e.getMessage());
                            }
                        }
                    });
                }
            }

            rep.saveStepAttribute(id_transformation, id_step, "SHARED_DIMENSION",
                    getModelAnnotations().isSharedDimension());
            rep.saveStepAttribute(id_transformation, id_step, "DESCRIPTION",
                    getModelAnnotations().getDescription());

            List<DataProvider> dataProviders = getModelAnnotations().getDataProviders();
            if (dataProviders != null && !dataProviders.isEmpty()) {
                for (int dIdx = 0; dIdx < dataProviders.size(); dIdx++) {

                    DataProvider dataProvider = dataProviders.get(dIdx);

                    // Save Data Provider properties
                    rep.saveStepAttribute(id_transformation, id_step, dIdx, "DP_NAME", dataProvider.getName());
                    rep.saveStepAttribute(id_transformation, id_step, dIdx, "DP_SCHEMA_NAME",
                            dataProvider.getSchemaName());
                    rep.saveStepAttribute(id_transformation, id_step, dIdx, "DP_TABLE_NAME",
                            dataProvider.getTableName());
                    rep.saveStepAttribute(id_transformation, id_step, dIdx, "DP_DATABASE_META_NAME_REF",
                            dataProvider.getDatabaseMetaNameRef());

                    List<ColumnMapping> columnMappings = dataProvider.getColumnMappings();
                    if (columnMappings != null && !columnMappings.isEmpty()) {

                        // Save count for loading
                        rep.saveStepAttribute(id_transformation, id_step, "CM_COUNT_" + dIdx,
                                columnMappings.size());

                        for (int cIdx = 0; cIdx < columnMappings.size(); cIdx++) {

                            ColumnMapping columnMapping = columnMappings.get(cIdx);

                            // Save ColumnMapping properties
                            rep.saveStepAttribute(id_transformation, id_step, dIdx, "CM_NAME_" + cIdx,
                                    columnMapping.getName());
                            rep.saveStepAttribute(id_transformation, id_step, dIdx, "CM_COLUMN_NAME_" + cIdx,
                                    columnMapping.getColumnName());

                            if (columnMapping.getColumnDataType() != null) {
                                rep.saveStepAttribute(id_transformation, id_step, dIdx, "CM_DATA_TYPE_" + cIdx,
                                        columnMapping.getColumnDataType().name());
                            }
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        throw new KettleException(
                BaseMessages.getString(PKG, "ModelAnnotationMeta.Exception.UnableToSaveStepInfoToRepository")
                        + id_step,
                e);
    }
}

From source file:org.apache.jcs.engine.memory.mru.MRUMemoryCache.java

/**
 * Gets an item out of the map. If it finds an item, it is removed from the
 * list and then added to the first position in the linked list.
 * @return/*from w w  w .  j av  a2 s  . co  m*/
 * @param key
 * @exception IOException
 */
public ICacheElement get(Serializable key) throws IOException {
    ICacheElement ce = null;
    boolean found = false;

    try {
        if (log.isDebugEnabled()) {
            log.debug("get> key=" + key);
            log.debug("get> key=" + key.toString());
        }

        ce = (ICacheElement) map.get(key);
        if (log.isDebugEnabled()) {
            log.debug("ce =" + ce);
        }

        if (ce != null) {
            found = true;
            ce.getElementAttributes().setLastAccessTimeNow();
            hitCnt++;
            if (log.isDebugEnabled()) {
                log.debug(cacheName + " -- RAM-HIT for " + key);
            }
        }
    } catch (Exception e) {
        log.error("Problem getting element.", e);
    }

    try {
        if (!found) {
            // Item not found in cache.
            missCnt++;
            if (log.isDebugEnabled()) {
                log.debug(cacheName + " -- MISS for " + key);
            }
            return null;
        }
    } catch (Exception e) {
        log.error("Error handling miss", e);
        return null;
    }

    try {
        synchronized (lockMe) {
            mrulist.remove(ce.getKey());
            mrulist.addFirst(ce.getKey());
        }
    } catch (Exception e) {
        log.error("Error making first", e);
        return null;
    }

    return ce;
}

From source file:org.bonitasoft.forms.server.api.impl.FormExpressionsAPIImplIT.java

@Test
public void testEvaluateExpressionOnProcess() throws Exception {
    final Map<String, FormFieldValue> fieldValues = new HashMap<String, FormFieldValue>();
    fieldValues.put("application", new FormFieldValue("Excel", String.class.getName()));
    final Expression expression = new Expression(null, "field_application", ExpressionType.TYPE_INPUT.name(),
            String.class.getName(), null, null);
    final Serializable result = formExpressionsAPI.evaluateProcessExpression(getSession(),
            processDefinition.getId(), expression, fieldValues, Locale.ENGLISH);
    Assert.assertEquals("Excel", result.toString());
}

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java

public static IRepositoryFileData getContent(final Session session,
        final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final Serializable versionId,
        final ITransformer<IRepositoryFileData> transformer) throws RepositoryException {
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    if (isVersioned(session, pentahoJcrConstants, fileNode)) {
        VersionManager vMgr = session.getWorkspace().getVersionManager();
        Version version = null;/*ww w.  j a v  a 2 s  . c  o m*/
        if (versionId != null) {
            version = vMgr.getVersionHistory(fileNode.getPath()).getVersion(versionId.toString());
        } else {
            version = vMgr.getBaseVersion(fileNode.getPath());
        }
        fileNode = getNodeAtVersion(pentahoJcrConstants, version);
    }
    Assert.isTrue(!isPentahoFolder(pentahoJcrConstants, fileNode));

    return transformer.fromContentNode(session, pentahoJcrConstants, fileNode);
}

From source file:io.cloudslang.lang.tools.build.tester.SlangTestRunner.java

private boolean outputsAreEqual(Serializable outputValue, Serializable executionOutputValue) {
    return executionOutputValue == outputValue
            || StringUtils.equals(executionOutputValue.toString(), outputValue.toString());
}

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java

public static Object getVersionSummary(final Session session, final PentahoJcrConstants pentahoJcrConstants,
        final Serializable fileId, final Serializable versionId) throws RepositoryException {
    VersionManager vMgr = session.getWorkspace().getVersionManager();
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    VersionHistory versionHistory = vMgr.getVersionHistory(fileNode.getPath());
    Version version = null;/*from   w  w w . ja v a 2 s  . co  m*/
    if (versionId != null) {
        version = versionHistory.getVersion(versionId.toString());
    } else {
        version = vMgr.getBaseVersion(fileNode.getPath());
    }
    return toVersionSummary(pentahoJcrConstants, versionHistory, version);
}