Source Code Cross Referenced for AutomationConfiguration.java in  » Net » j2ssh » com » sshtools » common » automate » 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 » Net » j2ssh » com.sshtools.common.automate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  SSHTools - Java SSH2 API
003:         *
004:         *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
005:         *
006:         *  Contributions made by:
007:         *
008:         *  Brett Smith
009:         *  Richard Pernavas
010:         *  Erwin Bolwidt
011:         *
012:         *  This program is free software; you can redistribute it and/or
013:         *  modify it under the terms of the GNU General Public License
014:         *  as published by the Free Software Foundation; either version 2
015:         *  of the License, or (at your option) any later version.
016:         *
017:         *  This program is distributed in the hope that it will be useful,
018:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:         *  GNU General Public License for more details.
021:         *
022:         *  You should have received a copy of the GNU General Public License
023:         *  along with this program; if not, write to the Free Software
024:         *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
025:         */
026:        package com.sshtools.common.automate;
027:
028:        import org.xml.sax.Attributes;
029:        import org.xml.sax.SAXException;
030:        import org.xml.sax.helpers.DefaultHandler;
031:
032:        import java.io.IOException;
033:        import java.io.InputStream;
034:
035:        import java.util.HashMap;
036:        import java.util.Map;
037:
038:        import javax.xml.parsers.ParserConfigurationException;
039:        import javax.xml.parsers.SAXParser;
040:        import javax.xml.parsers.SAXParserFactory;
041:
042:        /**
043:         *
044:         *
045:         * @author $author$
046:         * @version $Revision: 1.13 $
047:         */
048:        public class AutomationConfiguration {
049:            private HashMap remoteIdentifications = new HashMap();
050:
051:            /**
052:             * Creates a new AutomationConfiguration object.
053:             *
054:             * @param in
055:             *
056:             * @throws IOException
057:             * @throws SAXException
058:             * @throws ParserConfigurationException
059:             */
060:            public AutomationConfiguration(InputStream in) throws IOException,
061:                    SAXException, ParserConfigurationException {
062:                SAXParserFactory saxFactory = SAXParserFactory.newInstance();
063:                SAXParser saxParser = saxFactory.newSAXParser();
064:                saxParser.parse(in, new AutomationConfigurationSAXHandler());
065:            }
066:
067:            /**
068:             *
069:             *
070:             * @return
071:             */
072:            public Map getRemoteIdentifications() {
073:                return remoteIdentifications;
074:            }
075:
076:            /**
077:             *
078:             *
079:             * @param args
080:             */
081:            public static void main(String[] args) {
082:                try {
083:                } catch (Exception e) {
084:                    e.printStackTrace();
085:                }
086:            }
087:
088:            private class AutomationConfigurationSAXHandler extends
089:                    DefaultHandler {
090:                private String AUTOMATION_ELEMENT = "Automation";
091:                private String REMOTEID_ELEMENT = "RemoteIdentification";
092:                private String AUTHORIZEDKEYSFORMAT_ELEMENT = "AuthorizedKeysFormat";
093:                private String RULE_ELEMENT = "Rule";
094:                private String STARTSWITH_ATTRIBUTE = "startsWith";
095:                private String CONTAINS_ATTRIBUTE = "contains";
096:                private String DEFAULTNAME_ATTRIBUTE = "defaultName";
097:                private String NAME_ATTRIBUTE = "name";
098:                private String IMPLEMENTATION_ATTRIBUTE = "implementationClass";
099:                private String PRIORITY_ATTRIBUTE = "priority";
100:                private String DEFAULTPATH_ATTRIBUTE = "defaultPath";
101:                private String currentElement = null;
102:                private RemoteIdentification currentRID = null;
103:
104:                public void startElement(String uri, String localName,
105:                        String qname, Attributes attrs) throws SAXException {
106:                    if (currentElement == null) {
107:                        if (!qname.equals(AUTOMATION_ELEMENT)) {
108:                            throw new SAXException("Unexpected root element <"
109:                                    + qname + ">");
110:                        }
111:                    } else {
112:                        if (currentElement.equals(AUTOMATION_ELEMENT)) {
113:                            if (qname.equals(REMOTEID_ELEMENT)) {
114:                                String defaultName = attrs
115:                                        .getValue(DEFAULTNAME_ATTRIBUTE);
116:
117:                                if (defaultName == null) {
118:                                    throw new SAXException(
119:                                            DEFAULTNAME_ATTRIBUTE
120:                                                    + " attribute must be specified");
121:                                }
122:
123:                                currentRID = new RemoteIdentification(
124:                                        defaultName);
125:                            } else {
126:                                throw new SAXException("Unexpected element <"
127:                                        + qname + ">");
128:                            }
129:                        } else if (currentElement.equals(REMOTEID_ELEMENT)) {
130:                            if (qname.equals(RULE_ELEMENT)) {
131:                                String startsWith = attrs
132:                                        .getValue(STARTSWITH_ATTRIBUTE);
133:                                String contains = attrs
134:                                        .getValue(CONTAINS_ATTRIBUTE);
135:                                String name = attrs.getValue(NAME_ATTRIBUTE);
136:                                String priority = attrs
137:                                        .getValue(PRIORITY_ATTRIBUTE);
138:
139:                                try {
140:                                    RemoteIdentificationRule rule = new RemoteIdentificationRule();
141:
142:                                    if (startsWith != null) {
143:                                        rule.addExpression(
144:                                                STARTSWITH_ATTRIBUTE,
145:                                                startsWith);
146:                                    }
147:
148:                                    if (contains != null) {
149:                                        rule.addExpression(CONTAINS_ATTRIBUTE,
150:                                                contains);
151:                                    }
152:
153:                                    if (name != null) {
154:                                        rule.setName(name);
155:                                    }
156:
157:                                    try {
158:                                        if (priority != null) {
159:                                            rule.setPriority(Integer
160:                                                    .parseInt(priority));
161:                                        }
162:                                    } catch (NumberFormatException ex1) {
163:                                        throw new SAXException(
164:                                                "Failed to parse priority value! value="
165:                                                        + priority);
166:                                    }
167:
168:                                    currentRID.addRule(rule);
169:                                } catch (UnsupportedRuleException ure) {
170:                                    throw new SAXException(ure.getMessage());
171:                                }
172:                            } else if (qname
173:                                    .equals(AUTHORIZEDKEYSFORMAT_ELEMENT)) {
174:                                String implementationClass = attrs
175:                                        .getValue(IMPLEMENTATION_ATTRIBUTE);
176:                                String defaultPath = attrs
177:                                        .getValue(DEFAULTPATH_ATTRIBUTE);
178:
179:                                if (implementationClass == null) {
180:                                    throw new SAXException(
181:                                            IMPLEMENTATION_ATTRIBUTE
182:                                                    + " attribute is required");
183:                                }
184:
185:                                try {
186:                                    currentRID.setAuthorizedKeysFormat(Class
187:                                            .forName(implementationClass));
188:                                    currentRID
189:                                            .setAuthorizedKeysDefaultPath(defaultPath);
190:                                } catch (ClassNotFoundException ex) {
191:                                    throw new SAXException(ex.getMessage());
192:                                }
193:                            } else {
194:                                throw new SAXException("Unexpected element <"
195:                                        + qname + ">");
196:                            }
197:                        } else {
198:                            throw new SAXException("Unexpected element <"
199:                                    + qname + ">");
200:                        }
201:                    }
202:
203:                    currentElement = qname;
204:                }
205:
206:                public void endElement(String uri, String localName,
207:                        String qname) throws SAXException {
208:                    if (currentElement != null) {
209:                        if (!currentElement.equals(qname)) {
210:                            throw new SAXException(
211:                                    "Unexpected end element found <" + qname
212:                                            + ">");
213:                        }
214:
215:                        if (currentElement.equals(REMOTEID_ELEMENT)) {
216:                            if (currentRID.getRules().size() > 0) {
217:                                remoteIdentifications.put(currentRID
218:                                        .getDefaultName(), currentRID);
219:                            } else {
220:                                throw new SAXException("<" + REMOTEID_ELEMENT
221:                                        + "> "
222:                                        + " requires at least one child <"
223:                                        + RULE_ELEMENT + "> element!");
224:                            }
225:
226:                            currentElement = AUTOMATION_ELEMENT;
227:                        } else if (currentElement.equals(RULE_ELEMENT)) {
228:                            currentElement = REMOTEID_ELEMENT;
229:                        } else if (currentElement
230:                                .equals(AUTHORIZEDKEYSFORMAT_ELEMENT)) {
231:                            currentElement = REMOTEID_ELEMENT;
232:                        } else if (currentElement.equals(AUTOMATION_ELEMENT)) {
233:                            currentElement = null;
234:                        } else {
235:                            throw new SAXException("Unexpected end element <"
236:                                    + qname + ">");
237:                        }
238:                    }
239:                }
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.