You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2014/05/05 22:09:04 UTC
[50/51] [partial] FLEX-34306 - [BlazeDS] Make the BlazeDS build run
on Windows machines - Added some mkdir commands to the ANT Build.java - Did
some fine-tuning to resolve some compile errors
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/4f6a3052/modules/common/src/flex/messaging/LocalizedException.java
----------------------------------------------------------------------
diff --git a/modules/common/src/flex/messaging/LocalizedException.java b/modules/common/src/flex/messaging/LocalizedException.java
old mode 100755
new mode 100644
index d1967d3..4cc80d8
--- a/modules/common/src/flex/messaging/LocalizedException.java
+++ b/modules/common/src/flex/messaging/LocalizedException.java
@@ -1,379 +1,379 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging;
-
-import java.util.Locale;
-
-import flex.messaging.util.PropertyStringResourceLoader;
-import flex.messaging.util.ResourceLoader;
-
-/**
- * The LocalizedException class is the base class for server
- * exceptions that use localized error message and details strings. This class overloads
- * <code>setMessage</code> and <code>setDetails</code> to support passing an error
- * number and an optional message variant that is used to look up a localized error
- * message or details string using a <code>ResourceLoader</code>. These methods also
- * set the number property of the exception instance.
- * <p>
- * The various overloads optionally support specifying a target locale as well as
- * arguments to substitute into the localized string if it is parameterized.
- * </p><p>
- * Localized error message and details strings are stored in the flex.messaging.errors
- * resource bundle. Entries must have the following format.
- * <ul>
- * <li>Error message: {number}[-{variant}]={message}</li>
- * <li>Error details: {number}[-{variant}]-details={details}</li>
- * </ul>
- * </p>
- *
- * @see ResourceLoader
- */
-public class LocalizedException extends RuntimeException
-{
- /** @exclude - transient, the resourceLoader for localized strings doesn't need to serialize. */
- protected transient ResourceLoader resourceLoader;
- /** @exclude */
- protected int number;
- /** @exclude */
- protected String message;
- /** @exclude */
- protected String details;
- /** @exclude */
- protected Throwable rootCause;
-
- /**
- * This number was generated using the 'serialver' command line tool.
- * This number should remain consistent with the version used by
- * ColdFusion to communicate with the message broker over RMI.
- */
- private static final long serialVersionUID = 7980539484335065853L;
-
- /**
- * Create a LocalizedException with the default ResourceLoader.
- */
- public LocalizedException()
- {
- super();
- }
-
- /**
- * Create a LocalizedException that will use the specified
- * ResourceLoader.
- *
- * @param resourceLoader The resource loader to use.
- */
- public LocalizedException(ResourceLoader resourceLoader)
- {
- this.resourceLoader = resourceLoader;
- }
-
- /**
- * Returns the exception details.
- *
- * @return The exception details.
- */
- public String getDetails()
- {
- return details;
- }
-
- /**
- * Sets the exception details.
- *
- * @param details The exception details.
- */
- public void setDetails(String details)
- {
- this.details = details;
- }
-
- /**
- * Sets the message property to a localized string based on error number.
- *
- * @param number The error number for this exception instance.
- */
- public void setMessage(int number)
- {
- setMessage(number, null, null, null);
- }
-
- /**
- * Sets the message property to a localized string based on error number and target locale.
- *
- * @param number The error number for this exception instance.
- * @param locale The target locale for error message lookup.
- */
- public void setMessage(int number, Locale locale)
- {
- setMessage(number, null, locale, null);
- }
-
- /**
- * Sets the message property to a localized string based on error number.
- * The passed arguments are substituted into the parameterized error message string.
- *
- * @param number The error number for this exception instance.
- * @param arguments The arguments to substitute into the error message.
- */
- public void setMessage(int number, Object[] arguments)
- {
- setMessage(number, null, null, arguments);
- }
-
- /**
- * Sets the message property to a localized string based on error number and variant.
- *
- * @param number The error number for this exception instance.
- * @param variant The variant of the error message for this instance.
- */
- public void setMessage(int number, String variant)
- {
- setMessage(number, variant, null, null);
- }
-
- /**
- * Sets the message property to a localized string based on error number, variant
- * and target locale.
- *
- * @param number The error number for this exception instance.
- * @param variant The variant of the error message for this instance.
- * @param locale The target locale for error message lookup.
- */
- public void setMessage(int number, String variant, Locale locale)
- {
- setMessage(number, variant, locale, null);
- }
-
- /**
- * Sets the message property to a localized string based on error number and variant.
- * The passed arguments are substituted into the parameterized error message string.
- *
- * @param number The error number for this exception instance.
- * @param variant The varient of the error message for this instance.
- * @param arguments The arguments to substitute into the error message.
- */
- public void setMessage(int number, String variant, Object[] arguments)
- {
- setMessage(number, variant, null, arguments);
- }
-
- /**
- * Sets the message property to a localized string based on error number, variant and
- * target locale. The passed arguments are substituted into the parameterized error
- * message string.
- *
- * @param number The error number for this exception instance.
- * @param variant The variant of the error message for this instance.
- * @param locale The target locale for error message lookup.
- * @param arguments The arguments to substitute into the error message.
- */
- public void setMessage(int number, String variant, Locale locale, Object[] arguments)
- {
- setNumber(number);
- ResourceLoader resources = getResourceLoader();
- setMessage(resources.getString(generateFullKey(number, variant), locale, arguments));
- }
-
- /**
- * Returns the exception message.
- *
- * @return The exception message.
- */
- public String getMessage()
- {
- return message;
- }
-
- /**
- * Sets the exception message.
- *
- * @param message The exception message.
- */
- public void setMessage(String message)
- {
- this.message = message;
- }
-
- /**
- * Sets the localized exception number.
- *
- * @param number The localized exception number.
- */
- public void setNumber(int number)
- {
- this.number = number;
- }
-
- /**
- * Returns the localized exception number.
- *
- * @return The localized exception number.
- */
- public int getNumber()
- {
- return number;
- }
-
- /**
- * Sets the details property to a localized string based on error number.
- *
- * @param number The error number to lookup details for.
- */
- public void setDetails(int number)
- {
- setDetails(number, null, null, null);
- }
-
- /**
- * Sets the details property to a localized string based on error number and variant.
- *
- * @param number The error number to lookup details for.
- * @param variant The variant of the details string to lookup.
- */
- public void setDetails(int number, String variant)
- {
- setDetails(number, variant, null, null);
- }
-
- /**
- * Sets the details property to a localized string based on error number, variant
- * and target locale.
- *
- * @param number The error number to lookup details for.
- * @param variant The variant of the details string to lookup.
- * @param locale The target locale for the lookup.
- */
- public void setDetails(int number, String variant, Locale locale)
- {
- setDetails(number, variant, locale, null);
- }
-
- /**
- * Sets the details property to a localized string based on error number and variant.
- * The passed arguments are substituted into the parameterized error details string.
- *
- * @param number The error number to lookup details for.
- * @param variant The variant of the details string to lookup.
- * @param arguments The arguments to substitute into the details string.
- */
- public void setDetails(int number, String variant, Object[] arguments)
- {
- setDetails(number, variant, null, arguments);
- }
-
-
- /**
- * Sets the details property to a localized string based on error number, variant,
- * and target locale. The passed arguments are substituted into the parameterized error
- * details string.
- *
- * @param number The error number to lookup a localized details string for.
- * @param variant The variant of the details string to lookup.
- * @param locale The target locale for the lookup.
- * @param arguments The arguments to substitute into the details string.
- */
- public void setDetails(int number, String variant, Locale locale, Object[] arguments)
- {
- setNumber(number);
- ResourceLoader resources = getResourceLoader();
- setDetails(resources.getString(generateDetailsKey(number, variant), locale, arguments));
- }
-
- /**
- * Returns the root cause for this exception.
- *
- * @return The root cause for this exception.
- */
- public Throwable getRootCause()
- {
- return rootCause;
- }
-
- /**
- * Sets the root cause for this exception.
- *
- * @param cause The root cause for this exception.
- */
- public void setRootCause(Throwable cause)
- {
- rootCause = cause;
- // Assign through to the base cause property to include it in general stack traces.
- initCause(cause);
- }
-
- /**
- * Returns the <code>ResourceLoader</code> used to load localized strings.
- *
- * @return The <code>ResourceLoader</code> used to load localized strings.
- */
- protected ResourceLoader getResourceLoader()
- {
- if (resourceLoader == null)
- resourceLoader = new PropertyStringResourceLoader();
-
- return resourceLoader;
- }
-
- /**
- * Generates the full key to lookup a localized error message based on an error number
- * and an optional variant followed by a "-details" suffix. If the variant is null, the
- * lookup key is the error number.
- *
- * @param number The error number.
- * @param variant The variant of the error message.
- * @return The full lookup key for a localized error message.
- */
- private String generateFullKey(int number, String variant)
- {
- return (variant != null) ? (number + "-" + variant) : String.valueOf(number);
- }
-
- /**
- * Generates the full key to lookup a localized details string based on an error number
- * and an optional variant followed by a "-details" suffix. If the variant is null, the
- * lookup key is the error number followed by a "-details" suffix.
- *
- * @param number The error number.
- * @param variant The variant of the details message.
- * @return The full lookup key for a localized details message.
- */
- private String generateDetailsKey(int number, String variant)
- {
- return (generateFullKey(number, variant) + "-details");
- }
-
- /**
- * Returns a string represenation of the exception.
- *
- * @return A string representation of the exception.
- */
- public String toString()
- {
- String result = super.toString();
- if (details != null)
- {
- StringBuffer buffer = new StringBuffer(result);
- if (!result.endsWith("."))
- {
- buffer.append(".");
- }
- buffer.append(' ').append(details);
- result = buffer.toString();
- }
- return result;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package flex.messaging;
+
+import java.util.Locale;
+
+import flex.messaging.util.PropertyStringResourceLoader;
+import flex.messaging.util.ResourceLoader;
+
+/**
+ * The LocalizedException class is the base class for server
+ * exceptions that use localized error message and details strings. This class overloads
+ * <code>setMessage</code> and <code>setDetails</code> to support passing an error
+ * number and an optional message variant that is used to look up a localized error
+ * message or details string using a <code>ResourceLoader</code>. These methods also
+ * set the number property of the exception instance.
+ * <p>
+ * The various overloads optionally support specifying a target locale as well as
+ * arguments to substitute into the localized string if it is parameterized.
+ * </p><p>
+ * Localized error message and details strings are stored in the flex.messaging.errors
+ * resource bundle. Entries must have the following format.
+ * <ul>
+ * <li>Error message: {number}[-{variant}]={message}</li>
+ * <li>Error details: {number}[-{variant}]-details={details}</li>
+ * </ul>
+ * </p>
+ *
+ * @see ResourceLoader
+ */
+public class LocalizedException extends RuntimeException
+{
+ /** @exclude - transient, the resourceLoader for localized strings doesn't need to serialize. */
+ protected transient ResourceLoader resourceLoader;
+ /** @exclude */
+ protected int number;
+ /** @exclude */
+ protected String message;
+ /** @exclude */
+ protected String details;
+ /** @exclude */
+ protected Throwable rootCause;
+
+ /**
+ * This number was generated using the 'serialver' command line tool.
+ * This number should remain consistent with the version used by
+ * ColdFusion to communicate with the message broker over RMI.
+ */
+ private static final long serialVersionUID = 7980539484335065853L;
+
+ /**
+ * Create a LocalizedException with the default ResourceLoader.
+ */
+ public LocalizedException()
+ {
+ super();
+ }
+
+ /**
+ * Create a LocalizedException that will use the specified
+ * ResourceLoader.
+ *
+ * @param resourceLoader The resource loader to use.
+ */
+ public LocalizedException(ResourceLoader resourceLoader)
+ {
+ this.resourceLoader = resourceLoader;
+ }
+
+ /**
+ * Returns the exception details.
+ *
+ * @return The exception details.
+ */
+ public String getDetails()
+ {
+ return details;
+ }
+
+ /**
+ * Sets the exception details.
+ *
+ * @param details The exception details.
+ */
+ public void setDetails(String details)
+ {
+ this.details = details;
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number.
+ *
+ * @param number The error number for this exception instance.
+ */
+ public void setMessage(int number)
+ {
+ setMessage(number, null, null, null);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number and target locale.
+ *
+ * @param number The error number for this exception instance.
+ * @param locale The target locale for error message lookup.
+ */
+ public void setMessage(int number, Locale locale)
+ {
+ setMessage(number, null, locale, null);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number.
+ * The passed arguments are substituted into the parameterized error message string.
+ *
+ * @param number The error number for this exception instance.
+ * @param arguments The arguments to substitute into the error message.
+ */
+ public void setMessage(int number, Object[] arguments)
+ {
+ setMessage(number, null, null, arguments);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number and variant.
+ *
+ * @param number The error number for this exception instance.
+ * @param variant The variant of the error message for this instance.
+ */
+ public void setMessage(int number, String variant)
+ {
+ setMessage(number, variant, null, null);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number, variant
+ * and target locale.
+ *
+ * @param number The error number for this exception instance.
+ * @param variant The variant of the error message for this instance.
+ * @param locale The target locale for error message lookup.
+ */
+ public void setMessage(int number, String variant, Locale locale)
+ {
+ setMessage(number, variant, locale, null);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number and variant.
+ * The passed arguments are substituted into the parameterized error message string.
+ *
+ * @param number The error number for this exception instance.
+ * @param variant The varient of the error message for this instance.
+ * @param arguments The arguments to substitute into the error message.
+ */
+ public void setMessage(int number, String variant, Object[] arguments)
+ {
+ setMessage(number, variant, null, arguments);
+ }
+
+ /**
+ * Sets the message property to a localized string based on error number, variant and
+ * target locale. The passed arguments are substituted into the parameterized error
+ * message string.
+ *
+ * @param number The error number for this exception instance.
+ * @param variant The variant of the error message for this instance.
+ * @param locale The target locale for error message lookup.
+ * @param arguments The arguments to substitute into the error message.
+ */
+ public void setMessage(int number, String variant, Locale locale, Object[] arguments)
+ {
+ setNumber(number);
+ ResourceLoader resources = getResourceLoader();
+ setMessage(resources.getString(generateFullKey(number, variant), locale, arguments));
+ }
+
+ /**
+ * Returns the exception message.
+ *
+ * @return The exception message.
+ */
+ public String getMessage()
+ {
+ return message;
+ }
+
+ /**
+ * Sets the exception message.
+ *
+ * @param message The exception message.
+ */
+ public void setMessage(String message)
+ {
+ this.message = message;
+ }
+
+ /**
+ * Sets the localized exception number.
+ *
+ * @param number The localized exception number.
+ */
+ public void setNumber(int number)
+ {
+ this.number = number;
+ }
+
+ /**
+ * Returns the localized exception number.
+ *
+ * @return The localized exception number.
+ */
+ public int getNumber()
+ {
+ return number;
+ }
+
+ /**
+ * Sets the details property to a localized string based on error number.
+ *
+ * @param number The error number to lookup details for.
+ */
+ public void setDetails(int number)
+ {
+ setDetails(number, null, null, null);
+ }
+
+ /**
+ * Sets the details property to a localized string based on error number and variant.
+ *
+ * @param number The error number to lookup details for.
+ * @param variant The variant of the details string to lookup.
+ */
+ public void setDetails(int number, String variant)
+ {
+ setDetails(number, variant, null, null);
+ }
+
+ /**
+ * Sets the details property to a localized string based on error number, variant
+ * and target locale.
+ *
+ * @param number The error number to lookup details for.
+ * @param variant The variant of the details string to lookup.
+ * @param locale The target locale for the lookup.
+ */
+ public void setDetails(int number, String variant, Locale locale)
+ {
+ setDetails(number, variant, locale, null);
+ }
+
+ /**
+ * Sets the details property to a localized string based on error number and variant.
+ * The passed arguments are substituted into the parameterized error details string.
+ *
+ * @param number The error number to lookup details for.
+ * @param variant The variant of the details string to lookup.
+ * @param arguments The arguments to substitute into the details string.
+ */
+ public void setDetails(int number, String variant, Object[] arguments)
+ {
+ setDetails(number, variant, null, arguments);
+ }
+
+
+ /**
+ * Sets the details property to a localized string based on error number, variant,
+ * and target locale. The passed arguments are substituted into the parameterized error
+ * details string.
+ *
+ * @param number The error number to lookup a localized details string for.
+ * @param variant The variant of the details string to lookup.
+ * @param locale The target locale for the lookup.
+ * @param arguments The arguments to substitute into the details string.
+ */
+ public void setDetails(int number, String variant, Locale locale, Object[] arguments)
+ {
+ setNumber(number);
+ ResourceLoader resources = getResourceLoader();
+ setDetails(resources.getString(generateDetailsKey(number, variant), locale, arguments));
+ }
+
+ /**
+ * Returns the root cause for this exception.
+ *
+ * @return The root cause for this exception.
+ */
+ public Throwable getRootCause()
+ {
+ return rootCause;
+ }
+
+ /**
+ * Sets the root cause for this exception.
+ *
+ * @param cause The root cause for this exception.
+ */
+ public void setRootCause(Throwable cause)
+ {
+ rootCause = cause;
+ // Assign through to the base cause property to include it in general stack traces.
+ initCause(cause);
+ }
+
+ /**
+ * Returns the <code>ResourceLoader</code> used to load localized strings.
+ *
+ * @return The <code>ResourceLoader</code> used to load localized strings.
+ */
+ protected ResourceLoader getResourceLoader()
+ {
+ if (resourceLoader == null)
+ resourceLoader = new PropertyStringResourceLoader();
+
+ return resourceLoader;
+ }
+
+ /**
+ * Generates the full key to lookup a localized error message based on an error number
+ * and an optional variant followed by a "-details" suffix. If the variant is null, the
+ * lookup key is the error number.
+ *
+ * @param number The error number.
+ * @param variant The variant of the error message.
+ * @return The full lookup key for a localized error message.
+ */
+ private String generateFullKey(int number, String variant)
+ {
+ return (variant != null) ? (number + "-" + variant) : String.valueOf(number);
+ }
+
+ /**
+ * Generates the full key to lookup a localized details string based on an error number
+ * and an optional variant followed by a "-details" suffix. If the variant is null, the
+ * lookup key is the error number followed by a "-details" suffix.
+ *
+ * @param number The error number.
+ * @param variant The variant of the details message.
+ * @return The full lookup key for a localized details message.
+ */
+ private String generateDetailsKey(int number, String variant)
+ {
+ return (generateFullKey(number, variant) + "-details");
+ }
+
+ /**
+ * Returns a string represenation of the exception.
+ *
+ * @return A string representation of the exception.
+ */
+ public String toString()
+ {
+ String result = super.toString();
+ if (details != null)
+ {
+ StringBuffer buffer = new StringBuffer(result);
+ if (!result.endsWith("."))
+ {
+ buffer.append(".");
+ }
+ buffer.append(' ').append(details);
+ result = buffer.toString();
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/4f6a3052/modules/common/src/flex/messaging/config/AbstractConfigurationParser.java
----------------------------------------------------------------------
diff --git a/modules/common/src/flex/messaging/config/AbstractConfigurationParser.java b/modules/common/src/flex/messaging/config/AbstractConfigurationParser.java
old mode 100755
new mode 100644
index 98fcfce..820f7ea
--- a/modules/common/src/flex/messaging/config/AbstractConfigurationParser.java
+++ b/modules/common/src/flex/messaging/config/AbstractConfigurationParser.java
@@ -1,559 +1,559 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.config;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import flex.messaging.util.FileUtils;
-
-/**
- * Provides a common base for DOM / XPath based ConfigurationParsers.
- *
- * @author Peter Farland
- * @exclude
- */
-public abstract class AbstractConfigurationParser implements ConfigurationParser, ConfigurationConstants, EntityResolver
-{
- protected ServicesConfiguration config;
- protected DocumentBuilder docBuilder;
- protected ConfigurationFileResolver fileResolver;
- protected TokenReplacer tokenReplacer;
-
- private Map fileByDocument = new HashMap();
-
- protected AbstractConfigurationParser()
- {
- initializeDocumentBuilder();
- tokenReplacer = new TokenReplacer();
- }
-
- /**
- * Parse the configurations in the configuration file.
- * <p/>
- * @param path the configuration file path
- * @param fileResolver the ConfigurationFileResolver object
- * @param config the ServicesConfiguration object
- **/
- public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config)
- {
- this.config = config;
- this.fileResolver = fileResolver;
- Document doc = loadDocument(path, fileResolver.getConfigurationFile(path));
- initializeExpressionQuery();
- parseTopLevelConfig(doc);
- }
-
- /**
- * Report Tokens.
- * <p/>
- **/
- public void reportTokens()
- {
- tokenReplacer.reportTokens();
- }
-
- protected void initializeDocumentBuilder()
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setIgnoringComments(true);
- factory.setIgnoringElementContentWhitespace(true);
-
- try
- {
- docBuilder = factory.newDocumentBuilder();
- docBuilder.setEntityResolver(this);
- }
- catch (ParserConfigurationException ex)
- {
- // Error initializing configuration parser.
- ConfigurationException e = new ConfigurationException();
- e.setMessage(PARSER_INIT_ERROR);
- e.setRootCause(ex);
- throw e;
- }
- }
-
- protected Document loadDocument(String path, InputStream in)
- {
- try
- {
- Document doc;
-
- if (!in.markSupported())
- in = new BufferedInputStream(in);
-
- // Consume UTF-8 Byte Order Mark (BOM). The InputStream must support mark()
- // as FileUtils.consumeBOM sets a mark for 3 bytes in order to check for a BOM.
- String encoding = FileUtils.consumeBOM(in, null);
- if (FileUtils.UTF_8.equals(encoding) || FileUtils.UTF_16.equals(encoding))
- {
- InputSource inputSource = new InputSource(in);
- inputSource.setEncoding(encoding);
- doc = docBuilder.parse(inputSource);
- }
- else
- {
- doc = docBuilder.parse(in);
- }
-
- addFileByDocument(path, doc);
- doc.getDocumentElement().normalize();
- return doc;
- }
- catch (SAXParseException ex)
- {
- Integer line = new Integer(ex.getLineNumber());
- Integer col = new Integer(ex.getColumnNumber());
- String message = ex.getMessage();
-
- // Configuration error on line {line}, column {col}: '{message}'
- ConfigurationException e = new ConfigurationException();
- e.setMessage(XML_PARSER_ERROR, new Object[]{line, col, message});
- e.setRootCause(ex);
- throw e;
- }
- catch (SAXException ex)
- {
- ConfigurationException e = new ConfigurationException();
- e.setMessage(ex.getMessage());
- e.setRootCause(ex);
- throw e;
- }
- catch (IOException ex)
- {
- ConfigurationException e = new ConfigurationException();
- e.setMessage(ex.getMessage());
- e.setRootCause(ex);
- throw e;
- }
- }
-
- protected void addFileByDocument(String path, Node node)
- {
- String shortPath = path;
- if (shortPath != null && ((shortPath.indexOf('/') != -1) || (shortPath.indexOf("\\") != -1)) )
- {
- int start = 0;
- start = shortPath.lastIndexOf('/');
- if (start == -1)
- {
- start = shortPath.lastIndexOf("\\");
- }
- shortPath = path.substring(start + 1);
- }
- fileByDocument.put(node, shortPath);
- }
-
- protected String getSourceFileOf(Node node)
- {
- return (String)fileByDocument.get(node.getOwnerDocument());
- }
-
- protected abstract void parseTopLevelConfig(Document doc);
-
- protected abstract void initializeExpressionQuery();
- protected abstract Node selectSingleNode(Node source, String expression);
- protected abstract NodeList selectNodeList(Node source, String expression);
- protected abstract Object evaluateExpression(Node source, String expression);
-
- /**
- * Recursively processes all child elements for each of the properties in the provided
- * node list.
- * <p>
- * If a property is a simple element with a text value then it is stored as a String
- * using the element name as the property name. If the same element appears again then
- * the element is converted to a List of values and further occurences are simply added
- * to the List.
- * </p>
- * <p>
- * If a property element has child elements the children are recursively processed
- * and added as a Map.
- * </p>
- * <p>
- * The sourceFileName argument is used as a parameter for token replacement in order
- * to generate a meaningful error message when a token is failed to be replaced.
- * </p>
- * @param properties the NodeList object
- * @return ConfigMap the ConfigMap object
- */
- public ConfigMap properties(NodeList properties)
- {
- return properties(properties, ConfigurationConstants.UNKNOWN_SOURCE_FILE);
- }
-
- /**
- * Recursively processes all child elements for each of the properties in the provided
- * node list.
- * <p/>
- * @param properties the NodeList object
- * @param sourceFileName the source file name
- * @return ConfigMap the ConfigMap object
- */
- public ConfigMap properties(NodeList properties, String sourceFileName)
- {
- int length = properties.getLength();
- ConfigMap map = new ConfigMap(length);
-
- for (int p = 0; p < length; p++)
- {
- Node prop = properties.item(p);
- String propName = prop.getNodeName();
-
- if (propName != null)
- {
- propName = propName.trim();
- if (prop.getNodeType() == Node.ELEMENT_NODE)
- {
- NodeList attributes = selectNodeList(prop, "@*");
- NodeList children = selectNodeList(prop, "*");
- if (children.getLength() > 0 || attributes.getLength() > 0)
- {
- ConfigMap childMap = new ConfigMap();
-
- if (children.getLength() > 0)
- childMap.addProperties(properties(children, sourceFileName));
-
- if (attributes.getLength() > 0)
- childMap.addProperties(properties(attributes, sourceFileName));
-
- map.addProperty(propName, childMap);
- }
- else
- {
- // replace tokens before setting property
- tokenReplacer.replaceToken(prop, sourceFileName);
- String propValue = evaluateExpression(prop, ".").toString();
- map.addProperty(propName, propValue);
- }
- }
- else
- {
- // replace tokens before setting property
- tokenReplacer.replaceToken(prop, sourceFileName);
- map.addProperty(propName, prop.getNodeValue());
- }
- }
- }
-
- return map;
- }
-
- /**
- * Get the item value by name if the item is present in the current node as attribute or child element.
- * <p/>
- * @param node the current Node object
- * @param name item name
- * @return String the value of item
- **/
- public String getAttributeOrChildElement(Node node, String name)
- {
- String attr = evaluateExpression(node, "@" + name).toString().trim();
- if (attr.length() == 0)
- {
- attr = evaluateExpression(node, name).toString().trim();
- }
- return attr;
- }
-
- /**
- * Check whether the required items are present in the current node as child elements.
- * <p/>
- * @param node the current Node object
- * @param allowed the String array of the allowed items
- **/
- public void allowedChildElements(Node node, String[] allowed)
- {
- NodeList children = selectNodeList(node, "*");
-
- String unexpected = unexpected(children, allowed);
- if (unexpected != null)
- {
- // Unexpected child element '{0}' found in '{1}'.
- ConfigurationException ex = new ConfigurationException();
- Object[] args = {unexpected, node.getNodeName(), getSourceFilename(node)};
- ex.setMessage(UNEXPECTED_ELEMENT, args);
- throw ex;
- }
-
- NodeList textNodes = selectNodeList(node, "text()");
- for (int i = 0; i < textNodes.getLength(); i++)
- {
- String text = evaluateExpression(textNodes.item(i), ".").toString().trim();
- if (text.length() > 0)
- {
- //Unexpected text '{0}' found in '{1}'.
- ConfigurationException ex = new ConfigurationException();
- Object[] args = {text, node.getNodeName(), getSourceFilename(node)};
- ex.setMessage(UNEXPECTED_TEXT, args);
- throw ex;
- }
- }
- }
-
- /**
- * Check whether the required items are present in the current node as attributes.
- * <p/>
- * @param node the current Node object
- * @param allowed the String array of the allowed items
- **/
-
- public void allowedAttributes(Node node, String[] allowed)
- {
- NodeList attributes = selectNodeList(node, "@*");
- String unexpectedAttribute = unexpected(attributes, allowed);
- if (unexpectedAttribute != null)
- {
- //Unexpected attribute '{0}' found in '{1}'.
- ConfigurationException ex = new ConfigurationException();
- Object[] args =
- {unexpectedAttribute, node.getNodeName(), getSourceFilename(node)};
- ex.setMessage(UNEXPECTED_ATTRIBUTE, args);
- throw ex;
- }
- }
-
- private String getSourceFilename(Node node)
- {
- return getSourceFileOf(node);
- }
-
- /**
- * Check whether the allowed items are present in the current node as elements or attributes.
- * <p/>
- * @param node the current Node object
- * @param allowed the String array of the allowed items
- **/
-
- public void allowedAttributesOrElements(Node node, String[] allowed)
- {
- allowedAttributes(node, allowed);
- allowedChildElements(node, allowed);
- }
-
- /**
- * Check whether the required items are present in the current node as elements or attributes.
- * <p/>
- * @param node the current Node object
- * @param required the String array of the required items
- **/
- public void requiredAttributesOrElements(Node node, String[] required)
- {
- String nodeName = node.getNodeName();
- NodeList attributes = selectNodeList(node, "@*");
-
- List list = new ArrayList();
- for (int i = 0; i < required.length; i++)
- {
- list.add(required[i]);
- }
-
- String missingAttribute = null;
-
- do
- {
- missingAttribute = required(attributes, list);
- if (missingAttribute != null)
- {
- Node child = selectSingleNode(node, missingAttribute);
- if (child != null)
- {
- list.remove(missingAttribute);
- }
- else
- {
- // Attribute '{0}' must be specified for element '{1}'
- ConfigurationException ex = new ConfigurationException();
- ex.setMessage(MISSING_ATTRIBUTE, new Object[]{missingAttribute, nodeName});
- throw ex;
- }
- }
- }
- while (missingAttribute != null && list.size() > 0);
- }
-
- /**
- * Check whether the required items are present in the current node (Child elements).
- * <p/>
- * @param node the current Node object
- * @param required the String array of the required items
- **/
- public void requiredChildElements(Node node, String[] required)
- {
- String nodeName = node.getNodeName();
- NodeList children = selectNodeList(node, "*");
-
- List list = new ArrayList();
- for (int i = 0; i < required.length; i++)
- {
- list.add(required[i]);
- }
-
- String missing = required(children, list);
- if (missing != null)
- {
- // Child element '{0}' must be specified for element '{1}'
- ConfigurationException ex = new ConfigurationException();
- ex.setMessage(MISSING_ELEMENT, new Object[]{missing, nodeName});
- throw ex;
- }
- }
-
- /**
- * Check whether there is any unexpected item in the node list object.
- * <p/>
- * @param attributes the current NodeList object
- * @param allowed, the String array of allowed items
- * @return Name of the first unexpected item from the list of allowed attributes, or null if all
- * items present were allowed.
- **/
- public String unexpected(NodeList attributes, String[] allowed)
- {
- for (int i = 0; i < attributes.getLength(); i++)
- {
- Node attrib = attributes.item(i);
- String attribName = attrib.getNodeName();
- boolean match = false;
-
- for (int j = 0; j < allowed.length; j++)
- {
- String a = allowed[j];
- if (a.equals(attribName))
- {
- match = true;
- break;
- }
- }
-
- if (!match)
- {
- return attribName;
- }
-
- // Go ahead and replace tokens in node values.
- tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
- }
-
- return null;
- }
-
- /**
- * Check whether all the required items are present in the node list.
- * @param attributes the NodeList object
- * @param required a list of required items
- * @return Name of the first missing item from the list of required attributes, or null if all required
- * items were present.
- **/
- public String required(NodeList attributes, List required)
- {
- for (int i = 0; i < required.size(); i++)
- {
- boolean found = false;
- String req = (String)required.get(i);
-
- Node attrib = null;
- for (int j = 0; j < attributes.getLength(); j++)
- {
- attrib = attributes.item(j);
- String attribName = attrib.getNodeName();
-
- if (req.equals(attribName))
- {
- found = true;
- break;
- }
- }
-
- if (!found)
- {
- return req;
- }
-
- // Go ahead and replace tokens in node values.
- tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
-
- }
-
- return null;
- }
-
-
- /**
- * Tests whether a configuration element's id is a valid
- * identifier. An id must be a String that is not null,
- * greater than 0 characters in length and not contain
- * any of the list delimiter characters, i.e. commas,
- * semi-colons or colons.
- * @param id the Id String
- * @return boolean true if the id string is valid identification
- * @see ConfigurationConstants#LIST_DELIMITERS
- */
- public static boolean isValidID(String id)
- {
- if (id != null && id.length() > 0 && id.length() < 256)
- {
- char[] chars = id.toCharArray();
- for (int i = 0; i < chars.length; i++)
- {
- char c = chars[i];
- if (LIST_DELIMITERS.indexOf(c) != -1)
- {
- return false;
- }
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Implement {@link org.xml.sax.EntityResolver#resolveEntity(String, String)}.
- *
- * Flex Configuration does not need or use external entities, so disallow external entities
- * to prevent external entity injection attacks.
- * @param publicId the public Id
- * @param systemId the system Id
- * @throws SAXException, IOException when the parsing process failed with exceptions
- * @return InputSource the InputSource object
- */
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
- {
- // Flex Configuration does not allow external entity defined by publicId {0} and SystemId {1}
- ConfigurationException ex = new ConfigurationException();
- ex.setMessage(EXTERNAL_ENTITY_NOT_ALLOW, new Object[] { publicId, systemId });
- throw ex;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package flex.messaging.config;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import flex.messaging.util.FileUtils;
+
+/**
+ * Provides a common base for DOM / XPath based ConfigurationParsers.
+ *
+ * @author Peter Farland
+ * @exclude
+ */
+public abstract class AbstractConfigurationParser implements ConfigurationParser, ConfigurationConstants, EntityResolver
+{
+ protected ServicesConfiguration config;
+ protected DocumentBuilder docBuilder;
+ protected ConfigurationFileResolver fileResolver;
+ protected TokenReplacer tokenReplacer;
+
+ private Map fileByDocument = new HashMap();
+
+ protected AbstractConfigurationParser()
+ {
+ initializeDocumentBuilder();
+ tokenReplacer = new TokenReplacer();
+ }
+
+ /**
+ * Parse the configurations in the configuration file.
+ * <p/>
+ * @param path the configuration file path
+ * @param fileResolver the ConfigurationFileResolver object
+ * @param config the ServicesConfiguration object
+ **/
+ public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config)
+ {
+ this.config = config;
+ this.fileResolver = fileResolver;
+ Document doc = loadDocument(path, fileResolver.getConfigurationFile(path));
+ initializeExpressionQuery();
+ parseTopLevelConfig(doc);
+ }
+
+ /**
+ * Report Tokens.
+ * <p/>
+ **/
+ public void reportTokens()
+ {
+ tokenReplacer.reportTokens();
+ }
+
+ protected void initializeDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setIgnoringComments(true);
+ factory.setIgnoringElementContentWhitespace(true);
+
+ try
+ {
+ docBuilder = factory.newDocumentBuilder();
+ docBuilder.setEntityResolver(this);
+ }
+ catch (ParserConfigurationException ex)
+ {
+ // Error initializing configuration parser.
+ ConfigurationException e = new ConfigurationException();
+ e.setMessage(PARSER_INIT_ERROR);
+ e.setRootCause(ex);
+ throw e;
+ }
+ }
+
+ protected Document loadDocument(String path, InputStream in)
+ {
+ try
+ {
+ Document doc;
+
+ if (!in.markSupported())
+ in = new BufferedInputStream(in);
+
+ // Consume UTF-8 Byte Order Mark (BOM). The InputStream must support mark()
+ // as FileUtils.consumeBOM sets a mark for 3 bytes in order to check for a BOM.
+ String encoding = FileUtils.consumeBOM(in, null);
+ if (FileUtils.UTF_8.equals(encoding) || FileUtils.UTF_16.equals(encoding))
+ {
+ InputSource inputSource = new InputSource(in);
+ inputSource.setEncoding(encoding);
+ doc = docBuilder.parse(inputSource);
+ }
+ else
+ {
+ doc = docBuilder.parse(in);
+ }
+
+ addFileByDocument(path, doc);
+ doc.getDocumentElement().normalize();
+ return doc;
+ }
+ catch (SAXParseException ex)
+ {
+ Integer line = new Integer(ex.getLineNumber());
+ Integer col = new Integer(ex.getColumnNumber());
+ String message = ex.getMessage();
+
+ // Configuration error on line {line}, column {col}: '{message}'
+ ConfigurationException e = new ConfigurationException();
+ e.setMessage(XML_PARSER_ERROR, new Object[]{line, col, message});
+ e.setRootCause(ex);
+ throw e;
+ }
+ catch (SAXException ex)
+ {
+ ConfigurationException e = new ConfigurationException();
+ e.setMessage(ex.getMessage());
+ e.setRootCause(ex);
+ throw e;
+ }
+ catch (IOException ex)
+ {
+ ConfigurationException e = new ConfigurationException();
+ e.setMessage(ex.getMessage());
+ e.setRootCause(ex);
+ throw e;
+ }
+ }
+
+ protected void addFileByDocument(String path, Node node)
+ {
+ String shortPath = path;
+ if (shortPath != null && ((shortPath.indexOf('/') != -1) || (shortPath.indexOf("\\") != -1)) )
+ {
+ int start = 0;
+ start = shortPath.lastIndexOf('/');
+ if (start == -1)
+ {
+ start = shortPath.lastIndexOf("\\");
+ }
+ shortPath = path.substring(start + 1);
+ }
+ fileByDocument.put(node, shortPath);
+ }
+
+ protected String getSourceFileOf(Node node)
+ {
+ return (String)fileByDocument.get(node.getOwnerDocument());
+ }
+
+ protected abstract void parseTopLevelConfig(Document doc);
+
+ protected abstract void initializeExpressionQuery();
+ protected abstract Node selectSingleNode(Node source, String expression);
+ protected abstract NodeList selectNodeList(Node source, String expression);
+ protected abstract Object evaluateExpression(Node source, String expression);
+
+ /**
+ * Recursively processes all child elements for each of the properties in the provided
+ * node list.
+ * <p>
+ * If a property is a simple element with a text value then it is stored as a String
+ * using the element name as the property name. If the same element appears again then
+ * the element is converted to a List of values and further occurences are simply added
+ * to the List.
+ * </p>
+ * <p>
+ * If a property element has child elements the children are recursively processed
+ * and added as a Map.
+ * </p>
+ * <p>
+ * The sourceFileName argument is used as a parameter for token replacement in order
+ * to generate a meaningful error message when a token is failed to be replaced.
+ * </p>
+ * @param properties the NodeList object
+ * @return ConfigMap the ConfigMap object
+ */
+ public ConfigMap properties(NodeList properties)
+ {
+ return properties(properties, ConfigurationConstants.UNKNOWN_SOURCE_FILE);
+ }
+
+ /**
+ * Recursively processes all child elements for each of the properties in the provided
+ * node list.
+ * <p/>
+ * @param properties the NodeList object
+ * @param sourceFileName the source file name
+ * @return ConfigMap the ConfigMap object
+ */
+ public ConfigMap properties(NodeList properties, String sourceFileName)
+ {
+ int length = properties.getLength();
+ ConfigMap map = new ConfigMap(length);
+
+ for (int p = 0; p < length; p++)
+ {
+ Node prop = properties.item(p);
+ String propName = prop.getNodeName();
+
+ if (propName != null)
+ {
+ propName = propName.trim();
+ if (prop.getNodeType() == Node.ELEMENT_NODE)
+ {
+ NodeList attributes = selectNodeList(prop, "@*");
+ NodeList children = selectNodeList(prop, "*");
+ if (children.getLength() > 0 || attributes.getLength() > 0)
+ {
+ ConfigMap childMap = new ConfigMap();
+
+ if (children.getLength() > 0)
+ childMap.addProperties(properties(children, sourceFileName));
+
+ if (attributes.getLength() > 0)
+ childMap.addProperties(properties(attributes, sourceFileName));
+
+ map.addProperty(propName, childMap);
+ }
+ else
+ {
+ // replace tokens before setting property
+ tokenReplacer.replaceToken(prop, sourceFileName);
+ String propValue = evaluateExpression(prop, ".").toString();
+ map.addProperty(propName, propValue);
+ }
+ }
+ else
+ {
+ // replace tokens before setting property
+ tokenReplacer.replaceToken(prop, sourceFileName);
+ map.addProperty(propName, prop.getNodeValue());
+ }
+ }
+ }
+
+ return map;
+ }
+
+ /**
+ * Get the item value by name if the item is present in the current node as attribute or child element.
+ * <p/>
+ * @param node the current Node object
+ * @param name item name
+ * @return String the value of item
+ **/
+ public String getAttributeOrChildElement(Node node, String name)
+ {
+ String attr = evaluateExpression(node, "@" + name).toString().trim();
+ if (attr.length() == 0)
+ {
+ attr = evaluateExpression(node, name).toString().trim();
+ }
+ return attr;
+ }
+
+ /**
+ * Check whether the required items are present in the current node as child elements.
+ * <p/>
+ * @param node the current Node object
+ * @param allowed the String array of the allowed items
+ **/
+ public void allowedChildElements(Node node, String[] allowed)
+ {
+ NodeList children = selectNodeList(node, "*");
+
+ String unexpected = unexpected(children, allowed);
+ if (unexpected != null)
+ {
+ // Unexpected child element '{0}' found in '{1}'.
+ ConfigurationException ex = new ConfigurationException();
+ Object[] args = {unexpected, node.getNodeName(), getSourceFilename(node)};
+ ex.setMessage(UNEXPECTED_ELEMENT, args);
+ throw ex;
+ }
+
+ NodeList textNodes = selectNodeList(node, "text()");
+ for (int i = 0; i < textNodes.getLength(); i++)
+ {
+ String text = evaluateExpression(textNodes.item(i), ".").toString().trim();
+ if (text.length() > 0)
+ {
+ //Unexpected text '{0}' found in '{1}'.
+ ConfigurationException ex = new ConfigurationException();
+ Object[] args = {text, node.getNodeName(), getSourceFilename(node)};
+ ex.setMessage(UNEXPECTED_TEXT, args);
+ throw ex;
+ }
+ }
+ }
+
+ /**
+ * Check whether the required items are present in the current node as attributes.
+ * <p/>
+ * @param node the current Node object
+ * @param allowed the String array of the allowed items
+ **/
+
+ public void allowedAttributes(Node node, String[] allowed)
+ {
+ NodeList attributes = selectNodeList(node, "@*");
+ String unexpectedAttribute = unexpected(attributes, allowed);
+ if (unexpectedAttribute != null)
+ {
+ //Unexpected attribute '{0}' found in '{1}'.
+ ConfigurationException ex = new ConfigurationException();
+ Object[] args =
+ {unexpectedAttribute, node.getNodeName(), getSourceFilename(node)};
+ ex.setMessage(UNEXPECTED_ATTRIBUTE, args);
+ throw ex;
+ }
+ }
+
+ private String getSourceFilename(Node node)
+ {
+ return getSourceFileOf(node);
+ }
+
+ /**
+ * Check whether the allowed items are present in the current node as elements or attributes.
+ * <p/>
+ * @param node the current Node object
+ * @param allowed the String array of the allowed items
+ **/
+
+ public void allowedAttributesOrElements(Node node, String[] allowed)
+ {
+ allowedAttributes(node, allowed);
+ allowedChildElements(node, allowed);
+ }
+
+ /**
+ * Check whether the required items are present in the current node as elements or attributes.
+ * <p/>
+ * @param node the current Node object
+ * @param required the String array of the required items
+ **/
+ public void requiredAttributesOrElements(Node node, String[] required)
+ {
+ String nodeName = node.getNodeName();
+ NodeList attributes = selectNodeList(node, "@*");
+
+ List list = new ArrayList();
+ for (int i = 0; i < required.length; i++)
+ {
+ list.add(required[i]);
+ }
+
+ String missingAttribute = null;
+
+ do
+ {
+ missingAttribute = required(attributes, list);
+ if (missingAttribute != null)
+ {
+ Node child = selectSingleNode(node, missingAttribute);
+ if (child != null)
+ {
+ list.remove(missingAttribute);
+ }
+ else
+ {
+ // Attribute '{0}' must be specified for element '{1}'
+ ConfigurationException ex = new ConfigurationException();
+ ex.setMessage(MISSING_ATTRIBUTE, new Object[]{missingAttribute, nodeName});
+ throw ex;
+ }
+ }
+ }
+ while (missingAttribute != null && list.size() > 0);
+ }
+
+ /**
+ * Check whether the required items are present in the current node (Child elements).
+ * <p/>
+ * @param node the current Node object
+ * @param required the String array of the required items
+ **/
+ public void requiredChildElements(Node node, String[] required)
+ {
+ String nodeName = node.getNodeName();
+ NodeList children = selectNodeList(node, "*");
+
+ List list = new ArrayList();
+ for (int i = 0; i < required.length; i++)
+ {
+ list.add(required[i]);
+ }
+
+ String missing = required(children, list);
+ if (missing != null)
+ {
+ // Child element '{0}' must be specified for element '{1}'
+ ConfigurationException ex = new ConfigurationException();
+ ex.setMessage(MISSING_ELEMENT, new Object[]{missing, nodeName});
+ throw ex;
+ }
+ }
+
+ /**
+ * Check whether there is any unexpected item in the node list object.
+ * <p/>
+ * @param attributes the current NodeList object
+ * @param allowed, the String array of allowed items
+ * @return Name of the first unexpected item from the list of allowed attributes, or null if all
+ * items present were allowed.
+ **/
+ public String unexpected(NodeList attributes, String[] allowed)
+ {
+ for (int i = 0; i < attributes.getLength(); i++)
+ {
+ Node attrib = attributes.item(i);
+ String attribName = attrib.getNodeName();
+ boolean match = false;
+
+ for (int j = 0; j < allowed.length; j++)
+ {
+ String a = allowed[j];
+ if (a.equals(attribName))
+ {
+ match = true;
+ break;
+ }
+ }
+
+ if (!match)
+ {
+ return attribName;
+ }
+
+ // Go ahead and replace tokens in node values.
+ tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
+ }
+
+ return null;
+ }
+
+ /**
+ * Check whether all the required items are present in the node list.
+ * @param attributes the NodeList object
+ * @param required a list of required items
+ * @return Name of the first missing item from the list of required attributes, or null if all required
+ * items were present.
+ **/
+ public String required(NodeList attributes, List required)
+ {
+ for (int i = 0; i < required.size(); i++)
+ {
+ boolean found = false;
+ String req = (String)required.get(i);
+
+ Node attrib = null;
+ for (int j = 0; j < attributes.getLength(); j++)
+ {
+ attrib = attributes.item(j);
+ String attribName = attrib.getNodeName();
+
+ if (req.equals(attribName))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ return req;
+ }
+
+ // Go ahead and replace tokens in node values.
+ tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
+
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Tests whether a configuration element's id is a valid
+ * identifier. An id must be a String that is not null,
+ * greater than 0 characters in length and not contain
+ * any of the list delimiter characters, i.e. commas,
+ * semi-colons or colons.
+ * @param id the Id String
+ * @return boolean true if the id string is valid identification
+ * @see ConfigurationConstants#LIST_DELIMITERS
+ */
+ public static boolean isValidID(String id)
+ {
+ if (id != null && id.length() > 0 && id.length() < 256)
+ {
+ char[] chars = id.toCharArray();
+ for (int i = 0; i < chars.length; i++)
+ {
+ char c = chars[i];
+ if (LIST_DELIMITERS.indexOf(c) != -1)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Implement {@link org.xml.sax.EntityResolver#resolveEntity(String, String)}.
+ *
+ * Flex Configuration does not need or use external entities, so disallow external entities
+ * to prevent external entity injection attacks.
+ * @param publicId the public Id
+ * @param systemId the system Id
+ * @throws SAXException, IOException when the parsing process failed with exceptions
+ * @return InputSource the InputSource object
+ */
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
+ {
+ // Flex Configuration does not allow external entity defined by publicId {0} and SystemId {1}
+ ConfigurationException ex = new ConfigurationException();
+ ex.setMessage(EXTERNAL_ENTITY_NOT_ALLOW, new Object[] { publicId, systemId });
+ throw ex;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/4f6a3052/modules/common/src/flex/messaging/config/AdapterSettings.java
----------------------------------------------------------------------
diff --git a/modules/common/src/flex/messaging/config/AdapterSettings.java b/modules/common/src/flex/messaging/config/AdapterSettings.java
old mode 100755
new mode 100644
index 8d53ff2..0881f4f
--- a/modules/common/src/flex/messaging/config/AdapterSettings.java
+++ b/modules/common/src/flex/messaging/config/AdapterSettings.java
@@ -1,130 +1,130 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.config;
-
-/**
- * A service must register the adapters that it will use
- * to process messages. Each destination selects an adapter
- * that processes the request by referring to it by id.
- * <p>
- * Adapters can also be configured with initialization
- * properties.
- * </p>
- *
- * @see flex.messaging.services.ServiceAdapter
- * @author Peter Farland
- * @exclude
- */
-public class AdapterSettings extends PropertiesSettings
-{
- private final String id;
- private String sourceFile;
- private String className;
- private boolean defaultAdapter;
-
- /**
- * Used to construct a new set of properties to describe an adapter. Note
- * that an identity is required in order for destinations to refer to this
- * adapter.
- *
- * @param id the <code>String</code> representing the unique identity for
- * this adapter.
- */
- public AdapterSettings(String id)
- {
- super();
- this.id = id;
- }
-
- /**
- * The identity that destinations will refer to when assigning and adapter.
- *
- * @return the adapter identity as a <code>String</code>.
- */
- public String getId()
- {
- return id;
- }
-
- /**
- * Gets the name of the Java class implementation for this adapter.
- *
- * @return String The name of the adapter implementation.
- * @see flex.messaging.services.ServiceAdapter
- */
- public String getClassName()
- {
- return className;
- }
-
- /**
- * Sets name of the Java class implementation for this adapter. The
- * implementation is resolved from the current classpath and must extend
- * <code>flex.messaging.services.ServiceAdapter</code>.
- *
- * @param name the <code>String</code>
- */
- public void setClassName(String name)
- {
- className = name;
- }
-
- /**
- * Returns a boolean flag that determines whether this adapter is the
- * default for a service's destinations. Only one default adapter can be
- * set for a given service.
- *
- * @return boolean true if this adapter is the default.
- */
- public boolean isDefault()
- {
- return defaultAdapter;
- }
-
- /**
- * Sets a flag to determine whether an adapter will be used as the default
- * (for example, in the event that a destination did not specify an adapter
- * explicitly).
- *
- * Only one default can be set for a given service.
- *
- * @param b a <code>boolean</code> flag, true if this adapter should be
- * used as the default for the service.
- */
- public void setDefault(boolean b)
- {
- defaultAdapter = b;
- }
-
- /**
- * Internal use only.
- * @exclude
- */
- String getSourceFile()
- {
- return sourceFile;
- }
-
- /**
- * Internal use only.
- * @exclude
- */
- void setSourceFile(String file)
- {
- this.sourceFile = file;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package flex.messaging.config;
+
+/**
+ * A service must register the adapters that it will use
+ * to process messages. Each destination selects an adapter
+ * that processes the request by referring to it by id.
+ * <p>
+ * Adapters can also be configured with initialization
+ * properties.
+ * </p>
+ *
+ * @see flex.messaging.services.ServiceAdapter
+ * @author Peter Farland
+ * @exclude
+ */
+public class AdapterSettings extends PropertiesSettings
+{
+ private final String id;
+ private String sourceFile;
+ private String className;
+ private boolean defaultAdapter;
+
+ /**
+ * Used to construct a new set of properties to describe an adapter. Note
+ * that an identity is required in order for destinations to refer to this
+ * adapter.
+ *
+ * @param id the <code>String</code> representing the unique identity for
+ * this adapter.
+ */
+ public AdapterSettings(String id)
+ {
+ super();
+ this.id = id;
+ }
+
+ /**
+ * The identity that destinations will refer to when assigning and adapter.
+ *
+ * @return the adapter identity as a <code>String</code>.
+ */
+ public String getId()
+ {
+ return id;
+ }
+
+ /**
+ * Gets the name of the Java class implementation for this adapter.
+ *
+ * @return String The name of the adapter implementation.
+ * @see flex.messaging.services.ServiceAdapter
+ */
+ public String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * Sets name of the Java class implementation for this adapter. The
+ * implementation is resolved from the current classpath and must extend
+ * <code>flex.messaging.services.ServiceAdapter</code>.
+ *
+ * @param name the <code>String</code>
+ */
+ public void setClassName(String name)
+ {
+ className = name;
+ }
+
+ /**
+ * Returns a boolean flag that determines whether this adapter is the
+ * default for a service's destinations. Only one default adapter can be
+ * set for a given service.
+ *
+ * @return boolean true if this adapter is the default.
+ */
+ public boolean isDefault()
+ {
+ return defaultAdapter;
+ }
+
+ /**
+ * Sets a flag to determine whether an adapter will be used as the default
+ * (for example, in the event that a destination did not specify an adapter
+ * explicitly).
+ *
+ * Only one default can be set for a given service.
+ *
+ * @param b a <code>boolean</code> flag, true if this adapter should be
+ * used as the default for the service.
+ */
+ public void setDefault(boolean b)
+ {
+ defaultAdapter = b;
+ }
+
+ /**
+ * Internal use only.
+ * @exclude
+ */
+ String getSourceFile()
+ {
+ return sourceFile;
+ }
+
+ /**
+ * Internal use only.
+ * @exclude
+ */
+ void setSourceFile(String file)
+ {
+ this.sourceFile = file;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/4f6a3052/modules/common/src/flex/messaging/config/ApacheXPathClientConfigurationParser.java
----------------------------------------------------------------------
diff --git a/modules/common/src/flex/messaging/config/ApacheXPathClientConfigurationParser.java b/modules/common/src/flex/messaging/config/ApacheXPathClientConfigurationParser.java
old mode 100755
new mode 100644
index 6ad4468..c9590ad
--- a/modules/common/src/flex/messaging/config/ApacheXPathClientConfigurationParser.java
+++ b/modules/common/src/flex/messaging/config/ApacheXPathClientConfigurationParser.java
@@ -1,87 +1,87 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package flex.messaging.config;
-
-import org.apache.xpath.CachedXPathAPI;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import javax.xml.transform.TransformerException;
-
-/**
- * Uses Apache XPath on a DOM representation of a messaging configuration
- * file.
- * <p>
- * NOTE: Since reference ids are used between elements, certain
- * sections of the document need to be parsed first.
- * </p>
- *
- * @author Peter Farland
- * @exclude
- */
-public class ApacheXPathClientConfigurationParser extends ClientConfigurationParser
-{
- private CachedXPathAPI xpath;
-
- protected void initializeExpressionQuery()
- {
- this.xpath = new CachedXPathAPI();
- }
-
- protected Node selectSingleNode(Node source, String expression)
- {
- try
- {
- return xpath.selectSingleNode(source, expression);
- }
- catch (TransformerException transformerException)
- {
- throw wrapException(transformerException);
- }
- }
-
- protected NodeList selectNodeList(Node source, String expression)
- {
- try
- {
- return xpath.selectNodeList(source, expression);
- }
- catch (TransformerException transformerException)
- {
- throw wrapException(transformerException);
- }
- }
-
- protected Object evaluateExpression(Node source, String expression)
- {
- try
- {
- return xpath.eval(source, expression);
- }
- catch (TransformerException transformerException)
- {
- throw wrapException(transformerException);
- }
- }
-
- private ConfigurationException wrapException(TransformerException exception)
- {
- ConfigurationException result = new ConfigurationException();
- result.setDetails(PARSER_INTERNAL_ERROR);
- result.setRootCause(exception);
- return result;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package flex.messaging.config;
+
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import javax.xml.transform.TransformerException;
+
+/**
+ * Uses Apache XPath on a DOM representation of a messaging configuration
+ * file.
+ * <p>
+ * NOTE: Since reference ids are used between elements, certain
+ * sections of the document need to be parsed first.
+ * </p>
+ *
+ * @author Peter Farland
+ * @exclude
+ */
+public class ApacheXPathClientConfigurationParser extends ClientConfigurationParser
+{
+ private CachedXPathAPI xpath;
+
+ protected void initializeExpressionQuery()
+ {
+ this.xpath = new CachedXPathAPI();
+ }
+
+ protected Node selectSingleNode(Node source, String expression)
+ {
+ try
+ {
+ return xpath.selectSingleNode(source, expression);
+ }
+ catch (TransformerException transformerException)
+ {
+ throw wrapException(transformerException);
+ }
+ }
+
+ protected NodeList selectNodeList(Node source, String expression)
+ {
+ try
+ {
+ return xpath.selectNodeList(source, expression);
+ }
+ catch (TransformerException transformerException)
+ {
+ throw wrapException(transformerException);
+ }
+ }
+
+ protected Object evaluateExpression(Node source, String expression)
+ {
+ try
+ {
+ return xpath.eval(source, expression);
+ }
+ catch (TransformerException transformerException)
+ {
+ throw wrapException(transformerException);
+ }
+ }
+
+ private ConfigurationException wrapException(TransformerException exception)
+ {
+ ConfigurationException result = new ConfigurationException();
+ result.setDetails(PARSER_INTERNAL_ERROR);
+ result.setRootCause(exception);
+ return result;
+ }
+}