View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.model;
12  
13  import java.io.File;
14  import java.io.Serializable;
15  import java.sql.Timestamp;
16  
17  import psiprobe.tools.logging.LogDestination;
18  
19  /**
20   * This class holds attributes of any other LogDestination so that LogDestination can be serialized.
21   * It is generally difficult to make just any LogDestination to be serializable as they more often
22   * than not are connected to underlying Log implementation that are in many cases not serializable.
23   */
24  public class DisconnectedLogDestination implements LogDestination, Serializable {
25  
26    /** The Constant serialVersionUID. */
27    private static final long serialVersionUID = 1L;
28  
29    /** The application. */
30    private Application application;
31  
32    /** The root. */
33    private boolean root;
34  
35    /** The context. */
36    private boolean context;
37  
38    /** The name. */
39    private String name;
40  
41    /** The index. */
42    private String index;
43  
44    /** The target class. */
45    private String targetClass;
46  
47    /** The conversion pattern. */
48    private String conversionPattern;
49  
50    /** The file. */
51    private File file;
52  
53    /** The log type. */
54    private String logType;
55  
56    /** The size. */
57    private long size;
58  
59    /** The last modified. */
60    private Timestamp lastModified;
61  
62    /** The level. */
63    private String level;
64  
65    /** The valid levels. */
66    private String[] validLevels;
67  
68    /** The file encoding name. */
69    private String encoding;
70  
71    /**
72     * Loads and returns disconnected log destination.
73     *
74     * @param destination the destination
75     *
76     * @return the disconnected log destination
77     */
78    public DisconnectedLogDestination builder(LogDestination destination) {
79      this.application = destination.getApplication();
80      this.root = destination.isRoot();
81      this.context = destination.isContext();
82      this.name = destination.getName();
83      this.index = destination.getIndex();
84      this.targetClass = destination.getTargetClass();
85      this.conversionPattern = destination.getConversionPattern();
86      this.file = destination.getFile();
87      this.logType = destination.getLogType();
88      this.size = destination.getSize();
89      this.lastModified = destination.getLastModified();
90      this.level = destination.getLevel();
91      this.validLevels = destination.getValidLevels();
92      this.encoding = destination.getEncoding();
93      return this;
94    }
95  
96    @Override
97    public Application getApplication() {
98      return application;
99    }
100 
101   @Override
102   public boolean isRoot() {
103     return root;
104   }
105 
106   @Override
107   public boolean isContext() {
108     return context;
109   }
110 
111   @Override
112   public String getName() {
113     return name;
114   }
115 
116   @Override
117   public String getIndex() {
118     return index;
119   }
120 
121   @Override
122   public String getTargetClass() {
123     return targetClass;
124   }
125 
126   @Override
127   public String getConversionPattern() {
128     return conversionPattern;
129   }
130 
131   @Override
132   public File getFile() {
133     return file;
134   }
135 
136   @Override
137   public String getLogType() {
138     return logType;
139   }
140 
141   @Override
142   public long getSize() {
143     return size;
144   }
145 
146   @Override
147   public Timestamp getLastModified() {
148     return lastModified == null ? null : new Timestamp(lastModified.getTime());
149   }
150 
151   @Override
152   public String getLevel() {
153     return level;
154   }
155 
156   @Override
157   public String[] getValidLevels() {
158     return validLevels == null ? new String[0] : validLevels.clone();
159   }
160 
161   @Override
162   public String getEncoding() {
163     return encoding;
164   }
165 }