2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.dbcapi.model;
23 import java.lang.reflect.Field;
24 import java.util.ArrayList;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
29 import javax.xml.bind.annotation.XmlRootElement;
31 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
34 public abstract class DmaapObject extends BaseLoggingClass {
35 protected Date lastMod;
36 protected DmaapObject_Status status;
38 public Date getLastMod() {
42 public void setLastMod(Date lastMod) {
43 this.lastMod = lastMod;
46 public void setLastMod() {
47 this.lastMod = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
50 public enum DmaapObject_Status {
58 public DmaapObject_Status getStatus() {
62 public void setStatus(DmaapObject_Status status) {
66 public boolean isStatusValid() {
67 if ( this.status == DmaapObject_Status.VALID ) {
74 * TODO: get this working so arrays and sub-class within an Object can be logged
76 public String toString() {
77 return classToString( this );
80 private String classToString( Object obj ) {
81 Field[] fields = obj.getClass().getDeclaredFields();
82 StringBuilder res = new StringBuilder( "{");
84 for ( Field field: fields ) {
85 logger.info( field.getName() + " toString=" + field.toString() + " toGenericString=" + field.toGenericString());
93 field.setAccessible(true); // avoid IllegalAccessException
96 Class<?> t = field.getType();
98 if ( t == String.class ) {
99 res.append( "\"" ).append( field.getName() ).append( "\": \"");
102 res.append(field.get(this));
103 } catch ( IllegalAccessException iae) {
104 res.append( "UNK(iae)");
105 } catch (IllegalArgumentException iae2 ) {
106 res.append( "UNK(iae2)");
107 } catch ( NullPointerException npe ) {
108 res.append( "UNK(npe)");
109 } catch ( ExceptionInInitializerError eie ) {
110 res.append( "UNK(eie)");
113 } else if ( t == ArrayList.class ){
115 res.append( classToString( field ));
121 return( res.toString());