Java Code Examples for org.apache.commons.lang.ClassUtils#getShortClassName()
The following examples show how to use
org.apache.commons.lang.ClassUtils#getShortClassName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamingThreadFactory.java From prong-uid with Apache License 2.0 | 5 votes |
/** * Get the method invoker's class name * * @param depth * @return */ private String getInvoker(int depth) { Exception e = new Exception(); StackTraceElement[] stes = e.getStackTrace(); if (stes.length > depth) { return ClassUtils.getShortClassName(stes[depth].getClassName()); } return getClass().getSimpleName(); }
Example 2
Source File: NamingThreadFactory.java From Almost-Famous with MIT License | 5 votes |
/** * Get the method invoker's class name * * @param depth * @return */ private String getInvoker(int depth) { Exception e = new Exception(); StackTraceElement[] stes = e.getStackTrace(); if (stes.length > depth) { return ClassUtils.getShortClassName(stes[depth].getClassName()); } return getClass().getSimpleName(); }
Example 3
Source File: ApiResponse.java From usergrid with Apache License 2.0 | 5 votes |
public static String exceptionToErrorCode( Throwable e ) { if ( e == null ) { return "service_error"; } String s = ClassUtils.getShortClassName( e.getClass() ); s = StringUtils.removeEnd( s, "Exception" ); s = InflectionUtils.underscore( s ).toLowerCase(); return s; }
Example 4
Source File: Enum.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Human readable description of this Enum item.</p> * * @return String in the form <code>type[name]</code>, for example: * <code>Color[Red]</code>. Note that the package name is stripped from * the type name. */ public String toString() { if (iToString == null) { String shortName = ClassUtils.getShortClassName(getEnumClass()); iToString = shortName + "[" + getName() + "]"; } return iToString; }
Example 5
Source File: Lang_64_ValuedEnum_s.java From coming with MIT License | 5 votes |
/** * <p>Human readable description of this <code>Enum</code> item.</p> * * @return String in the form <code>type[name=value]</code>, for example: * <code>JavaVersion[Java 1.0=100]</code>. Note that the package name is * stripped from the type name. */ public String toString() { if (iToString == null) { String shortName = ClassUtils.getShortClassName(getEnumClass()); iToString = shortName + "[" + getName() + "=" + getValue() + "]"; } return iToString; }
Example 6
Source File: Lang_64_ValuedEnum_t.java From coming with MIT License | 5 votes |
/** * <p>Human readable description of this <code>Enum</code> item.</p> * * @return String in the form <code>type[name=value]</code>, for example: * <code>JavaVersion[Java 1.0=100]</code>. Note that the package name is * stripped from the type name. */ public String toString() { if (iToString == null) { String shortName = ClassUtils.getShortClassName(getEnumClass()); iToString = shortName + "[" + getName() + "=" + getValue() + "]"; } return iToString; }
Example 7
Source File: ValuedEnum.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Human readable description of this <code>Enum</code> item.</p> * * @return String in the form <code>type[name=value]</code>, for example: * <code>JavaVersion[Java 1.0=100]</code>. Note that the package name is * stripped from the type name. */ public String toString() { if (iToString == null) { String shortName = ClassUtils.getShortClassName(getEnumClass()); iToString = shortName + "[" + getName() + "=" + getValue() + "]"; } return iToString; }
Example 8
Source File: ValuedEnum.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Human readable description of this <code>Enum</code> item.</p> * * @return String in the form <code>type[name=value]</code>, for example: * <code>JavaVersion[Java 1.0=100]</code>. Note that the package name is * stripped from the type name. */ public String toString() { if (iToString == null) { String shortName = ClassUtils.getShortClassName(getEnumClass()); iToString = shortName + "[" + getName() + "=" + getValue() + "]"; } return iToString; }
Example 9
Source File: SortedMovingWindow.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void endWindow() { super.endWindow(); tuplesInCurrentStreamWindow = new LinkedList<T>(); if (lastExpiredWindowState == null) { // not ready to emit value or empty in a certain window return; } // Assumption: the expiring tuple and any tuple before are already sorted. So it's safe to emit tuples from sortedListInSlidingWin till the expiring tuple for (T expiredTuple : lastExpiredWindowState) { // Find sorted list for the given key PriorityQueue<T> sortedListForE = sortedListInSlidingWin.get(function.apply(expiredTuple)); for (Iterator<T> iterator = sortedListForE.iterator(); iterator.hasNext();) { T minElemInSortedList = iterator.next(); int k = 0; if (comparator == null) { if (expiredTuple instanceof Comparable) { k = ((Comparable<T>)expiredTuple).compareTo(minElemInSortedList); } else { errorOutput.emit(expiredTuple); throw new IllegalArgumentException("Operator \"" + ClassUtils.getShortClassName(this.getClass()) + "\" encounters an invalid tuple " + expiredTuple + "\nNeither the tuple is comparable Nor Comparator is specified!"); } } else { k = comparator.compare(expiredTuple, minElemInSortedList); } if (k < 0) { // If the expiring tuple is less than the first element of the sorted list. No more tuples to emit break; } else { // Emit the element in sorted list if it's less than the expiring tuple outputPort.emit(minElemInSortedList); // remove the element from the sorted list iterator.remove(); } } } }
Example 10
Source File: BaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") private void getHistoryEntries(final Session session, final BaseSearchFilter filter, final Set<Integer> idSet, final Class< ? > clazz, final boolean searchStringInHistory) { if (log.isDebugEnabled() == true) { log.debug("Searching in " + clazz); } // First get all history entries matching the filter and the given class. final String className = ClassUtils.getShortClassName(clazz); if (searchStringInHistory == true) { final StringBuffer buf = new StringBuffer(); buf.append("(+className:").append(className); if (filter.getStartTimeOfModification() != null || filter.getStopTimeOfModification() != null) { final DateFormat df = new SimpleDateFormat(DateFormats.LUCENE_TIMESTAMP_MINUTE); df.setTimeZone(DateHelper.UTC); buf.append(" +timestamp:["); if (filter.getStartTimeOfModification() != null) { buf.append(df.format(filter.getStartTimeOfModification())); } else { buf.append("000000000000"); } buf.append(" TO "); if (filter.getStopTimeOfModification() != null) { buf.append(df.format(filter.getStopTimeOfModification())); } else { buf.append("999999999999"); } buf.append("]"); } if (filter.getModifiedByUserId() != null) { buf.append(" +userName:").append(filter.getModifiedByUserId()); } buf.append(") AND ("); final String searchString = buf.toString() + modifySearchString(filter.getSearchString()) + ")"; try { final FullTextSession fullTextSession = Search.getFullTextSession(getSession()); final org.apache.lucene.search.Query query = createFullTextQuery(HISTORY_SEARCH_FIELDS, null, searchString); if (query == null) { // An error occured: return; } final FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, HistoryEntry.class); fullTextQuery.setCacheable(true); fullTextQuery.setCacheRegion("historyItemCache"); fullTextQuery.setProjection("entityId"); final List<Object[]> result = fullTextQuery.list(); if (result != null && result.size() > 0) { for (final Object[] oa : result) { idSet.add((Integer) oa[0]); } } } catch (final Exception ex) { final String errorMsg = "Lucene error message: " + ex.getMessage() + " (for " + this.getClass().getSimpleName() + ": " + searchString + ")."; filter.setErrorMessage(errorMsg); log.info(errorMsg); } } else { final Criteria criteria = session.createCriteria(HistoryEntry.class); setCacheRegion(criteria); criteria.add(Restrictions.eq("className", className)); if (filter.getStartTimeOfModification() != null && filter.getStopTimeOfModification() != null) { criteria.add(Restrictions.between("timestamp", filter.getStartTimeOfModification(), filter.getStopTimeOfModification())); } else if (filter.getStartTimeOfModification() != null) { criteria.add(Restrictions.ge("timestamp", filter.getStartTimeOfModification())); } else if (filter.getStopTimeOfModification() != null) { criteria.add(Restrictions.le("timestamp", filter.getStopTimeOfModification())); } if (filter.getModifiedByUserId() != null) { criteria.add(Restrictions.eq("userName", filter.getModifiedByUserId().toString())); } criteria.setCacheable(true); criteria.setCacheRegion("historyItemCache"); criteria.setProjection(Projections.property("entityId")); final List<Integer> idList = criteria.list(); if (idList != null && idList.size() > 0) { for (final Integer id : idList) { idSet.add(id); } } } }
Example 11
Source File: XStreamSavingConverter.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
private String getClassname4History(final Class< ? > cls) { return ClassUtils.getShortClassName(cls); }
Example 12
Source File: ManyToOneResolver.java From rice with Educational Community License v2.0 | 4 votes |
/** gets the annotation but also adds an import in the process if a Convert annotation is required. */ @Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final ObjectReferenceDescriptor ord = OjbUtil.findObjectReferenceDescriptor(mappedClass, fieldName, descriptorRepositories); if (ord != null) { final List<MemberValuePair> pairs = new ArrayList<MemberValuePair>(); final Collection<ImportDeclaration> additionalImports = new ArrayList<ImportDeclaration>(); final Collection<String> fks = ord.getForeignKeyFields(); if (fks == null || fks.isEmpty()) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not have any foreign keys configured"); return null; } final Collection<String> pks = OjbUtil.getPrimaryKeyNames(mappedClass, descriptorRepositories); if (!(pks.size() == fks.size() && pks.containsAll(fks))) { final String className = ord.getItemClassName(); if (StringUtils.isBlank(className)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not class name attribute"); } else { final String shortClassName = ClassUtils.getShortClassName(className); final String packageName = ClassUtils.getPackageName(className); pairs.add(new MemberValuePair("targetEntity", new NameExpr(shortClassName + ".class"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(packageName), shortClassName), false, false)); } final boolean proxy = ord.isLazy(); if (proxy) { pairs.add(new MemberValuePair("fetch", new NameExpr("FetchType.LAZY"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "FetchType"), false, false)); } final boolean refresh = ord.isRefresh(); if (refresh) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has refresh set to " + refresh + ", unsupported conversion to @OneToOne attributes"); } final List<Expression> cascadeTypes = new ArrayList<Expression>(); final boolean autoRetrieve = ord.getCascadeRetrieve(); if (autoRetrieve) { cascadeTypes.add(new NameExpr("CascadeType.REFRESH")); } else { // updated default logging - false would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-retrieve set to " + autoRetrieve + ", unsupported conversion to CascadeType"); } } final int autoDelete = ord.getCascadingDelete(); if (autoDelete == ObjectReferenceDescriptor.CASCADE_NONE) { // updated default logging - none would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to none, unsupported conversion to CascadeType"); } } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to link, unsupported conversion to CascadeType"); } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.REMOVE")); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to an invalid value"); } final int autoUpdate = ord.getCascadingStore(); if (autoUpdate == ObjectReferenceDescriptor.CASCADE_NONE) { // updated default logging - none would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to none, unsupported conversion to CascadeType"); } } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to link, unsupported conversion to CascadeType"); } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.PERSIST")); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to an invalid value"); } if (!cascadeTypes.isEmpty()) { pairs.add(new MemberValuePair("cascade", new ArrayInitializerExpr(cascadeTypes))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "CascadeType"), false, false)); } return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports); } } return null; }
Example 13
Source File: StopLimitOrderImpl.java From AlgoTrader with GNU General Public License v2.0 | 4 votes |
public String toString() { return getSide() + " " + getQuantity() + " " + ClassUtils.getShortClassName(this.getClass()) + " " + getSecurity().getSymbol() + " stop " + getStop() + " limit " + getLimit(); }
Example 14
Source File: ValuedEnum.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Tests for order.</p> * * <p>The default ordering is numeric by value, but this * can be overridden by subclasses.</p> * * <p>NOTE: From v2.2 the enums must be of the same type. * If the parameter is in a different class loader than this instance, * reflection is used to compare the values.</p> * * @see java.lang.Comparable#compareTo(Object) * @param other the other object to compare to * @return -ve if this is less than the other object, +ve if greater than, * <code>0</code> of equal * @throws ClassCastException if other is not an <code>Enum</code> * @throws NullPointerException if other is <code>null</code> */ public int compareTo(Object other) { if (other == this) { return 0; } if (other.getClass() != this.getClass()) { if (other.getClass().getName().equals(this.getClass().getName())) { return iValue - getValueInOtherClassLoader(other); } throw new ClassCastException( "Different enum class '" + ClassUtils.getShortClassName(other.getClass()) + "'"); } return iValue - ((ValuedEnum) other).iValue; }
Example 15
Source File: ValuedEnum.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Tests for order.</p> * * <p>The default ordering is numeric by value, but this * can be overridden by subclasses.</p> * * <p>NOTE: From v2.2 the enums must be of the same type. * If the parameter is in a different class loader than this instance, * reflection is used to compare the values.</p> * * @see java.lang.Comparable#compareTo(Object) * @param other the other object to compare to * @return -ve if this is less than the other object, +ve if greater than, * <code>0</code> of equal * @throws ClassCastException if other is not an <code>Enum</code> * @throws NullPointerException if other is <code>null</code> */ public int compareTo(Object other) { if (other == this) { return 0; } if (other.getClass() != this.getClass()) { if (other.getClass().getName().equals(this.getClass().getName())) { return iValue - getValueInOtherClassLoader(other); } throw new ClassCastException( "Different enum class '" + ClassUtils.getShortClassName(other.getClass()) + "'"); } return iValue - ((ValuedEnum) other).iValue; }
Example 16
Source File: ExceptionUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Gets a short message summarising the exception. * <p> * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since Commons Lang 2.2 */ public static String getMessage(Throwable th) { if (th == null) { return ""; } String clsName = ClassUtils.getShortClassName(th, null); String msg = th.getMessage(); return clsName + ": " + StringUtils.defaultString(msg); }
Example 17
Source File: Enum.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Tests for order.</p> * * <p>The default ordering is alphabetic by name, but this * can be overridden by subclasses.</p> * * <p>If the parameter is in a different class loader than this instance, * reflection is used to compare the names.</p> * * @see java.lang.Comparable#compareTo(Object) * @param other the other object to compare to * @return -ve if this is less than the other object, +ve if greater * than, <code>0</code> of equal * @throws ClassCastException if other is not an Enum * @throws NullPointerException if other is <code>null</code> */ public int compareTo(Object other) { if (other == this) { return 0; } if (other.getClass() != this.getClass()) { if (other.getClass().getName().equals(this.getClass().getName())) { return iName.compareTo( getNameInOtherClassLoader(other) ); } throw new ClassCastException( "Different enum class '" + ClassUtils.getShortClassName(other.getClass()) + "'"); } return iName.compareTo(((Enum) other).iName); }
Example 18
Source File: Enum.java From lams with GNU General Public License v2.0 | 3 votes |
/** * <p>Tests for order.</p> * * <p>The default ordering is alphabetic by name, but this * can be overridden by subclasses.</p> * * <p>If the parameter is in a different class loader than this instance, * reflection is used to compare the names.</p> * * @see java.lang.Comparable#compareTo(Object) * @param other the other object to compare to * @return -ve if this is less than the other object, +ve if greater * than, <code>0</code> of equal * @throws ClassCastException if other is not an Enum * @throws NullPointerException if other is <code>null</code> */ public int compareTo(Object other) { if (other == this) { return 0; } if (other.getClass() != this.getClass()) { if (other.getClass().getName().equals(this.getClass().getName())) { return iName.compareTo( getNameInOtherClassLoader(other) ); } throw new ClassCastException( "Different enum class '" + ClassUtils.getShortClassName(other.getClass()) + "'"); } return iName.compareTo(((Enum) other).iName); }
Example 19
Source File: OrderImpl.java From AlgoTrader with GNU General Public License v2.0 | 2 votes |
public String toString() { return getSide() + " " + getQuantity() + " " + ClassUtils.getShortClassName(this.getClass()) + " " + getSecurity().getSymbol(); }
Example 20
Source File: ToStringStyle.java From astor with GNU General Public License v2.0 | 2 votes |
/** * <p>Gets the short class name for a class.</p> * * <p>The short class name is the classname excluding * the package name.</p> * * @param cls the <code>Class</code> to get the short name of * @return the short name */ protected String getShortClassName(Class cls) { return ClassUtils.getShortClassName(cls); }