Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

In this page you can find the example usage for java.util NoSuchElementException NoSuchElementException.

Prototype

public NoSuchElementException(String s) 

Source Link

Document

Constructs a NoSuchElementException , saving a reference to the error message string s for later retrieval by the getMessage method.

Usage

From source file:de.codesourcery.jasm16.ide.ProjectBuilder.java

@Override
public synchronized ICompilationUnit getCompilationUnit(IResource resource) throws NoSuchElementException {
    final ICompilationUnit result = findCompilationUnit(resource);
    if (result == null) {
        throw new NoSuchElementException("Could not find compilation unit for " + resource);
    }/*  w w  w .  j av a 2 s.c o m*/
    return result;
}

From source file:brooklyn.util.ResourceUtils.java

public String getClassLoaderDir(String resourceInThatDir) {
    resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/");
    URL resourceUrl = getLoader().getResource(resourceInThatDir);
    if (resourceUrl == null)
        throw new NoSuchElementException("Resource (" + resourceInThatDir + ") not found");

    URL containerUrl = getContainerUrl(resourceUrl, resourceInThatDir);

    if (!"file".equals(containerUrl.getProtocol()))
        throw new IllegalStateException(
                "Resource (" + resourceInThatDir + ") not on file system (at " + containerUrl + ")");

    //convert from file: URL to File
    File file;/*from w w w.  ja  v  a2s  .  c o m*/
    try {
        file = new File(containerUrl.toURI());
    } catch (URISyntaxException e) {
        throw new IllegalStateException(
                "Resource (" + resourceInThatDir + ") found at invalid URI (" + containerUrl + ")", e);
    }

    if (!file.exists())
        throw new IllegalStateException(
                "Context class url substring (" + containerUrl + ") not found on filesystem");
    return file.getPath();

}

From source file:com.twinsoft.convertigo.eclipse.views.loggers.EngineLogView.java

private ColumnInfo getColumnInfo(String columnName) {
    // Searching for the default column info
    for (ColumnInfo columnInfo : columnInfos) {
        if (columnInfo.getName().equals(columnName)) {
            return columnInfo;
        }// www .  j av a  2 s .  c o  m
    }

    throw new NoSuchElementException("Column info for '" + columnName + "' not found");
}

From source file:org.hawk.service.emf.impl.HawkResourceImpl.java

private static EClass getEClass(final String metamodelUri, final String typeName,
        final Registry packageRegistry) {
    final EPackage pkg = packageRegistry.getEPackage(metamodelUri);
    if (pkg == null) {
        throw new NoSuchElementException(
                String.format("Could not find EPackage with URI '%s' in the registry", metamodelUri));
    }// www .  j a va 2s . c om

    final EClassifier eClassifier = pkg.getEClassifier(typeName);
    if (!(eClassifier instanceof EClass)) {
        throw new NoSuchElementException(
                String.format("Received an element of type '%s', which is not an EClass", eClassifier));
    }
    final EClass eClass = (EClass) eClassifier;
    return eClass;
}

From source file:org.geowebcache.config.XMLConfiguration.java

/**
 * Method responsible for modifying an existing layer.
 * /*from w  w w.  jav  a 2  s. c o  m*/
 * @param tl
 *            the new layer to overwrite the existing layer
 * @throws NoSuchElementException
 * @see org.geowebcache.config.Configuration#modifyLayer(org.geowebcache.layer.TileLayer)
 */
public synchronized void modifyLayer(TileLayer tl) throws NoSuchElementException {
    TileLayer previous = getTileLayer(tl.getName());
    if (null == previous) {
        throw new NoSuchElementException("Layer " + tl.getName() + " does not exist");
    }

    gwcConfig.getLayers().remove(previous);
    initialize(tl);
    gwcConfig.getLayers().add(tl);
    updateLayers();
}

From source file:com.germinus.easyconf.ComponentProperties.java

protected void validateValue(String key, Object value) {
    if ((value == null) && isThrowExceptionOnMissing()) {
        throw new NoSuchElementException("Property with key=" + key + " was not found");
    }//from  www. j  a v a 2s. c  o  m
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenter.java

/**
 * Executes a health check and returns its result. The actual name of the health check may contain a postfix,
 * depending on the value returned by {@link NamingConfig#getAppendTypeToHealthCheckNames()}.
 * <br><br>/*from  w  w w.j a v a  2  s  .co  m*/
 * All illegal characters contained in the provided name will be escaped as documented for
 * {@link net.centro.rtb.monitoringcenter.util.MetricNamingUtil#sanitize(String)}.
 *
 * @param name name of the health check to execute.
 * @return result of the executed health check.
 * @throws IllegalArgumentException if <tt>name</tt> is blank.
 * @throws NoSuchElementException if MonitoringCenter has not been configured or if health check could not be found.
 */
public static HealthCheck.Result runHealthCheck(String name) {
    if (!configured.get()) {
        throw new NoSuchElementException(
                "MonitoringCenter has not been initialized. No health checks are available.");
    }

    String normalizedName = normalizeHealthCheckName(name);
    try {
        return healthCheckRegistry.runHealthCheck(normalizedName);
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException("Health check " + normalizedName + " could not be found.");
    }
}

From source file:com.meidusa.amoeba.net.poolable.GenericObjectPool.java

public Object borrowObject() throws Exception {
    if (!isValid) {
        if (this.getNumActive() > 0 && this.getNumIdle() == 0) {
            throw new NoSuchElementException("poolName=" + name + ", pool is invalid");
        }/*w  w  w .j  av a 2s .  c o  m*/
    }
    try {
        return super.borrowObject();
    } catch (Exception e) {
        isValid = false;
        throw e;
    }
}

From source file:com.eucalyptus.images.Images.java

public static KernelImageInfo lookupKernel(final String kernelId) {
    EntityTransaction tx = Entities.get(KernelImageInfo.class);
    KernelImageInfo ret = new KernelImageInfo();
    try {/*w  w w .j av a 2s  .co  m*/
        ret = Entities.uniqueResult(Images.exampleKernelWithImageId(kernelId));
        tx.commit();
    } catch (Exception e) {
        LOG.error("Kernel '" + kernelId + "' does not exist" + e);
        throw new NoSuchElementException("InvalidAMIID.NotFound");
    } finally {
        if (tx.isActive())
            tx.rollback();
    }
    return ret;
}

From source file:com.eucalyptus.images.Images.java

public static RamdiskImageInfo lookupRamdisk(final String ramdiskId) {
    EntityTransaction tx = Entities.get(RamdiskImageInfo.class);
    RamdiskImageInfo ret = new RamdiskImageInfo();
    try {//from ww w .j ava2 s .co m
        ret = Entities.uniqueResult(Images.exampleRamdiskWithImageId(ramdiskId));
        tx.commit();
    } catch (Exception e) {
        LOG.error("Ramdisk '" + ramdiskId + "' does not exist" + e);
        throw new NoSuchElementException("InvalidAMIID.NotFound");
    } finally {
        if (tx.isActive())
            tx.rollback();
    }
    return ret;
}