Example usage for java.lang Class toString

List of usage examples for java.lang Class toString

Introduction

In this page you can find the example usage for java.lang Class toString.

Prototype

public String toString() 

Source Link

Document

Converts the object to a string.

Usage

From source file:com.apdplat.platform.struts.APDPlatPackageBasedActionConfigBuilder.java

/**
 * Creates a single ActionConfig object.
 *
 * @param pkgCfg       The package the action configuration instance will belong to.
 * @param actionClass  The action class.
 * @param actionName   The name of the action.
 * @param actionMethod The method that the annotation was on (if the annotation is not null) or
 *                     the default method (execute).
 * @param annotation   The ActionName annotation that might override the action name and possibly
 */// ww  w  . ja  v a  2s  .  c o  m
protected void createActionConfig(PackageConfig.Builder pkgCfg, Class<?> actionClass, String actionName,
        String actionMethod, Action annotation) {
    if (annotation != null) {
        actionName = annotation.value() != null && annotation.value().equals(Action.DEFAULT_VALUE) ? actionName
                : annotation.value();
        actionName = StringUtils.contains(actionName, "/") ? StringUtils.substringAfterLast(actionName, "/")
                : actionName;
    }

    ActionConfig.Builder actionConfig = new ActionConfig.Builder(pkgCfg.getName(), actionName,
            actionClass.getName());
    actionConfig.methodName(actionMethod);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating action config for class [" + actionClass.toString() + "], name [" + actionName
                + "] and package name [" + pkgCfg.getName() + "] in namespace [" + pkgCfg.getNamespace() + "]");
    }

    //build interceptors
    List<InterceptorMapping> interceptors = interceptorMapBuilder.build(actionClass, pkgCfg, actionName,
            annotation);
    actionConfig.addInterceptors(interceptors);

    //build results
    Map<String, ResultConfig> results = resultMapBuilder.build(actionClass, annotation, actionName,
            pkgCfg.build());
    actionConfig.addResultConfigs(results);

    //add params
    if (annotation != null)
        actionConfig.addParams(StringTools.createParameterMap(annotation.params()));

    //add exception mappings from annotation
    if (annotation != null && annotation.exceptionMappings() != null)
        actionConfig.addExceptionMappings(buildExceptionMappings(annotation.exceptionMappings(), actionName));

    //add exception mapping from class
    ExceptionMappings exceptionMappings = actionClass.getAnnotation(ExceptionMappings.class);
    if (exceptionMappings != null)
        actionConfig.addExceptionMappings(buildExceptionMappings(exceptionMappings.value(), actionName));

    //add
    pkgCfg.addActionConfig(actionName, actionConfig.build());

    //check if an action with the same name exists on that package (from XML config probably)
    PackageConfig existingPkg = configuration.getPackageConfig(pkgCfg.getName());
    if (existingPkg != null) {
        // there is a package already with that name, check action
        ActionConfig existingActionConfig = existingPkg.getActionConfigs().get(actionName);
        if (existingActionConfig != null && LOG.isWarnEnabled())
            LOG.warn("Duplicated action definition in package [#0] with name [#1].", pkgCfg.getName(),
                    actionName);
    }

    //watch class file
    if (isReloadEnabled()) {
        URL classFile = actionClass.getResource(actionClass.getSimpleName() + ".class");
        FileManager.loadFile(classFile, false);
        loadedFileUrls.add(classFile.toString());
    }
}

From source file:org.eclipse.winery.repository.importing.CSARImporter.java

private TDefinitions createDefinitionsByThirdparty(final List<String> errors, Path defsPath) {
    TDefinitions defs = null;//from w  ww.  ja  va 2s.c  o m
    try {
        Reflections reflections = new Reflections("org.eclipse.winery.repository.ext");
        Set<Class<? extends DefinitionGenerator>> implenmetions = reflections
                .getSubTypesOf(org.eclipse.winery.repository.ext.imports.custom.DefinitionGenerator.class);
        Iterator<Class<? extends DefinitionGenerator>> it = implenmetions.iterator();
        while (it.hasNext()) {
            Class<? extends DefinitionGenerator> impl = it.next();
            if (!Modifier.isAbstract(impl.getModifiers())) {
                DefinitionGenerator generator = impl.newInstance();
                if (generator.accept(defsPath)) {
                    try {
                        defs = generator.makeDefinitions(defsPath);
                    } catch (Exception e) {
                        CSARImporter.logger.error("error occurs while make defintions by: " + impl.toString());
                        continue;
                    }
                } else
                    CSARImporter.logger
                            .info(impl.toString() + " refuse to deal with file: " + defsPath.getFileName());
            }
        }

    } catch (Exception e) {
        errors.add("Could not parse definitions " + defsPath.getFileName() + " ");
        CSARImporter.logger.debug("parse error", e);
    }
    return defs;
}

From source file:org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase.java

/**
 * This method tests to make sure the MaintenanceDocument passed in is based on the class you are expecting.
 *
 * It does this based on the NewMaintainableObject of the MaintenanceDocument.
 *
 * @param document - MaintenanceDocument instance you want to test
 * @param clazz - class you are expecting the MaintenanceDocument to be based on
 * @return true if they match, false if not
 *//* w  w w.j a  v a 2 s .c o  m*/
protected boolean isCorrectMaintenanceClass(MaintenanceDocument document, Class clazz) {

    // disallow null arguments
    if (document == null || clazz == null) {
        throw new IllegalArgumentException("Null arguments were passed in.");
    }

    // compare the class names
    if (clazz.toString().equals(document.getNewMaintainableObject().getDataObjectClass().toString())) {
        return true;
    } else {
        return false;
    }
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public void draw(Object... objects) {
    ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>();

    if ((objects == null) || (objects[0] == null))
        return;//from ww w  . j av a2 s.c  om

    Class clazz = objects[0].getClass();

    if (clazz == VersatileTimeSeries.class) {
        ArrayList<VersatileTimeSeries> atsArray = new ArrayList<VersatileTimeSeries>();

        for (Object o : objects) {
            VersatileTimeSeries ats = (VersatileTimeSeries) o;
            atsArray.add(ats);
        }

        charts.add(drawTimeSeries(atsArray));
    } else if (clazz == VersatileTimeSeriesCollection.class) {
        ArrayList<VersatileTimeSeriesCollection> atscArray = new ArrayList<VersatileTimeSeriesCollection>();

        for (Object o : objects) {
            VersatileTimeSeriesCollection atsc = (VersatileTimeSeriesCollection) o;
            atscArray.add(atsc);
        }

        charts.add(drawTimeSeriesCollections(atscArray));
    } else if (clazz == VersatileDataTable.class) {
        //            ArrayList<VersatileDataTable> acdsArray = new ArrayList<VersatileDataTable>();
        //            
        //            for (Object o : objects) {
        //                VersatileDataTable acds = (VersatileDataTable) o;
        //                acdsArray.add(acds);
        //            }
        //            
        //            charts.addAll((drawCategoryDatasets(atscArray));            
    } else
        Assertion.assertStrict(false, Assertion.Level.ERR,
                "Class '" + clazz.toString() + "' currently not supported by VersatileChart");

    for (JFreeChart chart : charts) {
        ChartFrame frame = new ChartFrame("UNKNOWN", chart);
        frame.pack();
        frame.setVisible(true);
    }

    //      frame.getContentPane().setLayout(new GridLayout(numRows, numCols));
    //      frame.getContentPane().add(barChart);
    //      frame.getContentPane().add(pieChart);
}

From source file:org.mitre.dsmiley.httpproxy.ProxyServletTest.java

@SuppressWarnings({ "unchecked" })
private <M> M makeMethodRequest(String incomingUrl, Class<M> clazz) {
    log.info("Making request to url " + incomingUrl);
    final String url = rewriteMakeMethodUrl(incomingUrl);
    String urlNoQuery;/*w  w w  .  jav  a2  s .  c  om*/
    final String queryString;
    int qIdx = url.indexOf('?');
    if (qIdx == -1) {
        urlNoQuery = url;
        queryString = null;
    } else {
        urlNoQuery = url.substring(0, qIdx);
        queryString = url.substring(qIdx + 1);

    }
    //WARNING: Ugly! Groovy could do this better.
    if (clazz == PostMethodWebRequest.class) {
        return (M) new PostMethodWebRequest(urlNoQuery) {
            @Override
            public String getQueryString() {
                return queryString;
            }

            @Override
            protected String getURLString() {
                return url;
            }
        };
    } else if (clazz == GetMethodWebRequest.class) {
        return (M) new GetMethodWebRequest(urlNoQuery) {
            @Override
            public String getQueryString() {
                return queryString;
            }

            @Override
            protected String getURLString() {
                return url;
            }
        };
    }
    throw new IllegalArgumentException(clazz.toString());
}

From source file:de.damdi.fitness.activity.settings.sync.WgerJSONParser.java

/**
 * A generic parsing method for parsing JSON to SportsEquipment, Muscle or Locale.
 *//*from  w  ww  . ja v a 2s  .c om*/
private <T> SparseArray<T> parse(String jsonString, Class<T> c) throws JSONException {
    JSONObject mainObject = new JSONObject(jsonString);
    Log.d(TAG, "jsonString: " + mainObject.toString());
    JSONArray mainArray = mainObject.getJSONArray("objects");

    SparseArray<T> sparseArray = new SparseArray<T>();

    // parse each exercise of the JSON Array
    for (int i = 0; i < mainArray.length(); i++) {
        JSONObject singleObject = mainArray.getJSONObject(i);

        Integer id = singleObject.getInt("id");
        Object parsedObject;
        if (c.equals(Muscle.class)) {
            // handle Muscles
            String name = singleObject.getString("name");
            parsedObject = mDataProvider.getMuscleByName(name);

            if (parsedObject == null)
                Log.e(TAG, "Could not find Muscle: " + name);

        } else if (c.equals(SportsEquipment.class)) {
            // handle SportsEquipment
            String name = singleObject.getString("name");
            parsedObject = mDataProvider.getEquipmentByName(name);

            if (parsedObject == null)
                Log.e(TAG, "Could not find SportsEquipment: " + name);

        } else if (c.equals(Locale.class)) {
            // handle Locales
            String short_name = singleObject.getString("short_name");
            parsedObject = new Locale(short_name);

            if (parsedObject == null)
                Log.e(TAG, "Could not find Locale.class: " + short_name);

        } else {
            throw new IllegalStateException(
                    "parse(String, Class<T>) cannot be applied for class: " + c.toString());
        }

        sparseArray.put(id, (T) parsedObject);

    }

    return sparseArray;
}

From source file:org.apache.axis.client.Call.java

/** Register a Transport that should be used for URLs of the specified
 * protocol./*from   w w w. j av a2 s .  c o m*/
 *
 * Note: Not part of JAX-RPC specification.
 *
 * @param protocol the URL protocol (i.e. "tcp" for "tcp://" urls)
 * @param transportClass the class of a Transport type which will be used
 *                       for matching URLs.
 */
public static void setTransportForProtocol(String protocol, Class transportClass) {
    if (Transport.class.isAssignableFrom(transportClass)) {
        transports.put(protocol, transportClass);
    } else {
        throw new InternalException(transportClass.toString());
    }
}

From source file:io.realm.Realm.java

private void checkHasPrimaryKey(Class<? extends RealmObject> clazz) {
    if (!getTable(clazz).hasPrimaryKey()) {
        throw new IllegalArgumentException(
                "A RealmObject with no @PrimaryKey cannot be updated: " + clazz.toString());
    }/*from  ww  w  .  ja v  a 2s. com*/
}

From source file:org.apache.hadoop.hbase.regionserver.HRegionServer.java

/**
 * Utility for constructing an instance of the passed HRegionServer class.
 *
 * @param regionServerClass//from w  ww  .  java  2 s.c om
 * @param conf2
 * @return HRegionServer instance.
 */
public static HRegionServer constructRegionServer(Class<? extends HRegionServer> regionServerClass,
        final Configuration conf2, CoordinatedStateManager cp) {
    try {
        Constructor<? extends HRegionServer> c = regionServerClass.getConstructor(Configuration.class,
                CoordinatedStateManager.class);
        return c.newInstance(conf2, cp);
    } catch (Exception e) {
        throw new RuntimeException("Failed construction of " + "Regionserver: " + regionServerClass.toString(),
                e);
    }
}

From source file:org.apache.struts2.convention.PackageBasedActionConfigBuilder.java

/**
 * Creates a single ActionConfig object.
 *
 * @param pkgCfg       The package the action configuration instance will belong to.
 * @param actionClass  The action class.
 * @param actionName   The name of the action.
 * @param actionMethod The method that the annotation was on (if the annotation is not null) or
 *                     the default method (execute).
 * @param annotation   The ActionName annotation that might override the action name and possibly
 *//*from www  .  j  av a 2s . c  o m*/
protected void createActionConfig(PackageConfig.Builder pkgCfg, Class<?> actionClass, String actionName,
        String actionMethod, Action annotation) {
    String className = actionClass.getName();
    if (annotation != null) {
        actionName = annotation.value() != null && annotation.value().equals(Action.DEFAULT_VALUE) ? actionName
                : annotation.value();
        actionName = StringUtils.contains(actionName, "/") && !slashesInActionNames
                ? StringUtils.substringAfterLast(actionName, "/")
                : actionName;
        if (!Action.DEFAULT_VALUE.equals(annotation.className())) {
            className = annotation.className();
        }
    }

    ActionConfig.Builder actionConfig = new ActionConfig.Builder(pkgCfg.getName(), actionName, className);
    actionConfig.methodName(actionMethod);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating action config for class [#0], name [#1] and package name [#2] in namespace [#3]",
                actionClass.toString(), actionName, pkgCfg.getName(), pkgCfg.getNamespace());
    }

    //build interceptors
    List<InterceptorMapping> interceptors = interceptorMapBuilder.build(actionClass, pkgCfg, actionName,
            annotation);
    actionConfig.addInterceptors(interceptors);

    //build results
    Map<String, ResultConfig> results = resultMapBuilder.build(actionClass, annotation, actionName,
            pkgCfg.build());
    actionConfig.addResultConfigs(results);

    //add params
    if (annotation != null)
        actionConfig.addParams(StringTools.createParameterMap(annotation.params()));

    //add exception mappings from annotation
    if (annotation != null && annotation.exceptionMappings() != null)
        actionConfig.addExceptionMappings(buildExceptionMappings(annotation.exceptionMappings(), actionName));

    //add exception mapping from class
    ExceptionMappings exceptionMappings = actionClass.getAnnotation(ExceptionMappings.class);
    if (exceptionMappings != null)
        actionConfig.addExceptionMappings(buildExceptionMappings(exceptionMappings.value(), actionName));

    //add
    pkgCfg.addActionConfig(actionName, actionConfig.build());

    //check if an action with the same name exists on that package (from XML config probably)
    PackageConfig existingPkg = configuration.getPackageConfig(pkgCfg.getName());
    if (existingPkg != null) {
        // there is a package already with that name, check action
        ActionConfig existingActionConfig = existingPkg.getActionConfigs().get(actionName);
        if (existingActionConfig != null && LOG.isWarnEnabled())
            LOG.warn("Duplicated action definition in package [#0] with name [#1].", pkgCfg.getName(),
                    actionName);
    }

    //watch class file
    if (isReloadEnabled()) {
        URL classFile = actionClass.getResource(actionClass.getSimpleName() + ".class");
        fileManager.monitorFile(classFile);
        loadedFileUrls.add(classFile.toString());
    }
}