From: <st...@us...> - 2011-03-07 11:12:40
|
Revision: 8529 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8529&view=rev Author: steve_l Date: 2011-03-07 11:12:33 +0000 (Mon, 07 Mar 2011) Log Message: ----------- convert tabs to spaces. Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java 2011-03-01 11:42:57 UTC (rev 8528) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java 2011-03-07 11:12:33 UTC (rev 8529) @@ -105,7 +105,7 @@ super(parent, cxt, eager); if (types != null) this.types = types; } - + /** * Constructor. * @@ -422,9 +422,9 @@ * @throws SmartFrogResolutionException */ static public SFComponentDescription composeTypes(ComponentDescription parent, Vector types) throws SmartFrogResolutionException { - SFComponentDescriptionImpl sfcd = new SFComponentDescriptionImpl(types, (SFComponentDescription) parent, null, true); - sfcd.typeResolve(); - return sfcd; + SFComponentDescriptionImpl sfcd = new SFComponentDescriptionImpl(types, (SFComponentDescription) parent, null, true); + sfcd.typeResolve(); + return sfcd; } /** @@ -510,7 +510,7 @@ */ protected boolean resolveType(ResolutionState resState, Reference type) throws SmartFrogTypeResolutionException { try { - SFComponentDescription superType = (SFComponentDescription) sfResolve(type); + SFComponentDescription superType = (SFComponentDescription) sfResolve(type); superType.doTypeResolve(resState); if (!resState.moreToResolve()) { @@ -585,7 +585,7 @@ key = e.nextElement(); value = sfContext.get(key); boolean finalAttr = false; - + //The following is code contributed by Ming Fang - thanks! boolean overrideAttr = false; try { @@ -601,7 +601,7 @@ } } // End of code - + try { finalAttr = sContext.sfContainsTag(key, "sfFinal"); } catch (SmartFrogException e1) { @@ -625,7 +625,7 @@ sfContext = sContext; } - + /** * 'Link' resolve a description. This involves iterating over the * description tree a number of times and looking at the attribute values. @@ -640,12 +640,12 @@ //We now synchronise link resolution, at no great inconvenience I suspect, for the purpose of constraint solving //Easiest solution to apply universally even in the absence of constraints in some descriptions. ADHF synchronized (CoreSolver.getInstance()){ - do { - resState.clear(); - doLinkResolve(resState); - } while (resState.moreToResolve()); //this while loop is not actually necessary ADHF + do { + resState.clear(); + doLinkResolve(resState); + } while (resState.moreToResolve()); //this while loop is not actually necessary ADHF } - + if (resState.unresolved().size() > 0) { throw new SmartFrogLinkResolutionException ( MessageUtil.formatMessage(MSG_UNRESOLVED_REFERENCE), null, @@ -653,78 +653,78 @@ } } - - /** Link Resolution State Record. A record of where link resolution is currently at. We maintain a chain of these*/ - public class LRSRecord { - /** SFComponentDescription being processed */ SFComponentDescription sfcd; - /** My parent record */ LRSRecord par; - /** My index into my parent */ int my_idx; - } - - /** Indicates current component description being link-resolved, as a LRSRecord (link resolution state record) */ - private LRSRecord currentLRSRecord=null; - + + /** Link Resolution State Record. A record of where link resolution is currently at. We maintain a chain of these*/ + public class LRSRecord { + /** SFComponentDescription being processed */ SFComponentDescription sfcd; + /** My parent record */ LRSRecord par; + /** My index into my parent */ int my_idx; + } + + /** Indicates current component description being link-resolved, as a LRSRecord (link resolution state record) */ + private LRSRecord currentLRSRecord=null; + /** Indicates index of attribute currently being processed in current description */ private int currentLRSIndex=0; - + /** * Gets the index of attribute currently being processed in current description * @return idx index of attribute */ public int getLRSIdx(){ return currentLRSIndex; } - + /** * Sets the index of attribute currently being processed in current description * @param idx index of attribute */ public void setLRSIdx(int idx){ currentLRSIndex=idx; } - + /** * Sets the current LRSRecord (link resolution state record) * @param lrsr LRSRecord (link resolution state record) to make current */ public void setLRSRecord(LRSRecord lrsr){ currentLRSRecord=lrsr; } - + /** * Gets the current LRS record (corresponding to component description being currently link-resolved) * @return current LRSRecord (link resolution state record) */ public LRSRecord getLRSRecord(){ return currentLRSRecord; } - - /** - * Pop a record off the link history - */ - private void popLRSRecord(){ - currentLRSIndex = currentLRSRecord.my_idx; + + /** + * Pop a record off the link history + */ + private void popLRSRecord(){ + currentLRSIndex = currentLRSRecord.my_idx; currentLRSRecord = currentLRSRecord.par; currentLRSIndex++; - } - - /** - * Create and add an LRSRecord (link resolution state record) to the end of the chain of link records being kept - * @param sfcd - * @param idx - */ - private LRSRecord addLRSRecord(SFComponentDescription sfcd, int idx){ - LRSRecord lrsr = new LRSRecord(); - lrsr.sfcd = sfcd; - lrsr.par = currentLRSRecord; - lrsr.my_idx = idx; - - currentLRSIndex = 0; - currentLRSRecord = lrsr; - return currentLRSRecord; - } - - private void resetLRSState(){ - currentLRSRecord = new LRSRecord(); - currentLRSRecord.sfcd = this; - currentLRSRecord.my_idx = 0; - currentLRSRecord.par = null; - currentLRSIndex=0; - } - + } + + /** + * Create and add an LRSRecord (link resolution state record) to the end of the chain of link records being kept + * @param sfcd + * @param idx + */ + private LRSRecord addLRSRecord(SFComponentDescription sfcd, int idx){ + LRSRecord lrsr = new LRSRecord(); + lrsr.sfcd = sfcd; + lrsr.par = currentLRSRecord; + lrsr.my_idx = idx; + + currentLRSIndex = 0; + currentLRSRecord = lrsr; + return currentLRSRecord; + } + + private void resetLRSState(){ + currentLRSRecord = new LRSRecord(); + currentLRSRecord.sfcd = this; + currentLRSRecord.my_idx = 0; + currentLRSRecord.par = null; + currentLRSIndex=0; + } + /** * Internal method to iteratively perform link resolution * @param resState resolutionState @@ -734,84 +734,84 @@ //reset link resolution state resetLRSState(); - + //Set description in Constraint Solver logic CoreSolver.getInstance().setDescriptionMarkers(this); - + //Compile list of propositions for cardinality constraint checking Proposition.compilePropositions(this); - + while (true){ - //Get current description being processed... - SFComponentDescription sfcd = currentLRSRecord.sfcd; - //If all attributes processed... - if (currentLRSIndex==sfcd.sfContext().size()) { - //Pop record from chain... - popLRSRecord(); - //If no parent + //Get current description being processed... + SFComponentDescription sfcd = currentLRSRecord.sfcd; + //If all attributes processed... + if (currentLRSIndex==sfcd.sfContext().size()) { + //Pop record from chain... + popLRSRecord(); + //If no parent if (currentLRSRecord==null) { - CoreSolver.getInstance().tidyConstraintBasedDescription(this); - return; //link resolution chain is empty... + CoreSolver.getInstance().tidyConstraintBasedDescription(this); + return; //link resolution chain is empty... } continue; //around while... - } - - //Get attribute key - Object key = sfcd.sfContext().getKey(currentLRSIndex); - - //Get value - Object value = sfcd.sfContext().getVal(currentLRSIndex); - - //System.out.println("key:"+key+", value:"+value); - - //Do we need to do some additional constraints work? - try { - CoreSolver.getInstance().doConstraintsWork(key); - } catch (SmartFrogConstraintBacktrackError sfbe){ - if (CoreSolver.getInstance().getOriginalDescription()!=this) throw sfbe; - else continue; //need to try the latest again... - } - - //Is value SFComponentDescription? + } + + //Get attribute key + Object key = sfcd.sfContext().getKey(currentLRSIndex); + + //Get value + Object value = sfcd.sfContext().getVal(currentLRSIndex); + + //System.out.println("key:"+key+", value:"+value); + + //Do we need to do some additional constraints work? + try { + CoreSolver.getInstance().doConstraintsWork(key); + } catch (SmartFrogConstraintBacktrackError sfbe){ + if (CoreSolver.getInstance().getOriginalDescription()!=this) throw sfbe; + else continue; //need to try the latest again... + } + + //Is value SFComponentDescription? if (value instanceof SFComponentDescription) { - sfcd = (SFComponentDescription) value; - - if (!CoreSolver.getInstance().ignoreComponentDescription(sfcd)) { - //Yes, add a new record to link resolution state, which will determine that - //value is next explored (Depth First exploration) - addLRSRecord(sfcd, currentLRSIndex); - continue; //round while... - } - //Is value a Reference? + sfcd = (SFComponentDescription) value; + + if (!CoreSolver.getInstance().ignoreComponentDescription(sfcd)) { + //Yes, add a new record to link resolution state, which will determine that + //value is next explored (Depth First exploration) + addLRSRecord(sfcd, currentLRSIndex); + continue; //round while... + } + //Is value a Reference? } else if (value instanceof Reference) { Reference rv = (Reference)value; if (!rv.getData() && !Constraint.leaveResolve(sfcd, key)){ - try { - - //Resolve reference - Object result = sfcd.sfResolve((Reference) value); - - //Setting key to have value should be undoable - CoreSolver.getInstance().setShouldUndo(true); - - //Set key to have value - //System.out.println("Putting..."+key+":"+result); - sfcd.sfContext().put(key, result); - - //No more should we undo - CoreSolver.getInstance().setShouldUndo(false); - + try { + + //Resolve reference + Object result = sfcd.sfResolve((Reference) value); + + //Setting key to have value should be undoable + CoreSolver.getInstance().setShouldUndo(true); + + //Set key to have value + //System.out.println("Putting..."+key+":"+result); + sfcd.sfContext().put(key, result); + + //No more should we undo + CoreSolver.getInstance().setShouldUndo(false); + if (result instanceof SFComponentDescription) { - SFComponentDescription res_sfcd = (SFComponentDescription) result; + SFComponentDescription res_sfcd = (SFComponentDescription) result; // need to do this as it may link to the file root! if (res_sfcd.sfParent() == null) res_sfcd.setParent(sfcd); continue; //round while to resolve it... } - + } catch (SmartFrogConstraintBacktrackError sfbe){ - if (CoreSolver.getInstance().getOriginalDescription()!=this) throw sfbe; - else continue; //need to try the latest again... + if (CoreSolver.getInstance().getOriginalDescription()!=this) throw sfbe; + else continue; //need to try the latest again... } catch (SmartFrogLazyResolutionException slrex) { rv.setEager(false); } catch (Exception resex) { @@ -821,11 +821,11 @@ } resState.addUnresolved(value, sfcd.sfCompleteName(), key.toString(), resex); } catch (Throwable thr){ - if (thr instanceof CoreSolverFatalError) throw (CoreSolverFatalError) thr; + if (thr instanceof CoreSolverFatalError) throw (CoreSolverFatalError) thr; throw new SmartFrogLinkResolutionException( - "Failed to resolve '"+key+" "+value+"'"+ - (thr instanceof StackOverflowError || thr instanceof java.lang.OutOfMemoryError? - (". "+POSSIBLE_CAUSE_CYCLIC_REFERENCE):""), + "Failed to resolve '"+key+" "+value+"'"+ + (thr instanceof StackOverflowError || thr instanceof java.lang.OutOfMemoryError? + (". "+POSSIBLE_CAUSE_CYCLIC_REFERENCE):""), thr, sfCompleteName(), resState.unresolved() ); } @@ -845,26 +845,26 @@ * @throws SmartFrogException */ public static ComponentDescription simpleLinkResolve(ComponentDescription comp) throws SmartFrogException { - //Simple link resolve... + //Simple link resolve... if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); ComponentDescription newcomp = new SFComponentDescriptionImpl(); - newcomp.setParent(comp.sfParent()); - newcomp.setEager(comp.getEager()); - - for (Iterator v = comp.sfAttributes(); v.hasNext();) { - Object name = v.next(); + newcomp.setParent(comp.sfParent()); + newcomp.setEager(comp.getEager()); + + for (Iterator v = comp.sfAttributes(); v.hasNext();) { + Object name = v.next(); Reference ref = new Reference(ReferencePart.here(name)); Object value=comp.sfResolve(ref); SFSystem.sfLog().debug("key:value, "+ name +" : "+value); if (value instanceof ComponentDescription) value=simpleLinkResolve((ComponentDescription)value); - + newcomp.sfAddAttribute(name, value); newcomp.sfAddTags(name, comp.sfGetTags(name)); } - return newcomp; - } - + return newcomp; + } + /** * Returns a string representation of the component. This will give a * description of the component which is parseable, and deployable again... @@ -938,9 +938,9 @@ * */ protected ComponentDescription createComponentDescription(final ComponentDescription parentCD, final Context context, final boolean isEager) { - return new ComponentDescriptionImpl(parentCD, context, isEager); + return new ComponentDescriptionImpl(parentCD, context, isEager); } - + /** * Return a component description as required by the deployer. * Works by side-effect on the SFComponentDescription for efficiency. @@ -988,8 +988,8 @@ return res; } - - + + /** * Method to take a URL, parse it, add the addtional key-value parameters to the top level, and then resolve it. * @param url the file to parse @@ -1005,8 +1005,8 @@ throw new FileNotFoundException("Unable to load " + url); } Phases p = new SFParser().sfParse(instream); - - // add params + + // add params if (params != null) { for (Enumeration keys = params.keys(); keys.hasMoreElements(); ) { Object k = keys.nextElement(); @@ -1146,21 +1146,21 @@ *@return Vector of Phases */ public Vector sfGetPhases() throws SmartFrogException { - if (phases==null){ - Object phases_obj = sfContext.get(PHASE_LIST); - if (phases_obj!=null){ - if (!(phases_obj instanceof java.util.Vector)) throw new SmartFrogParseException("phaseList must be a primitive vector"); - phases = (java.util.Vector) phases_obj; - sfContext.remove(PHASE_LIST); - } else { - phases = new java.util.Vector(); - phases.add(PhaseNames.TYPE); - phases.add(PhaseNames.PLACE); - phases.add(PhaseNames.FUNCTION); - phases.add(PhaseNames.SFCONFIG); - phases.add(PhaseNames.LINK); - } - } + if (phases==null){ + Object phases_obj = sfContext.get(PHASE_LIST); + if (phases_obj!=null){ + if (!(phases_obj instanceof java.util.Vector)) throw new SmartFrogParseException("phaseList must be a primitive vector"); + phases = (java.util.Vector) phases_obj; + sfContext.remove(PHASE_LIST); + } else { + phases = new java.util.Vector(); + phases.add(PhaseNames.TYPE); + phases.add(PhaseNames.PLACE); + phases.add(PhaseNames.FUNCTION); + phases.add(PhaseNames.SFCONFIG); + phases.add(PhaseNames.LINK); + } + } return phases; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |