Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/parser Modified Files: Clause.java ClauseList.java NEClause.java NotClause.java OrClause.java Placeholder.java PlayerRolePair.java PlayerRoleVarPair.java Predicate.java Projection.java ProjectionImpl.java Sorting.java TologQuery.java TologResultsSetImpl.java TologRule.java TologRuleImpl.java TologRuleInstance.java TologRuleInstanceImpl.java Variable.java Log Message: Tabs -> Whitespaces Index: PlayerRolePair.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/PlayerRolePair.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlayerRolePair.java 9 Mar 2005 12:40:18 -0000 1.3 --- PlayerRolePair.java 8 Jul 2005 16:03:19 -0000 1.4 *************** *** 1,47 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import org.tmapiutils.query.tolog.utils.ReferenceUtils; ! // TMAPI ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PlayerRolePair { ! protected Topic m_pTopic; ! protected Topic m_rTopic; ! ! protected PlayerRolePair() { ! } ! public PlayerRolePair(Topic playerTopic, Topic roleTopic) { ! m_pTopic = playerTopic; ! m_rTopic = roleTopic; ! } ! ! public Topic getPlayerTopic() { return m_pTopic; } ! public Topic getRoleTopic() { return m_rTopic; } ! ! public String toString() { ! return ReferenceUtils.getTologReference(m_pTopic) + ":" + ReferenceUtils.getTologReference(m_rTopic); ! } ! } ! --- 1,47 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import org.tmapiutils.query.tolog.utils.ReferenceUtils; ! // TMAPI ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PlayerRolePair { ! protected Topic m_pTopic; ! protected Topic m_rTopic; ! ! protected PlayerRolePair() { ! } ! public PlayerRolePair(Topic playerTopic, Topic roleTopic) { ! m_pTopic = playerTopic; ! m_rTopic = roleTopic; ! } ! ! public Topic getPlayerTopic() { return m_pTopic; } ! public Topic getRoleTopic() { return m_rTopic; } ! ! public String toString() { ! return ReferenceUtils.getTologReference(m_pTopic) + ":" + ReferenceUtils.getTologReference(m_rTopic); ! } ! } ! Index: TologRuleImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologRuleImpl.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologRuleImpl.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,98 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologRuleImpl implements TologRule { ! ! private ClauseList m_body; ! ! private List m_headParams; ! ! private String m_name; ! ! public TologRuleImpl() { ! m_headParams = new ArrayList(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#getName() ! */ ! public String getName() { ! return m_name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#setName(java.lang.String) ! */ ! public void setName(String name) { ! m_name = name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#addParam(org.tmapiutils.query.tolog.Variable) ! */ ! public void addHeadParameter(Variable param) { ! m_headParams.add(param); ! } ! ! public void setRuleBody(ClauseList body) { ! m_body = body; ! } ! ! public ClauseList getRuleBody() { ! return m_body; ! } ! ! public List getHeadParameters() { ! return m_headParams; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#newInstance() ! */ ! public TologRuleInstance newInstance() { ! return new TologRuleInstanceImpl(this); ! } ! ! public String toString() { ! StringBuffer ret = new StringBuffer(); ! ret.append(getName()); ! ret.append("("); ! Iterator it = m_headParams.iterator(); ! while (it.hasNext()) { ! ret.append(it.next().toString()); ! if (it.hasNext()) { ! ret.append(", "); ! } ! } ! ret.append(") :- "); ! ret.append(m_body.toString()); ! ret.append("."); ! return ret.toString(); ! } ! } ! --- 1,98 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologRuleImpl implements TologRule { ! ! private ClauseList m_body; ! ! private List m_headParams; ! ! private String m_name; ! ! public TologRuleImpl() { ! m_headParams = new ArrayList(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#getName() ! */ ! public String getName() { ! return m_name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#setName(java.lang.String) ! */ ! public void setName(String name) { ! m_name = name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#addParam(org.tmapiutils.query.tolog.Variable) ! */ ! public void addHeadParameter(Variable param) { ! m_headParams.add(param); ! } ! ! public void setRuleBody(ClauseList body) { ! m_body = body; ! } ! ! public ClauseList getRuleBody() { ! return m_body; ! } ! ! public List getHeadParameters() { ! return m_headParams; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#newInstance() ! */ ! public TologRuleInstance newInstance() { ! return new TologRuleInstanceImpl(this); ! } ! ! public String toString() { ! StringBuffer ret = new StringBuffer(); ! ret.append(getName()); ! ret.append("("); ! Iterator it = m_headParams.iterator(); ! while (it.hasNext()) { ! ret.append(it.next().toString()); ! if (it.hasNext()) { ! ret.append(", "); ! } ! } ! ret.append(") :- "); ! ret.append(m_body.toString()); ! ret.append("."); ! return ret.toString(); ! } ! } ! Index: TologQuery.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologQuery.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologQuery.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologQuery.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,176 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologQuery { ! ! private ClauseList m_rootClauseList; ! private Projection m_projection; ! private Sorting m_sorting; ! private int m_pageStart; ! private int m_pageLength; ! private static final Log m_log = LogFactory.getLog(TologQuery.class); ! ! public TologQuery(ClauseList rootClauseList) { ! m_rootClauseList = rootClauseList; ! } ! ! public ClauseList getRootClauseList() { ! return m_rootClauseList; ! } ! ! /** ! * @return ! */ ! public Projection getProjection() { ! return m_projection; ! } ! ! /** ! * @param projection ! */ ! public void setProjection(Projection projection) { ! m_projection = projection; ! } ! ! /** ! * @return ! */ ! public Sorting getSorting() { ! return m_sorting; ! } ! ! /** ! * @param sorting ! */ ! public void setSorting(Sorting sorting) { ! m_sorting = sorting; ! } ! ! ! /** ! * @return ! */ ! public int getPageLength() { ! return m_pageLength; ! } ! ! /** ! * @return ! */ ! public int getPageStart() { ! return m_pageStart; ! } ! ! /** ! * @param i ! */ ! public void setPageLength(int i) { ! m_pageLength = i; ! } ! ! /** ! * @param i ! */ ! public void setPageStart(int i) { ! m_pageStart = i; ! } ! ! public TologResultsSet execute() throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! //varsIn.append(new HashMap()); ! //varsIn.addColumns(m_projection.getColumns()); ! //varsIn.addRow(m_projection.getColumns()); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! if (m_projection != null) { ! sb.append(m_projection.toString()); ! sb.append(" "); ! } ! sb.append(m_rootClauseList.toString()); ! if (m_sorting != null) { ! sb.append(" "); ! sb.append(m_sorting.toString()); ! sb.append(" "); ! } ! if (m_pageLength > 0) { ! sb.append(" limit "); ! sb.append(m_pageLength); ! sb.append(" "); ! } ! if (m_pageStart > 0) { ! sb.append("offset "); ! sb.append(m_pageStart); ! sb.append(" "); ! } ! sb.append("?"); ! return sb.toString(); ! } ! ! /** ! * @param params ! * @return ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! m_rootClauseList.doReplacement(params); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! ! } ! --- 1,176 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologQuery { ! ! private ClauseList m_rootClauseList; ! private Projection m_projection; ! private Sorting m_sorting; ! private int m_pageStart; ! private int m_pageLength; ! private static final Log m_log = LogFactory.getLog(TologQuery.class); ! ! public TologQuery(ClauseList rootClauseList) { ! m_rootClauseList = rootClauseList; ! } ! ! public ClauseList getRootClauseList() { ! return m_rootClauseList; ! } ! ! /** ! * @return ! */ ! public Projection getProjection() { ! return m_projection; ! } ! ! /** ! * @param projection ! */ ! public void setProjection(Projection projection) { ! m_projection = projection; ! } ! ! /** ! * @return ! */ ! public Sorting getSorting() { ! return m_sorting; ! } ! ! /** ! * @param sorting ! */ ! public void setSorting(Sorting sorting) { ! m_sorting = sorting; ! } ! ! ! /** ! * @return ! */ ! public int getPageLength() { ! return m_pageLength; ! } ! ! /** ! * @return ! */ ! public int getPageStart() { ! return m_pageStart; ! } ! ! /** ! * @param i ! */ ! public void setPageLength(int i) { ! m_pageLength = i; ! } ! ! /** ! * @param i ! */ ! public void setPageStart(int i) { ! m_pageStart = i; ! } ! ! public TologResultsSet execute() throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! //varsIn.append(new HashMap()); ! //varsIn.addColumns(m_projection.getColumns()); ! //varsIn.addRow(m_projection.getColumns()); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! if (m_projection != null) { ! sb.append(m_projection.toString()); ! sb.append(" "); ! } ! sb.append(m_rootClauseList.toString()); ! if (m_sorting != null) { ! sb.append(" "); ! sb.append(m_sorting.toString()); ! sb.append(" "); ! } ! if (m_pageLength > 0) { ! sb.append(" limit "); ! sb.append(m_pageLength); ! sb.append(" "); ! } ! if (m_pageStart > 0) { ! sb.append("offset "); ! sb.append(m_pageStart); ! sb.append(" "); ! } ! sb.append("?"); ! return sb.toString(); ! } ! ! /** ! * @param params ! * @return ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! m_rootClauseList.doReplacement(params); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! ! } ! Index: Variable.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Variable.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Variable.java 8 Mar 2005 12:33:40 -0000 1.2 --- Variable.java 8 Jul 2005 16:03:20 -0000 1.3 *************** *** 1,48 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Variable { ! ! private String m_name; ! public Variable(String name) { ! m_name = name; ! } ! public String getName() { return m_name; } ! ! public String toString() { ! return "$" + m_name; ! } ! ! public boolean equals(Object o) { ! if (o instanceof Variable) { ! return ((Variable)o).m_name.equals(m_name); ! } ! return false; ! } ! ! public int hashCode() { ! return m_name.hashCode(); ! } ! } ! --- 1,48 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Variable { ! ! private String m_name; ! public Variable(String name) { ! m_name = name; ! } ! public String getName() { return m_name; } ! ! public String toString() { ! return "$" + m_name; ! } ! ! public boolean equals(Object o) { ! if (o instanceof Variable) { ! return ((Variable)o).m_name.equals(m_name); ! } ! return false; ! } ! ! public int hashCode() { ! return m_name.hashCode(); ! } ! } ! Index: Projection.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Projection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Projection.java 8 Mar 2005 12:33:40 -0000 1.2 --- Projection.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,45 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Projection { ! public abstract void addVariable(Variable var); ! public abstract void addCount(Variable var); ! public abstract void addVariableSet(VariableSet varSet); ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public abstract List getColumns(); ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public abstract List getRows(); ! } ! --- 1,45 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Projection { ! public abstract void addVariable(Variable var); ! public abstract void addCount(Variable var); ! public abstract void addVariableSet(VariableSet varSet); ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public abstract List getColumns(); ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public abstract List getRows(); ! } ! Index: Sorting.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Sorting.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Sorting.java 8 Mar 2005 12:33:40 -0000 1.2 --- Sorting.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,107 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Collections; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.DefaultRowComparator; ! import org.tmapiutils.query.tolog.utils.InvertedComparator; ! import org.tmapiutils.query.tolog.utils.RowComparator; ! ! /** ! * Represents the sorting part of a tolog query. This class keeps track ! * of the sort columns and the sort direction and provides a method for ! * sorting a projection. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Sorting { ! ! private List m_sortCols = new ArrayList(); ! private boolean m_sortAscending = true; ! private RowComparator m_rowComparator = null; ! private Comparator m_invRowComparator; ! ! public void addSort(Variable sortVar) { ! m_sortCols.add(sortVar); ! } ! ! public void setSortAscending(boolean sortAscending) { ! m_sortAscending = sortAscending; ! } ! ! /** ! * Sorts a list of results rows by this class's sorting criteria. The sort ! * is executed as an in-place sort of <code>rows</code>, so the ! * List returned by this method is in fact the same List object passed ! * in in the <code>rows</code> parameter. ! * @param columns the column headings for the list data to be sorted ! * @param rows the list data to be sorted ! * @return the list data sorted by the sorting criteria of this class. ! * @throws TologProcessingException if one of the sort columns set on ! * this Sorting instance cannot be found in the <code>columns</code> ! * list passed into the method. ! */ ! public List sort(List columns, List rows) throws TologProcessingException { ! if (m_sortCols.isEmpty()) return rows; ! if (m_rowComparator == null) { ! m_rowComparator = new DefaultRowComparator(); ! m_invRowComparator = new InvertedComparator(m_rowComparator); ! } ! Iterator c = m_sortCols.iterator(); ! while (c.hasNext()) { ! Object col = c.next(); ! int sortIx = columns.indexOf(col); ! if (sortIx == -1) { ! throw new TologProcessingException("Attempt to sort on non-existent column '" + col.toString() + "'"); ! } ! m_rowComparator.addSortColumn(sortIx); ! } ! Collections.sort(rows, m_sortAscending ? m_rowComparator : m_invRowComparator); ! return rows; ! } ! ! public String toString() { ! if (m_sortCols.isEmpty()) { ! return ""; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("order by "); ! Iterator it = m_sortCols.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(","); ! } ! sb.append(" "); ! } ! if (m_sortAscending) { ! sb.append("asc"); ! } else { ! sb.append("desc"); ! } ! return sb.toString(); ! } ! } ! --- 1,107 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Collections; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.DefaultRowComparator; ! import org.tmapiutils.query.tolog.utils.InvertedComparator; ! import org.tmapiutils.query.tolog.utils.RowComparator; ! ! /** ! * Represents the sorting part of a tolog query. This class keeps track ! * of the sort columns and the sort direction and provides a method for ! * sorting a projection. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Sorting { ! ! private List m_sortCols = new ArrayList(); ! private boolean m_sortAscending = true; ! private RowComparator m_rowComparator = null; ! private Comparator m_invRowComparator; ! ! public void addSort(Variable sortVar) { ! m_sortCols.add(sortVar); ! } ! ! public void setSortAscending(boolean sortAscending) { ! m_sortAscending = sortAscending; ! } ! ! /** ! * Sorts a list of results rows by this class's sorting criteria. The sort ! * is executed as an in-place sort of <code>rows</code>, so the ! * List returned by this method is in fact the same List object passed ! * in in the <code>rows</code> parameter. ! * @param columns the column headings for the list data to be sorted ! * @param rows the list data to be sorted ! * @return the list data sorted by the sorting criteria of this class. ! * @throws TologProcessingException if one of the sort columns set on ! * this Sorting instance cannot be found in the <code>columns</code> ! * list passed into the method. ! */ ! public List sort(List columns, List rows) throws TologProcessingException { ! if (m_sortCols.isEmpty()) return rows; ! if (m_rowComparator == null) { ! m_rowComparator = new DefaultRowComparator(); ! m_invRowComparator = new InvertedComparator(m_rowComparator); ! } ! Iterator c = m_sortCols.iterator(); ! while (c.hasNext()) { ! Object col = c.next(); ! int sortIx = columns.indexOf(col); ! if (sortIx == -1) { ! throw new TologProcessingException("Attempt to sort on non-existent column '" + col.toString() + "'"); ! } ! m_rowComparator.addSortColumn(sortIx); ! } ! Collections.sort(rows, m_sortAscending ? m_rowComparator : m_invRowComparator); ! return rows; ! } ! ! public String toString() { ! if (m_sortCols.isEmpty()) { ! return ""; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("order by "); ! Iterator it = m_sortCols.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(","); ! } ! sb.append(" "); ! } ! if (m_sortAscending) { ! sb.append("asc"); ! } else { ! sb.append("desc"); ! } ! return sb.toString(); ! } ! } ! Index: TologRuleInstance.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleInstance.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologRuleInstance.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologRuleInstance.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,30 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologRuleInstance extends Predicate { ! ! ! } ! --- 1,30 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologRuleInstance extends Predicate { ! ! ! } ! Index: ProjectionImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/ProjectionImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProjectionImpl.java 8 Mar 2005 12:33:40 -0000 1.3 --- ProjectionImpl.java 8 Jul 2005 16:03:19 -0000 1.4 *************** *** 1,189 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionImpl implements Projection { ! private List m_columns; ! private List m_rows; ! ! private static final Log m_log = LogFactory.getLog(ProjectionImpl.class); ! ! public ProjectionImpl () { ! m_columns = new ArrayList(); ! m_rows = new ArrayList(); ! } ! ! public void addVariable(Variable var) { ! m_columns.add(var); ! } ! ! public void addCount(Variable var) { ! m_columns.add(new Count(var)); ! } ! ! public void addVariableSet(VariableSet varSet) { ! if (m_columns.isEmpty()) { ! Iterator it = varSet.getColumns().iterator(); ! while (it.hasNext()) { ! m_columns.add((Variable)it.next()); ! } ! } ! int max = varSet.size(); ! for (int i = 0; i < max; i++) { ! List srcRow = varSet.getRow(i); ! List newRow = new ArrayList(); ! Iterator it = m_columns.iterator(); ! while (it.hasNext()) { ! Object c = it.next(); ! if (c instanceof Count) { ! int ix = varSet.indexOf(((Count)c).getVariable()); ! Object srcVal = srcRow.get(ix); ! if (((srcRow == null) || (srcRow.get(ix) instanceof Variable))) { ! newRow.add(new Integer(0)); ! } else { ! newRow.add(new Integer(1)); ! } ! } else { ! int ix = varSet.indexOf((Variable)c); ! Object srcVal = srcRow.get(ix); ! if ((srcRow == null) || (srcVal instanceof Variable)) { ! newRow.add(null); ! } else { ! newRow.add(srcVal); ! } ! } ! } ! ! if (m_log.isDebugEnabled()) debugRow("Adding new row: ", newRow); ! boolean hasMatch = false; ! it = m_rows.iterator(); ! while (!hasMatch && it.hasNext()) { ! List row = (List)it.next(); ! if (m_log.isDebugEnabled()) debugRow(" Compare to ", row); ! hasMatch = compareRows(newRow, row); ! if (hasMatch) { ! m_log.debug("New row matches existing row. Updating counts..."); ! // Just add the count parts to the matched row's counts ! for (int col = 0; col < row.size(); col++) { ! if (m_columns.get(col) instanceof Count) { ! int count = ((Integer)row.get(col)).intValue(); ! count += ((Integer)newRow.get(col)).intValue(); ! row.set(col, new Integer(count)); ! } ! } ! } ! } ! if (!hasMatch) { ! m_log.debug("Adding new row to projection."); ! m_rows.add(newRow); ! } ! } ! } ! ! private boolean compareRows(List r1, List r2) { ! for (int col = 0; col < r1.size(); col++) { ! if (m_columns.get(col) instanceof Count) continue; ! Object v1 = r1.get(col); ! Object v2 = r2.get(col); ! if ((v1 == null && v2 != null) || (v2 == null && v1 != null)) { ! return false; ! } else if (v1 == null && v2 == null) { ! return true; ! } else if (!(r1.get(col).equals(r2.get(col)))) { ! return false; ! } ! } ! return true; ! } ! ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public List getColumns() { ! return m_columns; ! } ! ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public List getRows() { ! return m_rows; ! } ! ! public class Count { ! private Variable m_var; ! public Count(Variable var) { m_var = var; } ! public String getVarName() { return m_var.getName(); } ! public Variable getVariable() { return m_var; } ! public String toString() { ! return "count($" + m_var.getName() + ")"; ! } ! } ! ! private void debugRow(String msg, List row) { ! StringBuffer m = new StringBuffer(); ! m.append(msg); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! m.append(((TopicMapObject)o).getObjectId()); ! } else { ! m.append(String.valueOf(o)); ! } ! if (it.hasNext()) { ! m.append(", "); ! } ! } ! m_log.debug(m.toString()); ! } ! ! public String toString() { ! if (m_columns.isEmpty()) { ! return "select * from"; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("select"); ! Iterator it = m_columns.iterator(); ! while(it.hasNext()) { ! sb.append(" "); ! sb.append(it.next().toString()); ! if (it.hasNext()) sb.append(","); ! } ! sb.append(" from"); ! return sb.toString(); ! } ! } ! --- 1,189 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionImpl implements Projection { ! private List m_columns; ! private List m_rows; ! ! private static final Log m_log = LogFactory.getLog(ProjectionImpl.class); ! ! public ProjectionImpl () { ! m_columns = new ArrayList(); ! m_rows = new ArrayList(); ! } ! ! public void addVariable(Variable var) { ! m_columns.add(var); ! } ! ! public void addCount(Variable var) { ! m_columns.add(new Count(var)); ! } ! ! public void addVariableSet(VariableSet varSet) { ! if (m_columns.isEmpty()) { ! Iterator it = varSet.getColumns().iterator(); ! while (it.hasNext()) { ! m_columns.add((Variable)it.next()); ! } ! } ! int max = varSet.size(); ! for (int i = 0; i < max; i++) { ! List srcRow = varSet.getRow(i); ! List newRow = new ArrayList(); ! Iterator it = m_columns.iterator(); ! while (it.hasNext()) { ! Object c = it.next(); ! if (c instanceof Count) { ! int ix = varSet.indexOf(((Count)c).getVariable()); ! Object srcVal = srcRow.get(ix); ! if (((srcRow == null) || (srcRow.get(ix) instanceof Variable))) { ! newRow.add(new Integer(0)); ! } else { ! newRow.add(new Integer(1)); ! } ! } else { ! int ix = varSet.indexOf((Variable)c); ! Object srcVal = srcRow.get(ix); ! if ((srcRow == null) || (srcVal instanceof Variable)) { ! newRow.add(null); ! } else { ! newRow.add(srcVal); ! } ! } ! } ! ! if (m_log.isDebugEnabled()) debugRow("Adding new row: ", newRow); ! boolean hasMatch = false; ! it = m_rows.iterator(); ! while (!hasMatch && it.hasNext()) { ! List row = (List)it.next(); ! if (m_log.isDebugEnabled()) debugRow(" Compare to ", row); ! hasMatch = compareRows(newRow, row); ! if (hasMatch) { ! m_log.debug("New row matches existing row. Updating counts..."); ! // Just add the count parts to the matched row's counts ! for (int col = 0; col < row.size(); col++) { ! if (m_columns.get(col) instanceof Count) { ! int count = ((Integer)row.get(col)).intValue(); ! count += ((Integer)newRow.get(col)).intValue(); ! row.set(col, new Integer(count)); ! } ! } ! } ! } ! if (!hasMatch) { ! m_log.debug("Adding new row to projection."); ! m_rows.add(newRow); ! } ! } ! } ! ! private boolean compareRows(List r1, List r2) { ! for (int col = 0; col < r1.size(); col++) { ! if (m_columns.get(col) instanceof Count) continue; ! Object v1 = r1.get(col); ! Object v2 = r2.get(col); ! if ((v1 == null && v2 != null) || (v2 == null && v1 != null)) { ! return false; ! } else if (v1 == null && v2 == null) { ! return true; ! } else if (!(r1.get(col).equals(r2.get(col)))) { ! return false; ! } ! } ! return true; ! } ! ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public List getColumns() { ! return m_columns; ! } ! ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public List getRows() { ! return m_rows; ! } ! ! public class Count { ! private Variable m_var; ! public Count(Variable var) { m_var = var; } ! public String getVarName() { return m_var.getName(); } ! public Variable getVariable() { return m_var; } ! public String toString() { ! return "count($" + m_var.getName() + ")"; ! } ! } ! ! private void debugRow(String msg, List row) { ! StringBuffer m = new StringBuffer(); ! m.append(msg); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! m.append(((TopicMapObject)o).getObjectId()); ! } else { ! m.append(String.valueOf(o)); ! } ! if (it.hasNext()) { ! m.append(", "); ! } ! } ! m_log.debug(m.toString()); ! } ! ! public String toString() { ! if (m_columns.isEmpty()) { ! return "select * from"; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("select"); ! Iterator it = m_columns.iterator(); ! while(it.hasNext()) { ! sb.append(" "); ! sb.append(it.next().toString()); ! if (it.hasNext()) sb.append(","); ! } ! sb.append(" from"); ! return sb.toString(); ! } ! } ! Index: Clause.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Clause.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Clause.java 8 Mar 2005 12:33:40 -0000 1.2 --- Clause.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,39 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Clause { ! ! public void doReplacement(Object[] params) throws TologProcessingException; ! ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException; ! ! public List getVariables(); ! } ! --- 1,39 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Clause { ! ! public void doReplacement(Object[] params) throws TologProcessingException; ! ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException; ! ! public List getVariables(); ! } ! Index: OrClause.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/OrClause.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OrClause.java 8 Mar 2005 12:33:40 -0000 1.2 --- OrClause.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,97 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class OrClause implements Clause { ! ! private List m_children; ! private List m_vars; ! private static final Log m_log = LogFactory.getLog(OrClause.class); ! ! public OrClause() { ! m_children = new ArrayList(); ! m_vars = new ArrayList(); ! } ! ! public void add(Clause c) { ! m_children.add(c); ! Iterator it = c.getVariables().iterator(); ! while (it.hasNext()) { ! Variable v = (Variable)it.next(); ! if (!m_vars.contains(v)) { ! m_vars.add(v); ! } ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Clause#execute(org.tmapiutils.query.tolog.VariableSet) ! */ ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException { ! if (m_log.isDebugEnabled()) m_log.debug("Start OR " + toString()); ! VariableSet ret = new VariableSet(); ! Iterator it = m_children.iterator(); ! while (it.hasNext()) { ! ret.add(((Clause)it.next()).execute((VariableSet) in.clone(), context)); ! } ! if (m_log.isDebugEnabled()) m_log.debug("End OR " + toString()); ! return ret; ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! sb.append("{ "); ! Iterator it = m_children.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(" | "); ! } ! } ! sb.append(" }"); ! return sb.toString(); ! } ! ! public List getVariables() { ! return m_vars; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Clause#doReplacement(java.lang.Object[]) ! */ ! public void doReplacement(Object[] params) throws TologProcessingException { ! for (Iterator it = m_children.iterator(); it.hasNext();) { ! ((Clause)it.next()).doReplacement(params); ! } ! } ! } --- 1,97 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the s... [truncated message content] |