KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > policy > PolicyComponentImpl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.policy;
18
19 import java.lang.reflect.Field JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.alfresco.service.cmr.dictionary.AssociationDefinition;
27 import org.alfresco.service.cmr.dictionary.ClassDefinition;
28 import org.alfresco.service.cmr.dictionary.DictionaryService;
29 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
30 import org.alfresco.service.namespace.NamespaceService;
31 import org.alfresco.service.namespace.QName;
32 import org.alfresco.util.ParameterCheck;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36
37 /**
38  * Policy Component Implementation.
39  *
40  * @author David Caruana
41  *
42  */

43 public class PolicyComponentImpl implements PolicyComponent
44 {
45     // Logger
46
private static final Log logger = LogFactory.getLog(PolicyComponentImpl.class);
47     
48     // Policy interface annotations
49
private static String JavaDoc ANNOTATION_NAMESPACE = "NAMESPACE";
50
51     // Dictionary Service
52
private DictionaryService dictionary;
53     
54     // Behaviour Filter
55
private BehaviourFilter behaviourFilter;
56     
57     // Map of registered Policies
58
private Map JavaDoc<PolicyKey, PolicyDefinition> registeredPolicies;;
59
60     // Map of Class Behaviours (by policy name)
61
private Map JavaDoc<QName, ClassBehaviourIndex<ClassBehaviourBinding>> classBehaviours = new HashMap JavaDoc<QName, ClassBehaviourIndex<ClassBehaviourBinding>>();
62     
63     // Map of Property Behaviours (by policy name)
64
private Map JavaDoc<QName, ClassBehaviourIndex<ClassFeatureBehaviourBinding>> propertyBehaviours = new HashMap JavaDoc<QName, ClassBehaviourIndex<ClassFeatureBehaviourBinding>>();
65
66     // Map of Association Behaviours (by policy name)
67
private Map JavaDoc<QName, ClassBehaviourIndex<ClassFeatureBehaviourBinding>> associationBehaviours = new HashMap JavaDoc<QName, ClassBehaviourIndex<ClassFeatureBehaviourBinding>>();
68
69     // Wild Card Feature
70
private static final QName FEATURE_WILDCARD = QName.createQName(NamespaceService.DEFAULT_URI, "*");
71     
72
73     /**
74      * Construct
75      *
76      * @param dictionary dictionary service
77      * @param behaviourFilter behaviour filter
78      */

79     public PolicyComponentImpl(DictionaryService dictionary)
80     {
81         this.dictionary = dictionary;
82         this.registeredPolicies = new HashMap JavaDoc<PolicyKey, PolicyDefinition>();
83     }
84     
85
86     /**
87      * Sets the behaviour filter
88      *
89      * @param filter
90      */

91     public void setBehaviourFilter(BehaviourFilter filter)
92     {
93         this.behaviourFilter = filter;
94     }
95     
96     
97     /* (non-Javadoc)
98      * @see org.alfresco.repo.policy.PolicyComponent#registerClassPolicy()
99      */

100     @SuppressWarnings JavaDoc("unchecked")
101     public <P extends ClassPolicy> ClassPolicyDelegate<P> registerClassPolicy(Class JavaDoc<P> policy)
102     {
103         ParameterCheck.mandatory("Policy interface class", policy);
104         PolicyDefinition definition = createPolicyDefinition(policy);
105         registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
106         ClassPolicyDelegate<P> delegate = new ClassPolicyDelegate<P>(dictionary, policy, getClassBehaviourIndex(definition.getName()));
107         
108         if (logger.isInfoEnabled())
109             logger.info("Registered class policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
110         
111         return delegate;
112     }
113
114     
115     /* (non-Javadoc)
116      * @see org.alfresco.repo.policy.PolicyComponent#registerPropertyPolicy(java.lang.Class)
117      */

118     @SuppressWarnings JavaDoc("unchecked")
119     public <P extends PropertyPolicy> PropertyPolicyDelegate<P> registerPropertyPolicy(Class JavaDoc<P> policy)
120     {
121         ParameterCheck.mandatory("Policy interface class", policy);
122         PolicyDefinition definition = createPolicyDefinition(policy);
123         registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
124         PropertyPolicyDelegate<P> delegate = new PropertyPolicyDelegate<P>(dictionary, policy, getPropertyBehaviourIndex(definition.getName()));
125         
126         if (logger.isInfoEnabled())
127             logger.info("Registered property policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
128         
129         return delegate;
130     }
131
132     
133     /* (non-Javadoc)
134      * @see org.alfresco.repo.policy.PolicyComponent#registerAssociationPolicy(java.lang.Class)
135      */

136     @SuppressWarnings JavaDoc("unchecked")
137     public <P extends AssociationPolicy> AssociationPolicyDelegate<P> registerAssociationPolicy(Class JavaDoc<P> policy)
138     {
139         ParameterCheck.mandatory("Policy interface class", policy);
140         PolicyDefinition definition = createPolicyDefinition(policy);
141         registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
142         AssociationPolicyDelegate<P> delegate = new AssociationPolicyDelegate<P>(dictionary, policy, getAssociationBehaviourIndex(definition.getName()));
143         
144         if (logger.isInfoEnabled())
145             logger.info("Registered association policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
146         
147         return delegate;
148     }
149
150     
151     /* (non-Javadoc)
152      * @see org.alfresco.repo.policy.PolicyComponent#getRegisteredPolicies()
153      */

154     public Collection JavaDoc<PolicyDefinition> getRegisteredPolicies()
155     {
156         return Collections.unmodifiableCollection(registeredPolicies.values());
157     }
158
159
160     /* (non-Javadoc)
161      * @see org.alfresco.repo.policy.PolicyComponent#getRegisteredPolicy(org.alfresco.repo.policy.PolicyType, org.alfresco.repo.ref.QName)
162      */

163     public PolicyDefinition getRegisteredPolicy(PolicyType policyType, QName policy)
164     {
165         return registeredPolicies.get(new PolicyKey(policyType, policy));
166     }
167
168
169     /* (non-Javadoc)
170      * @see org.alfresco.repo.policy.PolicyComponent#isRegisteredPolicy(org.alfresco.repo.policy.PolicyType, org.alfresco.repo.ref.QName)
171      */

172     public boolean isRegisteredPolicy(PolicyType policyType, QName policy)
173     {
174         return registeredPolicies.containsKey(new PolicyKey(policyType, policy));
175     }
176
177
178     /* (non-Javadoc)
179      * @see org.alfresco.repo.policy.PolicyComponent#bindClassBehaviour(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.policy.Behaviour)
180      */

181     public BehaviourDefinition<ClassBehaviourBinding> bindClassBehaviour(QName policy, QName classRef, Behaviour behaviour)
182     {
183         // Validate arguments
184
ParameterCheck.mandatory("Policy", policy);
185         ParameterCheck.mandatory("Class Reference", classRef);
186         ParameterCheck.mandatory("Behaviour", behaviour);
187
188         // Validate Binding
189
ClassDefinition classDefinition = dictionary.getClass(classRef);
190         if (classDefinition == null)
191         {
192             throw new IllegalArgumentException JavaDoc("Class " + classRef + " has not been defined in the data dictionary");
193         }
194         
195         // Create behaviour definition and bind to policy
196
ClassBehaviourBinding binding = new ClassBehaviourBinding(dictionary, classRef);
197         BehaviourDefinition<ClassBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Class, policy, binding, behaviour);
198         getClassBehaviourIndex(policy).putClassBehaviour(definition);
199         
200         if (logger.isInfoEnabled())
201             logger.info("Bound " + behaviour + " to policy " + policy + " for class " + classRef);
202
203         return definition;
204     }
205     
206     
207     /* (non-Javadoc)
208      * @see org.alfresco.repo.policy.PolicyComponent#bindClassBehaviour(org.alfresco.repo.ref.QName, java.lang.Object, org.alfresco.repo.policy.Behaviour)
209      */

210     public BehaviourDefinition<ServiceBehaviourBinding> bindClassBehaviour(QName policy, Object JavaDoc service, Behaviour behaviour)
211     {
212         // Validate arguments
213
ParameterCheck.mandatory("Policy", policy);
214         ParameterCheck.mandatory("Service", service);
215         ParameterCheck.mandatory("Behaviour", behaviour);
216         
217         // Create behaviour definition and bind to policy
218
ServiceBehaviourBinding binding = new ServiceBehaviourBinding(service);
219         BehaviourDefinition<ServiceBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Class, policy, binding, behaviour);
220         getClassBehaviourIndex(policy).putServiceBehaviour(definition);
221         
222         if (logger.isInfoEnabled())
223             logger.info("Bound " + behaviour + " to policy " + policy + " for service " + service);
224
225         return definition;
226     }
227
228     
229     /* (non-Javadoc)
230      * @see org.alfresco.repo.policy.PolicyComponent#bindPropertyBehaviour(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.policy.Behaviour)
231      */

232     public BehaviourDefinition<ClassFeatureBehaviourBinding> bindPropertyBehaviour(QName policy, QName className, QName propertyName, Behaviour behaviour)
233     {
234         // Validate arguments
235
ParameterCheck.mandatory("Policy", policy);
236         ParameterCheck.mandatory("Class Reference", className);
237         ParameterCheck.mandatory("Property Reference", propertyName);
238         ParameterCheck.mandatory("Behaviour", behaviour);
239
240         // Validate Binding
241
PropertyDefinition propertyDefinition = dictionary.getProperty(className, propertyName);
242         if (propertyDefinition == null)
243         {
244             throw new IllegalArgumentException JavaDoc("Property " + propertyName + " of class " + className + " has not been defined in the data dictionary");
245         }
246         
247         // Create behaviour definition and bind to policy
248
ClassFeatureBehaviourBinding binding = new ClassFeatureBehaviourBinding(dictionary, className, propertyName);
249         BehaviourDefinition<ClassFeatureBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Property, policy, binding, behaviour);
250         getPropertyBehaviourIndex(policy).putClassBehaviour(definition);
251         
252         if (logger.isInfoEnabled())
253             logger.info("Bound " + behaviour + " to policy " + policy + " for property " + propertyName + " of class " + className);
254
255         return definition;
256     }
257     
258
259     /* (non-Javadoc)
260      * @see org.alfresco.repo.policy.PolicyComponent#bindPropertyBehaviour(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.policy.Behaviour)
261      */

262     public BehaviourDefinition<ClassFeatureBehaviourBinding> bindPropertyBehaviour(QName policy, QName className, Behaviour behaviour)
263     {
264         // Validate arguments
265
ParameterCheck.mandatory("Policy", policy);
266         ParameterCheck.mandatory("Class Reference", className);
267         ParameterCheck.mandatory("Behaviour", behaviour);
268
269         // Validate Binding
270
ClassDefinition classDefinition = dictionary.getClass(className);
271         if (classDefinition == null)
272         {
273             throw new IllegalArgumentException JavaDoc("Class " + className + " has not been defined in the data dictionary");
274         }
275         
276         // Create behaviour definition and bind to policy
277
ClassFeatureBehaviourBinding binding = new ClassFeatureBehaviourBinding(dictionary, className, FEATURE_WILDCARD);
278         BehaviourDefinition<ClassFeatureBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Property, policy, binding, behaviour);
279         getPropertyBehaviourIndex(policy).putClassBehaviour(definition);
280         
281         if (logger.isInfoEnabled())
282             logger.info("Bound " + behaviour + " to policy " + policy + " for property " + FEATURE_WILDCARD + " of class " + className);
283
284         return definition;
285     }
286
287     
288     /* (non-Javadoc)
289      * @see org.alfresco.repo.policy.PolicyComponent#bindPropertyBehaviour(org.alfresco.repo.ref.QName, java.lang.Object, org.alfresco.repo.policy.Behaviour)
290      */

291     public BehaviourDefinition<ServiceBehaviourBinding> bindPropertyBehaviour(QName policy, Object JavaDoc service, Behaviour behaviour)
292     {
293         // Validate arguments
294
ParameterCheck.mandatory("Policy", policy);
295         ParameterCheck.mandatory("Service", service);
296         ParameterCheck.mandatory("Behaviour", behaviour);
297         
298         // Create behaviour definition and bind to policy
299
ServiceBehaviourBinding binding = new ServiceBehaviourBinding(service);
300         BehaviourDefinition<ServiceBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Property, policy, binding, behaviour);
301         getPropertyBehaviourIndex(policy).putServiceBehaviour(definition);
302         
303         if (logger.isInfoEnabled())
304             logger.info("Bound " + behaviour + " to property policy " + policy + " for service " + service);
305
306         return definition;
307     }
308
309
310     /* (non-Javadoc)
311      * @see org.alfresco.repo.policy.PolicyComponent#bindAssociationBehaviour(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.policy.Behaviour)
312      */

313     public BehaviourDefinition<ClassFeatureBehaviourBinding> bindAssociationBehaviour(QName policy, QName className, QName assocName, Behaviour behaviour)
314     {
315         // Validate arguments
316
ParameterCheck.mandatory("Policy", policy);
317         ParameterCheck.mandatory("Class Reference", className);
318         ParameterCheck.mandatory("Association Reference", assocName);
319         ParameterCheck.mandatory("Behaviour", behaviour);
320
321         // Validate Binding
322
AssociationDefinition assocDefinition = dictionary.getAssociation(assocName);
323         if (assocDefinition == null)
324         {
325             throw new IllegalArgumentException JavaDoc("Association " + assocName + " of class " + className + " has not been defined in the data dictionary");
326         }
327         
328         // Create behaviour definition and bind to policy
329
ClassFeatureBehaviourBinding binding = new ClassFeatureBehaviourBinding(dictionary, className, assocName);
330         BehaviourDefinition<ClassFeatureBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Association, policy, binding, behaviour);
331         getAssociationBehaviourIndex(policy).putClassBehaviour(definition);
332         
333         if (logger.isInfoEnabled())
334             logger.info("Bound " + behaviour + " to policy " + policy + " for association " + assocName + " of class " + className);
335
336         return definition;
337     }
338
339
340     /* (non-Javadoc)
341      * @see org.alfresco.repo.policy.PolicyComponent#bindAssociationBehaviour(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName, org.alfresco.repo.policy.Behaviour)
342      */

343     public BehaviourDefinition<ClassFeatureBehaviourBinding> bindAssociationBehaviour(QName policy, QName className, Behaviour behaviour)
344     {
345         // Validate arguments
346
ParameterCheck.mandatory("Policy", policy);
347         ParameterCheck.mandatory("Class Reference", className);
348         ParameterCheck.mandatory("Behaviour", behaviour);
349
350         // Validate Binding
351
ClassDefinition classDefinition = dictionary.getClass(className);
352         if (classDefinition == null)
353         {
354             throw new IllegalArgumentException JavaDoc("Class " + className + " has not been defined in the data dictionary");
355         }
356         
357         // Create behaviour definition and bind to policy
358
ClassFeatureBehaviourBinding binding = new ClassFeatureBehaviourBinding(dictionary, className, FEATURE_WILDCARD);
359         BehaviourDefinition<ClassFeatureBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Association, policy, binding, behaviour);
360         getAssociationBehaviourIndex(policy).putClassBehaviour(definition);
361         
362         if (logger.isInfoEnabled())
363             logger.info("Bound " + behaviour + " to policy " + policy + " for association " + FEATURE_WILDCARD + " of class " + className);
364
365         return definition;
366     }
367
368
369     /* (non-Javadoc)
370      * @see org.alfresco.repo.policy.PolicyComponent#bindAssociationBehaviour(org.alfresco.repo.ref.QName, java.lang.Object, org.alfresco.repo.policy.Behaviour)
371      */

372     public BehaviourDefinition<ServiceBehaviourBinding> bindAssociationBehaviour(QName policy, Object JavaDoc service, Behaviour behaviour)
373     {
374         // Validate arguments
375
ParameterCheck.mandatory("Policy", policy);
376         ParameterCheck.mandatory("Service", service);
377         ParameterCheck.mandatory("Behaviour", behaviour);
378         
379         // Create behaviour definition and bind to policy
380
ServiceBehaviourBinding binding = new ServiceBehaviourBinding(service);
381         BehaviourDefinition<ServiceBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Association, policy, binding, behaviour);
382         getAssociationBehaviourIndex(policy).putServiceBehaviour(definition);
383         
384         if (logger.isInfoEnabled())
385             logger.info("Bound " + behaviour + " to association policy " + policy + " for service " + service);
386
387         return definition;
388     }
389     
390     
391     /**
392      * Gets the Class behaviour index for the specified Policy
393      *
394      * @param policy the policy
395      * @return the class behaviour index
396      */

397     private synchronized ClassBehaviourIndex<ClassBehaviourBinding> getClassBehaviourIndex(QName policy)
398     {
399         ClassBehaviourIndex<ClassBehaviourBinding> index = classBehaviours.get(policy);
400         if (index == null)
401         {
402             index = new ClassBehaviourIndex<ClassBehaviourBinding>(behaviourFilter);
403             classBehaviours.put(policy, index);
404         }
405         return index;
406     }
407
408     
409     /**
410      * Gets the Property behaviour index for the specified Policy
411      *
412      * @param policy the policy
413      * @return the property behaviour index
414      */

415     private synchronized ClassBehaviourIndex<ClassFeatureBehaviourBinding> getPropertyBehaviourIndex(QName policy)
416     {
417         ClassBehaviourIndex<ClassFeatureBehaviourBinding> index = propertyBehaviours.get(policy);
418         if (index == null)
419         {
420             index = new ClassBehaviourIndex<ClassFeatureBehaviourBinding>(behaviourFilter);
421             propertyBehaviours.put(policy, index);
422         }
423         return index;
424     }
425     
426
427     /**
428      * Gets the Association behaviour index for the specified Policy
429      *
430      * @param policy the policy
431      * @return the association behaviour index
432      */

433     private synchronized ClassBehaviourIndex<ClassFeatureBehaviourBinding> getAssociationBehaviourIndex(QName policy)
434     {
435         ClassBehaviourIndex<ClassFeatureBehaviourBinding> index = associationBehaviours.get(policy);
436         if (index == null)
437         {
438             index = new ClassBehaviourIndex<ClassFeatureBehaviourBinding>(behaviourFilter);
439             associationBehaviours.put(policy, index);
440         }
441         return index;
442     }
443
444     
445     /**
446      * Create a Behaviour Definition
447      *
448      * @param <B> the type of binding
449      * @param type policy type
450      * @param policy policy name
451      * @param binding the binding
452      * @param behaviour the behaviour
453      * @return the behaviour definition
454      */

455     @SuppressWarnings JavaDoc("unchecked")
456     private <B extends BehaviourBinding> BehaviourDefinition<B> createBehaviourDefinition(PolicyType type, QName policy, B binding, Behaviour behaviour)
457     {
458         // Determine if policy has already been registered
459
PolicyDefinition policyDefinition = getRegisteredPolicy(type, policy);
460         if (policyDefinition != null)
461         {
462             // Policy has already been registered, force validation of behaviour now
463
behaviour.getInterface(policyDefinition.getPolicyInterface());
464         }
465         else
466         {
467             if (logger.isInfoEnabled())
468                 logger.info("Behaviour " + behaviour + " is binding (" + binding + ") to policy " + policy + " before the policy is registered");
469         }
470         
471         // Construct the definition
472
return new BehaviourDefinitionImpl<B>(type, policy, binding, behaviour);
473     }
474     
475
476     /**
477      * Create a Policy Definition
478      *
479      * @param policyIF the policy interface
480      * @return the policy definition
481      */

482     private PolicyDefinition createPolicyDefinition(Class JavaDoc policyIF)
483     {
484         // Extract Policy Namespace
485
String JavaDoc namespaceURI = NamespaceService.DEFAULT_URI;
486         try
487         {
488             Field JavaDoc metadata = policyIF.getField(ANNOTATION_NAMESPACE);
489             if (!String JavaDoc.class.isAssignableFrom(metadata.getType()))
490             {
491                 throw new PolicyException("NAMESPACE metadata incorrectly specified in policy " + policyIF.getCanonicalName());
492             }
493             namespaceURI = (String JavaDoc)metadata.get(null);
494         }
495         catch(NoSuchFieldException JavaDoc e)
496         {
497             // Assume default namespace
498
}
499         catch(IllegalAccessException JavaDoc e)
500         {
501             // Shouldn't get here (interface definitions must be accessible)
502
}
503
504         // Extract Policy Name
505
Method JavaDoc[] methods = policyIF.getMethods();
506         if (methods.length != 1)
507         {
508             throw new PolicyException("Policy " + policyIF.getCanonicalName() + " must declare only one method");
509         }
510         String JavaDoc name = methods[0].getName();
511
512         // Create Policy Definition
513
return new PolicyDefinitionImpl(QName.createQName(namespaceURI, name), policyIF);
514     }
515
516     
517     /**
518      * Policy Key (composite of policy type and name)
519      *
520      * @author David Caruana
521      *
522      */

523     private static class PolicyKey
524     {
525         private PolicyType type;
526         private QName policy;
527         
528         private PolicyKey(PolicyType type, QName policy)
529         {
530             this.type = type;
531             this.policy = policy;
532         }
533
534         @Override JavaDoc
535         public boolean equals(Object JavaDoc obj)
536         {
537             if (obj == this)
538             {
539                 return true;
540             }
541             else if (obj == null || !(obj instanceof PolicyKey))
542             {
543                 return false;
544             }
545             PolicyKey other = (PolicyKey)obj;
546             return type.equals(other.type) && policy.equals(other.policy);
547         }
548
549         @Override JavaDoc
550         public int hashCode()
551         {
552             return 37 * type.hashCode() + policy.hashCode();
553         }
554     }
555     
556     
557     /**
558      * Policy Definition implementation.
559      *
560      * @author David Caruana
561      *
562      */

563     /*package*/ class PolicyDefinitionImpl implements PolicyDefinition
564     {
565         private QName policy;
566         private Class JavaDoc policyIF;
567
568         /*package*/ PolicyDefinitionImpl(QName policy, Class JavaDoc policyIF)
569         {
570             this.policy = policy;
571             this.policyIF = policyIF;
572         }
573         
574         /* (non-Javadoc)
575          * @see org.alfresco.repo.policy.PolicyDefinition#getName()
576          */

577         public QName getName()
578         {
579             return policy;
580         }
581         
582         /* (non-Javadoc)
583          * @see org.alfresco.repo.policy.PolicyDefinition#getPolicyInterface()
584          */

585         public Class JavaDoc getPolicyInterface()
586         {
587             return policyIF;
588         }
589
590         /* (non-Javadoc)
591          * @see org.alfresco.repo.policy.PolicyDefinition#getType()
592          */

593         public PolicyType getType()
594         {
595             if (ClassPolicy.class.isAssignableFrom(policyIF))
596             {
597                 return PolicyType.Class;
598             }
599             else if (PropertyPolicy.class.isAssignableFrom(policyIF))
600             {
601                 return PolicyType.Property;
602             }
603             else
604             {
605                 return PolicyType.Association;
606             }
607         }
608     }
609     
610
611     /**
612      * Behaviour Definition implementation.
613      *
614      * @author David Caruana
615      *
616      * @param <B> the type of binding
617      */

618     /*package*/ class BehaviourDefinitionImpl<B extends BehaviourBinding> implements BehaviourDefinition<B>
619     {
620         private PolicyType type;
621         private QName policy;
622         private B binding;
623         private Behaviour behaviour;
624         
625         /*package*/ BehaviourDefinitionImpl(PolicyType type, QName policy, B binding, Behaviour behaviour)
626         {
627             this.type = type;
628             this.policy = policy;
629             this.binding = binding;
630             this.behaviour = behaviour;
631         }
632         
633         /* (non-Javadoc)
634          * @see org.alfresco.repo.policy.BehaviourDefinition#getPolicy()
635          */

636         public QName getPolicy()
637         {
638             return policy;
639         }
640
641         /* (non-Javadoc)
642          * @see org.alfresco.repo.policy.BehaviourDefinition#getPolicyDefinition()
643          */

644         public PolicyDefinition getPolicyDefinition()
645         {
646             return getRegisteredPolicy(type, policy);
647         }
648
649         /* (non-Javadoc)
650          * @see org.alfresco.repo.policy.BehaviourDefinition#getBinding()
651          */

652         public B getBinding()
653         {
654             return binding;
655         }
656         
657         /* (non-Javadoc)
658          * @see org.alfresco.repo.policy.BehaviourDefinition#getBehaviour()
659          */

660         public Behaviour getBehaviour()
661         {
662             return behaviour;
663         }
664     }
665
666 }
667
Popular Tags