KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > sca > loader > JbiBindingLoader


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

17 package org.apache.servicemix.sca.loader;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import javax.xml.stream.XMLStreamException;
21 import javax.xml.stream.XMLStreamReader;
22
23 import org.apache.servicemix.sca.assembly.JbiAssemblyFactory;
24 import org.apache.servicemix.sca.assembly.JbiBinding;
25 import org.apache.servicemix.sca.assembly.impl.JbiAssemblyFactoryImpl;
26 import org.apache.tuscany.common.resource.ResourceLoader;
27 import org.apache.tuscany.core.config.ConfigurationLoadException;
28 import org.apache.tuscany.core.loader.StAXElementLoader;
29 import org.apache.tuscany.core.loader.StAXLoaderRegistry;
30 import org.apache.tuscany.core.system.annotation.Autowire;
31 import org.osoa.sca.annotations.Destroy;
32 import org.osoa.sca.annotations.Init;
33 import org.osoa.sca.annotations.Scope;
34
35 @Scope("MODULE")
36 public class JbiBindingLoader implements StAXElementLoader<JbiBinding>{
37
38     public static final QName JavaDoc BINDING_JBI = new QName JavaDoc("http://www.osoa.org/xmlns/sca/0.9", "binding.jbi");
39
40     private static final JbiAssemblyFactory jbiFactory = new JbiAssemblyFactoryImpl();
41
42     private StAXLoaderRegistry registry;
43
44     @Autowire
45     public void setRegistry(StAXLoaderRegistry registry) {
46         this.registry = registry;
47     }
48
49     @Init(eager = true)
50     public void start() {
51         registry.registerLoader(this);
52     }
53
54     @Destroy
55     public void stop() {
56         registry.unregisterLoader(this);
57     }
58
59     public QName JavaDoc getXMLType() {
60         return BINDING_JBI;
61     }
62
63     public Class JavaDoc<JbiBinding> getModelType() {
64         return JbiBinding.class;
65     }
66
67     public JbiBinding load(XMLStreamReader reader, ResourceLoader resourceLoader) throws XMLStreamException, ConfigurationLoadException {
68         JbiBinding binding = jbiFactory.createJbiBinding();
69         binding.setURI(reader.getAttributeValue(null, "uri"));
70         binding.setPortURI(reader.getAttributeValue(null, "port"));
71         return binding;
72     }
73 }
74
Popular Tags