Package org.jpox.metadata

Examples of org.jpox.metadata.FileMetaData


     * @param resolver Entity Resolver to use (null if not available)
     */
    public JPAMetaDataHandler(MetaDataManager mgr, String filename, EntityResolver resolver)
    {
        super(mgr, filename, resolver);
        metadata = new FileMetaData(filename, mgr, null, null);
        pushStack(metadata); // Start with FileMetaData on the stack
    }
View Full Code Here


        }
        try
        {
            if (localName.equals("entity-mappings"))
            {
                FileMetaData filemd = (FileMetaData)getStack();
                filemd.setType(FileMetaData.JPA_FILE);
            }
            else if (localName.equals("description"))
            {
                // Of no practical use so ignored
            }
            else if (localName.equals("persistence-unit-metadata"))
            {
                // Nothing to do - we use subelements
            }
            else if (localName.equals("xml-mapping-metadata-complete"))
            {
                // All classes in the file are complete without any annotations
                metaDataComplete = true;
            }
            else if (localName.equals("persistence-unit-defaults"))
            {
                // Nothing to do - we use subelements
            }
            else if (localName.equals("package"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("schema"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("catalog"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("access"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("sequence-generator"))
            {
                // Sequence generator (add to the default package whether they are specified there are not)
                MetaData md = getStack();
                String initValue = getAttr(attrs, "initial-value");
                if (StringUtils.isWhitespace(initValue))
                {
                    initValue = "1"; // JPA default
                }
                String allocSize = getAttr(attrs, "allocation-size");
                if (StringUtils.isWhitespace(allocSize))
                {
                    allocSize = "50"; // JPA default
                }
                SequenceMetaData seqmd = new SequenceMetaData(md, getAttr(attrs, "name"),
                    getAttr(attrs, "sequence-name"), null, null, initValue, allocSize);
                PackageMetaData pmd = null;
                if (defaultPackageName != null)
                {
                    pmd = ((FileMetaData)metadata).getPackage(defaultPackageName);
                }
                else
                {
                    if (((FileMetaData)metadata).getNoOfPackages() > 0)
                    {
                        pmd = ((FileMetaData)metadata).getPackage(0);
                    }
                    else
                    {
                        // Add a dummy (root) package to hold our sequences since no default package name set
                        pmd = new PackageMetaData((FileMetaData)metadata, "", null, null);
                        ((FileMetaData)metadata).addPackage(pmd);
                    }
                }
                pmd.addSequence(seqmd);
            }
            else if (localName.equals("table-generator"))
            {
                // Table generator (add to the default package whether they are specified there or not)
                MetaData md = getStack();
                TableGeneratorMetaData tgmd = new TableGeneratorMetaData(md, getAttr(attrs, "name"),
                    getAttr(attrs, "table"), getAttr(attrs, "catalog"), getAttr(attrs, "schema"), getAttr(attrs, "pk-column-name"),
                    getAttr(attrs, "value-column-name"), getAttr(attrs, "pk-column-value"), getAttr(attrs, "initial-value"),
                    getAttr(attrs, "allocation-size"));

                PackageMetaData pmd = null;
                if (defaultPackageName != null)
                {
                    pmd = ((FileMetaData)metadata).getPackage(defaultPackageName);
                }
                else
                {
                    if (((FileMetaData)metadata).getNoOfPackages() > 0)
                    {
                        pmd = ((FileMetaData)metadata).getPackage(0);
                    }
                    else
                    {
                        // Add a dummy (root) package to hold our sequences since no default package name set
                        pmd = new PackageMetaData((FileMetaData)metadata, "", null, null);
                        ((FileMetaData)metadata).addPackage(pmd);
                    }
                }
                pmd.addTableGenerator(tgmd);
            }
            else if (localName.equals("named-query"))
            {
                // Named JPQL query
                MetaData md = getStack();
                if (md instanceof FileMetaData)
                {
                    FileMetaData filemd = (FileMetaData)md;
                    QueryMetaData qmd = new QueryMetaData(filemd, null, getAttr(attrs, "name"), "javax.jdo.query.JPQL",
                        null, null, null, null, null);
                    filemd.addQuery(qmd);
                    pushStack(qmd);
                }
                else if (md instanceof ClassMetaData)
                {
                    ClassMetaData cmd = (ClassMetaData)md;
                    QueryMetaData qmd = new QueryMetaData(cmd, null, getAttr(attrs, "name"), "javax.jdo.query.JPQL",
                        null, null, null, null, null);
                    cmd.addQuery(qmd);
                    pushStack(qmd);
                }
            }
            else if (localName.equals("named-native-query"))
            {
                // Named SQL query
                MetaData md = getStack();
                if (md instanceof FileMetaData)
                {
                    FileMetaData filemd = (FileMetaData)md;
                    QueryMetaData qmd = new QueryMetaData(filemd, null, getAttr(attrs, "name"), "javax.jdo.query.SQL", null,
                        getAttr(attrs, "result-class"), getAttr(attrs, "result-set-mapping"), null, null);
                    filemd.addQuery(qmd);
                    pushStack(qmd);
                }
                else if (md instanceof ClassMetaData)
                {
                    ClassMetaData cmd = (ClassMetaData)md;
                    QueryMetaData qmd = new QueryMetaData(cmd, null, getAttr(attrs, "name"), "javax.jdo.query.SQL", null,
                        getAttr(attrs, "result-class"), getAttr(attrs, "result-set-mapping"), null, null);
                    cmd.addQuery(qmd);
                    pushStack(qmd);
                }
            }
            else if (localName.equals("sql-result-set-mapping"))
            {
                MetaData md = getStack();
                if (md instanceof FileMetaData)
                {
                    FileMetaData filemd = (FileMetaData)md;
                    QueryResultMetaData qrmd = new QueryResultMetaData(filemd, getAttr(attrs, "name"));
                    filemd.addQueryResultMetaData(qrmd);
                    pushStack(qrmd);
                }
                else if (md instanceof ClassMetaData)
                {
                    ClassMetaData cmd = (ClassMetaData)md;
                    QueryResultMetaData qrmd = new QueryResultMetaData(cmd, getAttr(attrs, "name"));
                    cmd.addQueryResultMetaData(qrmd);
                    pushStack(qrmd);
                }
            }
            else if (localName.equals("entity-result"))
            {
                // Add an entity (persistent class) mapping
                QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
                queryResultEntityName = getAttr(attrs, "entity-class"); // Save this for any field-result that arrives
                qrmd.addPersistentTypeMapping(queryResultEntityName,
                    null, // No field-column mappings info at this point
                    getAttr(attrs, "discriminator-column"));
            }
            else if (localName.equals("field-result"))
            {
                // Add a field-column mapping for the entity (persistent class)
                QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
                qrmd.addMappingForPersistentTypeMapping(queryResultEntityName,
                    getAttr(attrs, "name"), getAttr(attrs, "column"));
            }
            else if (localName.equals("column-result"))
            {
                // Add a scalar column mapping
                QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
                qrmd.addScalarColumn(getAttr(attrs, "name"));
            }
            else if (localName.equals("mapped-superclass"))
            {
                // New entity for this package
                FileMetaData filemd = (FileMetaData)getStack();
                String className = getAttr(attrs, "class");
                String packageName = null;
                if (className.indexOf('.') > 0)
                {
                    // Fully-qualified so use package name from class
                    packageName = className.substring(0, className.lastIndexOf('.'));
                }
                PackageMetaData pmd = null;
                if (packageName != null)
                {
                    pmd = filemd.getPackage(packageName);
                }
                if (pmd == null)
                {
                    if (packageName != null)
                    {
                        // Class fully qualified so add its package
                        pmd = new PackageMetaData(filemd, packageName, null, null);
                    }
                    else if (defaultPackageName != null)
                    {
                        // Use default package for entity-mappings
                        pmd = filemd.getPackage(defaultPackageName);
                    }
                    else
                    {
                        // Add root package
                        pmd = new PackageMetaData(filemd, "", null, null);
                    }
                }

                ClassMetaData cmd = newClassObject(pmd, attrs, false);
                pmd.addClass(cmd);

                // Set to use "subclass-table" since all subclasses inherit these fields
                cmd.setInheritanceMetaData(new InheritanceMetaData(cmd, InheritanceStrategy.SUBCLASS_TABLE.toString()));

                pushStack(cmd);
            }
            else if (localName.equals("query"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("entity"))
            {
                // New entity for this package
                FileMetaData filemd = (FileMetaData)getStack();
                String className = getAttr(attrs, "class");
                String packageName = null;
                if (className.indexOf('.') > 0)
                {
                    // Fully-qualified so use package name from class
                    packageName = className.substring(0, className.lastIndexOf('.'));
                }
                PackageMetaData pmd = null;
                if (packageName != null)
                {
                    pmd = filemd.getPackage(packageName);
                }
                if (pmd == null)
                {
                    if (packageName != null)
                    {
                        // Class fully qualified so add its package
                        pmd = new PackageMetaData(filemd, packageName, null, null);
                    }
                    else if (defaultPackageName != null)
                    {
                        // Use default package for entity-mappings
                        pmd = filemd.getPackage(defaultPackageName);
                    }
                    else
                    {
                        // Add root package
                        pmd = new PackageMetaData(filemd, "", null, null);
                    }
                }

                ClassMetaData cmd = newClassObject(pmd, attrs, false);
                pmd.addClass(cmd);

                pushStack(cmd);
            }
            else if (localName.equals("embeddable"))
            {
                // New embedded-only entity for this package
                FileMetaData filemd = (FileMetaData)getStack();
                String className = getAttr(attrs, "class");
                String packageName = null;
                if (className.indexOf('.') > 0)
                {
                    // Fully-qualified so use package name from class
                    packageName = className.substring(0, className.lastIndexOf('.'));
                }
                PackageMetaData pmd = null;
                if (packageName != null)
                {
                    pmd = filemd.getPackage(packageName);
                }
                if (pmd == null)
                {
                    if (packageName != null)
                    {
                        // Class fully qualified so add its package
                        pmd = new PackageMetaData(filemd, packageName, null, null);
                    }
                    else if (defaultPackageName != null)
                    {
                        // Use default package for entity-mappings
                        pmd = filemd.getPackage(defaultPackageName);
                    }
                    else
                    {
                        // Add root package
                        pmd = new PackageMetaData(filemd, "", null, null);
View Full Code Here

            else if (localName.equals("package"))
            {
                if (md instanceof FileMetaData)
                {
                    // Add the default package
                    FileMetaData filemd = (FileMetaData)md;
                    filemd.addPackage(new PackageMetaData(filemd, currentString, null, null));
                    defaultPackageName = currentString;
                }
            }
            else if (localName.equals("discriminator-value"))
            {
View Full Code Here

        {
            return acmd;
        }

        // No MetaData so check for annotations
        FileMetaData annFilemd = loadAnnotationsForClass(c, clr, true, true);
        if (annFilemd != null)
        {
            // No MetaData but annotations present so use that
            return annFilemd.getPackage(0).getClass(0);
        }

        // Not found, so add to known classes/interfaces without MetaData
        if (JPOXLogger.METADATA.isDebugEnabled())
        {
View Full Code Here

            {
                JPOXLogger.METADATA.info(LOCALISER.msg("MetaData.Annotations.ClassUsingAnnotations", cls.getName(), "JPA"));
                if (pmd == null)
                {
                    // No owning package defined so add one
                    FileMetaData filemd = new FileMetaData("annotations", null, null, null);
                    filemd.setType(FileMetaData.ANNOTATIONS);
                    pmd = new PackageMetaData(filemd, cls.getPackage().getName(), null, null);
                    filemd.addPackage(pmd);
                }
                boolean superClassPC = isClassPersistenceCapable(cls.getSuperclass());
                cmd = mgr.getMetaDataFactory().newClassObject(pmd, ClassUtils.getClassNameForClass(cls), identityType, idClassName,
                    requiresExtent, detachable, embeddedOnly, persistenceModifier,
                    superClassPC ? cls.getSuperclass().getName() : null, catalog, schema, table, entityName);
View Full Code Here

        {
            return the_md;
        }

        // No loaded MetaData so search valid location for a file for this class and load all in the process
        FileMetaData filemd = loadMetaDataForClass(c, clr, null, getJDOFileSuffix(), true);
        if (filemd != null)
        {
            // Class has had its metadata loaded
            utilisedFileMetaData.add(filemd);

            // If not MetaData complete will also merge in annotations at populate stage

            // Retrieve the MetaData for the requested class
            the_md = (AbstractClassMetaData)classMetaDataByClass.get(className);

            return the_md;
        }

        // No MetaData so check for annotations
        FileMetaData annFilemd = loadAnnotationsForClass(c, clr, true, true);
        if (annFilemd != null)
        {
            // No MetaData but annotations present so use that
            if (c.isInterface())
            {
                return annFilemd.getPackage(0).getInterface(0);
            }
            else
            {
                return annFilemd.getPackage(0).getClass(0);
            }
        }

        // Not found, so add to known classes/interfaces without MetaData
        if (JPOXLogger.METADATA.isDebugEnabled())
View Full Code Here

                {
                    URL fileURL = (URL) resources.nextElement();
                    if (fileMetaDataByURLString.get(fileURL.toString()) == null)
                    {
                        // File hasn't been loaded so load it
                        FileMetaData filemd = parseFile(fileURL);
                        filemd.setType(FileMetaData.JDOQUERY_FILE); // TODO Remove this since set in the parser at <jdoquery>
                        registerFile(fileURL.toString(), filemd, clr);

                        // Populate all classes in this file we've just parsed
                        // TODO Populate the classes found in this file
                    }
                }
                cmd = getMetaDataForClass(cls, clr);

                qmd = (QueryMetaData)queryMetaDataByName.get(query_key);
                if (qmd != null)
                {
                    if (JPOXLogger.METADATA.isDebugEnabled())
                    {
                        JPOXLogger.METADATA.debug(LOCALISER.msg("044053",query_key,location));
                    }
                    return qmd;
                }
                if (JPOXLogger.METADATA.isDebugEnabled())
                {
                    JPOXLogger.METADATA.debug(LOCALISER.msg("044050",query_key,location));
                }
            }
            return null;
        }

        // Query isn't scoped to a candidate class, so search the valid package-independent locations
        List locations = new ArrayList();
        locations.addAll(getValidMetaDataLocationsForItem(getJDOFileSuffix(), null, null, false));
        locations.addAll(getValidMetaDataLocationsForItem(getORMFileSuffix(), getORMMappingName(), null, false));
        locations.addAll(getValidMetaDataLocationsForItem(getJDOQueryFileSuffix(), null, null, false));

        for (int i=0; i<locations.size(); i++)
        {
            String location = (String) locations.get(i);
            // Process all resources for this location
            Enumeration resources;
            try
            {
                resources = clr.getResources(location, cls != null ? cls.getClassLoader() : null);
            }
            catch (IOException e)
            {
                throw new JPOXException("Error loading resources", e).setFatal();
            }
            while (resources.hasMoreElements())
            {
                URL fileURL = (URL) resources.nextElement();
                if (fileMetaDataByURLString.get(fileURL.toString()) == null)
                {
                    // File hasn't been loaded so load it
                    FileMetaData filemd = parseFile(fileURL);
                    registerFile(fileURL.toString(), filemd, clr);

                    // Populate all classes in this file we've just parsed
                    // TODO Populate the classes found in this file
                }
View Full Code Here

            {
                URL fileURL = (URL) resources.nextElement();
                if (fileMetaDataByURLString.get(fileURL.toString()) == null)
                {
                    // File hasn't been loaded so load it
                    FileMetaData filemd = parseFile(fileURL);
                    registerFile(fileURL.toString(), filemd, clr);

                    // Populate all classes in this file we've just parsed
                    // TODO Populate the classes found in this file
                }
View Full Code Here

            return;
        }

        // No ORM loaded for this class, so find if there is any ORM metadata available
        FileMetaData filemdORM = loadMetaDataForClass(c, clr, getORMMappingName(), getORMFileSuffix(), false);
        if (filemdORM != null)
        {
            // The ORM file has now been registered, so find the class and merge it into the JDO definition
            ormCmd = (AbstractClassMetaData)ormClassMetaDataByClass.get(c.getName());
            if (ormCmd != null)
View Full Code Here

            {
                URL url = (URL) resources.nextElement();
                if (url != null)
                {
                    // File exists (valid URL), so check if we already have this file registered
                    FileMetaData filemd = (FileMetaData)fileMetaDataByURLString.get(url.toString());
                    if (filemd == null)
                    {
                        // Not registered so load the file from the URL
                        filemd = parseFile(url);
                        registerFile(url.toString(), filemd, clr);

                        if (populate)
                        {
                            // Populate all classes in this file we've just parsed
                            populateFileMetaData(filemd, clr, pc_class.getClassLoader());
                        }
                    }

                    if ((filemd.getType() == FileMetaData.JDO_FILE && classMetaDataByClass.get(pc_class.getName()) != null) ||
                        (filemd.getType() == FileMetaData.ORM_FILE && ormClassMetaDataByClass.get(pc_class.getName()) != null))
                    {
                        // We now have the class, so it must have been in this file
                        if (JPOXLogger.METADATA.isDebugEnabled())
                        {
                            JPOXLogger.METADATA.debug(LOCALISER.msg("044052", metadata_file_extension, pc_class.getName(), url));
View Full Code Here

TOP

Related Classes of org.jpox.metadata.FileMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.