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.quartz.impl.jdbcjobstore.StdJDBCDelegate.java

/**
 * <p>/*  w ww.  j  a v  a2  s . co m*/
 * Select a trigger' state value.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param triggerName
 *          the name of the trigger
 * @param groupName
 *          the group containing the trigger
 * @return the <code>{@link org.quartz.Trigger}</code> object
 */
public String selectTriggerState(Connection conn, String triggerName, String groupName) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        String state = null;

        ps = conn.prepareStatement(rtp(SELECT_TRIGGER_STATE));
        ps.setString(1, triggerName);
        ps.setString(2, groupName);
        rs = ps.executeQuery();

        if (rs.next()) {
            state = rs.getString(COL_TRIGGER_STATE);
        } else {
            state = STATE_DELETED;
        }

        return state.intern();
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

}

From source file:com.cloud.storage.resource.VmwareStorageProcessor.java

private Ternary<String, Long, Long> createTemplateFromSnapshot(String installPath, String templateUniqueName,
        String secStorageUrl, String snapshotPath, Long templateId, long wait, Integer nfsVersion)
        throws Exception {
    //Snapshot path is decoded in this form: /snapshots/account/volumeId/uuid/uuid
    String backupSSUuid;//from w  w  w. j ava  2 s .com
    String snapshotFolder;
    if (snapshotPath.endsWith(".ova")) {
        int index = snapshotPath.lastIndexOf(File.separator);
        backupSSUuid = snapshotPath.substring(index + 1).replace(".ova", "");
        snapshotFolder = snapshotPath.substring(0, index);
    } else {
        String[] tokens = snapshotPath.split(File.separatorChar == '\\' ? "\\\\" : File.separator);
        backupSSUuid = tokens[tokens.length - 1];
        snapshotFolder = StringUtils.join(tokens, File.separator, 0, tokens.length - 1);
    }

    String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
    String installFullPath = secondaryMountPoint + "/" + installPath;
    String installFullOVAName = installFullPath + "/" + templateUniqueName + ".ova"; //Note: volss for tmpl
    String snapshotRoot = secondaryMountPoint + "/" + snapshotFolder;
    String snapshotFullOVAName = snapshotRoot + "/" + backupSSUuid + ".ova";
    String snapshotFullOvfName = snapshotRoot + "/" + backupSSUuid + ".ovf";
    String result;
    Script command;
    String templateVMDKName = "";
    String snapshotFullVMDKName = snapshotRoot + "/" + backupSSUuid + "/";

    synchronized (installPath.intern()) {
        command = new Script(false, "mkdir", _timeout, s_logger);
        command.add("-p");
        command.add(installFullPath);

        result = command.execute();
        if (result != null) {
            String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl
                    + ", error msg: " + result;
            s_logger.error(msg);
            throw new Exception(msg);
        }
    }

    try {
        if (new File(snapshotFullOVAName).exists()) {
            command = new Script(false, "cp", wait, s_logger);
            command.add(snapshotFullOVAName);
            command.add(installFullOVAName);
            result = command.execute();
            if (result != null) {
                String msg = "unable to copy snapshot " + snapshotFullOVAName + " to " + installFullPath;
                s_logger.error(msg);
                throw new Exception(msg);
            }

            // untar OVA file at template directory
            command = new Script("tar", wait, s_logger);
            command.add("--no-same-owner");
            command.add("-xf", installFullOVAName);
            command.setWorkDir(installFullPath);
            s_logger.info("Executing command: " + command.toString());
            result = command.execute();
            if (result != null) {
                String msg = "unable to untar snapshot " + snapshotFullOVAName + " to " + installFullPath;
                s_logger.error(msg);
                throw new Exception(msg);
            }

        } else { // there is no ova file, only ovf originally;
            if (new File(snapshotFullOvfName).exists()) {
                command = new Script(false, "cp", wait, s_logger);
                command.add(snapshotFullOvfName);
                //command.add(installFullOvfName);
                command.add(installFullPath);
                result = command.execute();
                if (result != null) {
                    String msg = "unable to copy snapshot " + snapshotFullOvfName + " to " + installFullPath;
                    s_logger.error(msg);
                    throw new Exception(msg);
                }

                s_logger.info("vmdkfile parent dir: " + snapshotRoot);
                File snapshotdir = new File(snapshotRoot);
                File[] ssfiles = snapshotdir.listFiles();
                if (ssfiles == null) {
                    String msg = "unable to find snapshot vmdk files in " + snapshotRoot;
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
                // List<String> filenames = new ArrayList<String>();
                for (int i = 0; i < ssfiles.length; i++) {
                    String vmdkfile = ssfiles[i].getName();
                    s_logger.info("vmdk file name: " + vmdkfile);
                    if (vmdkfile.toLowerCase().startsWith(backupSSUuid)
                            && vmdkfile.toLowerCase().endsWith(".vmdk")) {
                        snapshotFullVMDKName = snapshotRoot + File.separator + vmdkfile;
                        templateVMDKName += vmdkfile;
                        break;
                    }
                }
                if (snapshotFullVMDKName != null) {
                    command = new Script(false, "cp", wait, s_logger);
                    command.add(snapshotFullVMDKName);
                    command.add(installFullPath);
                    result = command.execute();
                    s_logger.info("Copy VMDK file: " + snapshotFullVMDKName);
                    if (result != null) {
                        String msg = "unable to copy snapshot vmdk file " + snapshotFullVMDKName + " to "
                                + installFullPath;
                        s_logger.error(msg);
                        throw new Exception(msg);
                    }
                }
            } else {
                String msg = "unable to find any snapshot ova/ovf files" + snapshotFullOVAName + " to "
                        + installFullPath;
                s_logger.error(msg);
                throw new Exception(msg);
            }
        }

        long physicalSize = new File(installFullPath + "/" + templateVMDKName).length();
        OVAProcessor processor = new OVAProcessor();
        // long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".ova").length();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        processor.configure("OVA Processor", params);
        long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateUniqueName);

        postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize);
        writeMetaOvaForTemplate(installFullPath, backupSSUuid + ".ovf", templateVMDKName, templateUniqueName,
                physicalSize);
        return new Ternary<String, Long, Long>(installPath + "/" + templateUniqueName + ".ova", physicalSize,
                virtualSize);
    } finally {
        // TODO, clean up left over files
    }
}

From source file:android.content.pm.PackageParser.java

private static String buildClassName(String pkg, CharSequence clsSeq, String[] outError) {
    if (clsSeq == null || clsSeq.length() <= 0) {
        outError[0] = "Empty class name in package " + pkg;
        return null;
    }//from  w  w w. j  a v a  2 s  .  co m
    String cls = clsSeq.toString();
    char c = cls.charAt(0);
    if (c == '.') {
        return (pkg + cls).intern();
    }
    if (cls.indexOf('.') < 0) {
        StringBuilder b = new StringBuilder(pkg);
        b.append('.');
        b.append(cls);
        return b.toString().intern();
    }
    if (c >= 'a' && c <= 'z') {
        return cls.intern();
    }
    outError[0] = "Bad class name " + cls + " in package " + pkg;
    return null;
}

From source file:org.apache.nifi.controller.FlowController.java

/**
 * Creates a funnel//from  ww w  .ja v a2  s  . c o m
 *
 * @param id funnel id
 * @return new funnel
 */
public Funnel createFunnel(final String id) {
    return new StandardFunnel(id.intern(), null, processScheduler);
}

From source file:org.apache.nifi.controller.FlowController.java

/**
 * <p>//from   ww w.  j  av  a 2s .com
 * Creates a new ProcessorNode with the given type and identifier and
 * optionally initializes it.
 * </p>
 *
 * @param type the fully qualified Processor class name
 * @param id the unique ID of the Processor
 * @param firstTimeAdded whether or not this is the first time this
 * Processor is added to the graph. If {@code true}, will invoke methods
 * annotated with the {@link OnAdded} annotation.
 * @return new processor node
 * @throws NullPointerException if either arg is null
 * @throws ProcessorInstantiationException if the processor cannot be
 * instantiated for any reason
 */
public ProcessorNode createProcessor(final String type, String id, final boolean firstTimeAdded)
        throws ProcessorInstantiationException {
    id = id.intern();

    boolean creationSuccessful;
    Processor processor;
    try {
        processor = instantiateProcessor(type, id);
        creationSuccessful = true;
    } catch (final ProcessorInstantiationException pie) {
        LOG.error("Could not create Processor of type " + type + " for ID " + id
                + "; creating \"Ghost\" implementation", pie);
        final GhostProcessor ghostProc = new GhostProcessor();
        ghostProc.setIdentifier(id);
        ghostProc.setCanonicalClassName(type);
        processor = ghostProc;
        creationSuccessful = false;
    }

    final ComponentLog logger = new SimpleProcessLogger(id, processor);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(
            controllerServiceProvider, variableRegistry);
    final ProcessorNode procNode;
    if (creationSuccessful) {
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler,
                controllerServiceProvider, nifiProperties, variableRegistry, logger);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler,
                controllerServiceProvider, componentType, type, nifiProperties, variableRegistry, logger);
    }

    final LogRepository logRepository = LogRepositoryFactory.getRepository(id);
    logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN,
            new ProcessorLogObserver(getBulletinRepository(), procNode));

    try {
        final Class<?> procClass = processor.getClass();
        if (procClass.isAnnotationPresent(DefaultSettings.class)) {
            DefaultSettings ds = procClass.getAnnotation(DefaultSettings.class);
            try {
                procNode.setYieldPeriod(ds.yieldDuration());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting yield period from DefaultSettings annotation:%s",
                        ex.getMessage()), ex);
            }
            try {

                procNode.setPenalizationPeriod(ds.penaltyDuration());
            } catch (Throwable ex) {
                LOG.error(
                        String.format("Error while setting penalty duration from DefaultSettings annotation:%s",
                                ex.getMessage()),
                        ex);
            }
            try {
                procNode.setBulletinLevel(ds.bulletinLevel());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting bulletin level from DefaultSettings annotation:%s",
                        ex.getMessage()), ex);
            }

        }
    } catch (Throwable ex) {
        LOG.error(String.format("Error while setting default settings from DefaultSettings annotation: %s",
                ex.getMessage()), ex);
    }

    if (firstTimeAdded) {
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getClass(),
                processor.getIdentifier())) {
            ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor);
        } catch (final Exception e) {
            logRepository.removeObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID);
            throw new ComponentLifeCycleException(
                    "Failed to invoke @OnAdded methods of " + procNode.getProcessor(), e);
        }

        if (firstTimeAdded) {
            try (final NarCloseable nc = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(),
                    processor.getIdentifier())) {
                ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class,
                        procNode.getProcessor());
            }
        }
    }

    return procNode;
}

From source file:android.content.pm.PackageParser.java

private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, AttributeSet attrs, int flags)
        throws IOException, XmlPullParserException, PackageParserException {

    int type;//from w w  w  . j  av  a 2  s .  co m
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    }

    if (type != XmlPullParser.START_TAG) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No start tag found");
    }
    if (!parser.getName().equals("manifest")) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No <manifest> tag");
    }

    final String packageName = attrs.getAttributeValue(null, "package");
    if (!"android".equals(packageName)) {
        final String error = validateName(packageName, true, true);
        if (error != null) {
            throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                    "Invalid manifest package: " + error);
        }
    }

    String splitName = attrs.getAttributeValue(null, "split");
    if (splitName != null) {
        if (splitName.length() == 0) {
            splitName = null;
        } else {
            final String error = validateName(splitName, false, false);
            if (error != null) {
                throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                        "Invalid manifest split: " + error);
            }
        }
    }

    return Pair.create(packageName.intern(), (splitName != null) ? splitName.intern() : splitName);
}

From source file:android.content.pm.PackageParser.java

private static String buildCompoundName(String pkg, CharSequence procSeq, String type, String[] outError) {
    String proc = procSeq.toString();
    char c = proc.charAt(0);
    if (pkg != null && c == ':') {
        if (proc.length() < 2) {
            outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
                    + ": must be at least two characters";
            return null;
        }//from  w  w  w.  j av a2  s.c o  m
        String subName = proc.substring(1);
        String nameError = validateName(subName, false, false);
        if (nameError != null) {
            outError[0] = "Invalid " + type + " name " + proc + " in package " + pkg + ": " + nameError;
            return null;
        }
        return (pkg + proc).intern();
    }
    String nameError = validateName(proc, true, false);
    if (nameError != null && !"system".equals(proc)) {
        outError[0] = "Invalid " + type + " name " + proc + " in package " + pkg + ": " + nameError;
        return null;
    }
    return proc.intern();
}

From source file:gate.creole.ontology.impl.sesame.OntologyServiceImplSesame.java

/**
 * Sets the datatype uri for the given restriction uri.
 * /*from w ww .j  a  v a 2s.  c om*/
 * @param restrictionURI
 * @param datatypeURI
 */
public void setPropertyValue(String restrictionURI, byte restrictionType, String value, String datatypeURI) {
    String whatValueURI = null;
    switch (restrictionType) {
    case OConstants.CARDINALITY_RESTRICTION:
        whatValueURI = OWL.CARDINALITY.toString();
        break;
    case OConstants.MAX_CARDINALITY_RESTRICTION:
        whatValueURI = OWL.MAXCARDINALITY.toString();
        break;
    case OConstants.MIN_CARDINALITY_RESTRICTION:
        whatValueURI = OWL.MINCARDINALITY.toString();
        break;
    default:
        throw new GateOntologyException(
                "Invalid restriction type :" + restrictionType + " for the restriction " + restrictionURI);
    }
    Statement toDelete = null;
    try {
        RepositoryResult<Statement> iter = repositoryConnection.getStatements(getResource(restrictionURI),
                makeSesameURI(whatValueURI), null, true);
        if (iter.hasNext()) {
            Statement stmt = iter.next();
            Value v = stmt.getObject();
            if (v instanceof Literal) {
                if (((Literal) v).getDatatype().toString().intern() == datatypeURI.intern()) {
                    toDelete = stmt;
                }
            }
        }
    } catch (Exception e) {
        throw new GateOntologyException(e);
    }

    if (toDelete != null) {
        Literal l = (Literal) toDelete.getObject();
        // TODO: !! replace !!
        removeUUUStatement(whatValueURI, l.getLabel(), l.getDatatype().toString());
    }
    // TODO: !! replace !!
    addUUDStatement(restrictionURI, whatValueURI, value, datatypeURI);
}

From source file:android.content.pm.PackageParser.java

private Instrumentation parseInstrumentation(Package owner, Resources res, XmlPullParser parser,
        AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestInstrumentation);

    if (mParseInstrumentationArgs == null) {
        mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_logo,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_banner);
        mParseInstrumentationArgs.tag = "<instrumentation>";
    }/*from ww w. j  a  v  a  2 s . c om*/

    mParseInstrumentationArgs.sa = sa;

    Instrumentation a = new Instrumentation(mParseInstrumentationArgs, new InstrumentationInfo());
    if (outError[0] != null) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    String str;
    // Note: don't allow this value to be a reference to a resource
    // that may change.
    str = sa.getNonResourceString(
            com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
    a.info.targetPackage = str != null ? str.intern() : null;

    a.info.handleProfiling = sa
            .getBoolean(com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, false);

    a.info.functionalTest = sa
            .getBoolean(com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, false);

    sa.recycle();

    if (a.info.targetPackage == null) {
        outError[0] = "<instrumentation> does not specify targetPackage";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a, outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.instrumentation.add(a);

    return a;
}

From source file:android.content.pm.PackageParser.java

private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data,
        String[] outError) throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData);

    if (data == null) {
        data = new Bundle();
    }/*from w  w w  . ja  v  a  2 s .  c o  m*/

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name,
            0);
    if (name == null) {
        outError[0] = "<meta-data> requires an android:name attribute";
        sa.recycle();
        return null;
    }

    name = name.intern();

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource);
    if (v != null && v.resourceId != 0) {
        //Slog.i(TAG, "Meta data ref " + name + ": " + v);
        data.putInt(name, v.resourceId);
    } else {
        v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value);
        //Slog.i(TAG, "Meta data " + name + ": " + v);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                data.putString(name, cs != null ? cs.toString().intern() : null);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                data.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) {
                data.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                data.putFloat(name, v.getFloat());
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG,
                            "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
                                    + parser.getName() + " at " + mArchiveSourcePath + " "
                                    + parser.getPositionDescription());
                } else {
                    outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
                    data = null;
                }
            }
        } else {
            outError[0] = "<meta-data> requires an android:value or android:resource attribute";
            data = null;
        }
    }

    sa.recycle();

    XmlUtils.skipCurrentTag(parser);

    return data;
}