Source Code Cross Referenced for JAXPExtensionsProvider.java in  » XML » xalan » org » apache » xpath » jaxp » 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 » XML » xalan » org.apache.xpath.jaxp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation.
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:
017:        // $Id: JAXPExtensionsProvider.java,v 1.1 2005/05/17 17:24:26 mkwan Exp $
018:        package org.apache.xpath.jaxp;
019:
020:        import javax.xml.transform.TransformerException;
021:        import javax.xml.xpath.XPathFunctionResolver;
022:        import javax.xml.xpath.XPathFunction;
023:        import javax.xml.xpath.XPathFunctionException;
024:
025:        import org.apache.xpath.ExtensionsProvider;
026:        import org.apache.xpath.XPathContext;
027:        import org.apache.xpath.objects.XObject;
028:        import org.apache.xpath.objects.XNodeSet;
029:        import org.apache.xpath.res.XPATHErrorResources;
030:        import org.apache.xalan.res.XSLMessages;
031:
032:        import org.apache.xpath.functions.FuncExtFunction;
033:        import java.util.Vector;
034:        import java.util.ArrayList;
035:        import javax.xml.namespace.QName;
036:
037:        /**
038:         * 
039:         * @author Ramesh Mandava ( ramesh.mandava@sun.com )
040:         */
041:        public class JAXPExtensionsProvider implements  ExtensionsProvider {
042:
043:            private final XPathFunctionResolver resolver;
044:            private boolean extensionInvocationDisabled = false;
045:
046:            public JAXPExtensionsProvider(XPathFunctionResolver resolver) {
047:                this .resolver = resolver;
048:                this .extensionInvocationDisabled = false;
049:            }
050:
051:            public JAXPExtensionsProvider(XPathFunctionResolver resolver,
052:                    boolean featureSecureProcessing) {
053:                this .resolver = resolver;
054:                this .extensionInvocationDisabled = featureSecureProcessing;
055:            }
056:
057:            /**
058:             * Is the extension function available?
059:             */
060:
061:            public boolean functionAvailable(String ns, String funcName)
062:                    throws javax.xml.transform.TransformerException {
063:                try {
064:                    if (funcName == null) {
065:                        String fmsg = XSLMessages.createXPATHMessage(
066:                                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
067:                                new Object[] { "Function Name" });
068:                        throw new NullPointerException(fmsg);
069:                    }
070:                    //Find the XPathFunction corresponding to namespace and funcName
071:                    javax.xml.namespace.QName myQName = new QName(ns, funcName);
072:                    javax.xml.xpath.XPathFunction xpathFunction = resolver
073:                            .resolveFunction(myQName, 0);
074:                    if (xpathFunction == null) {
075:                        return false;
076:                    }
077:                    return true;
078:                } catch (Exception e) {
079:                    return false;
080:                }
081:
082:            }
083:
084:            /**
085:             * Is the extension element available?
086:             */
087:            public boolean elementAvailable(String ns, String elemName)
088:                    throws javax.xml.transform.TransformerException {
089:                return false;
090:            }
091:
092:            /**
093:             * Execute the extension function.
094:             */
095:            public Object extFunction(String ns, String funcName,
096:                    Vector argVec, Object methodKey)
097:                    throws javax.xml.transform.TransformerException {
098:                try {
099:
100:                    if (funcName == null) {
101:                        String fmsg = XSLMessages.createXPATHMessage(
102:                                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
103:                                new Object[] { "Function Name" });
104:                        throw new NullPointerException(fmsg);
105:                    }
106:                    //Find the XPathFunction corresponding to namespace and funcName
107:                    javax.xml.namespace.QName myQName = new QName(ns, funcName);
108:
109:                    // JAXP 1.3 spec says When XMLConstants.FEATURE_SECURE_PROCESSING 
110:                    // feature is set then invocation of extension functions need to
111:                    // throw XPathFunctionException
112:                    if (extensionInvocationDisabled) {
113:                        String fmsg = XSLMessages
114:                                .createXPATHMessage(
115:                                        XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
116:                                        new Object[] { myQName.toString() });
117:                        throw new XPathFunctionException(fmsg);
118:                    }
119:
120:                    // Assuming user is passing all the needed parameters ( including
121:                    // default values )
122:                    int arity = argVec.size();
123:
124:                    javax.xml.xpath.XPathFunction xpathFunction = resolver
125:                            .resolveFunction(myQName, arity);
126:
127:                    // not using methodKey
128:                    ArrayList argList = new ArrayList(arity);
129:                    for (int i = 0; i < arity; i++) {
130:                        Object argument = argVec.elementAt(i);
131:                        // XNodeSet object() returns NodeVector and not NodeList
132:                        // Explicitly getting NodeList by using nodelist()
133:                        if (argument instanceof  XNodeSet) {
134:                            argList.add(i, ((XNodeSet) argument).nodelist());
135:                        } else if (argument instanceof  XObject) {
136:                            Object passedArgument = ((XObject) argument)
137:                                    .object();
138:                            argList.add(i, passedArgument);
139:                        } else {
140:                            argList.add(i, argument);
141:                        }
142:                    }
143:
144:                    return (xpathFunction.evaluate(argList));
145:                } catch (XPathFunctionException xfe) {
146:                    // If we get XPathFunctionException then we want to terminate
147:                    // further execution by throwing WrappedRuntimeException 
148:                    throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
149:                } catch (Exception e) {
150:                    throw new javax.xml.transform.TransformerException(e);
151:                }
152:
153:            }
154:
155:            /**
156:             * Execute the extension function.
157:             */
158:            public Object extFunction(FuncExtFunction extFunction, Vector argVec)
159:                    throws javax.xml.transform.TransformerException {
160:                try {
161:                    String namespace = extFunction.getNamespace();
162:                    String functionName = extFunction.getFunctionName();
163:                    int arity = extFunction.getArgCount();
164:                    javax.xml.namespace.QName myQName = new javax.xml.namespace.QName(
165:                            namespace, functionName);
166:
167:                    // JAXP 1.3 spec says  When XMLConstants.FEATURE_SECURE_PROCESSING
168:                    // feature is set then invocation of extension functions need to
169:                    // throw XPathFunctionException
170:                    if (extensionInvocationDisabled) {
171:                        String fmsg = XSLMessages
172:                                .createXPATHMessage(
173:                                        XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
174:                                        new Object[] { myQName.toString() });
175:                        throw new XPathFunctionException(fmsg);
176:                    }
177:
178:                    XPathFunction xpathFunction = resolver.resolveFunction(
179:                            myQName, arity);
180:
181:                    ArrayList argList = new ArrayList(arity);
182:                    for (int i = 0; i < arity; i++) {
183:                        Object argument = argVec.elementAt(i);
184:                        // XNodeSet object() returns NodeVector and not NodeList
185:                        // Explicitly getting NodeList by using nodelist()
186:                        if (argument instanceof  XNodeSet) {
187:                            argList.add(i, ((XNodeSet) argument).nodelist());
188:                        } else if (argument instanceof  XObject) {
189:                            Object passedArgument = ((XObject) argument)
190:                                    .object();
191:                            argList.add(i, passedArgument);
192:                        } else {
193:                            argList.add(i, argument);
194:                        }
195:                    }
196:
197:                    return (xpathFunction.evaluate(argList));
198:
199:                } catch (XPathFunctionException xfe) {
200:                    // If we get XPathFunctionException then we want to terminate 
201:                    // further execution by throwing WrappedRuntimeException
202:                    throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
203:                } catch (Exception e) {
204:                    throw new javax.xml.transform.TransformerException(e);
205:                }
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.