Source Code Cross Referenced for XMLPrototypeProviderPlugin.java in  » Science » Cougaar12_4 » org » cougaar » mlm » plugin » xml » 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 » Science » Cougaar12_4 » org.cougaar.mlm.plugin.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.mlm.plugin.xml;
028:
029:        import java.io.FileNotFoundException;
030:        import java.io.IOException;
031:
032:        import org.cougaar.core.service.LoggingService;
033:        import org.cougaar.lib.xml.parser.PrototypeParser;
034:        import org.cougaar.planning.ldm.PrototypeProvider;
035:        import org.cougaar.planning.ldm.asset.Asset;
036:        import org.cougaar.planning.plugin.legacy.SimplePlugin;
037:        import org.w3c.dom.Document;
038:        import org.w3c.dom.Node;
039:
040:        /**
041:         * <pre>
042:         * This plugin is a prototype provider that attempts to supply
043:         * prototypes by looking for XML files by name. It finds the prototype
044:         * file by using the ConfigFinder mechanism, and parses it using the
045:         * toolkit prototype XML Parser. If successful, it will cache and return the
046:         * generated prototype.
047:         * NOTE : The name of the prototype is modified to 
048:         * change '/' characters to '-' characters to allow for O/S compatibility:
049:         * Example : Prototype "NSN/1234567890123" looks for a 
050:         * file NSN-1234567890123.xml
051:         * 
052:         * </pre>
053:         * @see org.cougaar.lib.xml.parser.PrototypeParser#cachePrototype
054:         * @see org.cougaar.util.ConfigFinder#parseXMLConfigFile
055:         **/
056:        public class XMLPrototypeProviderPlugin extends SimplePlugin implements 
057:                PrototypeProvider {
058:            /** 
059:             * Rely upon load-time introspection to set these services - 
060:             * don't worry about revokation.
061:             */
062:            public final void setLoggingService(LoggingService bs) {
063:                logger = bs;
064:                prototypeParser = new PrototypeParser(logger);
065:            }
066:
067:            /**
068:             * Get the logging service, for subclass use.
069:             */
070:            protected LoggingService getLoggingService() {
071:                return logger;
072:            }
073:
074:            /**
075:             * While this is a plugin, we only expect it to operate 
076:             * as a prototype provider.  No subscriptions are made here.
077:             */
078:            public void setupSubscriptions() {
079:                // System.out.println("Loading XMLPrototypeProviderPlugin...");
080:            }
081:
082:            /** no subscriptions -- nothing happens here */
083:            public void execute() {
084:            }
085:
086:            /**
087:             * <pre>
088:             * Interface required for PrototypeProvider
089:             * If possible, Create a prototype from XML file given by name
090:             * <aTypeName>.xml and cache and return prototype
091:             * Otherwise, return null
092:             * </pre>
093:             * @param aTypeName name of the Prototype to create
094:             * @param ignoredAnAssetClassHint class hint not used, since we read from a file
095:             * @return asset prototype if we can find and parse the file, null otherwise
096:             */
097:            public Asset getPrototype(String aTypeName,
098:                    Class ignoredAnAssetClassHint) {
099:                Asset new_prototype = null;
100:                Node node = null;
101:
102:                // Find the file named 'aTypeName'.xml and parse it
103:                // Using ConfigFileFinder
104:                String filename = cleanupPrototypeName(aTypeName) + ".xml";
105:                try {
106:                    Document doc = getConfigFinder().parseXMLConfigFile(
107:                            filename);
108:                    if (doc != null) {
109:                        node = doc.getDocumentElement();
110:                    }
111:                } catch (FileNotFoundException fnfe) {
112:                } catch (IOException ie) {
113:                    logger.error("Exception parsing prototype file : "
114:                            + filename, ie);
115:                }
116:
117:                // Create a prototype from the parsed node
118:                // Using toolkit XML Asset parser
119:                if (node != null) {
120:                    new_prototype = prototypeParser.cachePrototype(getLDM(),
121:                            node, true);
122:                    if (new_prototype != null) {
123:                        getLDM().cachePrototype(aTypeName, new_prototype);
124:                        if (logger.isDebugEnabled())
125:                            logger
126:                                    .debug(".getPrototype : Caching prototype for "
127:                                            + aTypeName);
128:                        getLDM().fillProperties(new_prototype);
129:                    }
130:                }
131:
132:                // Return newly constructed prototype (or null, if none found)
133:                return new_prototype;
134:            }
135:
136:            /** Alter prototype string to change '/' to '-' */
137:            private String cleanupPrototypeName(String prototype) {
138:                return prototype.replace('/', '-');
139:            }
140:
141:            protected LoggingService logger;
142:            protected PrototypeParser prototypeParser;
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.