/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* A fairly simple but very specific stax XML Parser. Give it the location of domain.xml and the name of the server
* instance and it will return JVM options. Currently it is all package private.
*
* @author bnevins
*/
public class MiniXmlParser {
}
this.serverName = serverName;
try {
read();
if (!sawConfig)
throw new EndDocumentException(); // handled just below...
valid = true;
}
catch (EndDocumentException e) {
}
catch (Exception e) {
}
finally {
try {
}
}
catch (Exception e) {
// ignore
}
try {
}
}
catch (Exception e) {
// ignore
}
}
}
if (!valid) {
}
return javaConfig;
}
if (!valid) {
}
return jvmOptions;
}
if (!valid) {
}
return profilerConfig;
}
if (!valid) {
}
return profilerJvmOptions;
}
if (!valid) {
}
return profilerSysProps;
}
if (!valid) {
}
return sysProps.getCombinedSysProps();
}
return domainName;
}
}
}
return adminAddresses;
}
}
public boolean getSecureAdminEnabled() {
return secureAdminEnabled;
}
/**
* loggingConfig will return an IOException if there is no
* logging properties file.
*
* @return the log filename if available, otherwise return null
*/
try {
}
}
catch (Exception e) {
// just return null
}
return logFilename;
}
public boolean isMonitoringEnabled() {
return monitoringEnabled;
}
public boolean hasNetworkConfig() {
return sawNetworkConfig;
}
public boolean hasDefaultConfig() {
return sawDefaultConfig;
}
return adminRealm;
}
return adminRealmProperties;
}
///////////////////// all private below /////////////////////////
createParser();
try {
// this will fail if config is above servers in domain.xml!
getConfig(); // might throw
}
catch (EndDocumentException ex) {
createParser();
skipRoot("domain");
getConfig();
}
finalTouches();
}
// Set the resolver so that any external entity references, such
// as a reference to a DTD, return an empty file. The domain.xml
// file doesn't support entity references.
throws XMLStreamException {
return new ByteArrayInputStream(new byte[0]);
}
});
}
// In JDK 1.6, StAX is part of JRE, so we use no argument variant of
// newInstance(), where as on JDK 1.5, we use two argument version of
// newInstance() so that we can pass the classloader that loads
// XMLInputFactory to load the factory, otherwise by default StAX uses
// Thread's context class loader to locate the factory. See:
//
// jdk6+
return XMLInputFactory.newInstance();
// jdk5
}
return;
} // second pass!
skipRoot("domain");
// complications -- look for this element as a child of Domain...
// <property name="administrative.domain.name" value="domain1"/>
// also have to handle system-property at the domain level
while (true) {
break;
}
else
parseDomainProperty(); // maybe it is the domain name?
}
// the cursor is at the start-element of <servers>
while (true) {
// get to first <server> element
}
// get the attributes for this <server>
skipToEnd("servers");
return;
}
else
skipToEnd("server");
}
}
// complications -- look for this element as a child of Domain...
// <property name="administrative.domain.name" value="domain1"/>
// also have to handle system-property at the domain level
while (true) {
break;
}
else
parseDomainProperty(); // maybe it is the domain name?
}
// get the attributes for this <config>
sawDefaultConfig = true;
sawConfig = true;
parseConfig();
}
else {
skipTree("config");
}
}
}
// cursor --> <config>
// as we cruise through the section pull off any found <system-property>
// I.e. <system-property> AND <java-config> are both children of <config>
// Note that if the system-property already exists -- we do NOT override it.
// the <server> system-property takes precedence
// bnevins - 3/20/08 added support for log-service
while (true) {
// return when we get to the </config>
if (event == END_ELEMENT) {
return;
}
}
else if (event == START_ELEMENT) {
}
}
}
sawNetworkConfig = true;
}
}
}
}
else {
}
}
}
}
private void parseSecureAdmin() {
secureAdminEnabled = true;
}
}
}
private void parseNetworkConfig()
throws XMLStreamException, EndDocumentException {
// cursor --> <network-config>
while (true) {
// return when we get to the </network-config>
if (event == END_ELEMENT) {
return;
}
}
else if (event == START_ELEMENT) {
}
}
else
}
}
}
// cursor --> <server>
// these are the system-properties that OVERRIDE the ones in the <config>
while (true) {
// return when we get to the </config>
if (event == END_ELEMENT) {
return;
}
}
else if (event == START_ELEMENT) {
}
else {
}
}
}
}
// cursor --> <system-property>
}
}
// cursor --> <java-config>
// get the attributes for <java-config>
}
}
else {// profiler
}
}
}
// cursor --> START_ELEMENT of profiler
// it has attributes and <jvm-options>'s and <property>'s
// the default is true
}
else {
}
}
}
// cursor --> START_ELEMENT of property
// it has 2 attributes: name and value
}
}
while (true) {
if (event == START_ELEMENT) {
return;
}
}
}
// The cursor is pointing at the start of the document
// Move to the first 'top-level' element under name
// Return with cursor pointing to first sub-element
while (true) {
if (event == START_ELEMENT) {
throw new XMLStreamException("Unknown Domain XML Layout");
}
return;
}
}
}
/**
* The cursor will be pointing at the START_ELEMENT of name1 or name2 when it returns note that skipTree must be
* called. Otherwise we could be fooled by a sub-element with the same name as an outer element
*
* @param nameArgs An array of eligible element names to skip to
* @throws XMLStreamException
*/
while (true) {
// cursor is at a START_ELEMENT
return;
}
}
/**
* The cursor will be pointing at the START_ELEMENT of name when it returns note that skipTree must be called.
* Otherwise we could be fooled by a sub-element with the same name as an outer element Multiple startNames are
* accepted.
*
* @param endName the Element to skip to
*
* @throws XMLStreamException
*/
throws XMLStreamException, EndDocumentException {
while (true) {
if (event == START_ELEMENT) {
for (String s : startNames) {
return true;
}
}
}
if (event == END_ELEMENT) {
return false;
}
}
}
}
// The cursor is pointing at the start-element of name.
// throw everything in this element away and return with the cursor
// pointing at its end-element.
while (true) {
//System.out.println("END: " + parser.getLocalName());
return;
}
}
}
// The cursor is pointing who-knows-where
// throw everything away and return with the cursor
// pointing at the end-element.
while (true) {
return;
}
}
}
if (event == END_DOCUMENT) {
throw new EndDocumentException();
}
return event;
}
private void findOtherStuff() {
try {
// If we bump into the domain end tag first -- no sweat
//
// notice how everything is MUCH more difficult to understand because
// we are going through domain.xml in one long relentless sweep and
// we can't back up!
parseDomainProperty(); // property found -- maybe it is the domain name?
}
if (domainName == null) {
}
}
catch (Exception e) {
}
}
private void parseDomainProperty() {
// cursor --> pointing at "property" element that is a child of "domain" element
// <property name="administrative.domain.name" value="domain1"/>
if (domainName != null) {
return; // found it already
}
return;
}
domainName = value;
}
}
private void parseMonitoringService() {
// The default is, by definition, true.
// Here are all the possibilities and their resolution:
// 1. Attribute is not present --> true
// 2. Attribute is present and set to the exact string "false" --> false
// 3. Attribute is present and set to anything except "false" --> true
if (s == null) {
monitoringEnabled = true; // case 1
}
else if ("false".equals(s)) {
monitoringEnabled = false; // case 2
}
else {
monitoringEnabled = true; // case 3
}
}
}
}
private void populateAdminRealmProperties() throws
//If the adminrealm name has not been parsed,
//or if the adminRealmProperties is already populated, return
return;
}
while (true) {
while (true) {
break;
}
}
}
break;
}
}
}
// cursor --> <http-service> in <config>
// we are looking for the virtual server: "DEFAULT_ADMIN_VS_ID".
// inside it will be a ref. to a listener. We get the port from the listener.
// So -- squirrel away a copy of all the listeners and all the virt. servers --
//then post-process.
// Load the collections with both kinds of elements' attributes
while (true) {
}
}
break;
}
}
}
return; // can not find ports
}
}
// cursor --> START_ELEMENT of network-listeners
while (true) {
}
break;
}
}
}
// cursor --> START_ELEMENT of protocols
while (true) {
}
break;
}
}
}
// find the virtual server
}
break;
}
}
// make sure the "http-listeners" is kosher
}
}
if (listenerArray == null) {
}
return listenerArray;
}
// get the addresses and port numbers for all the listeners
// normally there is one listener
}
if (port >= 0) {
addr = "localhost";
boolean secure = false;
}
// ed: seven end-braces is six too many for my code!
}
break;
}
}
}
}
}
}
int port = -1;
try {
}
catch (Exception e) {
// HEY! Why are you not checking BEFORE the Exception?
// Well, it might be slower to call isToken() on strings that consist
// of just numbers. We just do this stuff if necessary...
try {
}
}
// GI but not GO !
}
}
return port;
}
}
return atts;
}
return null;
}
for (int i = 0; i < num; i++) {
}
return map;
}
// clusters is short and sweet. Just parse the whole thing first -- and then do
// the logic of finding our server in it and picking out sysprops...
// cursor ==> clusters
// if there is more than one clusters element (!weird!) only use the last one
// cursor ==> "cluster"
}
}
/*
* the cluster element has one server-ref for each server in the cluster.
* cluster has an attribute for the config-ref which is the same as in the server element
* that would make this MUCH simpler - compare server's config-ref with this
* cluster's config-ref. If they match -- then the server belongs to this cluster
* But we can't depend on it because of the nature of this serial parser. I.e.
* we may not yet have seen the server element. BUT we are given the server name
* in the constructor -- so we ALWAYS have that. So we check the more complex
* server-ref's
*/
// cursor --> cluster element
// NOT parseSystemProperty() because this might not be "our" cluster
// finalTouches() will add the correct system-property's
}
// atts is guaranteed to be non-null
}
}
}
// add any cluster system props to the data structure...
private void finalTouches() {
return;
break; // done!!
}
}
}
// this is so we can return from arbitrarily nested calls
}
}
private boolean valid = false;
private boolean monitoringEnabled = true; // Issue 12762 Absent <monitoring-service /> element means monitoring-enabled=true by default
private boolean sawNetworkConfig;
private boolean sawDefaultConfig;
private boolean sawConfig;
private boolean secureAdminEnabled = false;
}