KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > QueryParameterDefImpl


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.search;
18
19 import org.alfresco.service.cmr.dictionary.DictionaryService;
20 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
21 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
22 import org.alfresco.service.cmr.search.QueryParameterDefinition;
23 import org.alfresco.service.namespace.NamespacePrefixResolver;
24 import org.alfresco.service.namespace.NamespaceService;
25 import org.alfresco.service.namespace.QName;
26 import org.dom4j.Element;
27 import org.dom4j.Namespace;
28
29 public class QueryParameterDefImpl implements QueryParameterDefinition
30 {
31
32     private static final org.dom4j.QName ELEMENT_QNAME = new org.dom4j.QName("parameter-definition", new Namespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI));
33
34     private static final org.dom4j.QName DEF_QNAME = new org.dom4j.QName("qname", new Namespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI));
35
36     private static final org.dom4j.QName PROPERTY_QNAME = new org.dom4j.QName("property", new Namespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI));
37
38     private static final org.dom4j.QName PROPERTY_TYPE_QNAME = new org.dom4j.QName("type", new Namespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI));
39
40     private static final org.dom4j.QName DEFAULT_VALUE = new org.dom4j.QName("default-value", new Namespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI));
41
42     
43     private QName qName;
44
45     private PropertyDefinition propertyDefintion;
46
47     private DataTypeDefinition dataTypeDefintion;
48     
49     private boolean hasDefaultValue;
50     
51     private String JavaDoc defaultValue;
52
53     public QueryParameterDefImpl(QName qName, PropertyDefinition propertyDefinition, boolean hasDefaultValue, String JavaDoc defaultValue)
54     {
55         this(qName, hasDefaultValue, defaultValue);
56         this.propertyDefintion = propertyDefinition;
57         this.dataTypeDefintion = propertyDefinition.getDataType();
58     }
59
60     private QueryParameterDefImpl(QName qName, boolean hasDefaultValue, String JavaDoc defaultValue)
61     {
62         super();
63         this.qName = qName;
64         this.hasDefaultValue = hasDefaultValue;
65         this.defaultValue = defaultValue;
66     }
67     
68     public QueryParameterDefImpl(QName qName, DataTypeDefinition dataTypeDefintion, boolean hasDefaultValue, String JavaDoc defaultValue)
69     {
70         this(qName, hasDefaultValue, defaultValue);
71         this.propertyDefintion = null;
72         this.dataTypeDefintion = dataTypeDefintion;
73     }
74
75     public QName getQName()
76     {
77         return qName;
78     }
79
80     public PropertyDefinition getPropertyDefinition()
81     {
82         return propertyDefintion;
83     }
84
85     public DataTypeDefinition getDataTypeDefinition()
86     {
87         return dataTypeDefintion;
88     }
89
90     public static QueryParameterDefinition createParameterDefinition(Element element, DictionaryService dictionaryService, NamespacePrefixResolver nspr)
91     {
92
93         if (element.getQName().getName().equals(ELEMENT_QNAME.getName()))
94         {
95             QName qName = null;
96             Element qNameElement = element.element(DEF_QNAME.getName());
97             if (qNameElement != null)
98             {
99                 qName = QName.createQName(qNameElement.getText(), nspr);
100             }
101
102             PropertyDefinition propDef = null;
103             Element propDefElement = element.element(PROPERTY_QNAME.getName());
104             if (propDefElement != null)
105             {
106                 propDef = dictionaryService.getProperty(QName.createQName(propDefElement.getText(), nspr));
107             }
108
109             DataTypeDefinition typeDef = null;
110             Element typeDefElement = element.element(PROPERTY_TYPE_QNAME.getName());
111             if (typeDefElement != null)
112             {
113                 typeDef = dictionaryService.getDataType(QName.createQName(typeDefElement.getText(), nspr));
114             }
115
116             boolean hasDefault = false;
117             String JavaDoc defaultValue = null;
118             Element defaultValueElement = element.element(DEFAULT_VALUE.getName());
119             if(defaultValueElement != null)
120             {
121                 hasDefault = true;
122                 defaultValue = defaultValueElement.getText();
123             }
124             
125             if (propDef != null)
126             {
127                 return new QueryParameterDefImpl(qName, propDef, hasDefault, defaultValue);
128             }
129             else
130             {
131                 return new QueryParameterDefImpl(qName, typeDef, hasDefault, defaultValue);
132             }
133         }
134         else
135         {
136             return null;
137         }
138     }
139
140     public static org.dom4j.QName getElementQName()
141     {
142         return ELEMENT_QNAME;
143     }
144
145     public QueryParameterDefinition getQueryParameterDefinition()
146     {
147         return this;
148     }
149
150     /**
151      * There may be a default value which is null ie <default-value/> the empty
152      * string <default-value></default-value> or no entry at all for no default
153      * value
154      */

155     public String JavaDoc getDefault()
156     {
157         return defaultValue;
158     }
159
160     public boolean hasDefaultValue()
161     {
162         return hasDefaultValue;
163     }
164
165 }
166
Popular Tags