KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > metamodel > JBossClientDDObjectFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.metamodel;
23
24 import java.io.IOException JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import org.jboss.logging.Logger;
28 import org.jboss.metamodel.descriptor.DDObjectFactory;
29 import org.jboss.metamodel.descriptor.EjbRef;
30 import org.jboss.metamodel.descriptor.MessageDestinationRef;
31 import org.jboss.metamodel.descriptor.ResourceEnvRef;
32 import org.jboss.metamodel.descriptor.ResourceRef;
33 import org.jboss.metamodel.descriptor.ServiceRef;
34 import org.jboss.util.xml.JBossEntityResolver;
35 import org.jboss.xb.binding.JBossXBException;
36 import org.jboss.xb.binding.Unmarshaller;
37 import org.jboss.xb.binding.UnmarshallerFactory;
38 import org.jboss.xb.binding.UnmarshallingContext;
39 import org.xml.sax.Attributes JavaDoc;
40
41 /**
42  * A JBossXB object factory for parsing JBoss application client descriptor files.
43  *
44  * http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd
45  *
46  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
47  * @version $Revision: $
48  */

49 public class JBossClientDDObjectFactory extends DDObjectFactory
50 {
51    private static final Logger log = Logger.getLogger(JBossClientDDObjectFactory.class);
52    
53    private ApplicationClientDD dd;
54    
55    public static ApplicationClientDD parse(URL JavaDoc ddResource, ApplicationClientDD dd)
56       throws JBossXBException, IOException JavaDoc
57    {
58       // TODO: how to properly fix this
59
if(dd == null)
60          dd = new ApplicationClientDD();
61       
62       if(ddResource == null)
63          return dd;
64       
65       log.debug("found jboss-client.xml " + ddResource);
66       
67       JBossClientDDObjectFactory factory = new JBossClientDDObjectFactory(dd);
68       UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
69       unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, Boolean.TRUE);
70       Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
71       JBossEntityResolver entityResolver = new JBossEntityResolver();
72       unmarshaller.setEntityResolver(entityResolver);
73
74       dd = (ApplicationClientDD) unmarshaller.unmarshal(ddResource.openStream(), factory, null);
75       
76       return dd;
77    }
78    
79    public JBossClientDDObjectFactory(ApplicationClientDD dd)
80    {
81       this.dd = dd;
82    }
83    
84    public void addChild(ApplicationClientDD parent, EjbRef ref, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
85    {
86       dd.updateEjbRef(ref);
87    }
88    
89    public void addChild(ApplicationClientDD parent, MessageDestinationRef ref, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
90    {
91       dd.updateMessageDestinationRef(ref);
92    }
93
94    public void addChild(ApplicationClientDD parent, ServiceRef ref, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
95    {
96       dd.addServiceRef(ref);
97    }
98
99    public void addChild(ApplicationClientDD dd, ResourceEnvRef envRef, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
100    {
101       dd.updateResourceEnvRef(envRef);
102    }
103    
104    public void addChild(ApplicationClientDD parent, ResourceRef ref, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
105    {
106       dd.updateResourceRef(ref);
107    }
108    
109    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext navigator, String JavaDoc uri, String JavaDoc name)
110    {
111       return root;
112    }
113
114    public Object JavaDoc newChild(ApplicationClientDD dd, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
115    {
116       Object JavaDoc child = null;
117       
118       child = newEnvRefGroupChild(localName);
119       if(child != null)
120          return child;
121       
122       // space for more
123

124       return child;
125    }
126    
127    public Object JavaDoc newRoot(Object JavaDoc root, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
128    {
129       return dd;
130    }
131
132    public void setValue(ApplicationClientDD dd, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
133    {
134       if(localName.equals("jndi-name"))
135          dd.setJndiName(value);
136       else if(localName.equals("depends"))
137          dd.addDependency(value);
138    }
139 }
140
Popular Tags