All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.efaps.jms.JmsResourceConfig Maven / Gradle / Ivy

Go to download

eFaps is a framework used to map objects with or without attached files to a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface. The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.

There is a newer version: 3.2.0
Show newest version
/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev: 7740 $
 * Last Changed:    $Date: 2012-07-03 18:40:05 -0500 (Tue, 03 Jul 2012) $
 * Last Changed By: $Author: [email protected] $
 */

package org.efaps.jms;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.efaps.admin.program.esjp.EFapsClassLoader;
import org.efaps.rest.EFapsResourceConfig;
import org.efaps.util.EFapsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.jersey.core.spi.scanning.Scanner;
import com.sun.jersey.spi.scanning.AnnotationScannerListener;

/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id: JmsResourceConfig.java 7740 2012-07-03 23:40:05Z [email protected] $
 */
public class JmsResourceConfig
{
    /**
     * Singleton instance.
     */
    private static JmsResourceConfig CONFIG = new JmsResourceConfig();

    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(JmsResourceConfig.class);

    /**
     * Classes found by the scanner.
     */
    private final Set> classes = new LinkedHashSet>();

    /**
     * Constructor.
     */
    private JmsResourceConfig()
    {
        // Singelton
    }

    /**
     * Getter method for the instance variable {@link #classes}.
     *
     * @return value of instance variable {@link #classes}
     */
    public Set> getClasses()
    {
        return this.classes;
    }

    /**
     * Initialize and scan for root resource and provider classes using a scanner.
     *
     * @throws EFapsException on error
     */
    protected void init()
        throws EFapsException
    {
        @SuppressWarnings("unchecked")
        final AnnotationScannerListener asl = new AnnotationScannerListener(
                            EFapsClassLoader.getInstance(),
                            XmlAccessorType.class,
                            XmlType.class,
                            XmlElementWrapper.class,
                            XmlElementRef.class,
                            XmlRootElement.class,
                            XmlAttribute.class);
        try {
            final Scanner scanner = EFapsResourceConfig.EfapsResourceScanner.class.newInstance();
            scanner.scan(asl);
        } catch (final InstantiationException e) {
            throw new EFapsException("InstantiationException", e);
        } catch (final IllegalAccessException e) {
            throw new EFapsException("IllegalAccessException", e);
        }
        this.classes.clear();
        this.classes.addAll(asl.getAnnotatedClasses());

        if (JmsResourceConfig.LOG.isInfoEnabled() && !getClasses().isEmpty()) {
            logClasses("Jms classes found:", getClasses());
        }
    }

    /**
     * @param _text text to log
     * @param _classes classes to log
     */
    private void logClasses(final String _text,
                            final Set> _classes)
    {
        final StringBuilder b = new StringBuilder();
        b.append(_text);
        for (final Class c : _classes) {
            b.append('\n').append("  ").append(c);
        }
        JmsResourceConfig.LOG.info(b.toString());
    }

    /**
     * @return the singleton JmsResourceConfig instance
     */
    public static JmsResourceConfig getResourceConfig()
    {
        return JmsResourceConfig.CONFIG;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy