Java Code Examples for com.helger.commons.lang.ClassHelper#getClassLocalName()

The following examples show how to use com.helger.commons.lang.ClassHelper#getClassLocalName() . 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: AbstractMapBasedWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add or update an item. Must only be invoked inside a write-lock.
 *
 * @param aItem
 *        The item to be added or updated
 * @param eActionType
 *        The action type. Must be CREATE or UPDATE!
 * @throws IllegalArgumentException
 *         If on CREATE an item with the same ID is already contained. If on
 *         UPDATE an item with the provided ID does NOT exist.
 */
@MustBeLocked (ELockType.WRITE)
private void _addItem (@Nonnull final IMPLTYPE aItem, @Nonnull final EDAOActionType eActionType)
{
  ValueEnforcer.notNull (aItem, "Item");
  ValueEnforcer.isTrue (eActionType == EDAOActionType.CREATE || eActionType == EDAOActionType.UPDATE,
                        "Invalid action type provided!");

  final String sID = aItem.getID ();
  final IMPLTYPE aOldItem = m_aMap.get (sID);
  if (eActionType == EDAOActionType.CREATE)
  {
    if (aOldItem != null)
      throw new IllegalArgumentException (ClassHelper.getClassLocalName (getDataTypeClass ()) +
                                          " with ID '" +
                                          sID +
                                          "' is already in use and can therefore not be created again. Old item = " +
                                          aOldItem +
                                          "; New item = " +
                                          aItem);
  }
  else
  {
    // Update
    if (aOldItem == null)
      throw new IllegalArgumentException (ClassHelper.getClassLocalName (getDataTypeClass ()) +
                                          " with ID '" +
                                          sID +
                                          "' is not yet in use and can therefore not be updated! Updated item = " +
                                          aItem);
  }

  m_aMap.put (sID, aItem);
}
 
Example 2
Source File: IPSErrorHandler.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nullable
static String getErrorFieldName (@Nullable final IPSElement aSourceElement)
{
  if (aSourceElement == null)
    return null;
  String sField = ClassHelper.getClassLocalName (aSourceElement);
  if (aSourceElement instanceof IPSHasID && ((IPSHasID) aSourceElement).hasID ())
    sField += " [ID=" + ((IPSHasID) aSourceElement).getID () + "]";
  return sField;
}
 
Example 3
Source File: CommonsMock.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Override
public String toString ()
{
  return ClassHelper.getClassLocalName (m_aParamClass) + ":" + m_sParamName;
}
 
Example 4
Source File: AbstractCreateUBLActionCode.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
protected static void append (@Nonnull final IJAXBDocumentType e,
                              @Nonnull final EPhase ePhase,
                              @Nonnull final StringBuilder aSB,
                              @Nonnull final String sBuilderClass)
{
  final String sType = ClassHelper.getClassLocalName (e.getImplementationClass ());
  final String sName = StringHelper.trimEnd (sType, "Type");
  final String sBuilderMethodName = Character.toLowerCase (sName.charAt (0)) + sName.substring (1);

  switch (ePhase)
  {
    case READ:
      // Builder<T> read ()
      aSB.append ("/** Create a reader builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
    case WRITE:
      // Builder<T> write ()
      aSB.append ("/** Create a writer builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
    case VALIDATE:
      // Builder<T> validate ()
      aSB.append ("/** Create a validation builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
  }
}