From: Steve L. <st...@us...> - 2006-01-23 17:53:19
|
Update of /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9349/src/org/smartfrog/sfcore/languages/cdl/references Modified Files: EarlyReferenceProcessor.java InferEarlyReferenceState.java ReferencePath.java StepDown.java StepExecutionResult.java StepRefRoot.java StepRoot.java StepUp.java Log Message: Lots of fixes to extends, reference processing is a lot better. Namespaces get cached. Index: StepRefRoot.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/StepRefRoot.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StepRefRoot.java 18 Jan 2006 16:12:24 -0000 1.3 --- StepRefRoot.java 23 Jan 2006 17:53:05 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- import org.smartfrog.sfcore.languages.cdl.dom.CdlDocument; import org.smartfrog.sfcore.languages.cdl.dom.PropertyList; + import org.smartfrog.sfcore.languages.cdl.dom.ToplevelList; import javax.xml.namespace.QName; *************** *** 62,67 **** PropertyList target = owner.lookup(refroot); if(target==null) { ! throw new CdlResolutionException("Unknown reference root "+refroot.toString()); } return state.next(target); } --- 63,69 ---- PropertyList target = owner.lookup(refroot); if(target==null) { ! throw new CdlResolutionException("Unknown cdl:refroot \""+refroot.toString()+"\""); } + assert !(target instanceof ToplevelList) : "we have gone up too far!"; return state.next(target); } Index: ReferencePath.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/ReferencePath.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ReferencePath.java 18 Jan 2006 16:12:24 -0000 1.6 --- ReferencePath.java 23 Jan 2006 17:53:05 -0000 1.7 *************** *** 21,28 **** --- 21,31 ---- import org.smartfrog.sfcore.languages.cdl.dom.PropertyList; + import org.smartfrog.sfcore.languages.cdl.dom.ToplevelList; import org.smartfrog.sfcore.languages.cdl.faults.CdlRuntimeException; import org.smartfrog.sfcore.languages.cdl.faults.CdlResolutionException; import org.smartfrog.sfcore.languages.cdl.faults.CdlException; import org.smartfrog.sfcore.languages.cdl.Constants; + import org.smartfrog.sfcore.languages.cdl.utils.NamespaceLookup; + import org.smartfrog.sfcore.languages.cdl.utils.Namespaces; import org.smartfrog.services.xml.java5.NamespaceUtils; *************** *** 37,41 **** * Nothing in here is thread safe. */ ! public class ReferencePath { /** * Error message when constructing from something that lacks a cdl:ref attribute. --- 40,44 ---- * Nothing in here is thread safe. */ ! public class ReferencePath implements NamespaceLookup { /** * Error message when constructing from something that lacks a cdl:ref attribute. *************** *** 52,58 **** --- 55,67 ---- public ReferencePath() { + namespaces=new Namespaces(); } /** + * a cached ref to the owner. Why? so that + */ + private NamespaceLookup namespaces; + + /** * Build from a source * *************** *** 66,71 **** throw new IllegalArgumentException(ERROR_NON_REFERENCE); } ! build(refValue); //extract lazy flag. --- 75,81 ---- throw new IllegalArgumentException(ERROR_NON_REFERENCE); } + namespaces=source.getNamespaces(); ! build(refValue, refRootValue); //extract lazy flag. *************** *** 183,188 **** * * @param path */ ! public void build(String path) { //this is very easy to parse; no need for any complex recursive //parser. Even so, regexp work may make this tractable --- 193,199 ---- * * @param path + * @param refRootValue */ ! public void build(String path, String refRootValue) { //this is very easy to parse; no need for any complex recursive //parser. Even so, regexp work may make this tractable *************** *** 201,207 **** } } else { ! //relative refs have a step start, that puts the ! //cursor in the right place to begin resolution ! append(new StepStart()); } //now, scan through the source looking for stuff --- 212,220 ---- } } else { ! if(refRootValue==null) { ! //relative refs have a step start, that puts the ! //cursor in the right place to begin resolution ! append(new StepStart()); ! } } //now, scan through the source looking for stuff *************** *** 254,258 **** while (!node.isToplevel()) { //insert a new upward step - steps.add(0, new StepUp()); ParentNode parent = node.getParent(); if (parent==null || !(parent instanceof PropertyList)) { --- 267,270 ---- *************** *** 260,264 **** --- 272,280 ---- throw new CdlRuntimeException(ERROR_NO_TOPLEVEL); } + node = (PropertyList) parent; + if(!(node instanceof ToplevelList)) { + steps.add(0, new StepUp()); + } } //here we are at a toplevel node *************** *** 276,279 **** --- 292,296 ---- ReferencePath copy=new ReferencePath(); copy.steps=new ArrayList(steps); + copy.namespaces=namespaces; return copy; } *************** *** 324,326 **** --- 341,353 ---- return state; } + + /** + * Get the URI of a namespace + * + * @param prefix the prefix + * @return the URI or null for none. + */ + public String resolveNamespaceURI(String prefix) { + return namespaces.resolveNamespaceURI(prefix); + } } Index: StepDown.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/StepDown.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StepDown.java 18 Jan 2006 16:12:24 -0000 1.3 --- StepDown.java 23 Jan 2006 17:53:05 -0000 1.4 *************** *** 80,84 **** String uri=""; if(prefix!=null) { ! uri = node.getNamespaceURI(prefix); if(uri==null) { throw new CdlResolutionException("Unknown prefix :"+prefix,state); --- 80,84 ---- String uri=""; if(prefix!=null) { ! uri = state.resolveNamespaceURI(prefix); if(uri==null) { throw new CdlResolutionException("Unknown prefix :"+prefix,state); Index: EarlyReferenceProcessor.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/EarlyReferenceProcessor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EarlyReferenceProcessor.java 18 Jan 2006 16:12:24 -0000 1.4 --- EarlyReferenceProcessor.java 23 Jan 2006 17:53:05 -0000 1.5 *************** *** 68,72 **** DepthFirstOperationPhase processor = new DepthFirstOperationPhase(null, new InferEarlyReferenceState(), ! false, true); return processor; } --- 68,72 ---- DepthFirstOperationPhase processor = new DepthFirstOperationPhase(null, new InferEarlyReferenceState(), ! true, true); return processor; } *************** *** 90,95 **** boolean finished; do { ! state = resolveList(document.getConfiguration()); ! state.merge(resolveList(document.getSystem())); finished = state == ResolveEnum.ResolvedComplete; --- 90,98 ---- boolean finished; do { ! ToplevelList configuration = document.getConfiguration(); ! state = resolveList(configuration); ! ToplevelList system = document.getSystem(); ! ResolveEnum resolvedSystem = resolveList(system); ! state.merge(resolvedSystem); finished = state == ResolveEnum.ResolvedComplete; *************** *** 132,139 **** } boolean shouldResolve = target.isValueReference(); - PropertyList result = target; if (shouldResolve) { //its a reference, process it ! result = resolveReferenceNode(target); } else { --- 135,141 ---- } boolean shouldResolve = target.isValueReference(); if (shouldResolve) { //its a reference, process it ! return resolveReferenceNode(target); } else { *************** *** 142,146 **** //resolve child references ! for (Node node : target.nodes()) { if (node instanceof PropertyList) { //cast it --- 144,148 ---- //resolve child references ! for (Node node : target) { if (node instanceof PropertyList) { //cast it *************** *** 149,160 **** if (template != newTemplate) { target.replaceChild(template, newTemplate); - //then resolve it again, to get the children picked up } } } } ! } - return result; } --- 151,160 ---- if (template != newTemplate) { target.replaceChild(template, newTemplate); } } } } ! return target; } } *************** *** 174,178 **** StepExecutionResult result = path.execute(target); assert result.isFinished(); ! if(result.isLazyFlagFound()) { //lazy was hit. we need to mark ourselves as lazy and continue without resolving target.setLazy(true); --- 174,178 ---- StepExecutionResult result = path.execute(target); assert result.isFinished(); ! if(result.isLazyFlagFound() && result.getNode().isValueReference()) { //lazy was hit. we need to mark ourselves as lazy and continue without resolving target.setLazy(true); *************** *** 191,195 **** replacement.setNamespaceURI(target.getNamespaceURI()); replacement.setNamespacePrefix(target.getNamespacePrefix()); ! return target; } --- 191,195 ---- replacement.setNamespaceURI(target.getNamespaceURI()); replacement.setNamespacePrefix(target.getNamespacePrefix()); ! return replacement; } Index: StepExecutionResult.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/StepExecutionResult.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StepExecutionResult.java 17 Jan 2006 14:21:55 -0000 1.2 --- StepExecutionResult.java 23 Jan 2006 17:53:05 -0000 1.3 *************** *** 21,26 **** import org.smartfrog.sfcore.languages.cdl.dom.PropertyList; ! import org.smartfrog.sfcore.languages.cdl.faults.CdlResolutionException; import org.smartfrog.sfcore.languages.cdl.faults.CdlException; /** --- 21,27 ---- import org.smartfrog.sfcore.languages.cdl.dom.PropertyList; ! import org.smartfrog.sfcore.languages.cdl.dom.ToplevelList; import org.smartfrog.sfcore.languages.cdl.faults.CdlException; + import org.smartfrog.sfcore.languages.cdl.utils.NamespaceLookup; /** *************** *** 29,33 **** */ ! public class StepExecutionResult { private ReferencePath path; --- 30,34 ---- */ ! public class StepExecutionResult implements NamespaceLookup { private ReferencePath path; *************** *** 68,71 **** --- 69,73 ---- public void setNode(PropertyList node) { + assert !(node instanceof ToplevelList): "trying to move to a root node "+node; this.node = node; } *************** *** 125,127 **** --- 127,154 ---- } } + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object. + */ + public String toString() { + Step currentStep = getCurrentStep(); + if (currentStep == null) { + //already finished; do nothing else + return "(finished)"; + } else { + return "@"+currentStep.toString(); + } + } + + /** + * Get the URI of a namespace + * + * @param prefix the prefix + * @return the URI or null for none. + */ + public String resolveNamespaceURI(String prefix) { + return path.resolveNamespaceURI(prefix); + } } Index: StepUp.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/StepUp.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StepUp.java 6 Jan 2006 17:43:36 -0000 1.2 --- StepUp.java 23 Jan 2006 17:53:05 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- import org.smartfrog.sfcore.languages.cdl.faults.CdlResolutionException; import org.smartfrog.sfcore.languages.cdl.dom.PropertyList; + import org.smartfrog.sfcore.languages.cdl.dom.ToplevelList; import nu.xom.Node; *************** *** 27,30 **** --- 28,32 ---- */ public class StepUp extends Step { + public static final String ERROR_PATH_TOO_FAR_UP = " the path goes too far up"; /** *************** *** 53,56 **** --- 55,62 ---- throw new CdlResolutionException(ERROR_NO_STEP_UP + node + ERROR_WRONG_PARENT, state); } + if (parent instanceof ToplevelList) { + throw new CdlResolutionException(ERROR_NO_STEP_UP + node + ERROR_PATH_TOO_FAR_UP, state); + } + return state.next((PropertyList) parent); } Index: StepRoot.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/StepRoot.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StepRoot.java 6 Jan 2006 17:43:36 -0000 1.2 --- StepRoot.java 23 Jan 2006 17:53:05 -0000 1.3 *************** *** 41,45 **** * Is this step a root node? * ! * @return true always. */ public boolean isRoot() { --- 41,45 ---- * Is this step a root node? * ! * @return true always. */ public boolean isRoot() { *************** *** 56,67 **** public StepExecutionResult execute(StepExecutionResult state) throws CdlResolutionException { PropertyList node = state.getNode(); ! Node current =node; ! while(!(current instanceof ToplevelList)) { Node parent = node.getParent(); if (parent == null) { throw new CdlResolutionException(ERROR_NO_STEP_UP + node + ERROR_ORPHAN_NODE, state); } ! current =parent; ! } return state.next((PropertyList) current); --- 56,72 ---- public StepExecutionResult execute(StepExecutionResult state) throws CdlResolutionException { PropertyList node = state.getNode(); ! Node current = node; ! boolean finished=false; ! do { Node parent = node.getParent(); if (parent == null) { throw new CdlResolutionException(ERROR_NO_STEP_UP + node + ERROR_ORPHAN_NODE, state); } ! if(parent instanceof ToplevelList) { ! finished=true; ! } else { ! current=parent; ! } ! } while(!finished); return state.next((PropertyList) current); Index: InferEarlyReferenceState.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/references/InferEarlyReferenceState.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InferEarlyReferenceState.java 18 Jan 2006 16:12:24 -0000 1.1 --- InferEarlyReferenceState.java 23 Jan 2006 17:53:05 -0000 1.2 *************** *** 49,53 **** state=target.inferLocalResolutionState(); if(state==ResolveEnum.ResolvedLazyLinksRemaining) { ! //turn lazy links into complete ones. state=ResolveEnum.ResolvedComplete; } --- 49,53 ---- state=target.inferLocalResolutionState(); if(state==ResolveEnum.ResolvedLazyLinksRemaining) { ! //turn lazy links into complete ones, because there is no more resolution to do here state=ResolveEnum.ResolvedComplete; } *************** *** 56,60 **** for(Node node:target) { if(node instanceof PropertyList) { ! state=state.merge(((PropertyList)node).getResolveState()); } } --- 56,62 ---- for(Node node:target) { if(node instanceof PropertyList) { ! PropertyList child = (PropertyList) node; ! ResolveEnum childState = child.getResolveState(); ! state=state.merge(childState); } } |