Example usage for java.lang String intern

List of usage examples for java.lang String intern

Introduction

In this page you can find the example usage for java.lang String intern.

Prototype

public native String intern();

Source Link

Document

Returns a canonical representation for the string object.

Usage

From source file:org.wso2.carbon.appfactory.repository.mgt.git.GITBranchingStrategy.java

/**
 * {@inheritDoc}/*from   w  w w  .  java  2 s  .c  o m*/
 */
@Override
public void doRepositoryBranch(String appId, String currentVersion, String targetVersion,
        String currentRevision, String tenantDomain) throws RepositoryMgtException {
    String sourceURL = provider.getAppRepositoryURL(appId, tenantDomain);
    String applicationType;
    try {
        applicationType = ApplicationDAO.getInstance().getApplicationType(appId);
    } catch (AppFactoryException e1) {
        String msg = "Error while getting application type for " + appId;
        log.error(msg, e1);
        throw new RepositoryMgtException(msg, e1);
    }
    String dirpath = CarbonUtils.getTmpDir() + File.separator + "branch" + File.separator + appId
            + File.separator + targetVersion;
    String lock = tenantDomain + appId + targetVersion;

    synchronized (lock.intern()) {
        File workDir = new File(dirpath);
        try {
            FileUtils.forceMkdir(workDir);
            AppfactoryRepositoryClient client = provider.getRepositoryClient();
            String currentBranch = currentVersion;
            if (AppFactoryConstants.TRUNK.equals(currentVersion)) { // Since there is no branch called trunk in git
                currentBranch = MASTER_BRANCH;
            }

            client.retireveMetadata(sourceURL, true, workDir); // git clone without checkout
            client.branch(sourceURL, targetVersion, currentBranch, workDir); // create branch from remote references
            client.checkOut(sourceURL, targetVersion, workDir); // checkout new branch

            try {
                List<File> deletableFiles = ApplicationTypeManager.getInstance()
                        .getApplicationTypeBean(applicationType).getProcessor().getPreVersionDeleteableFiles(
                                appId, targetVersion, currentVersion, workDir.getAbsolutePath());

                for (File file : deletableFiles) {
                    client.delete(sourceURL, file, "", workDir); // git remove
                }
                if (deletableFiles.size() > 0) {
                    String deleteMsg = "Commit by the AppFactory System : deleting files before creating the branch.";
                    client.commitLocally(deleteMsg, true, workDir); // commit after git remove
                }
                ApplicationTypeManager.getInstance().getApplicationTypeBean(applicationType).getProcessor()
                        .doVersion(appId, targetVersion, currentVersion, workDir.getAbsolutePath());
            } catch (AppFactoryException e) {
                String msg = "Could not perform versioning for application : " + appId;
                log.error(msg, e);
                throw new RepositoryMgtException(msg, e);
            }
            String commitMsg = "Modified after the branching";
            client.add(sourceURL, workDir, true, false, workDir); // git add all the new and updated files
            client.commitLocally(commitMsg, true, workDir); // git commit after adding new files
            boolean isSuccessful = client.pushLocalCommits(sourceURL, targetVersion, workDir); // git push
            if (!isSuccessful) {
                String errorMsg = "Failed to complete git push because remote git server rejected the push command.";
                log.error(errorMsg);
                throw new RepositoryMgtException(errorMsg);
            }
        } catch (IOException e) {
            String msg = "Error creating work directory at location" + workDir.getAbsolutePath();
            log.error(msg, e);
            throw new RepositoryMgtException(msg, e);
        } finally {
            try {
                FileUtils.deleteDirectory(workDir);
            } catch (IOException e) {
                log.error("Error deleting work directory " + e.getMessage(), e);
            }
        }
    }
}

From source file:com.qwarz.graph.model.GraphNode.java

@JsonIgnore
@XmlTransient/*w  w  w  .j  av  a 2  s  .  c  o  m*/
public boolean removeEdge(String type, String value) {
    if (value == null || value.isEmpty())
        return false;
    if (edges == null)
        return false;
    if (type == null || type.isEmpty())
        return false;
    type = type.intern();
    Set<String> nodeIdSet = edges.get(type);
    if (nodeIdSet == null)
        return false;
    return nodeIdSet.remove(value);
}

From source file:com.thoughtworks.go.server.cache.GoCache.java

public void put(String key, String subKey, Object value) {
    KeyList subKeys;//from  w w w .  jav a2 s.  c o m
    synchronized (key.intern()) {
        subKeys = subKeyFamily(key);
        if (subKeys == null) {
            subKeys = new KeyList();
            put(key, subKeys);
        }
        subKeys.add(subKey);
    }
    put(compositeKey(key, subKey), value);
}

From source file:org.apache.axis.utils.NSStack.java

/**
 * Add a mapping for a namespaceURI to the specified prefix to the top
 * frame in the stack.  If the prefix is already mapped in that frame,
 * remap it to the (possibly different) namespaceURI.
 *///from  w  w  w.j  a va 2  s  .  c o m
public void add(String namespaceURI, String prefix) {
    int idx = top;
    prefix = prefix.intern();
    try {
        // Replace duplicate prefixes (last wins - this could also fault)
        for (int cursor = top; stack[cursor] != null; cursor--) {
            if (stack[cursor].getPrefix() == prefix) {
                stack[cursor].setNamespaceURI(namespaceURI);
                idx = cursor;
                return;
            }
        }

        push();
        stack[top] = new Mapping(namespaceURI, prefix);
        idx = top;
    } finally {
        // If this is the default namespace, note the new in-scope
        // default is here.
        if (prefix.length() == 0) {
            currentDefaultNS = idx;
        }
    }
}

From source file:com.netxforge.oss2.xml.event.Maskelement.java

/**
 * Sets the value of '_mevalueList' by setting it to the given
 * Vector. No type checking is performed.
 * @deprecated//from w w w .jav a 2s.c o  m
 * 
 * @param mevalueList the Vector to set.
 */
public void setMevalueCollection(final java.util.List<java.lang.String> mevalueList) {
    this._mevalueList.clear();
    for (final String value : mevalueList) {
        this._mevalueList.add(value.intern());
    }
}

From source file:com.netxforge.oss2.xml.event.Maskelement.java

/**
 * Sets the value of '_mevalueList' by copying the given
 * Vector. All elements will be checked for type safety.
 * //  w  ww . j a  v a2 s  .c o  m
 * @param vMevalueList the Vector to copy.
 */
public void setMevalue(final java.util.List<java.lang.String> vMevalueList) {
    // copy vector
    this._mevalueList.clear();
    for (final String value : vMevalueList) {
        this._mevalueList.add(value.intern());
    }
}

From source file:no.sesat.search.view.velocity.URLResourceLoader.java

/**
 * Get an InputStream so that the Runtime can build a
 * template with it./*from  w  w  w .j ava2s  .  c o m*/
 *
 * @param url  url of template to fetch bytestream of
 * @return InputStream containing the template
 * @throws ResourceNotFoundException if template not found
 *         in the file template path.
 */
public /*synchronized*/ InputStream getResourceStream(final String url) throws ResourceNotFoundException {

    LOG.trace("start getResourceStream( " + url + " )");
    try {
        synchronized (url.intern()) {
            return getStream(findUrl(url, site));
        }

    } catch (IOException e) {
        throw new ResourceNotFoundException(ERR_RESOURCE_NOT_FOUND + url);
    }
}

From source file:org.dkpro.tc.api.features.Instance.java

public Instance(Collection<Feature> features, String outcome) {
    this.features = new ArrayList<Feature>(features);
    this.features.sort(getComparator());
    this.outcomes = new ArrayList<String>();
    this.outcomes.add(outcome);
    outcome.intern();
}

From source file:com.headstrong.fusion.statemachine.StateMachineErrorReporter.java

/**
 * @see ErrorReporter#onError(String, String, Object)
 *//*from   w ww  .  j  a v a2s .  c  om*/
public void onError(final String errorCode, final String errDetail, final Object errCtx) {
    // Note: the if-then-else below is based on the actual usage
    // (codebase search), it has to be kept up-to-date as the code changes
    String errCode = errorCode.intern();
    StringBuffer msg = new StringBuffer();
    msg.append(errCode).append(" (");
    msg.append(errDetail).append("): ");
    if (errCode == ErrorConstants.NO_INITIAL) {
        if (errCtx instanceof SCXML) {
            // determineInitialStates
            msg.append("<SCXML>");
        } else if (errCtx instanceof State) {
            // determineInitialStates
            // determineTargetStates
            msg.append("State ").append(LogUtils.getTTPath((State) errCtx));
        }
    } else if (errCode == ErrorConstants.UNKNOWN_ACTION) {
        // executeActionList
        msg.append("Action: ").append(errCtx.getClass().getName());
    } else if (errCode == ErrorConstants.ILLEGAL_CONFIG) {
        // isLegalConfig
        if (errCtx instanceof Map.Entry) {
            TransitionTarget tt = (TransitionTarget) (((Map.Entry) errCtx).getKey());
            Set vals = (Set) (((Map.Entry) errCtx).getValue());
            msg.append(LogUtils.getTTPath(tt)).append(" : [");
            for (Iterator i = vals.iterator(); i.hasNext();) {
                TransitionTarget tx = (TransitionTarget) i.next();
                msg.append(LogUtils.getTTPath(tx));
                if (i.hasNext()) {
                    msg.append(", ");
                }
            }
            msg.append(']');
        } else if (errCtx instanceof Set) {
            Set vals = (Set) errCtx;
            msg.append("<SCXML> : [");
            for (Iterator i = vals.iterator(); i.hasNext();) {
                TransitionTarget tx = (TransitionTarget) i.next();
                msg.append(LogUtils.getTTPath(tx));
                if (i.hasNext()) {
                    msg.append(", ");
                }
            }
            msg.append(']');
        }
    }
    if (logger.isWarnEnabled()) {
        logger.warn(msg.toString());
    }
}