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

org.apache.openejb.jee.oejb3.OpenejbJar Maven / Gradle / Ivy

There is a newer version: 10.0.0-M3
Show newest version
/**
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

package org.apache.openejb.jee.oejb3;

import org.apache.openejb.jee.NamedModule;
import org.apache.openejb.jee.StatelessBean;
import org.apache.openejb.jee.EnterpriseBean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Properties;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"moduleName", "properties", "ejbDeployment", "pojoDeployment"})
@XmlRootElement(name = "openejb-jar")
public class OpenejbJar implements NamedModule {
    @XmlElement(name = "properties")
    @XmlJavaTypeAdapter(PropertiesAdapter.class)
    protected Properties properties;

    @XmlElement(name = "module-name")
    protected String moduleName;

    @XmlElement(name = "ejb-deployment", required = true)
    protected List ejbDeployment;

    @XmlElement(name = "pojo-deployment")
    protected List pojoDeployment;

    public List getEjbDeployment() {
        if (ejbDeployment == null) {
            ejbDeployment = new ArrayList();
        }
        return this.ejbDeployment;
    }

    public List getPojoDeployment() {
        if (pojoDeployment == null) {
            pojoDeployment = new ArrayList();
        }
        return pojoDeployment;
    }

    public Map getDeploymentsById() {
        final Map map = new LinkedHashMap();
        for (final EjbDeployment deployment : getEjbDeployment()) {
            map.put(deployment.getDeploymentId(), deployment);
        }
        return map;
    }

    public Map getDeploymentsByEjbName() {
        final Map map = new LinkedHashMap();
        for (final EjbDeployment deployment : getEjbDeployment()) {
            map.put(deployment.getEjbName(), deployment);
        }
        return map;
    }

    @Override
    public String getId() {
        return getModuleName();
    }

    @Override
    public void setId(final String id) {
        setModuleName(id);
    }

    @Override
    public String getModuleName() {
        return moduleName;
    }

    @Override
    public void setModuleName(final String moduleName) {
        this.moduleName = moduleName;
    }

    public int getEjbDeploymentCount() {
        return getEjbDeployment().size();
    }

    public EjbDeployment addEjbDeployment(final EjbDeployment ejbDeployment) {
        getEjbDeployment().add(ejbDeployment);
        return ejbDeployment;
    }

    public void removeEjbDeployment(final EjbDeployment ejbDeployment) {
        getEjbDeployment().remove(ejbDeployment);
    }

    public Properties getProperties() {
        if (properties == null) {
            properties = new Properties();
        }
        return properties;
    }

    public EjbDeployment addEjbDeployment(final EnterpriseBean bean) {
        return addEjbDeployment(new EjbDeployment(bean));
    }

    public OpenejbJar postRead() {
        if (pojoDeployment != null && properties != null) {
            for (final PojoDeployment pojo : pojoDeployment) {
                for (final String key : properties.stringPropertyNames()) {
                    if (!pojo.getProperties().containsKey(key)) {
                        pojo.getProperties().put(key, properties.get(key));
                    }
                }
            }
        }
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy