Source Code Cross Referenced for Declaration.java in  » Library » Apache-commons-digester-1.8-src » org » apache » commons » digester » plugins » 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 » Library » Apache commons digester 1.8 src » org.apache.commons.digester.plugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* $Id: Declaration.java 471661 2006-11-06 08:09:25Z skitching $
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:        package org.apache.commons.digester.plugins;
019:
020:        import java.util.Properties;
021:
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.digester.Digester;
024:
025:        /**
026:         * Represents a Class that can be instantiated by a PluginCreateRule, plus
027:         * info on how to load custom digester rules for mapping xml into that
028:         * plugged-in class.
029:         *
030:         * @since 1.6
031:         */
032:        public class Declaration {
033:
034:            /** The class of the object to be instantiated. */
035:            private Class pluginClass;
036:
037:            /** The name of the class of the object to be instantiated. */
038:            private String pluginClassName;
039:
040:            /** See {@link #setId}. */
041:            private String id;
042:
043:            /** See {@link #setProperties}. */
044:            private Properties properties = new Properties();
045:
046:            /** See {@link #init}. */
047:            private boolean initialized = false;
048:
049:            /**
050:             * Class which is responsible for dynamically loading this
051:             * plugin's rules on demand.
052:             */
053:            private RuleLoader ruleLoader = null;
054:
055:            //---------------------- constructors ----------------------------------
056:
057:            /**
058:             * Constructor.
059:             */
060:            public Declaration(String pluginClassName) {
061:                // We can't load the pluginClass at this time, because we don't
062:                // have a digester instance yet to load it through. So just
063:                // save the name away, and we'll load the Class object in the
064:                // init method.
065:                this .pluginClassName = pluginClassName;
066:            }
067:
068:            /**
069:             * Constructor.
070:             */
071:            public Declaration(Class pluginClass) {
072:                this .pluginClass = pluginClass;
073:                this .pluginClassName = pluginClass.getName();
074:            }
075:
076:            /**
077:             * Create an instance where a fully-initialised ruleLoader instance
078:             * is provided by the caller instead of having the PluginManager
079:             * "discover" an appropriate one.
080:             */
081:            public Declaration(Class pluginClass, RuleLoader ruleLoader) {
082:                this .pluginClass = pluginClass;
083:                this .pluginClassName = pluginClass.getName();
084:                this .ruleLoader = ruleLoader;
085:            }
086:
087:            //---------------------- properties -----------------------------------
088:
089:            /** 
090:             * The id that the user associated with a particular plugin declaration
091:             * in the input xml. This id is later used in the input xml to refer
092:             * back to the original declaration.
093:             * <p>
094:             * For plugins declared "in-line", the id is null.
095:             */
096:            public void setId(String id) {
097:                this .id = id;
098:            }
099:
100:            /**
101:             * Return the id associated with this declaration. For plugins
102:             * declared "inline", null will be returned.
103:             * 
104:             * @return The id value. May be null.
105:             */
106:            public String getId() {
107:                return id;
108:            }
109:
110:            /** 
111:             * Copy all (key,value) pairs in the param into the properties member of
112:             * this object.
113:             * <p>
114:             * The declaration properties cannot be explicit member variables,
115:             * because the set of useful properties a user can provide on a declaration
116:             * depends on what RuleFinder classes are available - and extra RuleFinders
117:             * can be added by the user. So here we keep a map of the settings, and
118:             * let the RuleFinder objects look for whatever properties they consider
119:             * significant.
120:             * <p>
121:             * The "id" and "class" properties are treated differently.
122:             */
123:            public void setProperties(Properties p) {
124:                properties.putAll(p);
125:            }
126:
127:            /**
128:             * Return plugin class associated with this declaration.
129:             * 
130:             * @return The pluginClass.
131:             */
132:            public Class getPluginClass() {
133:                return pluginClass;
134:            }
135:
136:            //---------------------- methods -----------------------------------
137:
138:            /**
139:             * Must be called exactly once, and must be called before any call
140:             * to the configure method.
141:             */
142:            public void init(Digester digester, PluginManager pm)
143:                    throws PluginException {
144:                Log log = digester.getLogger();
145:                boolean debug = log.isDebugEnabled();
146:                if (debug) {
147:                    log.debug("init being called!");
148:                }
149:
150:                if (initialized) {
151:                    throw new PluginAssertionFailure(
152:                            "Init called multiple times.");
153:                }
154:
155:                if ((pluginClass == null) && (pluginClassName != null)) {
156:                    try {
157:                        // load the plugin class object
158:                        pluginClass = digester.getClassLoader().loadClass(
159:                                pluginClassName);
160:                    } catch (ClassNotFoundException cnfe) {
161:                        throw new PluginException("Unable to load class "
162:                                + pluginClassName, cnfe);
163:                    }
164:                }
165:
166:                if (ruleLoader == null) {
167:                    // the caller didn't provide a ruleLoader to the constructor,
168:                    // so get the plugin manager to "discover" one.
169:                    log.debug("Searching for ruleloader...");
170:                    ruleLoader = pm.findLoader(digester, id, pluginClass,
171:                            properties);
172:                } else {
173:                    log.debug("This declaration has an explicit ruleLoader.");
174:                }
175:
176:                if (debug) {
177:                    if (ruleLoader == null) {
178:                        log.debug("No ruleLoader found for plugin declaration"
179:                                + " id [" + id + "]" + ", class ["
180:                                + pluginClass.getClass().getName() + "].");
181:                    } else {
182:                        log.debug("RuleLoader of type ["
183:                                + ruleLoader.getClass().getName()
184:                                + "] associated with plugin declaration"
185:                                + " id [" + id + "]" + ", class ["
186:                                + pluginClass.getClass().getName() + "].");
187:                    }
188:                }
189:
190:                initialized = true;
191:            }
192:
193:            /**
194:             * Attempt to load custom rules for the target class at the specified
195:             * pattern.
196:             * <p>
197:             * On return, any custom rules associated with the plugin class have
198:             * been loaded into the Rules object currently associated with the
199:             * specified digester object.
200:             */
201:
202:            public void configure(Digester digester, String pattern)
203:                    throws PluginException {
204:                Log log = digester.getLogger();
205:                boolean debug = log.isDebugEnabled();
206:                if (debug) {
207:                    log.debug("configure being called!");
208:                }
209:
210:                if (!initialized) {
211:                    throw new PluginAssertionFailure("Not initialized.");
212:                }
213:
214:                if (ruleLoader != null) {
215:                    ruleLoader.addRules(digester, pattern);
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.