From: Steve L. <st...@us...> - 2005-05-26 15:17:32
|
Update of /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9933/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom Modified Files: AnnotatedNode.java CdlDocument.java DocNode.java Documentation.java Expression.java Import.java Names.java PropertyList.java Type.java Variable.java Added Files: Ref.java Log Message: set of classes to match what we parse Index: DocNode.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/DocNode.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DocNode.java 25 May 2005 16:48:25 -0000 1.4 --- DocNode.java 26 May 2005 15:17:20 -0000 1.5 *************** *** 21,41 **** import org.smartfrog.sfcore.languages.cdl.CdlParsingException; import org.ggf.cddlm.generated.api.CddlmConstants; import nu.xom.Node; import nu.xom.Element; import nu.xom.Attribute; /** * created 21-Apr-2005 14:25:53 */ ! public class DocNode implements FromXML, Names { /** ! * Parse from XM ! * @throws CdlParsingException */ ! public void fromXML(Element element) throws CdlParsingException { } --- 21,74 ---- import org.smartfrog.sfcore.languages.cdl.CdlParsingException; + import org.smartfrog.sfcore.languages.cdl.utils.ElementIterator; import org.ggf.cddlm.generated.api.CddlmConstants; import nu.xom.Node; import nu.xom.Element; import nu.xom.Attribute; + import nu.xom.ParentNode; /** + * Representation of any node. * created 21-Apr-2005 14:25:53 */ ! public abstract class DocNode implements Names { ! ! protected DocNode() { ! } ! ! protected DocNode(Element node) throws CdlParsingException { ! bind(node); ! } /** ! * the node under the system here. */ ! private Element node; + public Element getNode() { + return node; + } + + public void setNode(Element node) { + this.node = node; + } + + /** + * Iterate just over elements + * + * @return + */ + public ElementIterator childElements() { + return new ElementIterator(node); + } + + /** + * Parse from XML. + * The base implementation sets the {@link #node} attribute + * @throws CdlParsingException + */ + public void bind(Element element) throws CdlParsingException { + setNode(element); } *************** *** 65,83 **** } - /** - * Get an attribute in the CDL namespace - * @param element node to examine - * @param attribute attribute to get - * @param required flag set to true if needed - * @return the string value of the attribute - * @throws CdlParsingException - */ - protected String getCdlAttribute(Element element, String attribute,boolean required) - throws CdlParsingException { - String value = element.getAttribute(attribute,DOC_NAMESPACE).getValue(); - if(value==null && required) { - throw new CdlParsingException("Missing attribute "+attribute+" from element "+element); - } - return value; - } } --- 98,100 ---- Index: PropertyList.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/PropertyList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PropertyList.java 25 May 2005 16:48:26 -0000 1.5 --- PropertyList.java 26 May 2005 15:17:20 -0000 1.6 *************** *** 58,62 **** public PropertyList(Element element) throws CdlParsingException { ! fromXML(element); } --- 58,62 ---- public PropertyList(Element element) throws CdlParsingException { ! bind(element); } *************** *** 66,70 **** * @throws CdlParsingException */ ! public void fromXML(Element element) throws CdlParsingException { //TODO --- 66,70 ---- * @throws CdlParsingException */ ! public void bind(Element element) throws CdlParsingException { //TODO Index: Variable.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Variable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Variable.java 21 Apr 2005 14:21:24 -0000 1.1 --- Variable.java 26 May 2005 15:17:20 -0000 1.2 *************** *** 20,27 **** package org.smartfrog.sfcore.languages.cdl.dom; /** * created 21-Apr-2005 14:43:52 */ ! public class Variable extends DocNode { } --- 20,72 ---- package org.smartfrog.sfcore.languages.cdl.dom; + import nu.xom.Element; + + import javax.xml.namespace.QName; + + import org.smartfrog.sfcore.languages.cdl.CdlParsingException; + import org.smartfrog.sfcore.languages.cdl.dom.attributes.NameAttribute; + /** * created 21-Apr-2005 14:43:52 */ ! public class Variable extends Ref { ! ! private NameAttribute name; ! ! public Variable() { ! } ! ! public Variable(Element node) throws CdlParsingException { ! super(node); ! } ! ! public void bind(Element element) throws CdlParsingException { ! //get the bits of ref ! super.bind(element); ! //add a name attribute ! name=NameAttribute.extract(element, true); ! } ! ! public NameAttribute getName() { ! return name; ! } ! ! /** ! * get the string value of the name; valid only when bound ! * @return ! */ ! public String getNameValue() { ! return name.getValue(); ! } ! ! /** ! * test that a node is of the right type ! * ! * @param element ! * @return true if the element namespace and localname match what we handle ! */ ! static boolean isA(Element element) { ! return isNode(element, ELEMENT_VARIABLE); ! } } Index: Names.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Names.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Names.java 25 May 2005 16:48:26 -0000 1.1 --- Names.java 26 May 2005 15:17:20 -0000 1.2 *************** *** 39,43 **** String ELEMENT_DOCUMENTATION = "documentation"; String ELEMENT_EXPRESSION = "expression"; ! String ELEMENT_VARIABLETYPE = "variableType"; String ELEMENT_REF = "ref"; --- 39,43 ---- String ELEMENT_DOCUMENTATION = "documentation"; String ELEMENT_EXPRESSION = "expression"; ! String ELEMENT_VARIABLE = "variable"; String ELEMENT_REF = "ref"; Index: Documentation.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Documentation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Documentation.java 25 May 2005 16:48:26 -0000 1.2 --- Documentation.java 26 May 2005 15:17:20 -0000 1.3 *************** *** 33,37 **** public Documentation(Element element) throws CdlParsingException { ! fromXML(element); } --- 33,37 ---- public Documentation(Element element) throws CdlParsingException { ! bind(element); } *************** *** 41,45 **** * @throws CdlParsingException */ ! public void fromXML(Element element) throws CdlParsingException { //TODO } --- 41,45 ---- * @throws CdlParsingException */ ! public void bind(Element element) throws CdlParsingException { //TODO } Index: Expression.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Expression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Expression.java 12 May 2005 16:48:26 -0000 1.2 --- Expression.java 26 May 2005 15:17:20 -0000 1.3 *************** *** 20,27 **** package org.smartfrog.sfcore.languages.cdl.dom; /** * created 21-Apr-2005 14:42:51 */ ! public class Expression extends AnnotatedNode { } --- 20,78 ---- package org.smartfrog.sfcore.languages.cdl.dom; + import org.smartfrog.sfcore.languages.cdl.dom.attributes.ValueOfAttribute; + import org.smartfrog.sfcore.languages.cdl.CdlParsingException; + + import java.util.List; + import java.util.LinkedList; + import java.util.HashMap; + import java.util.Collection; + + import nu.xom.Element; + /** * created 21-Apr-2005 14:42:51 */ ! public class Expression extends DocNode { ! ! public Expression() { ! } ! ! private ValueOfAttribute valueOf; ! ! private HashMap<String,Variable> variables =new HashMap<String, Variable>(); ! ! public Collection<Variable> getVariables() { ! return variables.values(); ! } ! ! public ValueOfAttribute getValueOf() { ! return valueOf; ! } ! ! protected void add(Variable v) { ! variables.put(v.getNameValue(),v); ! } ! ! /** ! * find a variable with a give name ! * @param name ! * @return ! */ ! public Variable lookupVariable(String name) { ! return variables.get(name); ! } ! ! public void bind(Element element) throws CdlParsingException { ! super.bind(element); ! valueOf=ValueOfAttribute.extract(element, true); ! //now run though our children, which must all be variables ! for(Element child:childElements()) { ! if(!Variable.isA(child)) { ! throw new CdlParsingException("Unexpected element "+element); ! } ! Variable v=new Variable(child); ! add(v); ! } ! } } Index: AnnotatedNode.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/AnnotatedNode.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AnnotatedNode.java 12 May 2005 16:48:26 -0000 1.1 --- AnnotatedNode.java 26 May 2005 15:17:20 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- package org.smartfrog.sfcore.languages.cdl.dom; + import org.smartfrog.sfcore.languages.cdl.CdlParsingException; + import nu.xom.Element; + /** * created 12-May-2005 17:33:10 *************** *** 25,27 **** --- 28,39 ---- public class AnnotatedNode extends DocNode { + + /** + * Parse from XML. The base implementation sets the {@link #node} attribute + * + * @throws CdlParsingException + */ + public void bind(Element element) throws CdlParsingException { + super.bind(element); + } } Index: Type.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Type.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Type.java 25 May 2005 16:48:26 -0000 1.1 --- Type.java 26 May 2005 15:17:20 -0000 1.2 *************** *** 35,39 **** public Type(Element node) throws CdlParsingException { ! fromXML(node); } --- 35,39 ---- public Type(Element node) throws CdlParsingException { ! bind(node); } *************** *** 43,47 **** * @throws CdlParsingException */ ! public void fromXML(Element element) throws CdlParsingException { //not implemented //TODO --- 43,48 ---- * @throws CdlParsingException */ ! public void bind(Element element) throws CdlParsingException { ! super.bind(element); //not implemented //TODO Index: Import.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/Import.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Import.java 25 May 2005 16:48:26 -0000 1.3 --- Import.java 26 May 2005 15:17:20 -0000 1.4 *************** *** 24,27 **** --- 24,28 ---- import org.ggf.cddlm.generated.api.CddlmConstants; import org.smartfrog.sfcore.languages.cdl.CdlParsingException; + import org.smartfrog.sfcore.languages.cdl.dom.attributes.GenericAttribute; /** *************** *** 32,38 **** public class Import extends DocNode { ! public String namespace; ! public String location; public Import() { --- 33,39 ---- public class Import extends DocNode { ! private String namespace; ! private String location; public Import() { *************** *** 40,44 **** public Import(Element node) throws CdlParsingException { ! fromXML(node); } --- 41,45 ---- public Import(Element node) throws CdlParsingException { ! super(node); } *************** *** 48,54 **** * @throws CdlParsingException */ ! public void fromXML(Element element) throws CdlParsingException { ! namespace = getCdlAttribute(element, ATTR_NAMESPACE, false); ! location = getCdlAttribute(element, ATTR_LOCATION, true); } --- 49,56 ---- * @throws CdlParsingException */ ! public void bind(Element element) throws CdlParsingException { ! super.bind(element); ! namespace = GenericAttribute.extractCdlAttributeValue(element, ATTR_NAMESPACE, false); ! location = GenericAttribute.extractCdlAttributeValue(element, ATTR_LOCATION, true); } --- NEW FILE: Ref.java --- /** (C) Copyright 2005 Hewlett-Packard Development Company, LP This library 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 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.sfcore.languages.cdl.dom; import org.smartfrog.sfcore.languages.cdl.dom.attributes.RefRootAttribute; import org.smartfrog.sfcore.languages.cdl.dom.attributes.RefAttribute; import org.smartfrog.sfcore.languages.cdl.dom.attributes.LazyAttribute; import org.smartfrog.sfcore.languages.cdl.CdlParsingException; import javax.xml.namespace.QName; import nu.xom.Element; /** * Reference type * created 26-May-2005 11:14:38 */ public class Ref extends DocNode { public Ref() { } public Ref(Element node) throws CdlParsingException { super(node); } /** * optional reference root */ private RefRootAttribute refRoot; private RefAttribute refAttr; private boolean lazy; public void bind(Element element) throws CdlParsingException { super.bind(element); lazy=LazyAttribute.isLazy(element,false); refRoot = RefRootAttribute.extract(element, false); refAttr = RefAttribute.extract(element, true); } } Index: CdlDocument.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/dom/CdlDocument.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CdlDocument.java 25 May 2005 16:48:25 -0000 1.5 --- CdlDocument.java 26 May 2005 15:17:20 -0000 1.6 *************** *** 161,173 **** String uri = root.getNamespaceURI(); - /* - Attribute pathLangAttr = root.getAttribute("pathlanguage", Constants.CDL_NAMESPACE); - if ( pathLangAttr != null ) { - assertTrue(ERROR_NO_PATHLANGUAGE, pathLangAttr != null); - String language = pathLangAttr.getValue(); - assertTrue(ERROR_BAD_PATHLANGUAGE, Constants.XPATH_URI.equals(language)); - } - */ - if (configuration != null) { configuration.validateToplevel(); --- 161,164 ---- |