KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > NamespaceConfig


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.36 2004/07/28 09:38:17 ib Exp $
3  * $Revision: 1.36 $
4  * $Date: 2004/07/28 09:38:17 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Vector JavaDoc;
29 import org.apache.slide.content.ContentInterceptor;
30 import org.apache.slide.content.NodeProperty;
31 import org.apache.slide.structure.ActionNode;
32 import org.apache.slide.structure.LinkNode;
33 import org.apache.slide.structure.ObjectNode;
34 import org.apache.slide.structure.SubjectNode;
35 import org.apache.slide.util.Messages;
36 import org.apache.slide.util.conf.Configuration;
37 import org.apache.slide.util.conf.ConfigurationException;
38 import org.apache.slide.util.logger.Logger;
39
40 /**
41  * Configuration of the Namespace.
42  *
43  * @version $Revision: 1.36 $
44  */

45 public final class NamespaceConfig {
46     
47     
48     // -------------------------------------------------------------- Constants
49

50     
51     /**
52      * Base role names.
53      */

54     public static final String JavaDoc NOBODY = "nobody";
55     public static final String JavaDoc NOBODY_ROLE = ObjectNode.class.getName();
56     public static final String JavaDoc BASE_ROLE = SubjectNode.class.getName();
57     public static final String JavaDoc ACTION_ROLE = ActionNode.class.getName();
58     public static final String JavaDoc LINK_ROLE = LinkNode.class.getName();
59     
60     
61     private final static String JavaDoc
62         ACL_INHERIT_TYPE = "acl_inheritance_type",
63         NESTED_ROLES_MAXDEPTH = "nested_roles_maxdepth";
64     
65     private final static int
66         NESTED_ROLES_MAXDEPTH_DEFAULT = 0;
67     
68     public final static int
69         ACL_INHERIT_TYPE_NONE = 0,
70         ACL_INHERIT_TYPE_ROOT = 1,
71         ACL_INHERIT_TYPE_PATH = 2,
72         ACL_INHERIT_TYPE_FULL = 3;
73     
74     
75     // ----------------------------------------------------- Instance Variables
76

77     
78     /**
79      * Namespace name.
80      */

81     protected String JavaDoc name;
82     
83     
84     /**
85      * Read object action.
86      */

87     protected ActionNode readObjectAction;
88     
89     
90     /**
91      * Create object action. Equivalent to createChildAction.
92      */

93     protected ActionNode createObjectAction;
94     
95     
96     /**
97      * Remove object action.
98      */

99     protected ActionNode removeObjectAction;
100     
101     
102     /**
103      * Grant permission action.
104      */

105     protected ActionNode grantPermissionAction;
106     
107     
108     /**
109      * Revoke permission action.
110      */

111     protected ActionNode revokePermissionAction;
112     
113     
114     /**
115      * Read permissions action.
116      */

117     protected ActionNode readPermissionsAction;
118     protected ActionNode readOwnPermissionsAction;
119     
120     
121     /**
122      * Lock object action.
123      */

124     protected ActionNode lockObjectAction;
125     
126     
127     /**
128      * Kill lock action.
129      */

130     protected ActionNode killLockAction;
131     
132     
133     /**
134      * Read locks action.
135      */

136     protected ActionNode readLocksAction;
137     
138     
139     /**
140      * Create revision metadata action.
141      */

142     protected ActionNode createRevisionMetadataAction;
143     
144     
145     /**
146      * Modify revision metadata action.
147      */

148     protected ActionNode modifyRevisionMetadataAction;
149     
150     
151     /**
152      * Remove revision metadata action.
153      */

154     protected ActionNode removeRevisionMetadataAction;
155     
156     
157     /**
158      * Read revision metadata action.
159      */

160     protected ActionNode readRevisionMetadataAction;
161     
162     
163     /**
164      * Read revision content action.
165      */

166     protected ActionNode readRevisionContentAction;
167     
168     
169     /**
170      * Create revision content action.
171      */

172     protected ActionNode createRevisionContentAction;
173     
174     
175     /**
176      * Modify revision content action.
177      */

178     protected ActionNode modifyRevisionContentAction;
179     
180     
181     /**
182      * Remove revision content action.
183      */

184     protected ActionNode removeRevisionContentAction;
185     
186     
187     /**
188      * Bind/unbind actions
189      */

190     protected ActionNode bindMemberAction;
191     protected ActionNode unbindMemberAction;
192     
193     
194     /**
195      * Users path.
196      */

197     protected String JavaDoc usersPath = null;
198     protected String JavaDoc groupsPath = null;
199     protected String JavaDoc rolesPath = null;
200     
201     private UriPath
202         usersUriPath,
203         groupsUriPath,
204         rolesUriPath;
205     
206     
207     /**
208      * Guest user path.
209      */

210     protected String JavaDoc guestPath;
211     
212     
213     /**
214      * File path.
215      */

216     protected String JavaDoc filesPath = null;
217     
218     
219     /**
220      * File path.
221      */

222     protected String JavaDoc actionsPath = null;
223     
224     
225     /**
226      * Additional parameters.
227      */

228     protected Hashtable JavaDoc parameters;
229     
230     
231     /**
232      * Role name -> role interface mappings.
233      * Note : One name is associated to only one interface.
234      */

235     protected Hashtable JavaDoc roleMappings = new Hashtable JavaDoc();
236     
237     
238     /**
239      * Role interface -> role name mappings.
240      * Note : One interface can be associated to multiple names, in which case
241      * only one is stored here.
242      */

243     protected Hashtable JavaDoc roleClassMappings = new Hashtable JavaDoc();
244     
245     
246     /**
247      * List of default properties.
248      * Role name -> Vector[NodeProperty].
249      */

250     protected Hashtable JavaDoc defaultProperties;
251     
252     
253     /**
254      * Empty vector. Don't add stuff there.
255      */

256     protected static Vector JavaDoc emptyVector = new Vector JavaDoc();
257     
258     
259     /**
260      * Content interceptors.
261      */

262     protected ContentInterceptor[] contentInterceptors
263         = new ContentInterceptor[0];
264     
265     /**
266      * Automatically create users.
267      */

268     protected boolean autoCreateUsers = false;
269     
270     
271     /**
272      * Roles implementation to be used for automatically created users.
273      */

274     protected String JavaDoc autoCreateUsersRole = "slideroles.basic.UserRoleImpl";
275     
276     
277     // ------------------------------------------------------------- Properties
278

279     
280     /**
281      * Default action accessor.
282      *
283      * @return ActionNode Default action
284      */

285     public ActionNode getDefaultAction() {
286         return ActionNode.DEFAULT;
287     }
288     
289     
290     /**
291      * Read object action accessor.
292      *
293      * @return ActionNode Read object action
294      */

295     public ActionNode getReadObjectAction() {
296         return readObjectAction;
297     }
298     
299     
300     /**
301      * Create object action accessor.
302      *
303      * @return ActionNode Create object action
304      */

305     public ActionNode getCreateObjectAction() {
306         return createObjectAction;
307     }
308     
309     
310     /**
311      * Remove object accessor.
312      *
313      * @return ActionNode Remove object action
314      */

315     public ActionNode getRemoveObjectAction() {
316         return removeObjectAction;
317     }
318     
319     
320     /**
321      * Grant permission accessor.
322      *
323      * @return ActionNode Grant permission action
324      */

325     public ActionNode getGrantPermissionAction() {
326         return grantPermissionAction;
327     }
328     
329     
330     /**
331      * Revoke permission accessor.
332      *
333      * @return ActionNode Revoke permission action
334      */

335     public ActionNode getRevokePermissionAction() {
336         return revokePermissionAction;
337     }
338     
339     
340     /**
341      * Read permissions accessor.
342      *
343      * @return ActionNode Read permissions action
344      */

345     public ActionNode getReadPermissionsAction() {
346         return readPermissionsAction;
347     }
348     public ActionNode getReadOwnPermissionsAction() {
349         return readOwnPermissionsAction;
350     }
351     
352     
353     /**
354      * Lock object accessor.
355      *
356      * @return ActionNode Lock object action
357      */

358     public ActionNode getLockObjectAction() {
359         return lockObjectAction;
360     }
361     
362     
363     /**
364      * Kill lock accessor.
365      *
366      * @return ActionNode Kill lock action
367      */

368     public ActionNode getKillLockAction() {
369         return killLockAction;
370     }
371     
372     
373     /**
374      * Read locks accessor.
375      *
376      * @return ActionNode Read locks action
377      */

378     public ActionNode getReadLocksAction() {
379         return readLocksAction;
380     }
381     
382     
383     /**
384      * Create revision metadata accessor.
385      *
386      * @return ActionNode Create revision metadata action
387      */

388     public ActionNode getCreateRevisionMetadataAction() {
389         return createRevisionMetadataAction;
390     }
391     
392     
393     /**
394      * Read revision metadata accessor.
395      *
396      * @return ActionNode Read revision metadata action
397      */

398     public ActionNode getReadRevisionMetadataAction() {
399         return readRevisionMetadataAction;
400     }
401     
402     
403     /**
404      * Modify revision metadata accessor.
405      *
406      * @return ActionNode Modify revision metadata action
407      */

408     public ActionNode getModifyRevisionMetadataAction() {
409         return modifyRevisionMetadataAction;
410     }
411     
412     
413     /**
414      * Remove revision metadata accessor.
415      *
416      * @return ActionNode Remove revision metadata action
417      */

418     public ActionNode getRemoveRevisionMetadataAction() {
419         return removeRevisionMetadataAction;
420     }
421     
422     
423     /**
424      * Read revision content accessor.
425      *
426      * @return ActionNode Read revision content action
427      */

428     public ActionNode getReadRevisionContentAction() {
429         return readRevisionContentAction;
430     }
431     
432     
433     /**
434      * Create revision content accessor.
435      *
436      * @return ActionNode Create revision content action
437      */

438     public ActionNode getCreateRevisionContentAction() {
439         return createRevisionContentAction;
440     }
441     
442     
443     /**
444      * Modify revision content accessor.
445      *
446      * @return ActionNode Modify revision content action
447      */

448     public ActionNode getModifyRevisionContentAction() {
449         return modifyRevisionContentAction;
450     }
451     
452     
453     /**
454      * Remove revision content accessor.
455      *
456      * @return ActionNode Remove revision content action
457      */

458     public ActionNode getRemoveRevisionContentAction() {
459         return removeRevisionContentAction;
460     }
461     
462     
463     /**
464      * Method getBindAction
465      *
466      * @return an ActionNode
467      */

468     public ActionNode getBindMemberAction() {
469         return bindMemberAction;
470     }
471     
472     
473     public ActionNode getUnbindMemberAction() {
474         return unbindMemberAction;
475     }
476     
477     /**
478      * Users path accessor.
479      *
480      * @return String Users path
481      */

482     public String JavaDoc getUsersPath() {
483         return usersPath;
484     }
485     
486     /**
487      * Groups path accessor.
488      *
489      * @return String Groups path
490      */

491     public String JavaDoc getGroupsPath() {
492         return groupsPath;
493     }
494     
495     /**
496      * Roles path accessor.
497      *
498      * @return String Roles path
499      */

500     public String JavaDoc getRolesPath() {
501         return rolesPath;
502     }
503     
504     
505     /**
506      * Guest path accessor.
507      *
508      * @return String Guest path
509      * @deprecated There is now a generic SubjectNode for "guest"
510      */

511     public String JavaDoc getGuestPath() {
512         return guestPath;
513     }
514     
515     
516     /**
517      * Files path accessor.
518      *
519      * @return String Files path
520      */

521     public String JavaDoc getFilesPath() {
522         return filesPath;
523     }
524     
525     
526     /**
527      * Actions path accessor.
528      *
529      * @return String Action path
530      */

531     public String JavaDoc getActionsPath() {
532         return actionsPath;
533     }
534     
535     
536     /**
537      * Get default properties for a given role.
538      *
539      * @return Enumeration of properties
540      */

541     public Enumeration JavaDoc getDefaultProperties(String JavaDoc role) {
542         Vector JavaDoc result = (Vector JavaDoc) defaultProperties.get(role);
543         if (result == null)
544             return emptyVector.elements();
545         else
546             return result.elements();
547     }
548     
549     
550     /**
551      * Get content interceptors.
552      */

553     ContentInterceptor[] getContentInterceptors() {
554         return contentInterceptors;
555     }
556     
557     
558     // --------------------------------------------------------- Public Methods
559

560     
561     /**
562      * Get parameter value.
563      *
564      * @param name Parameter name
565      * @return String Parameter value
566      */

567     public String JavaDoc getParameter(String JavaDoc name) {
568         Object JavaDoc result = parameters.get(name);
569         if (result==null) {
570             return null;
571         } else {
572             return (String JavaDoc) result;
573         }
574     }
575     
576     
577     /**
578      * Get role mapping. If the interface name is given, one of the names is
579      * returned. If the name is given, the interface name is returned.
580      *
581      * @param name Role name (or interface name)
582      * @return String Role interface name (or name)
583      */

584     public String JavaDoc getRoleMapping(String JavaDoc name) {
585         Object JavaDoc result = roleMappings.get(name);
586         if (result == null) {
587             return (String JavaDoc) roleClassMappings.get(name);
588         } else {
589             return (String JavaDoc) result;
590         }
591     }
592     
593     
594     /**
595      * Is automcatic user creation active ?
596      */

597     public boolean isAutoCreateUsers() {
598         return autoCreateUsers;
599     }
600
601     public boolean isPrincipal(String JavaDoc uri) {
602         UriPath uriPath = new UriPath(uri);
603         return (usersUriPath != null && usersUriPath.equals(uriPath.parent()) ||
604                            rolesUriPath != null && rolesUriPath.equals(uriPath.parent()) ||
605                            groupsUriPath != null && groupsUriPath.equals(uriPath.parent()));
606     }
607
608     public boolean isRole(String JavaDoc uri) {
609         UriPath uriPath = new UriPath(uri);
610         return (rolesUriPath != null && rolesUriPath.equals(uriPath.parent()));
611     }
612
613     public boolean isGroup(String JavaDoc uri) {
614         UriPath uriPath = new UriPath(uri);
615         return (groupsUriPath != null && groupsUriPath.equals(uriPath.parent()));
616     }
617     
618     
619     /**
620      * Get the class name of the role which will be used to create nodes which
621      * are automatically created when isAutoCreateUsers() returns true.
622      */

623     public String JavaDoc getAutoCreateUsersRole() {
624         return autoCreateUsersRole;
625     }
626     
627     public int getAclInheritanceType() {
628         String JavaDoc aclInheritanceTypeStr = getParameter(ACL_INHERIT_TYPE);
629         if ("none".equalsIgnoreCase(aclInheritanceTypeStr)) {
630             return ACL_INHERIT_TYPE_NONE;
631         }
632         else if ("root".equalsIgnoreCase(aclInheritanceTypeStr)) {
633             return ACL_INHERIT_TYPE_ROOT;
634         }
635         else if ("path".equalsIgnoreCase(aclInheritanceTypeStr)) {
636             return ACL_INHERIT_TYPE_PATH;
637         }
638         else if ("full".equalsIgnoreCase(aclInheritanceTypeStr)) {
639             return ACL_INHERIT_TYPE_FULL;
640         }
641         else {
642             return ACL_INHERIT_TYPE_PATH;
643         }
644     }
645     
646     public int getNestedRolesMaxDepth() {
647         int result = NESTED_ROLES_MAXDEPTH_DEFAULT;
648         String JavaDoc nestedRolesMaxDepthStr = getParameter(NESTED_ROLES_MAXDEPTH);
649         try {
650             result = Integer.parseInt(nestedRolesMaxDepthStr);
651         }
652         catch (NumberFormatException JavaDoc e) {}
653         return result;
654     }
655     
656     // -------------------------------------------------------- Package Methods
657

658     
659     /**
660      * Initialize the Namespace configuration using the given Configuration
661      * object.
662      *
663      * @param namespace Namespace on which we are trying to load the config
664      * @param config Castor Config object
665      * @exception InvalidNamespaceConfigurationException Namespace
666      * configuration is invalid
667      * @exception SlideException One of the action nodes doesn't exist
668      */

669     void initializeNamespaceConfig(Namespace namespace, Configuration config)
670         throws InvalidNamespaceConfigurationException, SlideException {
671         
672         name = namespace.getName();
673         
674         readObjectAction = getConfiguredNode(namespace, config, "read-object");
675         createObjectAction = getConfiguredNode(namespace, config, "create-object");
676         removeObjectAction = getConfiguredNode(namespace, config, "remove-object");
677         grantPermissionAction = getConfiguredNode(namespace, config, "grant-permission");
678         revokePermissionAction = getConfiguredNode(namespace, config, "revoke-permission");
679         readPermissionsAction = getConfiguredNode(namespace, config, "read-permissions");
680         readOwnPermissionsAction = getConfiguredNode(namespace, config, "read-own-permissions");
681         lockObjectAction = getConfiguredNode(namespace, config, "lock-object");
682         killLockAction = getConfiguredNode(namespace, config, "kill-lock");
683         readLocksAction = getConfiguredNode(namespace, config, "read-locks");
684         readRevisionMetadataAction = getConfiguredNode(namespace, config, "read-revision-metadata");
685         createRevisionMetadataAction = getConfiguredNode(namespace, config, "create-revision-metadata");
686         modifyRevisionMetadataAction = getConfiguredNode(namespace, config, "modify-revision-metadata");
687         removeRevisionMetadataAction = getConfiguredNode(namespace, config, "remove-revision-metadata");
688         readRevisionContentAction = getConfiguredNode(namespace, config, "read-revision-content");
689         createRevisionContentAction = getConfiguredNode(namespace, config, "create-revision-content");
690         modifyRevisionContentAction = getConfiguredNode(namespace, config, "modify-revision-content");
691         removeRevisionContentAction = getConfiguredNode(namespace, config, "remove-revision-content");
692         
693         bindMemberAction = getConfiguredNode(namespace, config, "bind-member");
694         unbindMemberAction = getConfiguredNode(namespace, config, "unbind-member");
695         
696         
697         setPathsAndConfigValues(config);
698         
699         setParameters(config, namespace);
700         
701         setRoles(config, namespace);
702         
703         setDefaultProperties(config, namespace);
704         
705         Enumeration JavaDoc contentInteceptorsDef =
706             config.getConfigurations("content-interceptor");
707         try {
708             while (contentInteceptorsDef.hasMoreElements()) {
709                 Configuration contentInterceptorDef =
710                     (Configuration) contentInteceptorsDef.nextElement();
711                 String JavaDoc classname = contentInterceptorDef.getAttribute("class");
712                 
713                 // Load contentInterceptor parameters
714
Enumeration JavaDoc contentInterceptorParametersDef =
715                     contentInterceptorDef.getConfigurations("parameter");
716                 Hashtable JavaDoc contentInterceptorParameters = new Hashtable JavaDoc();
717                 while (contentInterceptorParametersDef.hasMoreElements()) {
718                     Configuration parameterDefinition = (Configuration)
719                         contentInterceptorParametersDef.nextElement();
720                     String JavaDoc parameterName =
721                         parameterDefinition.getAttribute("name");
722                     String JavaDoc parameterValue = parameterDefinition.getValue();
723                     contentInterceptorParameters.put(parameterName,
724                                                      parameterValue);
725                 }
726                 
727                 try {
728                     Class JavaDoc contentInterceptorClass =
729                         Class.forName(classname);
730                     ContentInterceptor contentInterceptor =
731                         (ContentInterceptor)
732                         contentInterceptorClass.newInstance();
733                     contentInterceptor.setParameters(contentInterceptorParameters);
734                     ContentInterceptor[] tempArray =
735                         new ContentInterceptor[contentInterceptors.length + 1];
736                     for (int i = 0; i < contentInterceptors.length; i++) {
737                         tempArray[i] = contentInterceptors[i];
738                     }
739                     tempArray[contentInterceptors.length] = contentInterceptor;
740                     contentInterceptors = tempArray;
741                 } catch (Exception JavaDoc e) {
742                     namespace.getLogger().log
743                         (Messages.format
744                              ("org.apache.slide.common.InvalidContentInterceptor",
745                               classname, e.getMessage()), Logger.WARNING);
746                 }
747             }
748             
749             // Initialize the content interceptors with the
750
// NamespaceAccessToken
751
NamespaceAccessToken nat = new NamespaceAccessTokenImpl(namespace);
752             ContentInterceptor[] contentInterceptors =
753                 namespace.getContentInterceptors();
754             for (int i = 0; i < contentInterceptors.length; i++) {
755                 contentInterceptors[i].setNamespace(nat);
756             }
757         } catch (ConfigurationException e) {
758             throw new InvalidNamespaceConfigurationException
759                 (namespace, e.getMessage());
760         }
761         
762     }
763     
764     private void setDefaultProperties(Configuration config, Namespace namespace) throws InvalidNamespaceConfigurationException {
765         defaultProperties = new Hashtable JavaDoc();
766         Enumeration JavaDoc defaultPropertiesDef =
767             config.getConfigurations("default-property");
768         try {
769             while (defaultPropertiesDef.hasMoreElements()) {
770                 Configuration defaultProperty =
771                     (Configuration) defaultPropertiesDef.nextElement();
772                 String JavaDoc name = defaultProperty.getAttribute("name");
773                 String JavaDoc value = defaultProperty.getAttribute("value", "");
774                 String JavaDoc propertyNamespace = defaultProperty.getAttribute
775                     ("namespace", NodeProperty.DEFAULT_NAMESPACE);
776                 String JavaDoc role = defaultProperty.getAttribute("role");
777                 addDefaultProperty(role, name, value, propertyNamespace);
778             }
779         } catch (ConfigurationException e) {
780             throw new InvalidNamespaceConfigurationException
781                 (namespace, e.getMessage());
782         }
783     }
784     
785     private void setParameters(Configuration config, Namespace namespace) throws InvalidNamespaceConfigurationException {
786         parameters = new Hashtable JavaDoc();
787         Enumeration JavaDoc parametersDef = config.getConfigurations("parameter");
788         try {
789             while (parametersDef.hasMoreElements()) {
790                 Configuration parameter =
791                     (Configuration) parametersDef.nextElement();
792                 addParameter(parameter.getAttribute("name"),
793                              parameter.getValue());
794             }
795         } catch (ConfigurationException e) {
796             throw new InvalidNamespaceConfigurationException
797                 (namespace, e.getMessage());
798         }
799     }
800     
801     private ActionNode getConfiguredNode(Namespace namespace, Configuration config, String JavaDoc nodeName) throws SlideException {
802         ActionNode result = null;
803         try {
804             result = getActionNode(namespace, config.getConfiguration( nodeName).getValue());
805         } catch (ConfigurationException e) {
806             result = getDefaultAction();
807         }
808         return result;
809     }
810     
811     private void setPathsAndConfigValues(Configuration config) {
812         try {
813             usersPath = config.getConfiguration("userspath").getValue();
814             usersUriPath = new UriPath(usersPath);
815         } catch (ConfigurationException e) {
816             usersPath = "";
817         }
818         
819         try {
820             groupsPath = config.getConfiguration("groupspath").getValue();
821             groupsUriPath = new UriPath(groupsPath);
822         } catch (ConfigurationException e) {
823             groupsPath = "";
824         }
825         
826         try {
827             rolesPath = config.getConfiguration("rolespath").getValue();
828             rolesUriPath = new UriPath(rolesPath);
829         } catch (ConfigurationException e) {
830             rolesPath = "";
831         }
832         
833         try {
834             guestPath = config.getConfiguration("guestpath").getValue();
835         } catch (ConfigurationException e) {
836             guestPath = "";
837         }
838         
839         try {
840             filesPath = config.getConfiguration("filespath").getValue();
841         } catch (ConfigurationException e) {
842             filesPath = "";
843         }
844         
845         try {
846             actionsPath = config.getConfiguration("actionspath").getValue();
847         } catch (ConfigurationException e) {
848             actionsPath = "";
849         }
850         
851         try {
852             autoCreateUsers = Boolean.valueOf
853                 (config.getConfiguration("auto-create-users").getValue())
854                 .booleanValue();
855         } catch (ConfigurationException e) {
856             autoCreateUsers = false;
857         }
858         
859         try {
860             autoCreateUsersRole =
861                 config.getConfiguration("auto-create-users-role").getValue();
862         } catch (ConfigurationException e) {
863         }
864     }
865     
866     
867     /**
868      * Initialize the Namespace configuration using the given Configuration
869      * object.
870      *
871      * @param namespace Namespace on which we are trying to load the config
872      * @param config Castor Config object
873      * @exception InvalidNamespaceConfigurationException Namespace
874      * configuration is invalid
875      * @exception SlideException One of the action nodes doesn't exist
876      */

877     void initializeNamespaceParameters
878         (Namespace namespace, Configuration config)
879         throws InvalidNamespaceConfigurationException, SlideException {
880         
881         
882         setParameters(config, namespace);
883         
884         setPathsAndConfigValues(config);
885         
886         setRoles(config, namespace);
887         
888         setDefaultProperties(config, namespace);
889         
890     }
891     
892     private void setRoles(Configuration config, Namespace namespace) throws InvalidNamespaceConfigurationException {
893         // Add basic role mappings
894
addRoleMapping(NOBODY, NOBODY_ROLE);
895         addRoleMapping(NOBODY, LINK_ROLE);
896         addRoleMapping(NOBODY, ACTION_ROLE);
897         // Note : the base role should be the last one.
898
addRoleMapping(NOBODY, BASE_ROLE);
899         Enumeration JavaDoc roleMappingsDef = config.getConfigurations("role");
900         try {
901             while (roleMappingsDef.hasMoreElements()) {
902                 Configuration roleMappingDef =
903                     (Configuration) roleMappingsDef.nextElement();
904                 addRoleMapping(roleMappingDef.getAttribute("name"),
905                                roleMappingDef.getValue());
906             }
907         } catch (ConfigurationException e) {
908             throw new InvalidNamespaceConfigurationException
909                 (namespace, e.getMessage());
910         }
911     }
912     
913     
914     /**
915      * Create a dummy config, used to create the base namespace data.
916      *
917      * @param namespace Namespace
918      * @exception InvalidNamespaceConfigurationException Namespace
919      * configuration is invalid
920      */

921     void initializeAsDummyConfig(Namespace namespace)
922         throws InvalidNamespaceConfigurationException {
923         
924         name = namespace.getName();
925         
926         try {
927             readObjectAction = getDefaultAction();
928             createObjectAction = getDefaultAction();
929             removeObjectAction = getDefaultAction();
930             grantPermissionAction = getDefaultAction();
931             revokePermissionAction = getDefaultAction();
932             readPermissionsAction = getDefaultAction();
933             readOwnPermissionsAction = getDefaultAction();
934             lockObjectAction = getDefaultAction();
935             killLockAction = getDefaultAction();
936             readLocksAction = getDefaultAction();
937             readRevisionMetadataAction = getDefaultAction();
938             createRevisionMetadataAction = getDefaultAction();
939             modifyRevisionMetadataAction = getDefaultAction();
940             removeRevisionMetadataAction = getDefaultAction();
941             readRevisionContentAction = getDefaultAction();
942             createRevisionContentAction = getDefaultAction();
943             modifyRevisionContentAction = getDefaultAction();
944             removeRevisionContentAction = getDefaultAction();
945             bindMemberAction = getDefaultAction();
946             unbindMemberAction = getDefaultAction();
947         } catch (Exception JavaDoc e) {
948             throw new InvalidNamespaceConfigurationException
949                 (namespace, e.getMessage());
950         }
951     }
952     
953     
954     /**
955      * TEST PURPOSES ONLY.
956      */

957     public void initializeForTestPurposesOnly()
958         throws InvalidNamespaceConfigurationException {
959         
960         name = "slide";
961         
962         try {
963             readObjectAction = getDefaultAction();
964             createObjectAction = getDefaultAction();
965             removeObjectAction = getDefaultAction();
966             grantPermissionAction = getDefaultAction();
967             revokePermissionAction = getDefaultAction();
968             readPermissionsAction = getDefaultAction();
969             readOwnPermissionsAction = getDefaultAction();
970             lockObjectAction = getDefaultAction();
971             killLockAction = getDefaultAction();
972             readLocksAction = getDefaultAction();
973             readRevisionMetadataAction = getDefaultAction();
974             createRevisionMetadataAction = getDefaultAction();
975             modifyRevisionMetadataAction = getDefaultAction();
976             removeRevisionMetadataAction = getDefaultAction();
977             readRevisionContentAction = getDefaultAction();
978             createRevisionContentAction = getDefaultAction();
979             modifyRevisionContentAction = getDefaultAction();
980             removeRevisionContentAction = getDefaultAction();
981             bindMemberAction = getDefaultAction();
982             unbindMemberAction = getDefaultAction();
983         } catch (Exception JavaDoc e) {
984             throw new InvalidNamespaceConfigurationException
985                 (null, e.getMessage());
986         }
987     }
988     
989     
990     // ------------------------------------------------------ Protected Methods
991

992     
993     /**
994      * Add a new parameter.
995      *
996      * @param name Parameter name
997      * @param value Parameter value
998      */

999     protected void addParameter(String JavaDoc name, String JavaDoc value) {
1000        if ((name!=null) && (value!=null)) {
1001            parameters.put(name, value);
1002        }
1003    }
1004    
1005    
1006    /**
1007     * Add a new default property.
1008     *
1009     * @param role Role
1010     * @param name Property name
1011     * @param value Property value
1012     * @param namespace Property namespace
1013     */

1014    protected void addDefaultProperty(String JavaDoc role, String JavaDoc name, String JavaDoc value,
1015                                      String JavaDoc namespace) {
1016        if ((role!=null) && (name!=null) && (value!=null)) {
1017            Vector JavaDoc currentDefaultProperties =
1018                (Vector JavaDoc) defaultProperties.get(role);
1019            if (currentDefaultProperties == null) {
1020                currentDefaultProperties = new Vector JavaDoc();
1021                defaultProperties.put(role, currentDefaultProperties);
1022            }
1023            currentDefaultProperties.addElement
1024                (new NodeProperty(name, value, namespace));
1025        }
1026    }
1027    
1028    
1029    /**
1030     * Add a new role mapping.
1031     *
1032     * @param name Role mapping name
1033     * @param value Role mapping value
1034     */

1035    protected void addRoleMapping(String JavaDoc name, String JavaDoc value) {
1036        if ((name!=null) && (value!=null)) {
1037            roleMappings.put(name, value);
1038            roleClassMappings.put(value, name);
1039        }
1040    }
1041    
1042    
1043    /**
1044     * Retrieve an action node.
1045     *
1046     * @param namespace The namespace, that contains the action node
1047     * @param actionPath Path of the action
1048     */

1049    protected ActionNode getActionNode(Namespace namespace, String JavaDoc actionPath)
1050        throws InvalidNamespaceConfigurationException, SlideException {
1051        
1052        ActionNode result = null;
1053        
1054        if (actionPath != null) {
1055            Uri actionUri = namespace.getUri(actionPath);
1056            result = (ActionNode) actionUri.getStore()
1057                .retrieveObject(actionUri);
1058        }
1059        else {
1060            result = getDefaultAction();
1061        }
1062        
1063        return result;
1064        
1065    }
1066    
1067    
1068    // --------------------------------------------------------- Object Methods
1069

1070    
1071    /**
1072     * Get a String representation of this domain.
1073     */

1074    public String JavaDoc toString() {
1075        return name;
1076    }
1077    
1078    
1079}
1080
Popular Tags