001: package de.webman.content.attributs;
002:
003: import com.teamkonzept.field.db.*;
004: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
005: import com.teamkonzept.lib.TKHashtable;
006: import java.sql.SQLException;
007: import java.util.Hashtable;
008: import java.util.Enumeration;
009: import org.apache.log4j.Category;
010:
011: /**
012: verwaltet die Attribute einer Contentid
013:
014: * @author $Author: sebastian $
015: * @version $Revision: 1.5 $
016: */
017:
018: public class AttributeHandler {
019: /** enthält eine Liste der Attributclassen zum Content */
020: private Hashtable attributes = new Hashtable();
021:
022: /** for Logging */
023: private static Category cat = Category
024: .getInstance(AttributeHandler.class);
025:
026: /** initiert die einzelnen Attributklassen (@see AttributeInterface)
027: * @param contentId
028: */
029: public AttributeHandler(Integer contentId) {
030: TKContentDBData cdata = new TKContentDBData();
031: try {
032: // lade Attribute
033: cdata.content_id = contentId.intValue();
034: cdata.setIgnoreTable("CONTENT_VALUE", true);
035: cdata.setIgnoreTable("CONTENT_NODE", true);
036: TKContentDBInterface.Get(cdata);
037: // lade Attributklassen
038: if (cdata.content_attribute == null)
039: return;
040:
041: for (int i = 0; i < cdata.content_attribute.size(); i++) {
042: // gibt es diese Klasse schon im Cache ?
043: TKContentAttributeTableData table = (TKContentAttributeTableData) cdata.content_attribute
044: .elementAt(i);
045:
046: AttributeInterface attrclass = (AttributeInterface) attributes
047: .get(table.classname);
048: if (attrclass == null) {
049: // lade Klasse (classname)
050: try {
051: Class objectClass = Class
052: .forName(table.classname);
053: attrclass = (AttributeInterface) objectClass
054: .newInstance();
055: } catch (Exception e) {
056: cat
057: .error("Fehler beim laden der Attributklasse : "
058: + table.classname);
059: continue;
060: }
061:
062: // cache Klasse
063: attributes.put(table.classname, attrclass);
064: }
065: attrclass.putAttribute(new Attribute(table.name,
066: table.value, table.type));
067: }
068: } catch (Throwable t) {
069: cat.error("Fehler beim laden der Attribute");
070: t.printStackTrace();
071:
072: }
073:
074: }
075:
076: /** geht alle Attribute durch und gibt null zurück fals der Content generierbar ist,
077: wird der Klassenname des Attributes zurückgegeben, weswegen der Content nicht generierbar ist.
078:
079: @param options event. Generatoroptionen
080: @return String - null falls gültige Version; sonst KlassenID des Attributes das
081: die Version ungültig macht
082: */
083: public String getGeneratableStatus(TKHashtable options)
084: {
085: Enumeration enum = attributes.elements();
086: Enumeration keys = attributes.keys();
087: while (enum.hasMoreElements())
088: {
089: String key = (String)keys.nextElement();
090: AttributeInterface attr = (AttributeInterface)enum.nextElement();
091: if (! attr.isGeneratable(options))
092: return key;
093: }
094: return null;
095: }
096:
097: /**
098: @return boolean - true if there are no Attributes false otherwise
099: */
100: public boolean isEmpty() {
101: return attributes.isEmpty();
102: }
103: }
|