下面列出了javax.annotation.OverridingMethodsMustInvokeSuper#com.helger.commons.annotation.OverrideOnDemand 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
}
/**
* 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;
}
/**
* 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);
}
/**
* 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);
}
@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 ());
}
/**
* @return The document root element local name. May neither be
* <code>null</code> nor empty.
*/
@Nonnull
@Nonempty
@OverrideOnDemand
protected String getWriteElementName ()
{
return "settings";
}
@OverrideOnDemand
protected void debug (@Nonnull final Supplier <String> aSupplier)
{
if (m_bDebugMode)
if (LOGGER.isInfoEnabled ())
LOGGER.info (aSupplier.get ());
}
@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);
}
@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);
}
/**
* 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);
}
/**
* 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 ≥ 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);
}
/**
* @return The {@link IXMLWriterSettings} to be used to serialize the data.
*/
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getXMLWriterSettings ()
{
return WRITE_XWS;
}
/**
* @return The {@link IXMLWriterSettings} to be used to serialize the data.
*/
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getWALXMLWriterSettings ()
{
return WAL_XWS;
}
@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 ());
}
/**
* @return The {@link IXMLWriterSettings} to be used to serialize the data.
*/
@Nonnull
@OverrideOnDemand
protected IXMLWriterSettings getXMLWriterSettings ()
{
return XMLWriterSettings.DEFAULT_XML_SETTINGS;
}
@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);
}
/**
* Get the {@link URIResolver} to be used.
*
* @return Never <code>null</code>.
*/
@Nonnull
@OverrideOnDemand
protected URIResolver getURIResolver ()
{
return m_aXmlCatalog;
}
/**
* 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 <> ();
}
/**
* Get the {@link EntityResolver} to be used.
*
* @return Never <code>null</code>.
*/
@Nonnull
@OverrideOnDemand
protected EntityResolver getEntityResolver ()
{
return m_aXmlCatalog;
}
@Nonnull
@OverrideOnDemand
protected IMicroNode getAsDocument (@Nonnull final IMicroElement aElement)
{
final IMicroDocument aDoc = new MicroDocument ();
aDoc.appendChild (aElement);
return aDoc;
}
@OverrideOnDemand
protected void onClose (final long nTotalBytesWritten)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Close at " + nTotalBytesWritten);
}
@OverrideOnDemand
public void onEndPageMarginBlock (@Nonnull final CSSPageMarginBlock aPageMarginBlock)
{}
@OverrideOnDemand
protected void onMark (final int nReadLimit, final long nCurrentPosition)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Marked at " + nCurrentPosition + " with read-limit of " + nReadLimit);
}
@Override
@OverrideOnDemand
public void after ()
{
ScopeAwareTestSetup.shutdownScopeTests ();
}
@OverrideOnDemand
public void onBeginSupportsRule (@Nonnull final CSSSupportsRule aSupportsRule)
{}
@Nonnegative
@OverrideOnDemand
public int getMinimumArgumentCount ()
{
return 1;
}
@OverrideOnDemand
public void onEndKeyframesBlock (@Nonnull final CSSKeyframesBlock aKeyframesBlock)
{}
@OverrideOnDemand
public void onEndPageRule (@Nonnull final CSSPageRule aPageRule)
{}
@OverrideOnDemand
public void onUnknownRule (@Nonnull final CSSUnknownRule aUnknownRule)
{}
@OverrideOnDemand
public void onBeginKeyframesBlock (@Nonnull final CSSKeyframesBlock aKeyframesBlock)
{}