001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xml.multispaced;
023:
024: import org.jboss.xb.binding.ObjectModelFactory;
025: import org.jboss.xb.binding.UnmarshallingContext;
026: import org.jboss.test.xml.multispaced.pm.jdbc.JDBCPm;
027: import org.xml.sax.Attributes;
028:
029: /**
030: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
031: * @version <tt>$Revision: 57211 $</tt>
032: */
033: public class XMBeanMetaDataFactory implements ObjectModelFactory {
034: public static final XMBeanMetaDataFactory INSTANCE = new XMBeanMetaDataFactory();
035:
036: private XMBeanMetaDataFactory() {
037: }
038:
039: public Object newRoot(Object root, UnmarshallingContext navigator,
040: String namespaceURI, String localName, Attributes attrs) {
041: return root == null ? new XMBeanMetaData() : root;
042: }
043:
044: public Object completeRoot(Object root, UnmarshallingContext ctx,
045: String uri, String name) {
046: return root;
047: }
048:
049: public void setValue(XMBeanMetaData xmbean,
050: UnmarshallingContext navigator, String namespaceUri,
051: String localName, String value) {
052: if ("description".equals(localName)) {
053: xmbean.setDescription(value);
054: } else if ("class".equals(localName)) {
055: xmbean.setMbeanClass(value);
056: }
057: }
058:
059: public Object newChild(XMBeanMetaData xmbean,
060: UnmarshallingContext navigator, String namespaceUri,
061: String localName, Attributes attrs) {
062: Object child;
063: if ("constructor".equals(localName)) {
064: child = new XMBeanConstructorMetaData();
065: } else if ("attribute".equals(localName)) {
066: final XMBeanAttributeMetaData attribute = new XMBeanAttributeMetaData();
067: for (int i = 0; i < attrs.getLength(); ++i) {
068: final String attrName = attrs.getLocalName(i);
069: if ("access".equals(attrName)) {
070: attribute.setAccess(attrs.getValue(i));
071: } else if ("getMethod".equals(attrName)) {
072: attribute.setGetMethod(attrs.getValue(i));
073: } else if ("setMethod".equals(attrName)) {
074: attribute.setSetMethod(attrs.getValue(i));
075: }
076: }
077: child = attribute;
078: } else if ("operation".equals(localName)) {
079: child = new XMBeanOperationMetaData();
080: } else if ("notification".equals(localName)) {
081: child = new XMBeanNotificationMetaData();
082: } else {
083: child = null;
084: }
085:
086: return child;
087: }
088:
089: public void addChild(XMBeanMetaData xmbean,
090: XMBeanConstructorMetaData constructor,
091: UnmarshallingContext navigator, String namespaceURI,
092: String localName) {
093: xmbean.addConstructor(constructor);
094: }
095:
096: public void addChild(XMBeanMetaData xmbean,
097: XMBeanAttributeMetaData attribute,
098: UnmarshallingContext navigator, String namespaceURI,
099: String localName) {
100: xmbean.addAttribute(attribute);
101: }
102:
103: public void addChild(XMBeanMetaData xmbean,
104: XMBeanOperationMetaData operation,
105: UnmarshallingContext navigator, String namespaceURI,
106: String localName) {
107: xmbean.addOperation(operation);
108: }
109:
110: public void addChild(XMBeanMetaData xmbean,
111: XMBeanNotificationMetaData notification,
112: UnmarshallingContext navigator, String namespaceURI,
113: String localName) {
114: xmbean.addNotification(notification);
115: }
116:
117: public void addChild(XMBeanMetaData xmbean, Object pm,
118: UnmarshallingContext navigator, String namespaceURI,
119: String localName) {
120: xmbean.setPersistenceManager(pm);
121: }
122:
123: public void setValue(XMBeanConstructorMetaData constructor,
124: UnmarshallingContext navigator, String namespaceUri,
125: String localName, String value) {
126: if ("description".equals(localName)) {
127: constructor.setDescription(value);
128: } else if ("name".equals(localName)) {
129: constructor.setName(value);
130: }
131: }
132:
133: public void setValue(XMBeanAttributeMetaData attribute,
134: UnmarshallingContext navigator, String namespaceUri,
135: String localName, String value) {
136: if ("description".equals(localName)) {
137: attribute.setDescription(value);
138: } else if ("name".equals(localName)) {
139: attribute.setName(value);
140: } else if ("type".equals(localName)) {
141: attribute.setType(value);
142: }
143: }
144:
145: public void setValue(XMBeanOperationMetaData operation,
146: UnmarshallingContext navigator, String namespaceUri,
147: String localName, String value) {
148: if ("description".equals(localName)) {
149: operation.setDescription(value);
150: } else if ("name".equals(localName)) {
151: operation.setName(value);
152: } else if ("return-type".equals(localName)) {
153: operation.setReturnType(value);
154: }
155: }
156:
157: public void setValue(XMBeanNotificationMetaData notification,
158: UnmarshallingContext navigator, String namespaceUri,
159: String localName, String value) {
160: if ("description".equals(localName)) {
161: notification.setDescription(value);
162: } else if ("name".equals(localName)) {
163: notification.setName(value);
164: } else if ("notification-type".equals(localName)) {
165: notification.setNotificationType(value);
166: }
167: }
168: }
|