KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > binding > ImportJXPathBindingBuilder


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.binding;
17
18 import org.apache.cocoon.forms.binding.JXPathBindingManager.Assistant;
19 import org.apache.cocoon.forms.binding.library.Library;
20 import org.apache.cocoon.forms.binding.library.LibraryException;
21 import org.apache.cocoon.forms.util.DomHelper;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * Handles binding library imports
26  *
27  * @version $Id: ImportJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
28  */

29 public class ImportJXPathBindingBuilder extends JXPathBindingBuilderBase {
30
31     /* (non-Javadoc)
32      * @see org.apache.cocoon.forms.binding.JXPathBindingBuilderBase#buildBinding(org.w3c.dom.Element, org.apache.cocoon.forms.binding.JXPathBindingManager.Assistant)
33      */

34     public JXPathBindingBase buildBinding(Element JavaDoc bindingElm,
35             Assistant assistant) throws BindingException {
36
37         Library lib = assistant.getContext().getLocalLibrary();
38         
39         String JavaDoc prefix = DomHelper.getAttribute(bindingElm, "prefix", null);
40         String JavaDoc uri = DomHelper.getAttribute(bindingElm, "uri", null);
41         
42         if(prefix==null || uri==null)
43             throw new BindingException("Import needs to specify both @uri and @prefix! (at "+DomHelper.getLocation(bindingElm)+")");
44         
45         try {
46             lib.includeAs(prefix,uri);
47         } catch(LibraryException e) {
48             throw new BindingException("Could not import library !(at "+DomHelper.getLocation(bindingElm)+")",e);
49         }
50         
51         return new ImportJXPathBinding();
52     }
53
54 }
55
Popular Tags