Kirk Rader  1.0-SNAPSHOT
Public Member Functions | Static Public Attributes | Static Package Functions | Static Package Attributes | Static Private Member Functions | Private Attributes | List of all members
us.rader.logging.statuscodes.MonitoredStatusCodeInfoList Class Reference

Sequence of MonitoredStatusCodeInfo elements. More...

Public Member Functions

 MonitoredStatusCodeInfoList ()
 Initialize empty error codes sequence. More...
 
 MonitoredStatusCodeInfoList (final Class<?>... classes) throws ReflectiveOperationException
 Initialize error codes sequence from given classes. More...
 
List< MonitoredStatusCodeInfogetErrorCodes ()
 
Properties toProperties ()
 
String toXML (final boolean formatted) throws IOException
 
void toXML (final OutputStream stream, final boolean formatted) throws IOException
 Write the XML representation of this instance to the given output stream. More...
 

Static Public Attributes

static final String NAMESPACE = "us.rader.logging.statuscodes"
 XML name space. More...
 

Static Package Functions

 [static initializer]
 

Static Package Attributes

static Logger logger
 Debug logging / tracing. More...
 

Static Private Member Functions

static Set< MonitoredStatusCodeInfoextract (final Class<?>... classes) throws ReflectiveOperationException
 Search the given classes for error code information. More...
 

Private Attributes

final List< MonitoredStatusCodeInfostatusCodes
 Sequence of MonitoredStatusCodeInfo elements. More...
 

Detailed Description

Sequence of MonitoredStatusCodeInfo elements.

Definition at line 43 of file MonitoredStatusCodeInfoList.java.

Constructor & Destructor Documentation

◆ MonitoredStatusCodeInfoList() [1/2]

us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.MonitoredStatusCodeInfoList ( )

Initialize empty error codes sequence.

Definition at line 69 of file MonitoredStatusCodeInfoList.java.

69  {
70 
71  statusCodes = new LinkedList<>();
72 
73  }
final List< MonitoredStatusCodeInfo > statusCodes
Sequence of MonitoredStatusCodeInfo elements.

◆ MonitoredStatusCodeInfoList() [2/2]

us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.MonitoredStatusCodeInfoList ( final Class<?>...  classes) throws ReflectiveOperationException

Initialize error codes sequence from given classes.

Parameters
classesThe classes.
Exceptions
ReflectiveOperationExceptionThrown if an error occurs using reflection.
See also
extract

Definition at line 86 of file MonitoredStatusCodeInfoList.java.

86  {
87 
88  this();
89  statusCodes.addAll(extract(classes));
90 
91  }
final List< MonitoredStatusCodeInfo > statusCodes
Sequence of MonitoredStatusCodeInfo elements.
static Set< MonitoredStatusCodeInfo > extract(final Class<?>... classes)
Search the given classes for error code information.

Member Function Documentation

◆ [static initializer]()

us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.[static initializer] ( )
staticpackage

◆ extract()

static Set<MonitoredStatusCodeInfo> us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.extract ( final Class<?>...  classes) throws ReflectiveOperationException
staticprivate

Search the given classes for error code information.

Parameters
classesThe classes to search.
Returns
The error code information.
Exceptions
ReflectiveOperationExceptionThrown if there is an error using reflection.

Definition at line 104 of file MonitoredStatusCodeInfoList.java.

104  {
105 
106  final Set<MonitoredStatusCodeInfo> results = new HashSet<>();
107 
108  for (final Class<?> cls : classes) {
109 
110  for (final Class<?> member : cls.getDeclaredClasses()) {
111 
112  results.addAll(extract(member));
113 
114  }
115 
116  for (final Field field : cls.getDeclaredFields()) {
117 
118  final MonitoredStatusCode errorCode = field.getAnnotation(MonitoredStatusCode.class);
119 
120  if (errorCode != null) {
121 
122  results.add(new MonitoredStatusCodeInfo(errorCode, field));
123 
124  }
125  }
126  }
127 
128  return results;
129 
130  }
static Set< MonitoredStatusCodeInfo > extract(final Class<?>... classes)
Search the given classes for error code information.

◆ getErrorCodes()

List<MonitoredStatusCodeInfo> us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.getErrorCodes ( )
Returns
Sequence of error code elements.

Definition at line 136 of file MonitoredStatusCodeInfoList.java.

136  {
137 
138  return statusCodes;
139 
140  }
final List< MonitoredStatusCodeInfo > statusCodes
Sequence of MonitoredStatusCodeInfo elements.

◆ toProperties()

Properties us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.toProperties ( )
Returns
Properties object representing this collection of error code information

Definition at line 146 of file MonitoredStatusCodeInfoList.java.

Referenced by us.rader.logging.statuscodes.test.MonitoredStatusCodeInfoListTest.toPropertiesTest().

146  {
147 
148  final Properties properties = new Properties();
149 
150  for (final MonitoredStatusCodeInfo errorCode : statusCodes) {
151 
152  properties.setProperty(errorCode.getComponent() + "_" + errorCode.getValue(),
153  String.format("%s %s %s %s", errorCode.getComponent(), errorCode.getCategory(),
154  errorCode.getValue(), errorCode.getDescription()));
155 
156  }
157 
158  return properties;
159 
160  }
final List< MonitoredStatusCodeInfo > statusCodes
Sequence of MonitoredStatusCodeInfo elements.

◆ toXML() [1/2]

String us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.toXML ( final boolean  formatted) throws IOException
Parameters
formattedIndicates whether or not to format output with linefeeds and indentation.
Returns
The XML representation of this instance.
Exceptions
IOExceptionThrown if an error occurs.
See also
toXML *
Parameters
formattedIndicates whether or not to format output with linefeeds and indentation.

Definition at line 177 of file MonitoredStatusCodeInfoList.java.

Referenced by us.rader.logging.statuscodes.test.MonitoredStatusCodeInfoListTest.toXmlTest().

177  {
178 
179  try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
180 
181  toXML(stream, formatted);
182  return new String(stream.toByteArray(), "UTF-8");
183 
184  }
185  }

◆ toXML() [2/2]

void us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.toXML ( final OutputStream  stream,
final boolean  formatted 
) throws IOException

Write the XML representation of this instance to the given output stream.

Parameters
streamThe output stream.
formattedIndicates whether or not to format output with linefeeds and indentation.
Exceptions
IOExceptionThrown if an error occurs.

Definition at line 200 of file MonitoredStatusCodeInfoList.java.

200  {
201 
202  try {
203 
204  final JAXBContext context = JAXBContext.newInstance(getClass());
205  final Marshaller marshaller = context.createMarshaller();
206  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
207  marshaller.marshal(this, stream);
208 
209  } catch (JAXBException | FactoryConfigurationError e) {
210 
211  // bad style required by moronic SonarQube rule
212  throw new IOException(e);
213 
214  }
215 
216  }

Member Data Documentation

◆ logger

Logger us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.logger
staticpackage

Debug logging / tracing.

Definition at line 48 of file MonitoredStatusCodeInfoList.java.

◆ NAMESPACE

final String us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.NAMESPACE = "us.rader.logging.statuscodes"
static

◆ statusCodes

final List<MonitoredStatusCodeInfo> us.rader.logging.statuscodes.MonitoredStatusCodeInfoList.statusCodes
private

Sequence of MonitoredStatusCodeInfo elements.

Definition at line 64 of file MonitoredStatusCodeInfoList.java.


The documentation for this class was generated from the following file: