001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.metadata;
027:
028: import java.util.Iterator;
029: import java.util.Map;
030:
031: /**
032: * Represents the root of the Speedo meta information. This root contains the map
033: * of SpeedoXMLDescriptor meta object.
034: *
035: * @author S.Chassande-Barrioz
036: */
037: public class SpeedoMetaInfo {
038:
039: /**
040: * This fields is used by Speedo to reference the SpeedoXMLDescriptor.
041: * It is completed by the JDOParser or by the EJBParser.
042: * key = XML descriptor File Name
043: * value = SpeedoXMLDescriptor
044: */
045: public Map xmlDescriptors = null;
046:
047: /**
048: * Found into all XMLDescriptor the first a Speedo meta object
049: * corresponding to a class name.
050: * @param className is a name of a persistent class
051: * @return a SpeedoClass instance if found, otherwise null.
052: */
053: public SpeedoClass getSpeedoClass(String className) {
054: return getSpeedoClass(className, (SpeedoXMLDescriptor) null);
055: }
056:
057: /**
058: * Found into all XMLDescriptor the first a Speedo meta object
059: * corresponding to a class name.
060: * @param className is a name of a persistent class
061: * @param xml is the xmldescriptor which could contain the SpeedoClass
062: * @return a SpeedoClass instance if found, otherwise null.
063: */
064: public SpeedoClass getSpeedoClass(String className,
065: SpeedoXMLDescriptor xml) {
066: //System.out.println("SMI.getSpeedoClass(" + className + ", " + xml.xmlFile + "): ");
067: SpeedoClass sc = null;
068: if (xml != null) {
069: sc = xml.getSpeedoClass(className, false);
070: if (sc != null) {
071: //System.out.println("SMI.getSpeedoClass(XML): return " + sc);
072: return sc;
073: }
074: }
075: //Try in other xml
076: for (Iterator it = xmlDescriptors.values().iterator(); it
077: .hasNext()
078: && sc == null;) {
079: SpeedoXMLDescriptor _xml = (SpeedoXMLDescriptor) it.next();
080: if (xml == _xml) {
081: continue;
082: }
083: sc = _xml.getSpeedoClass(className, false);
084: }
085: //System.out.println("SMI.getSpeedoClass(): return " + sc);
086: return sc;
087: }
088:
089: /**
090: * Found into all XMLDescriptor the first a Speedo meta object
091: * corresponding to a class name.
092: * @param className is a name of a persistent class
093: * @param sp is the package which could contain the SpeedoClass
094: * @return a SpeedoClass instance if found, otherwise null.
095: */
096: public SpeedoClass getSpeedoClass(String className, SpeedoPackage sp) {
097: //System.out.println("SMI.getSpeedoClass(" + className + ", " + sp.name + "): ");
098: SpeedoXMLDescriptor xml = null;
099: if (sp != null) {
100: xml = sp.xmlDescriptor;
101: }
102: SpeedoClass sc = getSpeedoClass(className, xml);
103: if (sc == null) {
104: sc = getSpeedoClass(sp.name + '.' + className, xml);
105: }
106: //System.out.println("SMI.getSpeedoClass(P): return " + sc);
107: return sc;
108: }
109:
110: }
|