01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.comp;
15:
16: import org.itsnat.comp.ItsNatElementComponent;
17: import org.itsnat.comp.ui.ItsNatElementComponentUI;
18: import org.itsnat.core.ItsNatException;
19: import org.itsnat.core.NameValue;
20: import org.itsnat.core.domutil.ItsNatDOMUtil;
21: import org.itsnat.impl.core.MarkupTemplateVersionImpl;
22: import org.w3c.dom.Element;
23: import org.w3c.dom.Node;
24:
25: /**
26: *
27: * @author jmarranz
28: */
29: public abstract class ItsNatElementComponentImpl extends
30: ItsNatComponentImpl implements ItsNatElementComponent {
31:
32: /**
33: * Creates a new instance of ItsNatElementComponentImpl
34: */
35: public ItsNatElementComponentImpl(Element node,
36: NameValue[] artifacts,
37: ItsNatComponentManagerImpl componentMgr) {
38: super (node, artifacts, componentMgr);
39: }
40:
41: public boolean getBooleanArtifactOrAttribute(String name,
42: boolean defaultValue) {
43: Object valueObj = getArtifact(name, false); // Evitamos buscar en el documento en caso fallido porque debería haberse registrado para el componente concreto
44: if (valueObj == null) {
45: String nameStr = getElement().getAttributeNS(
46: MarkupTemplateVersionImpl.ITSNAT_NAMESPACE, name);
47: if (!nameStr.equals(""))
48: return Boolean.valueOf(nameStr).booleanValue();
49: } else if (valueObj instanceof Boolean)
50: return ((Boolean) valueObj).booleanValue();
51: else
52: return Boolean.valueOf(valueObj.toString()).booleanValue();
53:
54: return defaultValue;
55: }
56:
57: public Element getElement() {
58: return (Element) getNode();
59: }
60:
61: public ItsNatElementComponentUI getItsNatElementComponentUI() {
62: return (ItsNatElementComponentUI) compUI;
63: }
64:
65: public abstract Object createDefaultStructure();
66:
67: public Object getDeclaredStructure(Class expectedClass) {
68: Element elem = getElement();
69: Object structure = getArtifact("useStructure", false); // Evitamos buscar en el documento en caso fallido porque debería haberse registrado para el componente concreto pues no puede haber un registro más global con "useStructure" pues hay diferentes tipos de estructuras (listas, tablas etc)
70: if (structure == null) {
71: String structureName = elem.getAttributeNS(
72: MarkupTemplateVersionImpl.ITSNAT_NAMESPACE,
73: "useStructure");
74: if (structureName.length() > 0) {
75: structure = getArtifact(structureName, true); // busca también en el documento el objeto estructura con el nombre dado en el atributo
76: if (structure == null)
77: throw new ItsNatException(
78: "Artifact (structure) not found: \""
79: + structureName + "\"");
80: } else {
81: structure = createDefaultStructure(); // No puede ser null
82: }
83: }
84:
85: if (!expectedClass.isInstance(structure))
86: throw new ItsNatException("Expected an "
87: + expectedClass.getName() + " object");
88: return structure;
89: }
90:
91: }
|