![JAR search and dependency download from the Maven repository](/logo.png)
org.nuiton.eugene.java.extension.CodesManagerExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eugene Show documentation
Show all versions of eugene Show documentation
Efficient Universal Generator.
/*
* #%L
* EUGene :: EUGene
*
* $Id: CodesManagerExtension.java 1079 2011-06-28 09:15:23Z tchemit $
* $HeadURL: https://svn.nuiton.org/eugene/tags/eugene-2.10/eugene/src/main/java/org/nuiton/eugene/java/extension/CodesManagerExtension.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.java.extension;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import java.util.HashMap;
import java.util.Map;
/**
* Object model extensions to manage verbatim code to attzach to operations.
*
* @author tchemit
* @see CodesManager
* @since 2.0.2
*/
public class CodesManagerExtension {
private static final Log log = LogFactory.getLog(CodesManagerExtension.class);
/** Extension static used to identify CodesManagerExtension in ObjectModel */
public static final String OBJECTMODEL_EXTENSION = "codes";
/**
* Map of CodesManager with key equals to the classifier qualified name
* associated to the CodesManager
*/
protected Map managers;
/**
* Add the {@code code} for the given {@code operation} of the
* given {@code classifier}.
*
* @param classifier the classifier container of the operation
* @param operation the operation on which to add the code
* @param code the code to add for the operation
*/
public void addcode(ObjectModelClassifier classifier,
ObjectModelOperation operation,
String code) {
CodesManager codesManager = getManager(classifier);
codesManager.addCode(operation, code);
}
/**
* Get body code for a operation of the given classifier.
*
* The CodesManager must be defined in the model.
*
* @param classifier reference for the codes
* @param operation the operation to seek
* @return the body code of the method
*/
public String getCode(ObjectModelClassifier classifier,
ObjectModelOperation operation) {
CodesManager manager = getManager(classifier);
return manager.getCode(operation);
}
/**
* Get the CodesManager associated to the classifier.
*
* Note: If not exist, it will be created.
*
* @param classifier reference for the ImportsManager
* @return the codesManager associated to the classifier (never null)
*/
public CodesManager getManager(ObjectModelClassifier classifier) {
Map managers = getManagers();
String fqn = classifier.getQualifiedName();
CodesManager manager = managers.get(fqn);
if (manager == null) {
manager = new CodesManager();
managers.put(fqn, manager);
if (log.isDebugEnabled()) {
log.debug("Add new codesManager for : " + fqn);
}
}
return manager;
}
protected Map getManagers() {
if (managers == null) {
managers = new HashMap();
}
return managers;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy