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:org.xsystem.bpmn2.formats.xml.EnumConverter.java

@Override
public <T> T convert(Class<T> tClass, Object o) {
    String enumValName = (String) o;
    Enum[] enumConstants = (Enum[]) tClass.getEnumConstants();

    for (Enum enumConstant : enumConstants) {
        if (enumConstant.name().equals(enumValName)) {
            return (T) enumConstant;
        }//from  w w w.ja  v  a  2 s .c  o  m
    }

    throw new ConversionException(
            String.format("Failed to convert %s value to %s class", enumValName, tClass.toString()));
}

From source file:org.kalypso.core.catalog.CatalogManager.java

public synchronized void register(final IURNGenerator urnGenerator) {
    final Class<?> key = urnGenerator.getSupportingClass();
    if (m_urnGenerators.containsKey(key))
        throw new UnsupportedOperationException(
                Messages.getString("org.kalypso.core.catalog.CatalogManager.0") + key.toString()); //$NON-NLS-1$
    m_urnGenerators.put(key, urnGenerator);
}

From source file:org.apache.axis2.jaxws.WebServiceExceptionLogger.java

/**
 * Logs an error if the exception thrown by @WebMethod m is not a checked exception.
 * If debug logging is enabled, all exceptions are logged.
 * @param method//from   w w  w .ja  va 2s .  co m
 * @param throwable
 * @param logFully (if true then the exception is logged, otherwise only the class and stack is logged)
 * @param serviceImplClass class of service implementation
 * @param serviceInstance 
 * @param args Object[] arguments pass to method
 */
public static void log(Method method, Throwable throwable, boolean logFully, Class serviceImplClass,
        Object serviceInstance, Object[] args) {

    // Must have debug or error logging enabled
    if (!log.isDebugEnabled() && !log.isErrorEnabled()) {
        return;
    }

    // Get the root of the exception
    Throwable rootT = null;
    if (throwable instanceof InvocationTargetException) {
        rootT = ((InvocationTargetException) throwable).getTargetException();
    }

    String name = rootT.getClass().getName();
    String stack = stackToString(rootT);

    // Determine if this is a checked exception or non-checked exception
    Class checkedException = JavaUtils.getCheckedException(rootT, method);

    if (checkedException == null) {
        // Only log errors for non-checked exceptions
        if (log.isErrorEnabled()) {
            String text = "";
            if (logFully) {
                text = Messages.getMessage("failureLogger", name, rootT.toString());

            } else {
                text = Messages.getMessage("failureLogger", name, stack);
            }
            log.error(text);
        }

    }

    // Full logging if debug is enabled.
    if (log.isDebugEnabled()) {
        log.debug("Exception invoking a method of " + serviceImplClass.toString() + " of instance "
                + serviceInstance.toString());
        log.debug("Exception type thrown: " + throwable.getClass().getName());
        if (rootT != null) {
            log.debug("Root Exception type thrown: " + rootT.getClass().getName());
        }
        if (checkedException != null) {
            log.debug("The exception is an instance of checked exception: " + checkedException.getName());
        }

        // Extra trace if ElementNSImpl incompatibility problem.
        // The incompatibility exception occurs if the JAXB Unmarshaller 
        // unmarshals to a dom element instead of a generated object.  This can 
        // result in class cast exceptions.  The solution is usually a missing
        // @XmlSeeAlso annotation in the jaxws or jaxb classes. 
        if (rootT.toString().contains("org.apache.xerces.dom.ElementNSImpl incompatible")) {
            log.debug("This exception may be due to a missing @XmlSeeAlso in the client's jaxws or"
                    + " jaxb classes.");
        }
        log.debug("Method = " + method.toGenericString());
        for (int i = 0; i < args.length; i++) {
            String value = (args[i] == null) ? "null" : args[i].getClass().toString();
            log.debug(" Argument[" + i + "] is " + value);
        }
    }
    return;

}

From source file:nz.org.take.r2ml.R2MLDriver.java

/**
 * @param key/*from  w ww .  j  av a  2 s. c  om*/
 * @return
 * @throws R2MLException
 */
public XmlTypeHandler getHandlerByXmlType(Class<? extends java.lang.Object> key) {

    XmlTypeHandler handler = typeHandler.get(key);
    if (logger.isDebugEnabled() && (handler == null)) {
        logger.warn("XmlTypeHandler not found for " + key.toString());
    }
    if (handler == null)
        throw new NullPointerException("There must be a handler for class " + key.getCanonicalName());
    return handler;

}

From source file:org.eobjects.analyzer.descriptors.SimpleComponentDescriptor.java

@Override
public int compareTo(ComponentDescriptor<?> o) {
    if (o == null) {
        return 1;
    }/*w  ww .  jav  a  2  s .  c  o m*/
    Class<?> otherBeanClass = o.getComponentClass();
    if (otherBeanClass == null) {
        return 1;
    }
    String thisBeanClassName = this.getComponentClass().toString();
    String thatBeanClassName = otherBeanClass.toString();
    return thisBeanClassName.compareTo(thatBeanClassName);
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

public void switchToFragment(Class<? extends PhishBaseActivity> fragClass, Bundle arguments) {
    PhishBaseActivity newFrag;/* w w w . j  av  a  2 s . c  o m*/
    try {
        if (!fragCache.containsKey(fragClass.toString())) {
            PhishBaseActivity newinstance = fragClass.newInstance();
            addToFragCache(newinstance);
        }
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    newFrag = fragCache.get(fragClass.toString());

    if (newFrag.getArguments() != null) {
        newFrag.getArguments().clear();
        newFrag.getArguments().putAll(arguments);
    } else {
        newFrag.setArguments(arguments);
    }
    //TODO: commitAllowingStateLoss should not be needed.
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newFrag).commit();
    /**
     * ensure that we only run onswitchto when attached.
     * this is also called in PhishBaseActivity.onAttack() 
     */
    if (newFrag.getActivity() != null) {
        newFrag.onSwitchTo();
    }
    current_frag = newFrag.getClass().toString();
}

From source file:es.urjc.mctwp.bbeans.AbstractBean.java

/**
 * Return new instance of command identified by clazz
 * /*from  w ww. j a  v  a2 s  .  c  o m*/
 * @param clase
 * @return
 */
protected Command getCommand(Class<?> clazz) {
    Command command = null;

    //Build a new command using Web Application Context (wac)
    try {
        Constructor<?> c = clazz.getConstructor(BeanFactory.class);
        command = (Command) c.newInstance(wac);
    } catch (Exception e) {
        logger.error("Error creating new command [" + clazz.toString() + "] : " + e.getMessage());
    }

    return command;
}

From source file:PodbaseMetadataMigration2.java

public static <T extends AbstractEntry> List<T> parseFile(File f, Class<T> klass)
        throws IOException, InstantiationException, IllegalAccessException, InvocationTargetException,
        NoSuchMethodException, SecurityException {
    String fileContents = FileUtils.readFileToString(f);
    fileContents = fixFileContents(fileContents);

    List<T> entries = new LinkedList<T>();
    int i = 0;/*from  w  ww.j  a  v a  2 s .  co m*/
    int ignore = 0;
    for (String line : fileContents.split(RECORD_SEPARATOR, -1)) {
        i++;
        if (testMode && i > 10)
            break;
        if (line.trim().length() == 0)
            continue;

        String readable = line.replace(FIELD_SEPARATOR, "[###]");
        if (line.contains("Fatal error")) {
            ignore++;
            //System.out.println(klass.toString()+": Ignoring line "+i+": "+readable);
        }
        try {
            T entry = klass.getConstructor(String.class).newInstance(line);
            entries.add(entry);
        } catch (Exception e) {
            System.out.println(klass.toString() + ": Illegal entry on line " + i + ": " + readable + " ( "
                    + e.getMessage() + ")");
            //e.printStackTrace();
            return entries;
        }
    }
    if (ignore > 0)
        System.out.println("Ignored " + ignore + " entries");

    return entries;
}

From source file:uk.ac.cam.cl.dtg.segue.dao.content.ContentMapper.java

/**
 * Works the same as {@link #registerJsonTypeToDO(String, Class)}.
 * //w w  w  .j a va 2  s  . co m
 * @see #registerJsonTypeToDO(String, Class)
 * @param newTypes
 *            a map of types to merge with the segue type map. The classes added to the map must contain jsonType
 *            annotations and may contain DTOMapping annotations.
 */
public synchronized void registerJsonTypes(final List<Class<? extends Content>> newTypes) {
    Validate.notNull(newTypes, "New types map cannot be null");
    StringBuilder sb = new StringBuilder();
    sb.append("Adding new content Types to Segue: ");

    for (Class<? extends Content> contentClass : newTypes) {
        this.registerJsonTypeAndDTOMapping(contentClass);
        sb.append(contentClass.toString());
        sb.append(", ");
    }

    log.info(sb.toString());
}

From source file:org.apache.cayenne.modeler.action.ImportEOModelAction.java

protected void loadDataNode(Map eomodelIndex) {
    // if this is JDBC or JNDI node and connection dictionary is specified, load a
    // DataNode, otherwise ignore it (meaning that pre 5.* EOModels will not have a
    // node).//from  www  .j  a  v a  2s  . c  om

    String adapter = (String) eomodelIndex.get("adaptorName");
    Map connection = (Map) eomodelIndex.get("connectionDictionary");

    if (adapter != null && connection != null) {
        CreateNodeAction nodeBuilder = (CreateNodeAction) getApplication().getActionManager()
                .getAction(CreateNodeAction.class);

        // this should make created node current, resulting in the new map being added
        // to the node automatically once it is loaded
        DataNodeDescriptor node = nodeBuilder.buildDataNode();

        // configure node...
        if ("JNDI".equalsIgnoreCase(adapter)) {
            node.setDataSourceFactoryType(JNDIDataSourceFactory.class.getName());
            node.setParameters((String) connection.get("serverUrl"));
        } else {
            // guess adapter from plugin or driver
            AdapterMapping adapterDefaults = getApplication().getAdapterMapping();
            String cayenneAdapter = adapterDefaults.adapterForEOFPluginOrDriver(
                    (String) connection.get("plugin"), (String) connection.get("driver"));
            if (cayenneAdapter != null) {
                try {
                    Class<DbAdapter> adapterClass = getApplication().getClassLoadingService()
                            .loadClass(DbAdapter.class, cayenneAdapter);
                    node.setAdapterType(adapterClass.toString());
                } catch (Throwable ex) {
                    // ignore...
                }
            }

            node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());

            DataSourceInfo dsi = node.getDataSourceDescriptor();

            dsi.setDataSourceUrl(keyAsString(connection, "URL"));
            dsi.setJdbcDriver(keyAsString(connection, "driver"));
            dsi.setPassword(keyAsString(connection, "password"));
            dsi.setUserName(keyAsString(connection, "username"));
        }

        DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject()
                .getRootNode();
        domain.getNodeDescriptors().add(node);

        // send events after the node creation is complete
        getProjectController().fireDataNodeEvent(new DataNodeEvent(this, node, MapEvent.ADD));
        getProjectController().fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this,
                (DataChannelDescriptor) getProjectController().getProject().getRootNode(), node));
    }
}