List of usage examples for org.apache.commons.lang ClassUtils getShortClassName
public static String getShortClassName(String className)
Gets the class name minus the package name from a String.
The string passed in is assumed to be a class name - it is not checked.
From source file:org.apache.click.util.ContainerUtils.java
/** * Log a warning that the parent of the given control will be set to * the specified container.//from w w w . j av a2 s. c o m * * @param container the parent container * @param control the control which parent is being reset * @param currentParent the control current parent */ private static void logParentReset(Container container, Control control, Object currentParent) { HtmlStringBuffer message = new HtmlStringBuffer(); message.append("Changed "); message.append(ClassUtils.getShortClassName(control.getClass())); String controlId = control.getId(); if (controlId != null) { message.append("["); message.append(controlId); message.append("]"); } else { message.append("#"); message.append(control.hashCode()); } message.append(" parent from "); if (currentParent instanceof Page) { message.append(ClassUtils.getShortClassName(currentParent.getClass())); } else if (currentParent instanceof Container) { Container parentContainer = (Container) currentParent; message.append(ClassUtils.getShortClassName(parentContainer.getClass())); String parentId = parentContainer.getId(); if (parentId != null) { message.append("["); message.append(parentId); message.append("]"); } else { message.append("#"); message.append(parentContainer.hashCode()); } } message.append(" to "); message.append(ClassUtils.getShortClassName(container.getClass())); String id = container.getId(); if (id != null) { message.append("["); message.append(id); message.append("]"); } else { message.append("#"); message.append(container.hashCode()); } ClickUtils.getLogService().warn(message); }
From source file:org.apache.cocoon.util.log.CocoonLogFormatter.java
/** * Finds the class that has called Logger. *//*from w w w . j a v a 2s .c om*/ private String getClass(String format) { if (this.callStack != null) { Class[] stack = this.callStack.get(); // Traverse the call stack in reverse order until we find a Logger for (int i = stack.length - 1; i >= 0; i--) { if (this.logkitClass.isAssignableFrom(stack[i]) || this.loggerClass.isAssignableFrom(stack[i])) { // Found: the caller is the previous stack element String className = stack[i + 1].getName(); // Handle optional format if (TYPE_CLASS_SHORT_STR.equalsIgnoreCase(format)) { className = ClassUtils.getShortClassName(className); } return className; } } } // No callStack: can occur when running under SecurityManager, or // no logger found in call stack: can occur with AsyncLogTarget // where formatting takes place in a different thread. return "Unknown-Class"; }
From source file:org.apache.cocoon.util.log.XMLCocoonLogFormatter.java
/** * Finds the class that has called Logger. *///from ww w. j a va 2 s. c o m private String getClass(int format) { Class[] stack = this.callStack.get(); // Traverse the call stack in reverse order until we find a Logger for (int i = stack.length - 1; i >= 0; i--) { if (this.loggerClass.isAssignableFrom(stack[i])) { // Found : the caller is the previous stack element String className = stack[i + 1].getName(); // Handle optional format if (format == TYPE_CLASS_SHORT) { className = ClassUtils.getShortClassName(className); } return className; } } // No Logger found in call stack : can occur with AsyncLogTarget // where formatting takes place in a different thread. return "Unknown-class"; }
From source file:org.apache.maven.plugins.help.EvaluateMojo.java
/** * @param expr the user expression.//from w w w .ja v a 2s . c om * @param obj a not null. * @return the XML for the given object. */ private String toXML(String expr, Object obj) { XStream currentXStream = getXStream(); // beautify list if (obj instanceof List) { List<?> list = (List<?>) obj; if (list.size() > 0) { Object elt = list.iterator().next(); String name = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(elt.getClass())); currentXStream.alias(pluralize(name), List.class); } else { // try to detect the alias from question if (expr.indexOf('.') != -1) { String name = expr.substring(expr.indexOf('.') + 1, expr.indexOf('}')); currentXStream.alias(name, List.class); } } } return currentXStream.toXML(obj); }
From source file:org.apache.maven.plugins.help.EvaluateMojo.java
/** * @param xstreamObject not null/*from w w w . j a v a 2 s . com*/ * @param jarFile not null * @param packageFilter a package name to filter. */ private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) { JarInputStream jarStream = null; try { jarStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry = jarStream.getNextJarEntry(); while (jarEntry != null) { if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) { String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf(".")); name = name.replaceAll("/", "\\."); if (name.contains(packageFilter)) { try { Class<?> clazz = ClassUtils.getClass(name); String alias = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(clazz)); xstreamObject.alias(alias, clazz); if (!clazz.equals(Model.class)) { xstreamObject.omitField(clazz, "modelEncoding"); // unnecessary field } } catch (ClassNotFoundException e) { getLog().error(e); } } } jarStream.closeEntry(); jarEntry = jarStream.getNextJarEntry(); } } catch (IOException e) { if (getLog().isDebugEnabled()) { getLog().debug("IOException: " + e.getMessage(), e); } } finally { IOUtil.close(jarStream); } }
From source file:org.apache.ojb.broker.metadata.PersistentFieldPerfTest.java
private void printResult(PersistentField pf, long getterPeriod, long setterPeriod, boolean nested) { System.out.println(ClassUtils.getShortClassName(pf.getClass()) + (nested ? ": nestedGetter=" : ": getter=") + getterPeriod + (nested ? " nestedSetter=" : " setter=") + setterPeriod); }
From source file:org.apache.usergrid.rest.ApiResponse.java
public static String exceptionToErrorCode(Throwable e) { if (e == null) { return "service_error"; }// w ww . j a v a2 s. c o m String s = ClassUtils.getShortClassName(e.getClass()); s = StringUtils.removeEnd(s, "Exception"); s = InflectionUtils.underscore(s).toLowerCase(); return s; }
From source file:org.apache.usergrid.tools.ToolBase.java
public String getToolName() { return ClassUtils.getShortClassName(this.getClass()); }
From source file:org.carrot2.workbench.editors.impl.ImplementingClassesEditor.java
@Override protected AttributeEditorInfo init(Map<String, Object> defaultValues) { for (Annotation ann : descriptor.constraints) { if (ann instanceof ImplementingClasses) { constraint = (ImplementingClasses) ann; }//from w w w . java 2 s .co m } if (constraint == null) { throw new RuntimeException("Missing constraint: " + ImplementingClasses.class); } valueRequired = (descriptor.getAnnotation(Required.class) != null); final BiMap<Object, String> valueToName = HashBiMap.create(); final List<Object> valueOrder = Lists.newArrayList(); for (Class<?> clazz : constraint.classes()) { valueOrder.add(clazz); valueToName.put(clazz, StringUtils.splitCamelCase(ClassUtils.getShortClassName(clazz))); } setMappedValues(valueToName, valueOrder); return new AttributeEditorInfo(1, false); }
From source file:org.codehaus.griffon.commons.AbstractGriffonClass.java
/** * Used by all child classes to create a new instance and get the name right. * * @param clazz the Griffon class/*from w ww . j av a 2 s . c om*/ * @param trailingName the trailing part of the name for this class type */ public AbstractGriffonClass(Class<?> clazz, String trailingName) { Assert.notNull(clazz, "Clazz parameter should not be null"); this.clazz = clazz; fullName = clazz.getName(); packageName = ClassUtils.getPackageName(clazz); naturalName = GriffonUtil.getNaturalName(clazz.getName()); shortName = ClassUtils.getShortClassName(clazz); name = GriffonUtil.getLogicalName(clazz, trailingName); propertyName = GriffonUtil.getPropertyNameRepresentation(shortName); if (StringUtils.isBlank(name)) { logicalPropertyName = propertyName; } else { logicalPropertyName = GriffonUtil.getPropertyNameRepresentation(name); } classPropertyFetcher = ClassPropertyFetcher.forClass(clazz); }