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.debux.webmotion.server.render.RenderException.java

@Override
public void create(Mapping mapping, Call call) throws IOException, ServletException {
    HttpContext context = call.getContext();
    ErrorData errorData = context.getErrorData();

    // Request/* ww w.j av a 2  s.co m*/
    HttpServletRequest request = context.getRequest();
    model.put("request", request);
    model.put("requestParameters", request.getParameterMap());
    model.put("requestAttributes", getRequestAttributes(request));
    model.put("requestHeaders", getRequestHeaders(request));

    // Session
    HttpSession session = context.getSession();
    model.put("session", session);
    model.put("sessionAttributes", getSessionAttributes(session));

    // ServerContext
    ServerContext serverContext = context.getServerContext();
    model.put("serverContextAttributes", serverContext.getAttributes());

    // Servlet context
    ServletContext servletContext = context.getServletContext();
    model.put("servletContextAttributes", getServletContextAttributes(servletContext));

    // Message
    String message = errorData.getMessage();
    model.put("message", message);

    // Uri
    String uri = errorData.getRequestUri();
    if (uri == null) {
        uri = request.getRequestURI(); // in case there's no URI given
    }
    model.put("uri", uri);

    // The error reason is either the status code or exception type
    Class<?> type = errorData.getExceptionType();
    Integer code = errorData.getStatusCode();
    String reason = code != null ? "Error " + code.toString() : type.toString();
    model.put("reason", reason);

    // Get the stack trace
    StringWriter trace = new StringWriter();
    PrintWriter printTrace = new PrintWriter(trace);
    Throwable throwable = errorData.getException();
    if (throwable != null) {
        throwable.printStackTrace(printTrace);
    }
    model.put("trace", trace.toString());

    // Get exception
    if (throwable instanceof WebMotionException) {
        WebMotionException exception = (WebMotionException) throwable;

        Rule rule = exception.getRule();
        if (rule != null) {
            String name = rule.getMapping().getName();
            int line = rule.getLine();

            URL url = new URL(name);
            InputStream stream = url.openStream();
            List<String> readLines = IOUtils.readLines(stream);
            String content = readLines.get(line - 1);

            model.put("mappingName", name);
            model.put("mappingLine", line);
            model.put("mappingContent", content);
        }
    }

    // System properties
    model.put("system", System.getProperties());

    super.create(mapping, call);
}

From source file:org.apache.hama.bsp.PartitioningRunner.java

@SuppressWarnings("rawtypes")
public Partitioner getPartitioner() {
    Class<? extends Partitioner> partitionerClass = conf.getClass(Constants.RUNTIME_PARTITIONING_CLASS,
            HashPartitioner.class, Partitioner.class);

    LOG.debug(Constants.RUNTIME_PARTITIONING_CLASS + ": " + partitionerClass.toString());

    // Check for Hama Pipes Partitioner
    Partitioner partitioner = null;/*from w w w  .  ja va2s  .co  m*/
    if (PipesPartitioner.class.equals(partitionerClass)) {
        try {
            Constructor<? extends Partitioner> ctor = partitionerClass.getConstructor(Configuration.class);
            partitioner = ctor.newInstance(conf);
            this.pipesPartitioner = (PipesPartitioner) partitioner;
        } catch (Exception e) {
            LOG.error(e);
        }
    } else {
        partitioner = ReflectionUtils.newInstance(partitionerClass, conf);
    }
    return partitioner;
}

From source file:org.riksa.a3.fragment.KeyListFragment.java

private <T extends View> T findView(Class<? extends View> clazz, int id) {
    View view = getActivity().findViewById(id);
    if (view != null && view.getClass().isAssignableFrom(clazz)) {
        return (T) view;
    }//  www .ja  va2 s  . co  m
    log.error("Cannot find view of class {} with id {}", clazz.toString(), id);
    return null;
}

From source file:org.malaguna.cmdit.service.CommandRunner.java

/**
 * Dada una clase de un comando, instancia el mismo apropiadamente 
 * /*from  www  . j ava  2s  . c o  m*/
 * @param clazz
 * @return
 */
protected Command createCommand(Class<? extends Command> clazz) {
    Command comand = null;

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

    return comand;
}

From source file:com.github.juanmf.java2plant.render.PlantRenderer.java

protected void addClass(StringBuilder sb, Class<?> aClass) {
    String classDeclaration = aClass.isEnum() ? "enum " + aClass.getName() : aClass.toString();
    sb.append(classDeclaration);//from   w  w w  .j  a  v a 2s . com
    addClassTypeParams(sb, aClass);
    sb.append(" {\n");
    renderClassMembers(sb, aClass);
    sb.append("\n}\n");
}

From source file:org.apache.crunch.impl.mr.exec.MRExecutor.java

public MRExecutor(Configuration conf, Class<?> jarClass, Map<PCollectionImpl<?>, Set<Target>> outputTargets,
        Map<PCollectionImpl<?>, MaterializableIterable> toMaterialize) {
    this.control = new CrunchJobControl(conf, jarClass.toString());
    this.outputTargets = outputTargets;
    this.toMaterialize = toMaterialize;
    this.monitorThread = new Thread(new Runnable() {
        @Override/*from   w  w  w  .j av  a  2 s.  co m*/
        public void run() {
            monitorLoop();
        }
    });
    this.pollInterval = isLocalMode() ? new CappedExponentialCounter(50, 1000)
            : new CappedExponentialCounter(500, 10000);
}

From source file:ru.savvy.springjsf.system.CustomJsfInjectionProvider.java

private void injectFields(Object bean, Class<? extends Annotation> annotation)
        throws InjectionProviderException {
    // get current WebApplicationContext
    FacesContext fc = FacesContext.getCurrentInstance();
    if (fc == null) {
        throw new InjectionProviderException("Unable to get current Faces context",
                new NullPointerException("Faces context is null"));
    }/*  w ww. j ava 2s. com*/
    WebApplicationContext wac = FacesContextUtils.getWebApplicationContext(fc);
    if (wac == null) {
        throw new InjectionProviderException("Unable to get Spring WebApplicationContext",
                new NullPointerException("WebApplicationContext is null"));
    }
    Field[] fields = bean.getClass().getDeclaredFields();
    for (Field f : fields) {
        if (f.getAnnotationsByType(annotation).length > 0) {
            Class<?> typeClazz = f.getType();
            Object injection;
            try {
                injection = wac.getBean(typeClazz);
            } catch (NoSuchBeanDefinitionException e) {
                e.printStackTrace();
                throw new InjectionProviderException("Unable to inject bean of type " + typeClazz.toString(),
                        e);
            }
            if (!f.isAccessible()) {
                f.setAccessible(true);
            }
            try {
                f.set(bean, injection);
                if (logger.isDebugEnabled()) {
                    logger.debug("Injected field of type " + f.getType().getCanonicalName() + " into "
                            + bean.getClass().getCanonicalName());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

}

From source file:com.edmunds.etm.common.impl.ObjectSerializer.java

/**
 * Reads a value object from a byte array.
 *
 * @param src       the byte array to read
 * @param valueType the value object's Java class
 * @param <T>       value type//from  w  w w  . j  a v  a  2 s  .c  om
 * @return deserialized object
 * @throws java.io.IOException if deserialization failed
 */
public <T extends TBase> T readValue(byte[] src, Class<T> valueType) throws IOException {

    Validate.notNull(src, "Source byte array is null");
    Validate.notNull(valueType, "Value type is null");

    T value;
    try {
        value = valueType.newInstance();
    } catch (Exception e) {
        String message = String.format("Unable to instantiate object of type %s", valueType.toString());
        throw new IllegalArgumentException(message, e);
    }

    try {
        deserializer.deserialize(value, src);
    } catch (TException e) {
        throw new IOException(e);
    }
    return value;
}

From source file:org.jgentleframework.utils.ReflectUtils.java

/**
 * Creates {@link AnnotationMetadata} object.
 * /*  w  ww  .j a va2s. co  m*/
 * @param annos
 *            annotation instance need to be create to
 *            {@link AnnotationMetadata}
 * @param container
 *            the parrent {@link AnnotationMetadata} of returned
 *            {@link AnnotationMetadata}
 * @param definitionManager
 *            the {@link DefinitionManager} instance
 * @return AnnotationMetadata
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws IllegalArgumentException
 *             the illegal argument exception
 */
public static AnnotationMetadata buildAnnoMeta(Annotation annos, AnnotationMetadata container,
        DefinitionManager definitionManager)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {

    AnnotationMetadata thisMeta = null;
    Class<?> clazz = annos.annotationType();
    Method[] methods = clazz.getDeclaredMethods();
    thisMeta = MetaDataFactory.createAnnotationMetadata(clazz, annos, container, clazz.toString());
    if (methods.length > 0) {
        for (Method obj : methods) {
            Object value = null;
            obj.setAccessible(true);
            value = obj.invoke(annos);
            Metadata part = null;
            part = MetaDataFactory.createMetaData(obj.getName(), value);
            /*
             * ?a list sub annotationMetadata va c to vo trong
             * annotationMetadata hin hnh
             */
            thisMeta.putMetaData(part);
        }
    }
    /*
     * add annotationMetadata vo container (annotationMetadata cha ch n)
     */
    container.putMetaData(thisMeta);
    return thisMeta;
}

From source file:org.apache.streams.plugins.StreamsScalaSourceGenerator.java

@Override
public void run() {

    List<Class<?>> serializableClasses = detectSerializableClasses();

    LOGGER.info("Detected {} serialiables:", serializableClasses.size());
    for (Class clazz : serializableClasses) {
        LOGGER.debug(clazz.toString());
    }/*from w w  w.ja va2  s. c o m*/

    List<Class<?>> pojoClasses = detectPojoClasses(serializableClasses);

    LOGGER.info("Detected {} pojos:", pojoClasses.size());
    for (Class clazz : pojoClasses) {
        LOGGER.debug(clazz.toString());
    }

    List<Class<?>> traits = detectTraits(pojoClasses);

    LOGGER.info("Detected {} traits:", traits.size());
    for (Class clazz : traits) {
        LOGGER.debug(clazz.toString());
    }

    List<Class<?>> cases = detectCases(pojoClasses);

    LOGGER.info("Detected {} cases:", cases.size());
    for (Class clazz : cases) {
        LOGGER.debug(clazz.toString());
    }

    for (Class clazz : traits) {
        String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".", "/")
                + "/traits/";
        String pojoName = clazz.getSimpleName() + ".scala";
        String pojoScala = renderTrait(clazz);
        writeFile(outDir + "/" + pojoPath + pojoName, pojoScala);
    }

    for (Class clazz : traits) {
        String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".", "/") + "/";
        String pojoName = clazz.getSimpleName() + ".scala";
        String pojoScala = renderClass(clazz);
        writeFile(outDir + "/" + pojoPath + pojoName, pojoScala);
    }

    for (Class clazz : cases) {
        String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".", "/") + "/";
        String pojoName = clazz.getSimpleName() + ".scala";
        String pojoScala = renderCase(clazz);
        writeFile(outDir + "/" + pojoPath + pojoName, pojoScala);
    }

}