1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.xml.dav.request.properties;
14
15 import org.abstracthorizon.danube.http.Status;
16 import org.abstracthorizon.danube.webdav.ResourceAdapter;
17 import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
18 import org.abstracthorizon.danube.webdav.xml.dav.request.AbstractSimpleXMLHandler;
19 import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
20
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.InvocationTargetException;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27
28
29
30
31
32 public abstract class RequestProperty extends AbstractSimpleXMLHandler {
33
34
35 protected Logger logger = LoggerFactory.getLogger(getClass());
36
37
38 protected static final Class<?>[] CONSTRUCTOR_ARGUMENTS_CLASSES = new Class[]{Status.class};
39
40
41 protected static final String packageName = ResponseProperty.class.getPackage().getName();
42
43
44
45
46
47 public RequestProperty(XMLParserHandler parent) {
48 super(parent);
49 }
50
51
52
53
54
55
56 @SuppressWarnings("unchecked")
57 protected ResponseProperty constructResponse(Status status) {
58 try {
59 String clsName = getClass().getName();
60 int i = clsName.lastIndexOf('.');
61 clsName = packageName + '.' + clsName.substring(i + 1);
62 Class cls = Class.forName(clsName);
63 Constructor<ResponseProperty> constructor = cls.getConstructor(CONSTRUCTOR_ARGUMENTS_CLASSES);
64 ResponseProperty responseProperty = constructor.newInstance(new Object[]{status});
65 return responseProperty;
66 } catch (SecurityException e) {
67 logger.debug("", e);
68 } catch (NoSuchMethodException e) {
69 logger.debug("", e);
70 } catch (IllegalArgumentException e) {
71 logger.debug("", e);
72 } catch (InstantiationException e) {
73 logger.debug("", e);
74 } catch (IllegalAccessException e) {
75 logger.debug("", e);
76 } catch (InvocationTargetException e) {
77 logger.debug("", e);
78 } catch (ClassNotFoundException e) {
79 logger.debug("", e);
80 }
81 return null;
82 }
83
84
85
86
87
88
89
90 public ResponseProperty processResponse(ResourceAdapter adapter, Object resource) {
91 return constructResponse(Status.NOT_FOUND);
92 }
93
94
95
96
97
98
99
100 public ResponseProperty processSetProperty(ResourceAdapter adapter, Object resource) {
101 return constructResponse(Status.CONFLICT);
102 }
103
104
105
106
107
108
109
110 public ResponseProperty processRemoveProperty(ResourceAdapter webDAVAdapter, Object resource) {
111 return constructResponse(Status.CONFLICT);
112 }
113
114 }