com.helger.commons.annotation.OverrideOnDemand Java Examples

The following examples show how to use com.helger.commons.annotation.OverrideOnDemand. 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: AbstractValidationEventHandler.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Get the error level matching the passed JAXB severity.
 *
 * @param nSeverity
 *        The JAXB severity.
 * @return The matching {@link IErrorLevel}. Never <code>null</code>.
 */
@Nonnull
@OverrideOnDemand
protected IErrorLevel getErrorLevel (final int nSeverity)
{
  switch (nSeverity)
  {
    case ValidationEvent.WARNING:
      return EErrorLevel.WARN;
    case ValidationEvent.ERROR:
      return EErrorLevel.ERROR;
    case ValidationEvent.FATAL_ERROR:
      return EErrorLevel.FATAL_ERROR;
    default:
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Unknown JAXB validation severity: " + nSeverity + "; defaulting to error");
      return EErrorLevel.ERROR;
  }
}
 
Example #2
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Modify the created document by e.g. adding some comment or digital
 * signature or whatsoever.
 *
 * @param aDoc
 *        The created non-<code>null</code> document.
 */
@OverrideOnDemand
@MustBeLocked (ELockType.WRITE)
protected void modifyWriteData (@Nonnull final IMicroDocument aDoc)
{
  final IMicroComment aComment = new MicroComment ("This file was generated automatically - do NOT modify!\n" +
                                                   "Written at " +
                                                   PDTToString.getAsString (ZonedDateTime.now (Clock.systemUTC ()),
                                                                            Locale.US));
  final IMicroElement eRoot = aDoc.getDocumentElement ();
  // Add a small comment
  if (eRoot != null)
    aDoc.insertBefore (aComment, eRoot);
  else
    aDoc.appendChild (aComment);
}
 
Example #3
Source File: AbstractWritingJAXBBuilder.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Create the main marshaller with the contained settings.
 *
 * @return The Marshaller and never <code>null</code>.
 * @throws JAXBException
 *         In case creation fails
 */
@Nonnull
@OverrideOnDemand
protected Marshaller createMarshaller () throws JAXBException
{
  final JAXBContext aJAXBContext = getJAXBContext ();

  // create a Marshaller
  final Marshaller aMarshaller = aJAXBContext.createMarshaller ();

  // Validating (if possible)
  final Schema aSchema = getSchema ();
  if (aSchema != null)
    aMarshaller.setSchema (aSchema);

  return aMarshaller;
}
 
Example #4
Source File: AbstractSimpleDAO.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Modify the created document by e.g. adding some comment or digital
 * signature or whatsoever.
 *
 * @param aDoc
 *        The created non-<code>null</code> document.
 */
@OverrideOnDemand
@MustBeLocked (ELockType.WRITE)
protected void modifyWriteData (@Nonnull final IMicroDocument aDoc)
{
  final IMicroComment aComment = new MicroComment ("This file was generated automatically - do NOT modify!\n" +
                                                   "Written at " +
                                                   PDTToString.getAsString (ZonedDateTime.now (Clock.systemUTC ()),
                                                                            Locale.US));
  final IMicroElement eRoot = aDoc.getDocumentElement ();
  // Add a small comment
  if (eRoot != null)
    aDoc.insertBefore (aComment, eRoot);
  else
    aDoc.appendChild (aComment);
}
 
Example #5
Source File: AbstractSimpleDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return The {@link IXMLWriterSettings} to be used to serialize the data.
 */
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getXMLWriterSettings ()
{
  return XMLWriterSettings.DEFAULT_XML_SETTINGS;
}
 
Example #6
Source File: Schematron.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link EntityResolver} to be used.
 *
 * @return Never <code>null</code>.
 */
@Nonnull
@OverrideOnDemand
protected EntityResolver getEntityResolver ()
{
  return m_aXmlCatalog;
}
 
Example #7
Source File: MappedCache.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new cache map. This is the internal map that is used to store the
 * items.
 *
 * @return Never <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
@OverrideOnDemand
@CodingStyleguideUnaware
protected ICommonsMap <KEYSTORETYPE, Wrapper <VALUETYPE>> createCache ()
{
  return hasMaxSize () ? new SoftLinkedHashMap <> (m_nMaxSize) : new SoftHashMap <> ();
}
 
Example #8
Source File: SettingsPersistenceXML.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return The document root element local name. May neither be
 *         <code>null</code> nor empty.
 */
@Nonnull
@Nonempty
@OverrideOnDemand
protected String getWriteElementName ()
{
  return "settings";
}
 
Example #9
Source File: Schematron.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link URIResolver} to be used.
 *
 * @return Never <code>null</code>.
 */
@Nonnull
@OverrideOnDemand
protected URIResolver getURIResolver ()
{
  return m_aXmlCatalog;
}
 
Example #10
Source File: AbstractJAXBBuilder.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@OverrideOnDemand
protected JAXBContext getJAXBContext () throws JAXBException
{
  if (m_bUseJAXBContextCache)
  {
    // Since creating the JAXB context is quite cost intensive this is done
    // only once!
    return JAXBContextCache.getInstance ().getFromCache (m_aDocType.getImplementationClass (), getClassLoader ());
  }

  // Create a new JAXBContext - inefficient
  return JAXBContext.newInstance (m_aDocType.getImplementationClass ().getPackage ().getName (), getClassLoader ());
}
 
Example #11
Source File: PSWriter.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@OverrideOnDemand
protected IMicroNode getAsDocument (@Nonnull final IMicroElement aElement)
{
  final IMicroDocument aDoc = new MicroDocument ();
  aDoc.appendChild (aElement);
  return aDoc;
}
 
Example #12
Source File: SafeXMLStreamWriter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@OverrideOnDemand
protected void debug (@Nonnull final Supplier <String> aSupplier)
{
  if (m_bDebugMode)
    if (LOGGER.isInfoEnabled ())
      LOGGER.info (aSupplier.get ());
}
 
Example #13
Source File: XMLLoggingExceptionCallback.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@Nonempty
@OverrideOnDemand
protected String getLogMessage (@Nullable final Throwable t)
{
  if (t instanceof SAXParseException)
  {
    final SAXParseException ex = (SAXParseException) t;
    return AbstractSAXErrorHandler.getSaxParseError (EErrorLevel.ERROR, ex).getAsString (CGlobal.DEFAULT_LOCALE);
  }
  if (t instanceof SAXException)
  {
    return "Error parsing XML document";
  }
  if (t instanceof UnknownHostException)
  {
    // Must be checked before IOException because it is an IOException
    // Caught if entity resolver failed
    return "Failed to resolve entity host: " + t.getMessage ();
  }
  if (t instanceof IOException)
  {
    return "Error reading XML document: " + t.getMessage ();
  }
  return super.getLogMessage (t);
}
 
Example #14
Source File: ReadableResourceProviderChain.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@OverrideOnDemand
public IReadableResource getReadableResource (@Nonnull final String sName)
{
  // Use the first resource provider that supports the name
  for (final IReadableResourceProvider aResProvider : m_aReadingResourceProviders)
    if (aResProvider.supportsReading (sName))
      return aResProvider.getReadableResource (sName);
  throw new IllegalArgumentException ("Cannot handle reading '" +
                                      sName +
                                      "' by any of " +
                                      m_aReadingResourceProviders);
}
 
Example #15
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@OverrideOnDemand
protected String convertNativeToWALString (@Nonnull final DATATYPE aModifiedElement)
{
  final IMicroElement aElement = MicroTypeConverter.convertToMicroElement (aModifiedElement, "item");
  if (aElement == null)
    throw new IllegalStateException ("Failed to convert " +
                                     aModifiedElement +
                                     " of class " +
                                     aModifiedElement.getClass ().getName () +
                                     " to XML!");
  return MicroWriter.getNodeAsString (aElement, getWALXMLWriterSettings ());
}
 
Example #16
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return The {@link IXMLWriterSettings} to be used to serialize the data.
 */
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getWALXMLWriterSettings ()
{
  return WAL_XWS;
}
 
Example #17
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return The {@link IXMLWriterSettings} to be used to serialize the data.
 */
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getXMLWriterSettings ()
{
  return WRITE_XWS;
}
 
Example #18
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called, when the conversion from the read XML string to the
 * native type failed. By default an error message is logged and processing
 * continues.
 *
 * @param eActionType
 *        The action type to recover. May not be <code>null</code>
 * @param i
 *        The index of the element to recover. Always &ge; 0.
 * @param sElement
 *        The string read from the WAL file that could not be recovered.
 * @since 9.1.6
 */
@OverrideOnDemand
protected void onRecoveryErrorConvertToNative (@Nonnull final EDAOActionType eActionType,
                                               @Nonnegative final int i,
                                               @Nonnull final String sElement)
{
  if (LOGGER.isErrorEnabled ())
    LOGGER.error ("Action [" +
                  eActionType +
                  "][" +
                  i +
                  "]: failed to convert the following element to native:\n" +
                  sElement);
}
 
Example #19
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used upon recovery to convert a stored object to its native
 * representation. If you overwrite this method, you should consider
 * overriding {@link #convertNativeToWALString(Serializable)} as well.
 *
 * @param sElement
 *        The string representation to be converted. Never <code>null</code>.
 * @return The native representation of the object. If the return value is
 *         <code>null</code>, the recovery will fail with an exception!
 */
@Nullable
@OverrideOnDemand
@IsLocked (ELockType.WRITE)
protected DATATYPE convertWALStringToNative (@Nonnull final String sElement)
{
  final IMicroDocument aDoc = MicroReader.readMicroXML (sElement);
  if (aDoc == null || aDoc.getDocumentElement () == null)
    return null;
  return MicroTypeConverter.convertToNative (aDoc.getDocumentElement (), m_aDataTypeClass);
}
 
Example #20
Source File: LoggingSAXErrorHandler.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Nonempty
@OverrideOnDemand
protected String getErrorMessage (@Nonnull final IErrorLevel aErrorLevel, final SAXParseException aException)
{
  // As the SAX error messages are not localized at the moment, we can use
  // a fixed locale here
  return getSaxParseError (aErrorLevel, aException).getAsString (CGlobal.DEFAULT_LOCALE);
}
 
Example #21
Source File: DefaultCSSVisitor.java    From ph-css with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
public void onEndMediaRule (@Nonnull final CSSMediaRule aMediaRule)
{}
 
Example #22
Source File: DefaultCSSVisitor.java    From ph-css with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
public void onEndSupportsRule (@Nonnull final CSSSupportsRule aSupportsRule)
{}
 
Example #23
Source File: DefaultCSSVisitor.java    From ph-css with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
public void onStyleRuleSelector (@Nonnull final CSSSelector aSelector)
{}
 
Example #24
Source File: LoggingInputStream.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
protected void onRead (final int nBytesRead, final long nNewPosition)
{
  if (LOGGER.isInfoEnabled ())
    LOGGER.info ("Read " + nBytesRead + " byte(s); now at " + nNewPosition);
}
 
Example #25
Source File: LoggingInputStream.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
protected void onSkip (final long nBytesSkipped, final long nNewPosition)
{
  if (LOGGER.isInfoEnabled ())
    LOGGER.info ("Skipped " + nBytesSkipped + " byte(s); now at " + nNewPosition);
}
 
Example #26
Source File: LoggingInputStream.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
protected void onMark (final int nReadLimit, final long nCurrentPosition)
{
  if (LOGGER.isInfoEnabled ())
    LOGGER.info ("Marked at " + nCurrentPosition + " with read-limit of " + nReadLimit);
}
 
Example #27
Source File: LoggingInputStream.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
protected void onReset (final long nCurrentPosition)
{
  if (LOGGER.isInfoEnabled ())
    LOGGER.info ("Reset at " + nCurrentPosition);
}
 
Example #28
Source File: AbstractTreeItemWithIDFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
public void onRemoveItem (@Nonnull final ITEMTYPE aItem)
{
  // it doesn't matter to us
}
 
Example #29
Source File: AbstractTreeItemWithIDFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
public void onAddItem (@Nonnull final ITEMTYPE aItem)
{
  // it doesn't matter to us
}
 
Example #30
Source File: Base64Codec.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
@OverrideOnDemand
protected Base64InputStream createBase64InputStream (@Nonnull final NonBlockingByteArrayInputStream aBAIS)
{
  return new Base64InputStream (aBAIS);
}