KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > ServerValidationHandler


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
24 package com.sun.enterprise.config.serverbeans;
25
26 import org.xml.sax.helpers.DefaultHandler JavaDoc;
27 import org.xml.sax.SAXParseException JavaDoc;
28 import org.xml.sax.InputSource JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.InputStream JavaDoc;
33
34 import java.util.logging.Logger JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 //import com.sun.logging.LogDomains;
37

38 //The RelativePathResolver is used to translate relative paths containing
39
//embedded system properties (e.g. ${com.sun.aas.instanceRoot}/applications)
40
//into absolute paths
41
import com.sun.enterprise.util.RelativePathResolver;
42
43 public class ServerValidationHandler extends DefaultHandler JavaDoc {
44
45     //private static final Logger _logger = LogDomains.getLogger(LogDomains.CONFIG_LOGGER);
46

47     public static final String JavaDoc SERVER_8_DTD_PUBLIC_ID =
48         "-//Sun Microsystems Inc.//DTD Sun ONE Application Server 8.0//EN";
49     
50     public static final String JavaDoc SERVER_8_DTD_PUBLIC_ID_PATH =
51         "/sun-domain_1_2.dtd";
52     
53     //===========================================================
54
// SAX ErrorHandler methods
55
//===========================================================
56

57     // treat validation errors as fatal
58
public void error(SAXParseException JavaDoc e)
59     throws SAXParseException JavaDoc
60     {
61         /*
62     _logger.log(Level.SEVERE,"config.errorhandler_msg",new Object[]{"" + e.getLineNumber(),
63                                                                         "" + e.getColumnNumber(),
64                                                                         "" + e.getSystemId(),
65                                                                         "" + e.getPublicId()});
66     _logger.log(Level.SEVERE," " + e.getMessage());
67          */

68         throw e;
69     }
70
71     // dump warnings too
72
public void warning(SAXParseException JavaDoc e)
73     throws SAXParseException JavaDoc
74     {
75         /*
76     _logger.log(Level.WARNING,"config.errorhandler_msg",new Object[]{"" + e.getLineNumber(),
77                                                                         "" + e.getColumnNumber(),
78                                                                         "" + e.getSystemId(),
79                                                                         "" + e.getPublicId()});
80     _logger.log(Level.WARNING," " + e.getMessage());
81          */

82         //FIXME
83
}
84
85     public void fatalError(SAXParseException JavaDoc e)
86     throws SAXParseException JavaDoc {
87         /*
88     _logger.log(Level.SEVERE,"config.errorhandler_msg",new Object[]{"" + e.getLineNumber(),
89                                                                         "" + e.getColumnNumber(),
90                                                                         "" + e.getSystemId(),
91                                                                         "" + e.getPublicId()});
92     _logger.log(Level.SEVERE, e.toString());
93          */

94         throw e;
95     }
96
97     //===========================================================
98
// Resolver methods
99
//===========================================================
100

101     public InputSource JavaDoc resolveEntity(String JavaDoc publicID, String JavaDoc systemID) throws SAXException JavaDoc {
102         InputSource JavaDoc is = null;
103         try {
104             InputStream JavaDoc i = this.getClass().getResourceAsStream( SERVER_8_DTD_PUBLIC_ID_PATH );
105             if( i!= null ) {
106                 return new InputSource JavaDoc(i);
107             }
108
109             
110             is = new InputSource JavaDoc(
111                new FileInputStream JavaDoc(
112                new File JavaDoc(new java.net.URI JavaDoc(
113                    RelativePathResolver.resolvePath(systemID)))));
114         } catch(Exception JavaDoc e) {
115             throw new SAXException JavaDoc("cannot resolve dtd", e);
116         }
117         return is;
118     }
119 }
120
Popular Tags