KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > collect > CustomerInputCollector


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.collect;
24 import com.sun.enterprise.diagnostics.DiagnosticException;
25 import com.sun.enterprise.diagnostics.Data;
26 import com.sun.enterprise.diagnostics.Defaults;
27 import com.sun.enterprise.diagnostics.util.FileUtils;
28 import com.sun.logging.LogDomains;
29
30 import java.io.IOException JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33
34 /**
35  *
36  * @author mu125243
37  */

38 public class CustomerInputCollector implements Collector{
39
40     String JavaDoc customerInputFile;
41     String JavaDoc customerInput;
42     String JavaDoc intermediateReportLocation;
43     boolean local;
44
45     protected static Logger JavaDoc logger =
46             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
47
48     /** Creates a new instance of CustomerInputCollector */
49     public CustomerInputCollector(String JavaDoc customerInputFile , String JavaDoc customerInput,
50             String JavaDoc intermediateReportLocation, boolean local) {
51        this.intermediateReportLocation = intermediateReportLocation;
52        this.customerInput = customerInput;
53        this.customerInputFile = customerInputFile;
54        this.local = local;
55     }
56
57     public Data capture() throws DiagnosticException {
58         if(customerInputFile != null)
59             return copyCustomerInputFile(customerInputFile);
60         if(customerInput != null && customerInput.trim().length() > 0) {
61             WritableDataImpl customerInfo = new WritableDataImpl(DataType.CUSTOMER_INFO);
62             customerInfo.addValue(customerInput);
63             return customerInfo;
64         }
65         return null;
66     }
67
68     /**
69      * Copies customer input
70      * @param inputFile name of file to be copied.
71      */

72     private Data copyCustomerInputFile(String JavaDoc inputFile) {
73         if(inputFile != null) {
74             try {
75                 String JavaDoc destFile = intermediateReportLocation +
76                         Defaults.CUSTOMER_INPUT;
77                 FileUtils.copyFile(inputFile, destFile);
78                 return new FileData(destFile,
79                         DataType.CUSTOMER_INFO);
80             } catch (IOException JavaDoc ioe) {
81                 logger.log(Level.WARNING, "diagnostic-service.copy_failed",
82                         new Object JavaDoc[]{inputFile, ioe.getMessage()});
83             }
84         }
85         return null;
86     }
87
88 }
89
Popular Tags