Author: keith
Date: Thu Apr 24 22:04:07 2008
New Revision: 16127
Log:
Adding javadoc comments to the newly refractored methods
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/RegistryInitializer.java
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/RegistryInitializer.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/RegistryInitializer.java
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/RegistryInitializer.java
Thu Apr 24 22:04:07 2008
@@ -40,16 +40,27 @@
public class RegistryInitializer {
+ /**
+ * This class in the one that initializers the Registry and WSASRealm and
prepares it so that
+ * the Mashup Server can work smoothly. It prepopulates the registry with
predifined users, adds
+ * a set of predefined collections and queries and and also set the
default permissions. This
+ * class also creates the primary user of the Mashup Server.
+ * @param configCtx The Axis2 ConfigurationContext of the Mashup Server
+ * @throws MashupFault Thrown in case an error occurs while initializing
the registry
+ */
public static void initRegistry(ConfigurationContext configCtx) throws
MashupFault {
- UserRegistry systemRegistry;
-
+ // Get the server config of WSAS so that we can read properties that
we need from the
+ // server.xml
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
try {
-
+
+ // WSAS API requires a role for every user been added. Hence we
create a role calles
+ // mashup_user in WSAS
addMashupUserRole();
+ // Initializing the WSASRegistryRealm
UserRealm realm = createRealm(serverConfig);
UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
@@ -58,14 +69,16 @@
// execute these stuff each time the server is restarted. We need
it only on a first
// time start.
- // Add a set of users and roles that is needed by the Mashup Server
if
(!userStoreAdmin.isExistingUser(RegistryConstants.ANONYMOUS_USER)) {
- addInitialUsersToWSAS(userStoreAdmin);
+ // Add a set of users and roles that is needed by the Mashup
Server
+ addInitialUsersToWSAS(userStoreAdmin);
+ // Set the default permissions for the created users
provisionPermissions(realm);
}
+ // Initializing the Registry
EmbeddedRegistry embeddedRegistry = createRegistry(serverConfig,
realm);
// Add the realm and registry as parameters in the
AxisConfiguration so that they can be
@@ -76,17 +89,21 @@
// Instantiating a secure registry using the system account, in
order to create user
// profiles.
- systemRegistry = embeddedRegistry.getSystemRegistry();
+ UserRegistry systemRegistry = embeddedRegistry.getSystemRegistry();
if
(!systemRegistry.resourceExists(MashupConstants.QUERYSTORE_QUERY_PATH)) {
+ // Adding predefined collections into the registry
populatePredefinedCollections(systemRegistry);
+ // Adding predefined queries into the registry
populatePredefinedQueries(systemRegistry);
+ // Adding the initial set of users into the registry
createInitialUsersInRegistry(systemRegistry);
}
+ // Create the primary user accout for the Mashup Server
CreatePrimaryUser(systemRegistry, serverConfig, realm,
userStoreAdmin);
} catch (UserStoreException e) {
@@ -98,7 +115,12 @@
}
}
+ /**
+ * Adds mashup_user role into WSAS databases
+ * @throws AxisFault Thrown in case en exception occurs while adding the
new role
+ */
private static void addMashupUserRole() throws AxisFault {
+
// We need to create a new role called mashup_user so that all users
of the mashup
// server can be added to this role. We need this to set the defaults
permissions for
// users of the server
@@ -117,6 +139,16 @@
}
}
+ /**
+ * Cretes an instance of the registry using database connection details
given in the server.xml
+ * @param serverConfig An instance of the WSAS ServerConfiguration so that
details from the
+ * server.xml can be extracted
+ * @param realm An instance of the Realm used by the Mashup Server
+ * @return EmbeddedRegistry an instance of the EmbeddedRegistry
+ * @throws MashupFault Thrown incase database connection details are not
present in the
+ * server.xml
+ * @throws RegistryException Thrown in case the registry cannot be
initialized
+ */
private static EmbeddedRegistry createRegistry(ServerConfiguration
serverConfig,
UserRealm realm)
throws MashupFault, RegistryException {
@@ -152,6 +184,16 @@
return new EmbeddedRegistry(datasource, realm);
}
+ /**
+ * Cretes an instance of the WSASRegistryRealm using database connection
details given in the
+ * server.xml
+ * @param serverConfig An instance of the WSAS ServerConfiguration so that
details from the
+ * server.xml can be extracted
+ * @return UserRealm an instance of the WSASRegistryRealm
+ * @throws MashupFault Thrown incase database connection details are not
present in the
+ * server.xml
+ * @throws UserStoreException Thrown in case WSASRegistryRealm cannot be
initialized
+ */
private static UserRealm createRealm(ServerConfiguration serverConfig)
throws MashupFault, UserStoreException {
@@ -194,6 +236,18 @@
return realm;
}
+ /**
+ * Creates a primary user account for the Mashup Server if needed
+ * @param systemRegistry An instance of the UserRegistry for the system
user
+ * @param serverConfig An instance of the WSAS ServerConfiguration so that
details from the
+ * server.xml can be extracted
+ * @param realm An instance of the Realm used by the Mashup Server
+ * @param userStoreAdmin an instance of UserStoreAdmin whcih can be used
to add new users and
+ * get user details
+ * @throws UserStoreException Thrown in case the new user account cannot
be created in WSAS
+ * @throws RegistryException Thrown in case the new user account cannot be
created in the
+ * registry
+ */
private static void CreatePrimaryUser(UserRegistry systemRegistry,
ServerConfiguration serverConfig,
UserRealm realm,
UserStoreAdmin userStoreAdmin)
@@ -230,6 +284,13 @@
}
}
+ /**
+ * Populates the registry with a predefined set of users.
+ * @param systemRegistry An instance of the UserRegistry for the system
user
+ * @throws UserStoreException Thrown in case the new user account cannot
be created in WSAS
+ * @throws RegistryException Thrown in case the new user account cannot be
created in the
+ * registry
+ */
private static void createInitialUsersInRegistry(UserRegistry
systemRegistry)
throws UserStoreException, RegistryException {
@@ -255,6 +316,12 @@
SAMPLES_USER_NAME, NONE, SAMPLES_USER_BIO);
}
+ /**
+ * Populates the registry with a predefined set of collections
+ * @param systemRegistry An instance of the UserRegistry for the system
user
+ * @throws RegistryException Thrown in case the new user account cannot be
created in the
+ * registry
+ */
private static void populatePredefinedCollections(UserRegistry
systemRegistry)
throws RegistryException {
@@ -283,6 +350,12 @@
systemRegistry.put(MashupConstants.ALL_MASHUPS_PATH,
mashupsCollection);
}
+ /**
+ * Populates the registry with a predefined set of queries
+ * @param systemRegistry An instance of the UserRegistry for the system
user
+ * @throws RegistryException Thrown in case the new user account cannot be
created in the
+ * registry
+ */
private static void populatePredefinedQueries(UserRegistry systemRegistry)
throws RegistryException {
@@ -403,6 +476,11 @@
);
}
+ /**
+ * Provision default permissions to the newly created users
+ * @param realm An instance of the Realm used by the Mashup Server
+ * @throws UserStoreException Thrown in case the new user account cannot
be created in WSAS
+ */
private static void provisionPermissions(UserRealm realm) throws
UserStoreException {
AccessControlAdmin accessControlAdmin = realm.getAccessControlAdmin();
@@ -498,6 +576,11 @@
AccessControlConstants.READ);
}
+ /**
+ * Add the initial set of users to WSAS database
+ * @param userStoreAdmin an instance of UserStoreAdmin used to add new
users to WSAS
+ * @throws UserStoreException Thrown in case the new user account cannot
be created in WSAS
+ */
private static void addInitialUsersToWSAS(UserStoreAdmin userStoreAdmin)
throws UserStoreException {
@@ -528,6 +611,14 @@
.addUserToRole(MashupConstants.SYSTEM_USER,
RegistryConstants.ADMIN_ROLE);
}
+ /**
+ * A utility method to add queries to the registry
+ * @param registry An instance of the Registry
+ * @param path The path the query should be added to
+ * @param sql The SQL of the query
+ * @param type The expected result type
+ * @throws RegistryException Thrown in case the query cannot be added into
the registry
+ */
private static void addQuery(Registry registry, String path, String sql,
String type)
throws RegistryException {
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev