Source Code Cross Referenced for QuerySelectionListImpl.java in  » Content-Management-System » daisy » org » outerj » daisy » repository » commonimpl » schema » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » daisy » org.outerj.daisy.repository.commonimpl.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Outerthought bvba and Schaubroeck nv
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.outerj.daisy.repository.commonimpl.schema;
017:
018:        import org.outerj.daisy.repository.schema.QuerySelectionList;
019:        import org.outerj.daisy.repository.schema.ListItem;
020:        import org.outerj.daisy.repository.query.SortOrder;
021:        import org.outerj.daisy.repository.*;
022:        import org.outerx.daisy.x10.*;
023:
024:        import java.util.Locale;
025:        import java.util.List;
026:        import java.util.ArrayList;
027:        import java.util.Collections;
028:
029:        public class QuerySelectionListImpl implements  QuerySelectionList {
030:            private String query;
031:            private boolean filterVariants;
032:            private SortOrder sortOrder;
033:            private FieldTypeImpl owner;
034:
035:            public QuerySelectionListImpl(String query, boolean filterVariants,
036:                    SortOrder sortOrder, FieldTypeImpl owner) {
037:                checkQueryParam(query);
038:                this .query = query;
039:                this .filterVariants = filterVariants;
040:                this .sortOrder = sortOrder;
041:                if (this .sortOrder == null)
042:                    this .sortOrder = SortOrder.ASCENDING;
043:                this .owner = owner;
044:            }
045:
046:            public String getQuery() {
047:                return query;
048:            }
049:
050:            public SortOrder getSortOrder() {
051:                return sortOrder;
052:            }
053:
054:            public void setQuery(String query) {
055:                if (owner.isReadOnly())
056:                    throw new RuntimeException(FieldTypeImpl.READ_ONLY_MESSAGE);
057:
058:                checkQueryParam(query);
059:                this .query = query;
060:            }
061:
062:            public void setSortOrder(SortOrder sortOrder) {
063:                if (owner.isReadOnly())
064:                    throw new RuntimeException(FieldTypeImpl.READ_ONLY_MESSAGE);
065:
066:                if (sortOrder == null)
067:                    throw new IllegalArgumentException(
068:                            "sortOrder arg cannot be null");
069:                this .sortOrder = sortOrder;
070:            }
071:
072:            public boolean getFilterVariants() {
073:                return filterVariants;
074:            }
075:
076:            public void setFilterVariants(boolean filterVariants) {
077:                if (owner.isReadOnly())
078:                    throw new RuntimeException(FieldTypeImpl.READ_ONLY_MESSAGE);
079:                this .filterVariants = filterVariants;
080:            }
081:
082:            private void checkQueryParam(String query) {
083:                if (query == null || query.trim().length() == 0)
084:                    throw new IllegalArgumentException(
085:                            "query argument cannot be null, empty or whitespace");
086:            }
087:
088:            public QuerySelectionListDocument getXml() {
089:                QuerySelectionListDocument listDocument = QuerySelectionListDocument.Factory
090:                        .newInstance();
091:                QuerySelectionListDocument.QuerySelectionList listXml = listDocument
092:                        .addNewQuerySelectionList();
093:                listXml.setQuery(query);
094:                listXml.setFilterVariants(filterVariants);
095:                listXml.setSortOrder(sortOrder.toString());
096:                return listDocument;
097:            }
098:
099:            public List<? extends ListItem> getItems() {
100:                throw new RuntimeException(
101:                        "This method should only be called through QuerySelectionListWrapper");
102:            }
103:
104:            public List<? extends ListItem> getItems(Repository repository) {
105:                if (filterVariants)
106:                    throw new RepositoryRuntimeException(
107:                            "This selection list needs to filter on variants, so use getItems(branchId, languageId) instead.");
108:                return getItems(-1, -1, Locale.US, repository);
109:            }
110:
111:            public List<? extends ListItem> getItems(long branchId,
112:                    long languageId, Locale locale) {
113:                throw new RuntimeException(
114:                        "This method should only be called through QuerySelectionListWrapper");
115:            }
116:
117:            public List<? extends ListItem> getItems(long branchId,
118:                    long languageId, Locale locale, Repository repository) {
119:                DistinctSearchResultDocument searchResultDocument;
120:                try {
121:                    if (filterVariants) {
122:                        searchResultDocument = repository
123:                                .getQueryManager()
124:                                .performDistinctQuery(
125:                                        query,
126:                                        "branchId = " + branchId
127:                                                + " and languageId = "
128:                                                + languageId, sortOrder, locale);
129:                    } else {
130:                        searchResultDocument = repository.getQueryManager()
131:                                .performDistinctQuery(query, sortOrder, locale);
132:                    }
133:                } catch (RepositoryException e) {
134:                    throw new RuntimeException(
135:                            "Error executing query selection list query: "
136:                                    + query, e);
137:                }
138:                String resultValueTypeString = searchResultDocument
139:                        .getDistinctSearchResult().getValues().getValueType();
140:                ValueType resultValueType = ValueType
141:                        .fromString(resultValueTypeString);
142:
143:                if (resultValueType != owner.getValueType())
144:                    throw new RuntimeException(
145:                            "Values returned from selection list query are of a different type ("
146:                                    + resultValueType.toString()
147:                                    + ") then the field type ("
148:                                    + owner.getValueType().toString() + ").");
149:
150:                List<DistinctSearchResultDocument.DistinctSearchResult.Values.Value> valuesXml = searchResultDocument
151:                        .getDistinctSearchResult().getValues().getValueList();
152:                List<QueryListItem> items = new ArrayList<QueryListItem>(
153:                        valuesXml.size());
154:                FieldHelper.XmlFieldValueGetter valueGetter = FieldHelper
155:                        .getXmlFieldValueGetter(resultValueType);
156:                for (DistinctSearchResultDocument.DistinctSearchResult.Values.Value valueXml : valuesXml) {
157:                    items.add(new QueryListItem(valueGetter.getValue(valueXml,
158:                            false), valueXml.getLabel()));
159:                }
160:                return Collections.unmodifiableList(items);
161:            }
162:
163:            public String getLabel(Object value, Locale locale) {
164:                return getItemLabel(value, locale);
165:            }
166:
167:            public String getItemLabel(Object value, Locale locale) {
168:                return null;
169:            }
170:
171:            public void addToFieldTypeXml(
172:                    SelectionListDocument.SelectionList selectionListXml) {
173:                selectionListXml.setQuerySelectionList(getXml()
174:                        .getQuerySelectionList());
175:            }
176:
177:            public boolean equals(Object obj) {
178:                if (!(obj instanceof  QuerySelectionListImpl))
179:                    return false;
180:
181:                QuerySelectionListImpl other = (QuerySelectionListImpl) obj;
182:
183:                if (filterVariants != other.filterVariants)
184:                    return false;
185:
186:                if (sortOrder != other.sortOrder)
187:                    return false;
188:
189:                return query.equals(other.query);
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.