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

org.nuiton.eugene.models.object.xml.ObjectModelOperationImpl Maven / Gradle / Ivy

/*
 * #%L
 * EUGene :: EUGene
 * 
 * $Id: ObjectModelOperationImpl.java 863 2010-04-15 14:22:49Z tchemit $
 * $HeadURL: http://svn.nuiton.org/svn/eugene/tags/eugene-2.1.1/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelOperationImpl.java $
 * %%
 * Copyright (C) 2004 - 2010 CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */

package org.nuiton.eugene.models.object.xml;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.eugene.models.object.ObjectModelParameter;

/**
 * ObjectModelOperationImpl.java
 * 
 * Created: 14 janv. 2004
 * 
 * @author Cédric Pineau  Copyright Code Lutin
 * 
 * @version $Revision: 863 $
 * 
 * Last update : $Date: 2010-04-15 16:22:49 +0200 (jeu., 15 avril 2010) $ by : */
public class ObjectModelOperationImpl extends ObjectModelElementImpl implements
        ObjectModelOperation {

    protected ObjectModelParameter returnParameter;

    protected String visibility = "public";

    protected String transactionLevel = "supports";

    protected boolean abstractz;

    protected List parameters = new ArrayList();

    protected Set exceptions = new HashSet();

    protected String bodyCode = "";

    public ObjectModelOperationImpl() {
    }

    public String toString() {
        return getName() + "(" + parameters + ")" + "<<" + getStereotypes()
                + ">> throws " + exceptions + " tagvalue: " + getTagValues();
    }

    /**
     * 2 operations are equal if the have same name and same argument type.
     */
    public boolean equals(Object o) {
        if (o instanceof ObjectModelOperation) {
            ObjectModelOperation op = (ObjectModelOperation) o;
            if (getName().equals(op.getName())
                    && getParameters().size() == op.getParameters().size()) {
                for (Iterator i = getParameters().iterator(), opi = op
                        .getParameters().iterator(); i.hasNext()
                        && opi.hasNext();) {
                    ObjectModelParameter p = (ObjectModelParameter) i.next();
                    ObjectModelParameter pop = (ObjectModelParameter) opi
                            .next();
                    if (!p.getType().equals(pop.getType())) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }

    public void addParameter(ObjectModelParameterImpl parameter) {
        // if (parameter == null)
        // return new ObjectModelParameterImpl(objectModelImpl, this);
        parameter.postInit();
        parameter.setDeclaringElement(this);
        parameters.add(parameter);
        // return parameter;
    }

    public void setVisibility(String visibility) {
        this.visibility = visibility;
    }

    public void setAbstract(boolean abstractz) {
        this.abstractz = abstractz;
    }

    public void setReturnParameter(ObjectModelParameterImpl returnParameter) {
        // /if (returnParameter == null)
        // return new ObjectModelParameterImpl(objectModelImpl, this);
        returnParameter.postInit();
        returnParameter.setDeclaringElement(this);
        this.returnParameter = returnParameter;
    }

    public void setBodyCode(String bodyCode) {
        this.bodyCode = bodyCode;
    }

    /**
     * Add some code to current body
     * @param bodyCode code to add
     */
    public void addBodyCode(String bodyCode) {
        this.bodyCode += bodyCode;
    }

    @Override
    public ObjectModelParameter getReturnParameter() {
        return returnParameter;
    }

    @Override
    public String getReturnType() {
        if (returnParameter != null) {
            return returnParameter.getType();
        }
        return "void";
    }

    @Override
    public String getVisibility() {
        return visibility;
    }

    /**
     * Returns whether this operation is abstract or not.
     * 
     * @return a boolean indicating whether this operation is abstract or not.
     */
    @Override
    public boolean isAbstract() {
        return abstractz;
    }

    @Override
    public Collection getParameters() {
        return parameters;
    }

    /**
     * Add new raised exception.
     * 
     * @param raisedParameter exception to add
     */
    public void addExceptionParameter(ObjectModelParameterImpl raisedParameter) {
        raisedParameter.postInit();
        raisedParameter.setDeclaringElement(this);

        exceptions.add(raisedParameter.getType());
    }

    @Override
    public Set getExceptions() {
        return exceptions;
    }

    @Override
    public String getBodyCode() {
        return bodyCode;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy