001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.jaxb;
031:
032: import java.lang.reflect.*;
033: import java.util.*;
034: import javax.xml.bind.*;
035: import javax.xml.bind.annotation.*;
036: import javax.xml.namespace.QName;
037: import com.caucho.jaxb.skeleton.*;
038:
039: public class ObjectFactorySkeleton {
040: private JAXBContextImpl _context;
041: private Object _objectFactory;
042: //private HashMap<QName,Skeleton> _roots = new HashMap<QName,Skeleton>();
043: private HashMap<QName, Method> _roots = new HashMap<QName, Method>();
044: private HashMap<Class, ClassSkeleton> _classSkeletons = new HashMap<Class, ClassSkeleton>();
045:
046: public ObjectFactorySkeleton(JAXBContextImpl context,
047: Class objectFactoryClass) throws JAXBException {
048: _context = context;
049:
050: try {
051: _objectFactory = objectFactoryClass.newInstance();
052: } catch (Exception e) {
053: throw new JAXBException(e);
054: }
055:
056: String namespace = null;
057: Package pkg = objectFactoryClass.getPackage();
058:
059: if (pkg.isAnnotationPresent(XmlSchema.class)) {
060: XmlSchema schema = (XmlSchema) pkg
061: .getAnnotation(XmlSchema.class);
062:
063: if (!"".equals(schema.namespace()))
064: namespace = schema.namespace();
065: }
066:
067: Method[] methods = objectFactoryClass.getMethods();
068:
069: for (Method method : methods) {
070: if (method.getName().startsWith("create")) {
071: XmlElementDecl decl = method
072: .getAnnotation(XmlElementDecl.class);
073: Class cl = method.getReturnType();
074:
075: if (cl.equals(JAXBElement.class)) {
076: ParameterizedType type = (ParameterizedType) method
077: .getGenericReturnType();
078: cl = (Class) type.getActualTypeArguments()[0];
079: }
080:
081: if (decl != null) {
082: String localName = decl.name();
083:
084: if (!"##default".equals(decl.namespace()))
085: namespace = decl.namespace();
086:
087: QName root = null;
088:
089: if (namespace == null)
090: root = new QName(localName);
091: else
092: root = new QName(localName, namespace);
093:
094: _roots.put(root, method);
095: } else {
096: if (!_context.hasSkeleton(cl)) {
097: ClassSkeleton skeleton = new ClassSkeleton(
098: _context, cl);
099:
100: _classSkeletons.put(cl, skeleton);
101: }
102: }
103: } else if (method.getName().equals("newInstance")) {
104: // XXX
105: } else if (method.getName().equals("getProperty")) {
106: // XXX
107: } else if (method.getName().equals("setProperty")) {
108: // XXX
109: }
110: }
111: }
112: }
|