1 23 24 package org.apache.webdav.lib.properties; 25 26 import java.lang.reflect.Constructor ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.apache.webdav.lib.BaseProperty; 31 import org.apache.webdav.lib.Property; 32 import org.apache.webdav.lib.ResponseEntity; 33 import org.apache.webdav.lib.WebdavException; 34 import org.w3c.dom.Element ; 35 36 37 40 public class PropertyFactory 41 { 42 private static final Class [] CTOR_PARAMS = { ResponseEntity.class, Element .class }; 43 44 47 private static Map propertyClasses = new HashMap (); 48 49 static { 50 try { 51 PropertyFactory.register("DAV:", AclProperty.TAG_NAME, AclProperty.class); 52 PropertyFactory.register("DAV:", CheckedinProperty.TAG_NAME, CheckedinProperty.class); 53 PropertyFactory.register("DAV:", CheckedoutProperty.TAG_NAME, CheckedoutProperty.class); 54 PropertyFactory.register("DAV:", CreationDateProperty.TAG_NAME, CreationDateProperty.class); 55 PropertyFactory.register("DAV:", CurrentUserPrivilegeSetProperty.TAG_NAME, CurrentUserPrivilegeSetProperty.class); 56 PropertyFactory.register("DAV:", GetContentLengthProperty.TAG_NAME, GetContentLengthProperty.class); 57 PropertyFactory.register("DAV:", GetLastModifiedProperty.TAG_NAME, GetLastModifiedProperty.class); 58 PropertyFactory.register("DAV:", LockDiscoveryProperty.TAG_NAME, LockDiscoveryProperty.class); 59 PropertyFactory.register("DAV:", ModificationDateProperty.TAG_NAME, ModificationDateProperty.class); 60 PropertyFactory.register("DAV:", OwnerProperty.TAG_NAME, OwnerProperty.class); 61 PropertyFactory.register("DAV:", PrincipalCollectionSetProperty.TAG_NAME, PrincipalCollectionSetProperty.class); 62 PropertyFactory.register("DAV:", ResourceTypeProperty.TAG_NAME, ResourceTypeProperty.class); 63 PropertyFactory.register("DAV:", SupportedLockProperty.TAG_NAME, SupportedLockProperty.class); 64 } catch (Exception e) { 65 throw new WebdavException(e); 66 } 67 } 68 69 77 public static Property create(ResponseEntity response, Element element) 78 { 79 Map nsMap = (Map )propertyClasses.get(element.getNamespaceURI()); 81 if (nsMap != null) { 82 Constructor ctor = (Constructor )nsMap.get(element.getLocalName()); 84 if (ctor != null) { 85 try { 86 Object [] params = {response, element}; 88 return (Property)ctor.newInstance(params); 89 } catch (Exception e) { 90 throw new WebdavException(e); 91 } 92 } 93 } 94 95 return new BaseProperty(response, element); 96 }; 97 98 108 public static void register(String namespaceUri, String elementName, Class cls) 109 throws NoSuchMethodException , SecurityException 110 { 111 Constructor ctor = cls.getConstructor(CTOR_PARAMS); 112 113 Map nsMap = (Map )propertyClasses.get(namespaceUri); 114 if (nsMap == null) { 115 nsMap = new HashMap (); 116 propertyClasses.put(namespaceUri, nsMap); 117 } 118 nsMap.put(elementName, ctor); 119 } 120 } 121 | Popular Tags |