KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > metadata > xb > DescriptorSupportContainer


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., 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
23 package org.jboss.mx.metadata.xb;
24
25 import javax.management.modelmbean.DescriptorSupport JavaDoc;
26 import javax.xml.namespace.QName JavaDoc;
27
28 import org.jboss.xb.binding.GenericValueContainer;
29 import org.jboss.logging.Logger;
30 import org.jboss.mx.modelmbean.XMBeanConstants;
31 import org.jboss.mx.interceptor.Interceptor;
32
33 /**
34  @author Scott.Stark@jboss.org
35  @version $Revision: 41742 $
36  */

37 public class DescriptorSupportContainer
38    implements GenericValueContainer
39 {
40    private static final Logger log = Logger.getLogger(DescriptorSupportContainer.class);
41    DescriptorSupport JavaDoc support = new DescriptorSupport JavaDoc();
42
43    public Object JavaDoc instantiate()
44    {
45       return support;
46    }
47
48    public void addChild(QName JavaDoc name, Object JavaDoc value)
49    {
50       log.debug("addChild, " + name + "," + value);
51       String JavaDoc localName = name.getLocalPart();
52       if("name".equals(localName))
53       {
54          support.setField(XMBeanConstants.NAME, value);
55       }
56       else if (name.equals("persistence"))
57       {
58          PersistPolicy policy = (PersistPolicy) value;
59          String JavaDoc persistPolicy = policy.getPersistPolicy();
60          String JavaDoc persistPeriod = policy.getPersistPeriod();
61          String JavaDoc persistLocation = policy.getPersistLocation();
62          String JavaDoc persistName = policy.getPersistName();
63          if (persistPolicy != null)
64          {
65             //validate(persistPolicy, PERSIST_POLICIES);
66
support.setField(XMBeanConstants.PERSIST_POLICY, persistPolicy);
67          }
68          if (persistPeriod != null)
69          {
70             support.setField(XMBeanConstants.PERSIST_PERIOD, persistPeriod);
71          }
72          if (persistLocation != null)
73          {
74             support.setField(XMBeanConstants.PERSIST_LOCATION, persistLocation);
75          }
76          if (persistName != null)
77          {
78             support.setField(XMBeanConstants.PERSIST_NAME, persistName);
79          }
80       }
81       else if (name.equals(XMBeanConstants.CURRENCY_TIME_LIMIT))
82       {
83          support.setField(XMBeanConstants.CURRENCY_TIME_LIMIT, value);
84       }
85       else if (name.equals(XMBeanConstants.DEFAULT))
86       {
87          support.setField(XMBeanConstants.DEFAULT, value);
88       }
89       else if (name.equals("display-name"))
90       {
91          support.setField(XMBeanConstants.DISPLAY_NAME, value);
92       }
93       else if (name.equals(XMBeanConstants.CACHED_VALUE))
94       {
95          support.setField(XMBeanConstants.CACHED_VALUE, value);
96       }
97       else if (name.equals(XMBeanConstants.PERSISTENCE_MANAGER))
98       {
99          support.setField(XMBeanConstants.PERSISTENCE_MANAGER, value);
100       }
101       else if (name.equals(XMBeanConstants.DESCRIPTOR))
102       {
103          Holder desc = (Holder) value;
104          support.setField(desc.getName(), desc.getValue());
105       }
106       else if (name.equals("injection"))
107       {
108          Holder desc = (Holder) value;
109          support.setField(desc.getName(), desc.getValue());
110       }
111       else if("interceptors".equals(localName))
112       {
113          InterceptorsHolder holder = (InterceptorsHolder) value;
114          /* The value = Interceptor[] which is not compatible with the
115          XMBean1.2 and earlier Descriptor[] format which only contained the
116          info to create Interceptors, not the actual objects.
117          */

118          Interceptor[] ivalue = holder.getInterceptors();
119          support.setField(XMBeanConstants.INTERCEPTORS, ivalue);
120       }
121    }
122
123    public Class JavaDoc getTargetClass()
124    {
125       return DescriptorSupport JavaDoc.class;
126    }
127
128 }
129
Popular Tags