You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/02/15 18:33:19 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/common Domain.java Namespace.java NamespaceConfig.java
remm 01/02/15 09:33:18
Modified: src/share/org/apache/slide/common Domain.java Namespace.java
NamespaceConfig.java
Log:
- Add a way to specify default properties.
Revision Changes Path
1.18 +8 -6 jakarta-slide/src/share/org/apache/slide/common/Domain.java
Index: Domain.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Domain.java 2001/02/12 05:55:46 1.17
+++ Domain.java 2001/02/15 17:33:10 1.18
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v 1.17 2001/02/12 05:55:46 remm Exp $
- * $Revision: 1.17 $
- * $Date: 2001/02/12 05:55:46 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v 1.18 2001/02/15 17:33:10 remm Exp $
+ * $Revision: 1.18 $
+ * $Date: 2001/02/15 17:33:10 $
*
* ====================================================================
*
@@ -88,7 +88,7 @@
* For now, does not implement access control on Namespaces.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.17 $
+ * @version $Revision: 1.18 $
*/
public final class Domain {
@@ -505,6 +505,10 @@
namespace.loadDefinition(namespaceDefinition);
addNamespace(namespace);
+ Configuration namespaceConfigurationDefinition =
+ configuration.getConfiguration("configuration");
+ namespace.loadParameters(namespaceConfigurationDefinition);
+
try {
Configuration namespaceBaseDataDefinition =
configuration.getConfiguration("data");
@@ -513,8 +517,6 @@
info("No basedata found for the namespace");
}
- Configuration namespaceConfigurationDefinition =
- configuration.getConfiguration("configuration");
namespace.loadConfiguration(namespaceConfigurationDefinition);
info("Namespace configuration complete");
1.21 +25 -5 jakarta-slide/src/share/org/apache/slide/common/Namespace.java
Index: Namespace.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Namespace.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Namespace.java 2001/02/12 05:55:46 1.20
+++ Namespace.java 2001/02/15 17:33:12 1.21
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Namespace.java,v 1.20 2001/02/12 05:55:46 remm Exp $
- * $Revision: 1.20 $
- * $Date: 2001/02/12 05:55:46 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Namespace.java,v 1.21 2001/02/15 17:33:12 remm Exp $
+ * $Revision: 1.21 $
+ * $Date: 2001/02/15 17:33:12 $
*
* ====================================================================
*
@@ -93,7 +93,7 @@
* Namespace class.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.20 $
+ * @version $Revision: 1.21 $
*/
public final class Namespace {
@@ -600,7 +600,6 @@
tempActionUri.getStore().createObject(tempActionUri, tempAction);
// Create the dummy configuration
- config = new NamespaceConfig();
config.initializeAsDummyConfig(this);
// Create the Access token
@@ -659,6 +658,27 @@
config = new NamespaceConfig();
config.initializeNamespaceConfig(this,
namespaceConfigurationDefinition);
+
+ }
+
+
+ /**
+ * Parses the contents of the specified reader, and uses that info to
+ * initialize the specified Slide namespace.
+ *
+ * @param namespaceConfigurationDefinition Namespace configuration
+ * @exception SlideException Something went wrong during registry or
+ * services initialization
+ */
+ void loadParameters(Configuration namespaceConfigurationDefinition)
+ throws SlideException {
+
+ Domain.info("Loading namespace " + getName() + " parameters");
+
+ // Load Namespace Config
+ config = new NamespaceConfig();
+ config.initializeNamespaceParameters(this,
+ namespaceConfigurationDefinition);
}
1.12 +144 -5 jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java
Index: NamespaceConfig.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- NamespaceConfig.java 2001/02/10 19:18:29 1.11
+++ NamespaceConfig.java 2001/02/15 17:33:13 1.12
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.11 2001/02/10 19:18:29 remm Exp $
- * $Revision: 1.11 $
- * $Date: 2001/02/10 19:18:29 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.12 2001/02/15 17:33:13 remm Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/02/15 17:33:13 $
*
* ====================================================================
*
@@ -79,7 +79,7 @@
* Configuration of the Namespace.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public final class NamespaceConfig {
@@ -247,6 +247,19 @@
protected Hashtable roleClassMappings = new Hashtable();
+ /**
+ * List of default properties.
+ * Role name -> Vector[NodeProperty].
+ */
+ protected Hashtable defaultProperties;
+
+
+ /**
+ * Empty vector. Don't add stuff there.
+ */
+ protected static Vector emptyVector = new Vector();
+
+
// ------------------------------------------------------------- Properties
@@ -460,6 +473,20 @@
}
+ /**
+ * Get default properties for a given role.
+ *
+ * @return Enumeration of properties
+ */
+ public Enumeration getDefaultProperties(String role) {
+ Vector result = (Vector) defaultProperties.get(role);
+ if (result == null)
+ return emptyVector.elements();
+ else
+ return result.elements();
+ }
+
+
// --------------------------------------------------------- Public Methods
@@ -500,7 +527,8 @@
/**
- * Initialize the Namespace configuration using the given Castor object.
+ * Initialize the Namespace configuration using the given Configuration
+ * object.
*
* @param namespace Namespace on which we are trying to load the config
* @param config Castor Config object
@@ -707,10 +735,98 @@
(namespace, e.getMessage());
}
+ defaultProperties = new Hashtable();
+ Enumeration defaultPropertiesDef =
+ config.getConfigurations("default-property");
+ try {
+ while (defaultPropertiesDef.hasMoreElements()) {
+ Configuration defaultProperty =
+ (Configuration) defaultPropertiesDef.nextElement();
+ String name = defaultProperty.getAttribute("name");
+ String value = defaultProperty.getAttribute("value", "");
+ String propertyNamespace = defaultProperty.getAttribute
+ ("namespace", NodeProperty.DEFAULT_NAMESPACE);
+ String role = defaultProperty.getAttribute("role");
+ addDefaultProperty(role, name, value, propertyNamespace);
+ }
+ } catch (ConfigurationException e) {
+ throw new InvalidNamespaceConfigurationException
+ (namespace, e.getMessage());
+ }
+
}
/**
+ * Initialize the Namespace configuration using the given Configuration
+ * object.
+ *
+ * @param namespace Namespace on which we are trying to load the config
+ * @param config Castor Config object
+ * @exception InvalidNamespaceConfigurationException Namespace
+ * configuration is invalid
+ * @exception SlideException One of the action nodes doesn't exist
+ */
+ void initializeNamespaceParameters
+ (Namespace namespace, Configuration config)
+ throws InvalidNamespaceConfigurationException, SlideException {
+
+ parameters = new Hashtable();
+ Enumeration parametersDef = config.getConfigurations("parameter");
+ try {
+ while (parametersDef.hasMoreElements()) {
+ Configuration parameter =
+ (Configuration) parametersDef.nextElement();
+ addParameter(parameter.getAttribute("name"),
+ parameter.getValue());
+ }
+ } catch (ConfigurationException e) {
+ throw new InvalidNamespaceConfigurationException
+ (namespace, e.getMessage());
+ }
+
+ // Add basic role mappings
+ addRoleMapping(NOBODY, NOBODY_ROLE);
+ addRoleMapping(NOBODY, LINK_ROLE);
+ addRoleMapping(NOBODY, ACTION_ROLE);
+ // Note : the base role should be the last one.
+ addRoleMapping(NOBODY, BASE_ROLE);
+ Enumeration roleMappingsDef = config.getConfigurations("role");
+ try {
+ while (roleMappingsDef.hasMoreElements()) {
+ Configuration roleMappingDef =
+ (Configuration) roleMappingsDef.nextElement();
+ addRoleMapping(roleMappingDef.getAttribute("name"),
+ roleMappingDef.getValue());
+ }
+ } catch (ConfigurationException e) {
+ throw new InvalidNamespaceConfigurationException
+ (namespace, e.getMessage());
+ }
+
+ defaultProperties = new Hashtable();
+ Enumeration defaultPropertiesDef =
+ config.getConfigurations("default-property");
+ try {
+ while (defaultPropertiesDef.hasMoreElements()) {
+ Configuration defaultProperty =
+ (Configuration) defaultPropertiesDef.nextElement();
+ String name = defaultProperty.getAttribute("name");
+ String value = defaultProperty.getAttribute("value", "");
+ String propertyNamespace = defaultProperty.getAttribute
+ ("namespace", NodeProperty.DEFAULT_NAMESPACE);
+ String role = defaultProperty.getAttribute("role");
+ addDefaultProperty(role, name, value, propertyNamespace);
+ }
+ } catch (ConfigurationException e) {
+ throw new InvalidNamespaceConfigurationException
+ (namespace, e.getMessage());
+ }
+
+ }
+
+
+ /**
* Create a dummy config, used to create the base namespace data.
*
* @param namespace Namespace
@@ -766,6 +882,29 @@
protected void addParameter(String name, String value) {
if ((name!=null) && (value!=null)) {
parameters.put(name, value);
+ }
+ }
+
+
+ /**
+ * Add a new default property.
+ *
+ * @param role Role
+ * @param name Property name
+ * @param value Property value
+ * @param namespace Property namespace
+ */
+ protected void addDefaultProperty(String role, String name, String value,
+ String namespace) {
+ if ((role!=null) && (name!=null) && (value!=null)) {
+ Vector currentDefaultProperties =
+ (Vector) defaultProperties.get(role);
+ if (currentDefaultProperties == null) {
+ currentDefaultProperties = new Vector();
+ defaultProperties.put(role, currentDefaultProperties);
+ }
+ currentDefaultProperties.addElement
+ (new NodeProperty(name, value, namespace));
}
}