Example usage for java.lang String getClass

List of usage examples for java.lang String getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ch.cyberduck.core.LocalFactory.java

protected Local create(final String path) {
    final String clazz = PreferencesFactory.get().getProperty("factory.local.class");
    if (null == clazz) {
        throw new FactoryException(
                String.format("No implementation given for factory %s", this.getClass().getSimpleName()));
    }//from   w w  w.  j ava2s.com
    try {
        final Class<Local> name = (Class<Local>) Class.forName(clazz);
        final Constructor<Local> constructor = ConstructorUtils.getMatchingAccessibleConstructor(name,
                path.getClass());
        return constructor.newInstance(path);
    } catch (InstantiationException | InvocationTargetException | ClassNotFoundException
            | IllegalAccessException e) {
        throw new FactoryException(e.getMessage(), e);
    }
}

From source file:ch.cyberduck.core.LocalFactory.java

protected Local create(final Local parent, final String path) {
    final String clazz = PreferencesFactory.get().getProperty("factory.local.class");
    if (null == clazz) {
        throw new FactoryException(
                String.format("No implementation given for factory %s", this.getClass().getSimpleName()));
    }//from  ww  w .  j a v  a 2 s .c o  m
    try {
        final Class<Local> name = (Class<Local>) Class.forName(clazz);
        final Constructor<Local> constructor = ConstructorUtils.getMatchingAccessibleConstructor(name,
                parent.getClass(), path.getClass());
        return constructor.newInstance(parent, path);
    } catch (InstantiationException | InvocationTargetException | ClassNotFoundException
            | IllegalAccessException e) {
        throw new FactoryException(e.getMessage(), e);
    }
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

static Double getJSR77Statistic(MBeanServerConnection mServer, ObjectName objName, String attribute)
        throws MalformedURLException, MalformedObjectNameException, IOException, MBeanException,
        AttributeNotFoundException, InstanceNotFoundException, ReflectionException, PluginException {

    Stats stats;//from   w  w w.j a va2 s  .  c  o m
    Boolean provider = (Boolean) mServer.getAttribute(objName, "statisticsProvider");
    if ((provider == null) || !provider.booleanValue()) {
        String msg = objName + " does not provide statistics";
        throw new PluginException(msg);
    }

    stats = (Stats) mServer.getAttribute(objName, "stats");

    if (stats == null) {
        throw new PluginException(objName + " has no stats");
    }

    String statName = attribute.substring(STATS_PREFIX.length());
    Statistic stat = stats.getStatistic(statName);
    if (stat == null) {
        String msg = "Statistic '" + statName + "' not found [" + objName + "]";
        throw new AttributeNotFoundException(msg);
    }

    long value;
    if (stat instanceof CountStatistic) {
        value = ((CountStatistic) stat).getCount();
    } else if (stat instanceof RangeStatistic) {
        value = ((RangeStatistic) stat).getCurrent();
    } else if (stat instanceof TimeStatistic) {
        // get the average time
        long count = ((TimeStatistic) stat).getCount();
        if (count == 0)
            value = 0;
        else
            value = ((TimeStatistic) stat).getTotalTime() / count;
    } else {
        String msg = "Unsupported statistic type [" + statName.getClass().getName() + " for [" + objName + ":"
                + attribute + "]";
        throw new MetricInvalidException(msg);
    }

    //XXX: handle bug with geronimo uptime metric
    if (statName.equals("UpTime")) {
        value = System.currentTimeMillis() - value;
    }

    return new Double(value);
}

From source file:org.springframework.extensions.webscripts.connector.ConnectorService.java

/**
 * Internal method for building a Connector.
 * /*w  w w  .  ja  v  a  2 s  .co  m*/
 * Connectors are not cached.  A new Connector will be constructed each time.
 * 
 * @param descriptor the descriptor
 * @param url the url
 * 
 * @return the connector
 */
private Connector buildConnector(ConnectorDescriptor descriptor, String url) {
    Class[] argTypes = new Class[] { descriptor.getClass(), url.getClass() };
    Object[] args = new Object[] { descriptor, url };
    Connector conn = (Connector) ReflectionHelper.newObject(descriptor.getImplementationClass(), argTypes,
            args);

    // Set the application context for the Connector object
    // TODO: connectors should be Spring beans, but due to legacy config they are constructed from class names
    if (conn instanceof ApplicationContextAware) {
        ((ApplicationContextAware) conn).setApplicationContext(applicationContext);
    }

    return conn;
}

From source file:org.amanzi.awe.properties.ui.views.internal.PropertyCellEditor.java

@Override
protected Object doGetValue() {
    String newValue = (String) super.doGetValue();
    if (castedObject != null && castedObject.toString().equals(newValue)) {
        return castedObject;
    }/*from  www.  j a v  a 2  s  .  c  o m*/
    try {
        if (oldValue.getClass().isArray()) {
            castedObject = performArrayCasting(newValue);
        } else {
            if (oldValue.getClass().equals(Character.class)) {
                castedObject = oldValue.getClass().cast(newValue);
            }
            castedObject = oldValue.getClass().getConstructor(newValue.getClass()).newInstance(newValue);
        }
    } catch (Exception e) {
        LOGGER.error("Error on casting value ", e);
        castedObject = newValue;
        return castedObject;
    }
    return castedObject;
}

From source file:org.agnitas.dao.impl.MailingDaoImpl.java

public String getAutoURL(int mailingID) {
    JdbcTemplate jdbc = new JdbcTemplate((DataSource) applicationContext.getBean("dataSource"));
    String sql = "select auto_url from mailing_tbl where mailing_id=?";

    try {//from w w  w.j  a  v  a2  s  .  c om
        return (String) jdbc.queryForObject(sql, new Object[] { new Integer(mailingID) }, sql.getClass());
    } catch (Exception e) {
        AgnUtils.logger().error("getAutoURL: " + e.getMessage());
    }
    return null;
}

From source file:cordova.plugin.RequestLocationAccuracy.java

private boolean hasPermission(String permission) throws Exception {
    boolean hasPermission = true;
    Method method = null;// www. j  a v  a  2  s. c o  m
    try {
        method = cordova.getClass().getMethod("hasPermission", permission.getClass());
        Boolean bool = (Boolean) method.invoke(cordova, permission);
        hasPermission = bool.booleanValue();
    } catch (NoSuchMethodException e) {
        Log.w(TAG, "Cordova v" + CordovaWebView.CORDOVA_VERSION
                + " does not support runtime permissions so defaulting to GRANTED for " + permission);
    }
    return hasPermission;
}

From source file:org.jaxygen.http.HttpRequestParser.java

@Override
public Object getAsEnum(String paramName, Class<?> enumClass, boolean mandatory)
        throws InvalidRequestParameter {
    Object rc = null;/*from   w  w w. j ava 2 s .c  om*/
    try {
        String value = null;
        Object v = parameters.get(paramName);
        if (v != null) {
            value = v.toString();
        }

        if (value != null && value.length() > 0) {
            Method m = enumClass.getDeclaredMethod("valueOf", value.getClass());
            rc = m.invoke(null, value);
        } else if (mandatory) {
            throw new InvalidRequestParameter("Missing mandatory parameter :" + paramName);
        }
    } catch (Exception e) {
        throw new InvalidRequestParameter("Could not determinalte value of parameter " + paramName
                + " for enum class " + enumClass.getName());
    }
    return rc;
}

From source file:ch.cyberduck.core.threading.ThreadPoolFactory.java

/**
 * @param size    Maximum pool size//w  ww  .  j  ava  2s .co  m
 * @param handler Uncaught thread exception handler
 */
protected ThreadPool create(final String prefix, final Integer size,
        final Thread.UncaughtExceptionHandler handler) {
    final String clazz = PreferencesFactory.get().getProperty("factory.threadpool.class");
    if (null == clazz) {
        throw new FactoryException(
                String.format("No implementation given for factory %s", this.getClass().getSimpleName()));
    }
    try {
        final Class<ThreadPool> name = (Class<ThreadPool>) Class.forName(clazz);
        final Constructor<ThreadPool> constructor = ConstructorUtils.getMatchingAccessibleConstructor(name,
                prefix.getClass(), size.getClass(), handler.getClass());
        if (null == constructor) {
            log.warn(String.format("No matching constructor for parameter %s", handler.getClass()));
            // Call default constructor for disabled implementations
            return name.newInstance();
        }
        return constructor.newInstance(prefix, size, handler);
    } catch (InstantiationException | InvocationTargetException | ClassNotFoundException
            | IllegalAccessException e) {
        throw new FactoryException(e.getMessage(), e);
    }
}

From source file:org.lambdamatic.internal.elasticsearch.codec.DocumentCodec.java

/**
 * Sets the given {@code documentId} value to the given {@code domainObject} using the setter for
 * the property annotated with the {@link DocumentIdField} annotation.
 * /*from   www .j  a  va 2  s . co  m*/
 * @param domainObject the instance of DomainType on which to set the {@code id} property
 * @param documentId the value of the document id.
 */
public void setDomainObjectId(final T domainObject, final String documentId) {
    final Field idField = getIdField(domainObject.getClass());
    final PropertyDescriptor idPropertyDescriptor = getIdPropertyDescriptor(domainObject, idField);
    try {
        idPropertyDescriptor.getWriteMethod().invoke(domainObject, convertValue(documentId, idField.getType()));
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new CodecException("Failed to set value '" + documentId + "' (" + documentId.getClass().getName()
                + ") using method '" + idPropertyDescriptor.getWriteMethod().toString() + "'");
    }
}