Source Code Cross Referenced for ModuleRules.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » core » module » id » 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 » Code Analyzer » apache ivy » org.apache.ivy.core.module.id 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.ivy.core.module.id;
019:
020:        import java.util.Iterator;
021:        import java.util.LinkedHashMap;
022:        import java.util.Map;
023:
024:        import org.apache.ivy.plugins.matcher.MapMatcher;
025:        import org.apache.ivy.util.Checks;
026:        import org.apache.ivy.util.Message;
027:        import org.apache.ivy.util.filter.Filter;
028:        import org.apache.ivy.util.filter.NoFilter;
029:
030:        /**
031:         * A list of module specific rules.
032:         * <p>
033:         * This class defines a list of module specific rules. For each module only one rule apply,
034:         * sometimes none.
035:         * </p>
036:         * <p>
037:         * To know which rule to apply, they are configured using matchers. So you can define a rule
038:         * applying to all module from one particular organization, or to all modules with a revisions
039:         * matching a pattern, and so on.
040:         * </p>
041:         * <p>
042:         * Rules condition are evaluated in order, so the first matching rule is returned.
043:         * </p>
044:         * <p>
045:         * Rules themselves can be represented by any object, depending on the purpose of the rule (define
046:         * which resolver to use, which TTL in cache, ...)
047:         * </p>
048:         */
049:        public class ModuleRules {
050:            private Map/*<MapMatcher,Object>*/rules = new LinkedHashMap();
051:
052:            /**
053:             * Defines a new rule for the given condition.
054:             * 
055:             * @param condition
056:             *            the condition for which the rule should be applied. Must not be <code>null</code>.
057:             * @param rule
058:             *            the rule to apply. Must not be <code>null</code>.
059:             */
060:            public void defineRule(MapMatcher condition, Object rule) {
061:                Checks.checkNotNull(condition, "condition");
062:                Checks.checkNotNull(rule, "rule");
063:
064:                rules.put(condition, rule);
065:            }
066:
067:            /**
068:             * Returns the rule object matching the given {@link ModuleRevisionId}, or <code>null</code>
069:             * if no rule applies.
070:             * 
071:             * @param mrid
072:             *            the {@link ModuleRevisionId} to search the rule for. 
073:             *            Must not be <code>null</code>.
074:             * @return the rule object matching the given {@link ModuleRevisionId}, or <code>null</code>
075:             *         if no rule applies.
076:             * @see #getRule(ModuleRevisionId, Filter)
077:             */
078:            public Object getRule(ModuleRevisionId mrid) {
079:                return getRule(mrid, NoFilter.INSTANCE);
080:            }
081:
082:            /**
083:             * Returns the rule object matching the given {@link ModuleId} and accepted by the given
084:             * {@link Filter}, or <code>null</code> if no rule applies.
085:             * 
086:             * @param mrid
087:             *            the {@link ModuleRevisionId} to search the rule for. 
088:             *            Must not be <code>null</code>.
089:             * @param filter
090:             *            the filter to use to filter the rule to return. The {@link Filter#accept(Object)}
091:             *            method will be called only with rule objects matching the given
092:             *            {@link ModuleId}, and the first rule object accepted by the filter will
093:             *            be returned. Must not be <code>null</code>.
094:             * @return the rule object matching the given {@link ModuleId}, or <code>null</code>
095:             *         if no rule applies.
096:             * @see #getRule(ModuleRevisionId, Filter)
097:             */
098:            public Object getRule(ModuleId mid, Filter filter) {
099:                Checks.checkNotNull(mid, "mid");
100:                return getRule(new ModuleRevisionId(mid, "", ""), filter);
101:            }
102:
103:            /**
104:             * Returns the rule object matching the given {@link ModuleRevisionId} and accepted by the given
105:             * {@link Filter}, or <code>null</code> if no rule applies.
106:             * 
107:             * @param mrid
108:             *            the {@link ModuleRevisionId} to search the rule for. 
109:             *            Must not be <code>null</code>.
110:             * @param filter
111:             *            the filter to use to filter the rule to return. The {@link Filter#accept(Object)}
112:             *            method will be called only with rule objects matching the given
113:             *            {@link ModuleRevisionId}, and the first rule object accepted by the filter will
114:             *            be returned. Must not be <code>null</code>.
115:             * @return the rule object matching the given {@link ModuleRevisionId}, or <code>null</code>
116:             *         if no rule applies.
117:             * @see #getRule(ModuleRevisionId)
118:             */
119:            public Object getRule(ModuleRevisionId mrid, Filter filter) {
120:                Checks.checkNotNull(mrid, "mrid");
121:                Checks.checkNotNull(filter, "filter");
122:
123:                for (Iterator iter = rules.keySet().iterator(); iter.hasNext();) {
124:                    MapMatcher midm = (MapMatcher) iter.next();
125:                    if (midm.matches(mrid.getAttributes())) {
126:                        Object rule = rules.get(midm);
127:                        if (filter.accept(rule)) {
128:                            return rule;
129:                        }
130:                    }
131:                }
132:                return null;
133:            }
134:
135:            /**
136:             * Dump the list of rules to {@link Message#debug(String)}
137:             * 
138:             * @param prefix
139:             *            the prefix to use for each line dumped
140:             */
141:            public void dump(String prefix) {
142:                if (rules.isEmpty()) {
143:                    Message.debug(prefix + "NONE");
144:                } else {
145:                    for (Iterator iter = rules.keySet().iterator(); iter
146:                            .hasNext();) {
147:                        MapMatcher midm = (MapMatcher) iter.next();
148:                        Object rule = rules.get(midm);
149:                        Message.debug(prefix + midm + " -> " + rule);
150:                    }
151:                }
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.