You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2010/02/16 18:16:02 UTC
svn commit: r910600 [11/29] - in /db/torque/torque4/trunk:
maven-torque-gf-plugin/ maven-torque-gf-plugin/src/
maven-torque-gf-plugin/src/main/ maven-torque-gf-plugin/src/main/java/
maven-torque-gf-plugin/src/main/java/org/ maven-torque-gf-plugin/src/m...
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/RichSourceElementImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/RichSourceElementImpl.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/RichSourceElementImpl.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/RichSourceElementImpl.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,546 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Implementation of the RichSourceElement interface.
+ */
+public class RichSourceElementImpl
+ implements RichSourceElement, SourceElement
+{
+ /**
+ * The name of the source element.
+ */
+ private String name;
+
+ /**
+ * The parents of this element; may be empty but not null.
+ */
+ private List<SourceElement> parents = new ArrayList<SourceElement>();
+
+ /**
+ * All children elements.
+ */
+ private List<SourceElement> children = new ArrayList<SourceElement>();
+
+ /**
+ * the source element's attributes.
+ */
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ /**
+ * Constructor.
+ *
+ * @param name the name of the element, not null.
+ *
+ * @throws NullPointerException if name is null.
+ */
+ public RichSourceElementImpl(String name)
+ {
+ if (name == null)
+ {
+ throw new NullPointerException("name must not be null");
+ }
+ this.name = name;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name sourceElementName name of the element, not null.
+ *
+ * @throws NullPointerException if sourceElementName is null.
+ */
+ public RichSourceElementImpl(SourceElementName sourceElementName)
+ {
+ this(sourceElementName.getName());
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public SourceElement getParent()
+ {
+ if (parents.size() == 0)
+ {
+ return null;
+ }
+ return parents.get(0);
+ }
+
+ public void addParent(SourceElement parent)
+ {
+ if (parent == null)
+ {
+ throw new NullPointerException("parent must not be null");
+ }
+ parents.add(parent);
+ // We can use contains here as we did not overwrite the equals()
+ // and hassCode() methods.
+ if (!parent.getChildren().contains(this))
+ {
+ parent.addChild(this);
+ }
+ }
+
+ public List<SourceElement> getParents()
+ {
+ return parents;
+ }
+
+ public List<SourceElement> getChildren()
+ {
+ return children;
+ }
+
+ public void addChild(SourceElement child)
+ {
+ if (child == null)
+ {
+ throw new NullPointerException("child must not be null");
+ }
+ children.add(child);
+
+ // We can use contains here as we did not overwrite the equals()
+ // and hassCode() methods.
+ if (!child.getParents().contains(this))
+ {
+ child.addParent(this);
+ }
+ }
+
+ public void addChild(int position, SourceElement child)
+ {
+ if (child == null)
+ {
+ throw new NullPointerException("child must not be null");
+ }
+ children.add(position, child);
+
+ // We can use contains here as we did not overwrite the equals()
+ // and hashCode() methods.
+ if (!child.getParents().contains(this))
+ {
+ child.addParent(this);
+ }
+ }
+
+ public SourceElement removeChild(SourceElement toRemove)
+ {
+ if (toRemove == null)
+ {
+ throw new NullPointerException("toRemove must not be null");
+ }
+ Iterator<SourceElement> childIt = children.iterator();
+ while (childIt.hasNext())
+ {
+ SourceElement candidate = childIt.next();
+ if (candidate == toRemove)
+ {
+ childIt.remove();
+ return candidate;
+ }
+ }
+ return null;
+ }
+
+ public List<SourceElement> getChildren(String name)
+ {
+ if (name == null)
+ {
+ throw new NullPointerException("name must not be null");
+ }
+ List<SourceElement> result = new ArrayList<SourceElement>();
+ for (SourceElement sourceElement : children)
+ {
+ if (name.equals(sourceElement.getName()))
+ {
+ result.add(sourceElement);
+ }
+ }
+ return result;
+ }
+
+ public List<SourceElement> getChildren(SourceElementName sourceElementName)
+ {
+ return getChildren(sourceElementName.getName());
+ }
+
+ public SourceElement getChild(String name)
+ {
+ for (SourceElement sourceElement : children)
+ {
+ if (name.equals(sourceElement.getName()))
+ {
+ return sourceElement;
+ }
+ }
+ return null;
+ }
+
+ public SourceElement getChild(SourceElementName sourceElementName)
+ {
+ return getChild(sourceElementName.getName());
+ }
+
+ public boolean hasChild(String name)
+ {
+ return SourcePath.hasChild(this, name);
+ }
+
+ public int getChildIndex(SourceElement child)
+ {
+ return children.indexOf(child);
+ }
+
+
+ /**
+ * Returns all the following elements after this element
+ * with the given name.
+ * If name is null, all following elements are returned.
+ * If this element has no parent, an empty list is returned.
+ * @param name the name of the following elements to select,
+ * or null to select all following elements.
+ * @return a list containing the following elements with the given name,
+ * never null.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes"></a>
+ */
+ public List<SourceElement> getFollowing(String name)
+ {
+ return SourcePath.getFollowing(this, name);
+ }
+
+ public boolean hasFollowing()
+ {
+ return SourcePath.hasFollowing(this);
+ }
+
+ public boolean hasPreceding()
+ {
+ return SourcePath.hasPreceding(this);
+ }
+
+ public boolean hasFollowingSibling()
+ {
+ return SourcePath.hasFollowingSibling(this);
+ }
+
+ public boolean hasPrecedingSibling()
+ {
+ return SourcePath.hasPrecedingSibling(this);
+ }
+
+ /**
+ * Returns all the preceding elements before this element
+ * with the given name.
+ * If name is null, all preceding elements are returned.
+ * If this element has no parent, an empty list is returned.
+ * @param name the name of the preceding elements to select,
+ * or null to select all preceding elements.
+ * @return a list containing the following elements with the given name,
+ * never null.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes"></a>
+ */
+ public List<SourceElement> getPreceding(String name)
+ {
+ return SourcePath.getPreceding(this, name);
+ }
+
+ public Object getAttribute(String name)
+ {
+ return attributes.get(name);
+ }
+
+ public Object getAttribute(SourceAttributeName sourceAttributeName)
+ {
+ return getAttribute(sourceAttributeName.getName());
+ }
+
+ public Object setAttribute(String name, Object value)
+ {
+ if (value == null)
+ {
+ return attributes.remove(name);
+ }
+ return attributes.put(name, value);
+ }
+
+ public Object setAttribute(
+ SourceAttributeName sourceAttributeName,
+ Object value)
+ {
+ return setAttribute(sourceAttributeName.getName(), value);
+ }
+
+ public Set<String> getAttributeNames()
+ {
+ return attributes.keySet();
+ }
+
+ /**
+ * Creates a deep copy of this RichSourceelementImpl object.
+ *
+ * @return the copy, not null.
+ */
+ public RichSourceElementImpl copy()
+ {
+ Map<SourceElement, RichSourceElementImpl> copied
+ = new HashMap<SourceElement, RichSourceElementImpl>();
+ return copy(this, copied);
+ }
+
+ /**
+ * Deep copies the content of one RichSourceElementImpl object into another.
+ *
+ * @param toCopy the source element, not null.
+ * @param copiedElements Map containing all source elements which are
+ * already copied.
+ *
+ * @return the copy of the source, not null.
+ */
+ private RichSourceElementImpl copy(SourceElement toCopy,
+ Map<SourceElement, RichSourceElementImpl> copiedElements)
+ {
+ RichSourceElementImpl copied = copiedElements.get(toCopy);
+ if (copied != null)
+ {
+ return copied;
+ }
+ copied = new RichSourceElementImpl(toCopy.getName());
+ copiedElements.put(toCopy, copied);
+
+ for (String attributeName : toCopy.getAttributeNames())
+ {
+ copied.setAttribute(attributeName, toCopy.getAttribute(attributeName));
+ }
+
+ for (SourceElement child : toCopy.getChildren())
+ {
+ RichSourceElementImpl copiedChild = copy(child, copiedElements);
+ copied.addChild(copiedChild);
+ }
+
+ for (SourceElement parent : toCopy.getParents())
+ {
+ RichSourceElementImpl copiedParent
+ = copy(parent, copiedElements);
+ // do not use setParent because this will add copied as a child
+ // to copiedParent. Later on, when processing the children of
+ // copiedParent, it will be added again.
+ copied.parents.add(copiedParent);
+ }
+
+ return copied;
+ }
+
+ /**
+ * Checks whether the source element graph of this sourceElement,
+ * and its position therein, equals the source element graph
+ * and the position of the provided SourceElement.
+ * This is an expensive operation if the graphs are large.
+ *
+ * @param toCompare the source element to compare, may be null.
+ *
+ * @return true if all source elements in the toCompare tree have the equal
+ * content as the source elements in this tree.
+ */
+ public boolean graphEquals(SourceElement toCompare)
+ {
+ Set<SourceElement> alreadyCompared = new HashSet<SourceElement>();
+ return graphEquals(this, toCompare, alreadyCompared);
+ }
+
+ /**
+ * Checks whether the source element graph of one sourceElement,
+ * and its position therein, equals the source element graph
+ * and the position of another SourceElement.
+ * This is an expensive operation if the graphs are large.
+ *
+ * @param reference the reference element, may be null.
+ * @param toCompare the element which is to the referenced element,
+ * may be null.
+ * @param compared a set of elements which are already compared
+ * and which attributes and relative positions to the other
+ * compared elements were equal so far.
+ * @return true if the elements are equal or if equality is currently
+ * checked in another recursive iteration.
+ */
+ private boolean graphEquals(SourceElement reference,
+ SourceElement toCompare,
+ Set<SourceElement> compared)
+ {
+ if ((reference == null && toCompare != null)
+ || (reference != null && toCompare == null))
+ {
+ return false;
+ }
+ if (reference == null && toCompare == null)
+ {
+ return true;
+ }
+
+ if (compared.contains(reference))
+ {
+ // although it is not certain that reference is equal to toCompare
+ // if it is contained in compared, it does mean that equality
+ // was or is being checked and that place will return false
+ // if equality is not given; so we can return true here.
+ return true;
+ }
+
+ compared.add(reference);
+
+ if (!reference.getName().equals(toCompare.getName()))
+ {
+ return false;
+ }
+
+ if (reference.getAttributeNames().size()
+ != toCompare.getAttributeNames().size())
+ {
+ return false;
+ }
+
+ for (String attributeName : reference.getAttributeNames())
+ {
+ Object referenceAttributeContent
+ = reference.getAttribute(attributeName);
+ Object toCompareAttributeContent
+ = toCompare.getAttribute(attributeName);
+ if (referenceAttributeContent == null)
+ {
+ if (toCompareAttributeContent != null)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (!referenceAttributeContent.equals(
+ toCompareAttributeContent))
+ {
+ return false;
+ }
+ }
+ }
+
+ if (!graphEquals(reference.getParent(), toCompare.getParent(), compared))
+ {
+ return false;
+ }
+
+ if (reference.getChildren().size()
+ != toCompare.getChildren().size())
+ {
+ return false;
+ }
+
+ Iterator<SourceElement> referenceChildIt
+ = reference.getChildren().iterator();
+ Iterator<SourceElement> toCompareChildIt
+ = toCompare.getChildren().iterator();
+ while (referenceChildIt.hasNext())
+ {
+ SourceElement referenceChild = referenceChildIt.next();
+ SourceElement toCompareChild = toCompareChildIt.next();
+ if (!graphEquals(referenceChild, toCompareChild, compared))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ Set<SourceElement> alreadyProcessed = new HashSet<SourceElement>();
+ StringBuilder result = new StringBuilder();
+ toString(alreadyProcessed, result);
+ return result.toString();
+ }
+
+ /**
+ * Creates a String representation of the element for debugging purposes.
+ * @param alreadyProcessed the elements which are already processed
+ * (for avoiding loops). The current element is added to this set.
+ * @param result the String builder to which the string representation
+ * should be appended.
+ */
+ private void toString(
+ Set<SourceElement> alreadyProcessed,
+ StringBuilder result)
+ {
+ alreadyProcessed.add(this);
+ result.append("(name=").append(name)
+ .append(",attributes=(");
+ Iterator<Map.Entry<String, Object>> entryIt
+ = attributes.entrySet().iterator();
+ while (entryIt.hasNext())
+ {
+ Map.Entry<String, Object> entry = entryIt.next();
+ result.append(entry.getKey()).append("=").append(entry.getValue());
+ if (entryIt.hasNext())
+ {
+ result.append(",");
+ }
+ }
+ result.append("),children=(");
+ Iterator<SourceElement> childIt = children.iterator();
+ while (childIt.hasNext())
+ {
+ SourceElement child = childIt.next();
+ if (alreadyProcessed.contains(child))
+ {
+ result.append("<<loop detected>>");
+ }
+ else
+ {
+ if (child instanceof RichSourceElementImpl)
+ {
+
+ ((RichSourceElementImpl) child).toString(
+ alreadyProcessed, result);
+ }
+ else
+ {
+ result.append(child);
+ }
+ }
+ if (childIt.hasNext())
+ {
+ result.append(",");
+ }
+ }
+ result.append("))");
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SimpleSourcesImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SimpleSourcesImpl.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SimpleSourcesImpl.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SimpleSourcesImpl.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,122 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.torque.gf.configuration.ClassHelper;
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.source.filter.SourceFilter;
+
+/**
+ * A collection of Sources, which all have the same elements,
+ * Source filters and transformerDefinitions.
+ */
+public abstract class SimpleSourcesImpl implements Sources
+{
+ /**
+ * The elements which should be used as starting points for generation.
+ */
+ private String startElementsPath;
+
+ /**
+ * The source transformers which are executed when transform() is called.
+ */
+ private List<TransformerDefinition> transformerDefinitions
+ = new ArrayList<TransformerDefinition>();
+
+ /**
+ * The source filter, or null if none exists.
+ */
+ private SourceFilter sourceFilter;
+
+ /**
+ * Constructor.
+ *
+ * @param startElementsPath the path to the elements which are used
+ * as starting points for generation,
+ * or null if the root element should be used.
+ * @param sourceFilter the fully qualified class name of the source filter,
+ * or null. The referenced class must have a standard constructor.
+ *
+ * @throws ConfigurationException if the source filter cannot be
+ * instantiated.
+ */
+ protected SimpleSourcesImpl(
+ String startElementsPath,
+ String sourceFilter,
+ List<TransformerDefinition> transformerDefinitions)
+ throws ConfigurationException
+ {
+ this.startElementsPath = startElementsPath;
+ if (transformerDefinitions == null)
+ {
+ this.transformerDefinitions
+ = new ArrayList<TransformerDefinition>();
+ }
+ else
+ {
+ this.transformerDefinitions
+ = new ArrayList<TransformerDefinition>(
+ transformerDefinitions);
+ }
+
+ if (sourceFilter != null)
+ {
+ this.sourceFilter = (SourceFilter) ClassHelper.getInstance(
+ sourceFilter,
+ SourceFilter.class);
+ }
+ }
+
+ /**
+ * Returns the path to elements which should be used as starting points for
+ * generation.
+ *
+ * @return the elements to use, or null, in which case the root element
+ * is used.
+ */
+ public String getStartElementsPath()
+ {
+ return startElementsPath;
+ }
+
+ /**
+ * Return all currently registered transformer definitions.
+ *
+ * @return the transformer definitions, not null.
+ */
+ public List<TransformerDefinition> getTransformerDefinitions()
+ {
+ return Collections.unmodifiableList(transformerDefinitions);
+ }
+
+ /**
+ * Returns the current source filter.
+ *
+ * @return the current source filter, or null.
+ */
+ public SourceFilter getSourceFilter()
+ {
+ return sourceFilter;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Source.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Source.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Source.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Source.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,90 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.torque.gf.source.filter.SourceFilter;
+
+/**
+ * An entity which serves as an input for the generation process.
+ */
+public interface Source
+{
+ /**
+ * Returns the root element of the source.
+ *
+ * @return the root element of the source, not null.
+ *
+ * @throws SourceException if the source cannot be constructed.
+ */
+ SourceElement getRootElement() throws SourceException;
+
+ /**
+ * Returns the path to the elements which are selected as start elements
+ * from the transformed source.
+ *
+ * @return a path to the start elements, null for the root element.
+ */
+ String getStartElementsPath();
+
+ /**
+ * Returns the definitions for the source transformers which are
+ * executed before the generation process
+ *
+ * @return the source transformer definitions, not null.
+ * The first transformer in the list is executed first.
+ */
+ List<TransformerDefinition> getTransformerDefinitions()
+ throws SourceException;
+
+ /**
+ * The configured source filter, or null if there is no source filter
+ * for this source.
+ *
+ * The source filter must be executed after the file name is generated
+ * and the current source element and the options are set to the controller
+ * state.
+ *
+ * If its proceed(ControllerState) method returns false, generation of
+ * the current output file must be skipped. If no SourceFilter exists,
+ * generation proceeds.
+ *
+ * @return the source filter, or null.
+ */
+ SourceFilter getSourceFilter();
+
+ /**
+ * Gets a description of this source for debugging purposes.
+ *
+ * @return the description, which should make it possible to identify
+ * the currently processed output.
+ */
+ String getDescription();
+
+ /**
+ * Returns the source file, if it exists.
+ *
+ * @return the source file, or null if the source is not read from a file.
+ * @return
+ */
+ File getSourceFile();
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceAttributeName.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceAttributeName.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceAttributeName.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,36 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * An interface for a class respresenting the name of a source attribute.
+ * This is useful e.g. if enums are defined for attribute names.
+ *
+ * $Id: $
+ */
+public interface SourceAttributeName
+{
+ /**
+ * returns the name of the attribute.
+ *
+ * @return the name of the attribute, not null.
+ */
+ String getName();
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElement.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElement.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElement.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElement.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,189 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A Source element within the Source Graph.
+ */
+public interface SourceElement
+{
+ /**
+ * Returns the name of this source element.
+ *
+ * @return the name of this source element, never null.
+ */
+
+ String getName();
+
+ /**
+ * Returns the primary parent of this SourceElement.
+ *
+ * @return the primary parent of this SourceElement,
+ * or null if this is a root element of the source graph.
+ */
+ SourceElement getParent();
+
+ /**
+ * Returns the list of parents of this SourceElement.
+ *
+ * @return the list of parents of this source element, never null.
+ */
+ List<SourceElement> getParents();
+
+ /**
+ * Adds a parent to the parents of this SourceElement.
+ * This automatically adds this element as a child of the passed
+ * SourceElement, if it is not yet a child.
+ *
+ * @param parent the source element which should be added as a parent,
+ * not null.
+ */
+ void addParent(SourceElement parent);
+
+ /**
+ * Returns the list of children of this SourceElement.
+ *
+ * @return the list of children of this source element, never null.
+ */
+ List<SourceElement> getChildren();
+
+ /**
+ * Returns the list of children of this SourceElement which have
+ * the given name.
+ *
+ * @param name the name of the children to select, not null.
+ *
+ * @return the list of children of this source element with the given name,
+ * never null.
+ *
+ * @throws NullPointerException if name is null.
+ */
+ List<SourceElement> getChildren(String name);
+
+ /**
+ * Returns the list of children of this SourceElement which have
+ * the given name.
+ *
+ * @param sourceElementName contains the name of the child to select,
+ * not null.
+ *
+ * @return the list of children of this source element with the given name,
+ * never null.
+ *
+ * @throws NullPointerException if sourceElementName is null.
+ */
+ List<SourceElement> getChildren(SourceElementName sourceElementName);
+
+ /**
+ * Returns the first child of this SourceElement which has
+ * the given name.
+ *
+ * @param name the name of the child to select, not null.
+ *
+ * @return the first child with the given name, or null if no child with
+ * the given name exits.
+ *
+ * @throws NullPointerException if name is null.
+ */
+ SourceElement getChild(String name);
+
+ /**
+ * Returns the first child of this SourceElement which has
+ * the given name.
+ *
+ * @param sourceElementName contains the name of the child to select,
+ * not null.
+ *
+ * @return the first child with the given name, or null if no child with
+ * the given name exits.
+ *
+ * @throws NullPointerException if sourceElementName is null.
+ */
+ SourceElement getChild(SourceElementName sourceElementName);
+
+ /**
+ * Adds a Child element to this SourceElement. This element is added to the
+ * list of parents of the Source element.
+ *
+ * @param child the child to be added, not null.
+ *
+ * @throws NullPointerException if child is null.
+ */
+ void addChild(SourceElement child);
+
+ void addChild(int position, SourceElement child);
+
+ SourceElement removeChild(SourceElement child);
+
+ int getChildIndex(SourceElement child);
+
+ /**
+ * Returns the object stored in a given attribute.
+ *
+ * @param name the name of the attribute, can be null.
+ *
+ * @return the stored object, or null if no object is stored under that key.
+ */
+ Object getAttribute(String name);
+
+ /**
+ * Returns the object stored in a given attribute.
+ *
+ * @param sourceAttributeName contains the name of the attribute, not null.
+ *
+ * @return the stored object, or null if no object is stored under that key.
+ *
+ * @throws NullPointerException if sourceAttributeName is null.
+ */
+ Object getAttribute(SourceAttributeName sourceAttributeName);
+
+ /**
+ * Returns the name of all set attributes. Note : null may be contained
+ * in the set.
+ *
+ * @return the name of all set values.
+ */
+ Set<String> getAttributeNames();
+
+ /**
+ * Sets the attribute of a Source element.
+ *
+ * @param name the name of the attribute.
+ * @param value the value of the attribute,
+ * or null to remove the attribute.
+ *
+ * @return the previous value of this attribute.
+ */
+ Object setAttribute(String name, Object value);
+
+ /**
+ * Sets the attribute of a Source element.
+ *
+ * @param sourceAttributeName contains the name of the attribute, not null.
+ * @param value the value of the attribute,
+ * or null to remove the attribute.
+ *
+ * @return the previous value of this attribute.
+ */
+ Object setAttribute(SourceAttributeName sourceAttributeName, Object value);
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElementName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElementName.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElementName.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceElementName.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,36 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * An interface for a class respresenting the name of a source element.
+ * This is useful e.g. if enums are defined for element names.
+ *
+ * $Id: $
+ */
+public interface SourceElementName
+{
+ /**
+ * returns the name of the source element.
+ *
+ * @return the name of the source element, not null.
+ */
+ String getName();
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceException.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceException.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceException.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,80 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * This exception denotes that the source for a generator cannot be processed.
+ */
+public class SourceException extends Exception
+{
+ /**
+ * The version of the class
+ * (for serialisation and deserialisation purposes).
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructs a SourceException without error message.
+ *
+ * @see Exception#Exception()
+ */
+ public SourceException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a SourceException with the given error message.
+ *
+ * @param message the error message
+ *
+ * @see Exception#Exception(java.lang.String)
+ */
+ public SourceException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs a SourceException which wraps another exception.
+ *
+ * @param cause The root cause of the exception, can be null.
+ *
+ * @see Exception#Exception(java.lang.Throwable)
+ */
+ public SourceException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructs a SourceException which wraps another exception,
+ * and which has its own error message.
+ *
+ * @param message The error mesaage.
+ * @param cause The exception to wrap.
+ *
+ * @see Exception#Exception(java.lang.String, java.lang.Throwable)
+ */
+ public SourceException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceImpl.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceImpl.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceImpl.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,199 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.source.filter.SourceFilter;
+
+/**
+ * A Source which uses a file as input.
+ */
+public abstract class SourceImpl implements Source
+{
+ /**
+ * The path to the elements which should be used as starting points
+ * for generation.
+ */
+ private String startElementsPath;
+
+ /**
+ * The root element of the parsed source.
+ */
+ private transient SourceElement rootElement;
+
+ /**
+ * The source transformers which are executed when transform() is called.
+ */
+ private List<TransformerDefinition> transformerDefinitions
+ = new ArrayList<TransformerDefinition>();
+
+ /**
+ * The source filter, or null if none exists.
+ */
+ private SourceFilter sourceFilter;
+
+ /**
+ * Constructor.
+ *
+ * @param startElementsPath the element which should be used as input,
+ * or null if the root element should be used.
+ * @param sourceFilter the fully qualified class name of the source filter.
+ * The class must have a standard constructor.
+ *
+ * @throws ConfigurationException if the source filter cannot be
+ * instantiated.
+ */
+ protected SourceImpl(
+ String startElementsPath,
+ SourceFilter sourceFilter,
+ List<TransformerDefinition> transformerDefinitions)
+ throws ConfigurationException
+ {
+ this.startElementsPath = startElementsPath;
+ this.sourceFilter = sourceFilter;
+ this.transformerDefinitions = new ArrayList<TransformerDefinition>(
+ transformerDefinitions);
+
+ }
+
+ /**
+ * Reads the root element and the whole untransformed source tree.
+ *
+ * @return the root element, not null.
+ *
+ * @throws SourceException if the SourceElement cannot be created.
+ */
+ protected abstract SourceElement createRootElement() throws SourceException;
+
+ public synchronized SourceElement getRootElement()
+ throws SourceException
+ {
+ if (rootElement == null)
+ {
+ rootElement = createRootElement();
+ }
+ return rootElement;
+ }
+
+ /**
+ * Returns the path to the elements which are selected as start elements
+ * from the transformed source.
+ *
+ * @return a path to the start elements, null for the root element.
+ */
+ public String getStartElementsPath()
+ {
+ return startElementsPath;
+ }
+
+ /**
+ * Return all currently registered transformer definitions.
+ *
+ * @return the transformer definitions, not null.
+ */
+ public List<TransformerDefinition> getTransformerDefinitions()
+ {
+ return Collections.unmodifiableList(transformerDefinitions);
+ }
+
+ /**
+ * Returns the current source filter.
+ *
+ * @return the current source filter, or null.
+ */
+ public SourceFilter getSourceFilter()
+ {
+ return sourceFilter;
+ }
+
+ /**
+ * Sets a new source filter.
+ *
+ * @param sourceFilter the new source filter, or null to remove the old
+ * source filter.
+ */
+ public void setSourceFilter(SourceFilter sourceFilter)
+ {
+ this.sourceFilter = sourceFilter;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((startElementsPath == null) ? 0 : startElementsPath.hashCode());
+ result = prime * result + transformerDefinitions.hashCode();
+ result = prime * result
+ + ((sourceFilter == null) ? 0 : sourceFilter.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ final SourceImpl other = (SourceImpl) obj;
+ if (startElementsPath == null)
+ {
+ if (other.startElementsPath != null)
+ {
+ return false;
+ }
+ }
+ else if (!startElementsPath.equals(other.startElementsPath))
+ {
+ return false;
+ }
+ if (!transformerDefinitions.equals(other.transformerDefinitions))
+ {
+ return false;
+ }
+ if (sourceFilter == null)
+ {
+ if (other.sourceFilter != null)
+ {
+ return false;
+ }
+ }
+ else if (!sourceFilter.equals(other.sourceFilter))
+ {
+ return false;
+ }
+ return true;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceParser.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceParser.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceParser.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceParser.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,43 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.InputStream;
+
+/**
+ * An Interface for reading a source file from a Stream.
+ *
+ * $Id: $
+ */
+public interface SourceParser
+{
+ /**
+ * Parses a source file and returns its root element.
+ *
+ * @param inputStream the stream to read the source file from, not null.
+ *
+ * @return the root element of the source, containing the rest of
+ * the source as linked elements.
+ *
+ * @throws SourceException if reading or parsing the source fails.
+ * @throws NullPointerException if <code>inputStream</code> is null.
+ */
+ SourceElement parse(InputStream inputStream) throws SourceException;
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourcePath.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourcePath.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourcePath.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourcePath.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,485 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.torque.gf.generator.GeneratorException;
+
+/**
+ * Methods for traversing a source tree.
+ */
+public final class SourcePath
+{
+ /**
+ * The separator between different levels in the path.
+ */
+ private static final String PATH_LEVEL_SEPARATOR = "/";
+
+ /**
+ * The token denoting the current element.
+ */
+ private static final String THIS_TOKEN = ".";
+
+ /**
+ * The token denoting the parent element.
+ */
+ private static final String PARENT_TOKEN = "..";
+
+ /**
+ * Private constructor for utility class.
+ */
+ private SourcePath()
+ {
+ }
+
+ /**
+ * Returns whether children with the given name exist.
+ *
+ * @param sourceElement the start element, not null.
+ * @param name the name of the child element, not null.
+ *
+ * @return true if children with the given name exist, false otherwise.
+ *
+ * @throws NullPointerException if name is null.
+ */
+ public static boolean hasChild(SourceElement sourceElement, String name)
+ {
+ if (name == null)
+ {
+ throw new NullPointerException("name must not be null");
+ }
+ if (sourceElement == null)
+ {
+ throw new NullPointerException("sourceElement must not be null");
+ }
+ for (SourceElement child : sourceElement.getChildren())
+ {
+ if (name.equals(child.getName()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns whether a following element exists as a child of the parent of
+ * this element.
+ *
+ * @param sourceElement the start element, not null.
+ *
+ * @return true if a following element exists, false if not.
+ */
+ public static boolean hasFollowing(SourceElement sourceElement)
+ {
+ return !getFollowing(sourceElement, null).isEmpty();
+ }
+
+ /**
+ * Returns whether an preceding exists as a child of the parent of
+ * this element.
+ *
+ * @param sourceElement the start element, not null.
+ *
+ * @return true if a preceding element exists, false if not.
+ */
+ public static boolean hasPreceding(SourceElement sourceElement)
+ {
+ return !getPreceding(sourceElement, null).isEmpty();
+ }
+
+ /**
+ * Returns whether a following element exists as a child of the parent of
+ * this element, which has the same name as this source element.
+ *
+ * @param sourceElement the start element, not null.
+ *
+ * @return true if a following sibling exists, false if not.
+ */
+ public static boolean hasFollowingSibling(SourceElement sourceElement)
+ {
+ return !getFollowing(sourceElement, sourceElement.getName()).isEmpty();
+ }
+
+ /**
+ * Returns whether an preceding exists as a child of the parent of
+ * this element, which has the same name as this source element.
+ *
+ * @param sourceElement the start element, not null.
+ *
+ * @return true if a preceding sibling exists, false if not.
+ */
+ public static boolean hasPrecedingSibling(SourceElement sourceElement)
+ {
+ return !getPreceding(sourceElement, sourceElement.getName()).isEmpty();
+ }
+
+ /**
+ * Returns all the preceding elements before this element
+ * with the given name.
+ * If name is null, all preceding elements are returned.
+ * If this element has no parent, an empty list is returned.
+ *
+ * @param sourceElement the start element, not null.
+ * @param name the name of the preceding elements to select,
+ * or null to select all preceding elements.
+ *
+ * @return a list containing the preceding elements with the given name,
+ * never null.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes">xpath axes</a>
+ */
+ public static List<SourceElement> getPreceding(
+ SourceElement sourceElement,
+ String name)
+ {
+ if (sourceElement == null)
+ {
+ throw new NullPointerException("sourceElement must not be null");
+ }
+
+ List<SourceElement> result = new ArrayList<SourceElement>();
+ ListIterator<SourceElement> sameLevelIt
+ = getSiblingIteratorPositionedOnSelf(sourceElement);
+ if (sameLevelIt == null)
+ {
+ return result;
+ }
+ while (sameLevelIt.hasPrevious())
+ {
+ SourceElement sameLevelElement = sameLevelIt.previous();
+ if (name == null || name.equals(sameLevelElement.getName()))
+ {
+ result.add(sameLevelElement);
+ }
+ }
+ return result;
+
+ }
+
+ /**
+ * Returns all the following elements after this element
+ * with the given name.
+ * If name is null, all following elements are returned.
+ * If this element has no parent, an empty list is returned.
+ *
+ * @param sourceElement the start element, not null.
+ * @param name the name of the following elements to select,
+ * or null to select all following elements.
+ *
+ * @return a list containing the following elements with the given name,
+ * never null.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes">xpath axes</a>
+ */
+ public static List<SourceElement> getFollowing(
+ SourceElement sourceElement,
+ String name)
+ {
+ if (sourceElement == null)
+ {
+ throw new NullPointerException("sourceElement must not be null");
+ }
+ List<SourceElement> result = new ArrayList<SourceElement>();
+
+ ListIterator<SourceElement> sameLevelIt
+ = getSiblingIteratorPositionedOnSelf(sourceElement);
+ if (sameLevelIt == null)
+ {
+ return result;
+ }
+ while (sameLevelIt.hasNext())
+ {
+ SourceElement sameLevelElement = sameLevelIt.next();
+ if (name == null || name.equals(sameLevelElement.getName()))
+ {
+ result.add(sameLevelElement);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns a ListIterator of the siblings of the input source element.
+ * The iterator is positioned on the input element.
+ *
+ * @param sourceElement the source element for which the sibling iterator
+ * should be created, not null.
+ *
+ * @return the sibling iterator, or null if the input source element has
+ * no parent.
+ *
+ * @throws IllegalArgumentException if the element cannot be found in the
+ * list of children of its parent.
+ */
+ private static ListIterator<SourceElement> getSiblingIteratorPositionedOnSelf(
+ SourceElement sourceElement)
+ {
+ SourceElement parent = sourceElement.getParent();
+ if (parent == null)
+ {
+ return null;
+ }
+ ListIterator<SourceElement> sameLevelIt
+ = parent.getChildren().listIterator();
+
+ boolean found = false;
+ while (sameLevelIt.hasNext())
+ {
+ SourceElement sameLevelElement = sameLevelIt.next();
+ if (sameLevelElement == sourceElement)
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ throw new IllegalArgumentException("Inconsistent source tree: "
+ + "Source element " + sourceElement.getName()
+ + " not found in the list of the children of its parent");
+ }
+ return sameLevelIt;
+ }
+
+ /**
+ * Gets the elements which can be reached from the start element by a given
+ * path.
+ *
+ * @param sourceElement the start element, not null.
+ * @param path the path to use, not null.
+ *
+ * @return the list of matching source elements, not null, may be empty.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes">xpath axes</a>
+ */
+ public static List<SourceElement> getElements(
+ SourceElement sourceElement,
+ String path)
+ {
+ if (sourceElement == null)
+ {
+ throw new NullPointerException("sourceElement must not be null");
+ }
+
+ if (path.equals(THIS_TOKEN))
+ {
+ List<SourceElement> result = new ArrayList<SourceElement>(1);
+ result.add(sourceElement);
+ return result;
+ }
+ StringTokenizer selectionPathTokenizer
+ = new StringTokenizer(path, PATH_LEVEL_SEPARATOR);
+ List<SourceElement> currentSelection = new ArrayList<SourceElement>();
+ currentSelection.add(sourceElement);
+ while (selectionPathTokenizer.hasMoreTokens())
+ {
+ String childName = selectionPathTokenizer.nextToken();
+ List<SourceElement> nextSelection = new ArrayList<SourceElement>();
+ for (SourceElement currentElement : currentSelection)
+ {
+ if (childName.equals(PARENT_TOKEN))
+ {
+ SourceElement parent = currentElement.getParent();
+ if (parent != null && !nextSelection.contains(parent))
+ {
+ nextSelection.add(parent);
+ }
+ }
+ else
+ {
+ for (SourceElement child
+ : currentElement.getChildren(childName))
+ {
+ nextSelection.add(child);
+ }
+ }
+ }
+ currentSelection = nextSelection;
+ }
+ return currentSelection;
+ }
+
+ /**
+ * Gets the elements which can be reached from the root element by a given
+ * path. The name of the root element must appear first in the path,
+ * otherwise nothing is selected.
+ *
+ * @param rootElement the root element of the source tree, not null.
+ * @param path the path to use, null selects the root element..
+ *
+ * @return the list of matching source elements, not null, may be empty.
+ *
+ * @see <a href="http://www.w3.org/TR/xpath#axes">xpath axes</a>
+ */
+ public static List<SourceElement> getElementsFromRoot(
+ SourceElement rootElement,
+ String path)
+ {
+ if (rootElement == null)
+ {
+ throw new NullPointerException("rootElement must not be null");
+ }
+
+ if (path == null
+ || "".equals(path.trim())
+ || PATH_LEVEL_SEPARATOR.equals(path.trim()))
+ {
+ // use root element
+ List<SourceElement> result = new ArrayList<SourceElement>(1);
+ result.add(rootElement);
+ return result;
+ }
+
+ path = path.trim();
+ // remove leading slash
+ if (path.startsWith(PATH_LEVEL_SEPARATOR))
+ {
+ path = path.substring(1);
+ }
+ int firstSeparatorPos = path.indexOf(PATH_LEVEL_SEPARATOR);
+ String firstElementName;
+ if (firstSeparatorPos == -1)
+ {
+ firstElementName = path;
+ path = THIS_TOKEN;
+ }
+ else
+ {
+ firstElementName = path.substring(0, firstSeparatorPos);
+ path = path.substring(firstSeparatorPos + 1);
+ }
+ if (!rootElement.getName().equals(firstElementName))
+ {
+ return new ArrayList<SourceElement>();
+ }
+ return SourcePath.getElements(rootElement, path);
+ }
+
+
+ /**
+ * Gets a single source element which can be reached from the start element
+ * by a given path.
+ *
+ * @param sourceElement the start element, not null.
+ * @param path the path to use, not null.
+ * @param acceptEmpty whether no match is an error(acceptEmpty=false)
+ * or not (acceptEmpty=true)
+ *
+ * @return the single matching source elements, may be null only if
+ * acceptEmpty=true.
+ *
+ * @throws GeneratorException if more than one source element matches,
+ * or if no source element matches and acceptEmpty=false
+ * @see <a href="http://www.w3.org/TR/xpath#axes">xpath axes</a>
+ */
+ public static SourceElement getElement(
+ SourceElement sourceElement,
+ String path,
+ boolean acceptEmpty)
+ throws GeneratorException
+ {
+ List<SourceElement> sourceElements
+ = SourcePath.getElements(sourceElement, path);
+ if (sourceElements.isEmpty())
+ {
+ if (acceptEmpty)
+ {
+ return null;
+ }
+ else
+ {
+ throw new GeneratorException(
+ "Source element path "
+ + path
+ + " selects no element on source element "
+ + sourceElement.getName());
+ }
+ }
+ if (sourceElements.size() > 1)
+ {
+ throw new GeneratorException(
+ "Source element path "
+ + path
+ + " selects more than a single element on source element "
+ + sourceElement.getName());
+ }
+ return sourceElements.get(0);
+ }
+
+ /**
+ * Returns the path from the root element to the source element.
+ * The element names are separated by slashes.
+ * Example: root/firstLevelElement/secondLevelElement/currentNode
+ *
+ * @param sourceElement the element to output, not null.
+ *
+ * @return the path from root, not null.
+ *
+ * @throws GeneratorException if the parent chain contains a closed loop.
+ */
+ public static String getPathAsString(SourceElement sourceElement)
+ throws GeneratorException
+ {
+ StringBuilder result = new StringBuilder();
+ getParentPath(sourceElement, new HashSet<SourceElement>(), result);
+ result.append(sourceElement.getName());
+ return result.toString();
+ }
+
+ /**
+ * Gets the path to the parent of a source element.
+ * @param toProcess the source element for which parent the path should be
+ * calculated.
+ * @param alreadyProcessed the elements which are already processed
+ * by this method.
+ * @param result the path to the parent, ends with a slash if any parents
+ * are present.
+ *
+ * @throws GeneratorException if the parent is contained in alreadyProcessed
+ * or if the parent chain contains a closed loop.
+ */
+ private static void getParentPath(
+ SourceElement toProcess,
+ Set<SourceElement> alreadyProcessed,
+ StringBuilder result)
+ throws GeneratorException
+ {
+ SourceElement parent = toProcess.getParent();
+ if (alreadyProcessed.contains(parent))
+ {
+ throw new GeneratorException(
+ "getParentPath(): invoked on a closed loop");
+ }
+ if (parent == null)
+ {
+ return;
+ }
+ result.insert(0, parent.getName() + "/");
+ alreadyProcessed.add(parent);
+ getParentPath(parent, alreadyProcessed, result);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceType.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceType.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceType.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/SourceType.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,50 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * A type of a source.
+ *
+ * $Id: $
+ */
+public interface SourceType
+{
+ /**
+ * Returns an unique key for the source type.
+ *
+ * @return an unique key for the source type, not null.
+ */
+ String getKey();
+
+ /**
+ * Gets the filename extension this source type typically has.
+ *
+ * @return the filename extension without leading dot,
+ * or null if no typical extension exists.
+ */
+ String getFilenameExtension();
+
+ /**
+ * Returns a parser for this type of source.
+ *
+ * @return a source parser, not null.
+ */
+ SourceParser getParser();
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,31 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.Iterator;
+
+/**
+ * The input for an generation process.
+ * It can contain several Sources.
+ */
+public interface Sources extends Iterator<Source>
+{
+
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/TransformerDefinition.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/TransformerDefinition.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/TransformerDefinition.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/TransformerDefinition.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,59 @@
+package org.apache.torque.gf.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.torque.gf.source.transform.SourceTransformer;
+
+/**
+ * All necessary informations for doing a transformation.
+ * Contains the class name and the elements the transformer should run on.
+ *
+ * $Id: $
+ */
+public final class TransformerDefinition
+{
+ /**
+ * The transformer instance.
+ */
+ private SourceTransformer transformer;
+
+ /**
+ * The path to the source elements on which the transformer is applied.
+ */
+ private String elements;
+
+ public TransformerDefinition(
+ SourceTransformer transformer,
+ String elements)
+ {
+ this.transformer = transformer;
+ this.elements = elements;
+ }
+
+ public SourceTransformer getTransformer()
+ {
+ return transformer;
+ }
+
+ public String getElements()
+ {
+ return elements;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/SourceFilter.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/SourceFilter.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/SourceFilter.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/SourceFilter.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,39 @@
+package org.apache.torque.gf.source.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.torque.gf.control.ControllerState;
+
+/**
+ * A filter deciding whether the generation should proceed or not.
+ *
+ * $Id: $
+ */
+public interface SourceFilter
+{
+ /**
+ * Decides whether generation should proceed.
+ * @param controllerState the current controller state, containing e.g.
+ * the current source element.
+ * @return true if the current generation should proceed,
+ * false if the generation should be skipped.
+ */
+ boolean proceed(ControllerState controllerState);
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/StopGenerationSourceFilter.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/StopGenerationSourceFilter.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/StopGenerationSourceFilter.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/StopGenerationSourceFilter.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,43 @@
+package org.apache.torque.gf.source.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.torque.gf.control.ControllerState;
+
+/**
+ * A filter which always stops the current generation.
+ *
+ * $Id: $
+ */
+public class StopGenerationSourceFilter implements SourceFilter
+{
+ /**
+ * Decides whether generation should proceed. This implementation
+ * always stops the current generation.
+ *
+ * @param controllerState the current controller state.
+ *
+ * @return <code>false</code>
+ */
+ public boolean proceed(ControllerState controllerState)
+ {
+ return false;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/filter/package.html Tue Feb 16 17:15:43 2010
@@ -0,0 +1,26 @@
+<!--
+ Copyright 2001-2006 The Apache Software Foundation.
+
+ 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.
+-->
+<html>
+ <head>
+ <title>Torque-gf source filter</title>
+ </head>
+ <body>
+ <p>
+ This package contains the definition and implementations of source
+ filters.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/package.html Tue Feb 16 17:15:43 2010
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2001-2006 The Apache Software Foundation.
+
+ 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.
+-->
+<html>
+ <head>
+ <title>Torque-gf sources</title>
+ </head>
+ <body>
+ <p>
+ This package contains the handling of source files in Torque-gf.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceParser.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceParser.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceParser.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceParser.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,147 @@
+package org.apache.torque.gf.source.properties;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.collections.set.ListOrderedSet;
+import org.apache.torque.gf.source.RichSourceElementImpl;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.SourceException;
+import org.apache.torque.gf.source.SourceParser;
+
+/**
+ * Parses a stream containing properties data into a source element hierarchy.
+ * The source element hierarchy is processed according to the java properties
+ * DTD.
+ * See http://java.sun.com/dtd/properties.dtd
+ */
+public class PropertiesSourceParser implements SourceParser
+{
+ /**
+ * The name of the root element.
+ */
+ public static final String ROOT_ELEMENT_NAME = "properties";
+
+ /**
+ * The name of the entry element.
+ */
+ public static final String ENTRY_ELEMENT_NAME = "entry";
+
+ /**
+ * The name of the key attribute of the entry element.
+ */
+ public static final String KEY_ATTRIBUTE_NAME = "key";
+
+ /**
+ * parses a Stream in Properties format and returns the root element of the
+ * created element tree.
+ *
+ * @param inputStream the input stream to parse, not null.
+ *
+ * @return the root element of the created tree, not null.
+ *
+ * @throws SourceException if an error occurred when reading from the
+ * input stream.
+ * @throws IllegalArgumentException if the input stream contains a
+ * malformed unicode escape sequence.
+ * @throws NullPointerException if inputStream is null.
+ */
+ public SourceElement parse(InputStream inputStream)
+ throws SourceException
+ {
+ if (inputStream == null)
+ {
+ throw new NullPointerException("inputStream is null");
+ }
+ OrderedProperties properties = new OrderedProperties();
+ try
+ {
+ properties.load(inputStream);
+ }
+ catch (IOException e)
+ {
+ throw new SourceException(
+ "Error parsing Properties source file: " + e.getMessage(),
+ e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new SourceException(
+ "Error parsing Properties source file: " + e.getMessage(),
+ e);
+ }
+
+ RichSourceElementImpl result
+ = new RichSourceElementImpl(ROOT_ELEMENT_NAME);
+
+ for (String key : properties.orderedKeySet())
+ {
+ String value = properties.getProperty(key);
+ RichSourceElementImpl entryElement
+ = new RichSourceElementImpl(ENTRY_ELEMENT_NAME);
+ entryElement.setAttribute(KEY_ATTRIBUTE_NAME, key);
+ entryElement.setAttribute((String) null, value);
+ result.addChild(entryElement);
+ }
+ return result;
+ }
+
+ /**
+ * Properties which remember the order of the added elements.
+ *
+ * The class is NOT serializable although it implements the
+ * <code>Serializable</code> interface.
+ */
+ private static class OrderedProperties extends Properties
+ {
+ /**
+ * version for serialization and deserialisation purposes.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The ordered set of keys.
+ */
+ @SuppressWarnings("unchecked")
+ private Set<String> keySet = new ListOrderedSet();
+
+ @Override
+ public Object put(Object key, Object value)
+ {
+ keySet.add(key.toString());
+ return super.put(key, value);
+ }
+
+ /**
+ * Returns the set of keys, ordered by the order of addition.
+ * @return the ordered set of keys, not null.
+ * The returned set is unmodifiable.
+ */
+ public Set<String> orderedKeySet()
+ {
+ return Collections.unmodifiableSet(keySet);
+ }
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceType.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceType.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceType.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/properties/PropertiesSourceType.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,101 @@
+package org.apache.torque.gf.source.properties;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.torque.gf.source.SourceParser;
+import org.apache.torque.gf.source.SourceType;
+
+/**
+ * The source type representing an properties source.
+ *
+ * $Id: $
+ */
+public final class PropertiesSourceType implements SourceType
+{
+ /** The key for a properties source. */
+ private static final String KEY = "properties";
+
+ /** The filename extension for a properties source. */
+ private static final String FILENAME_EXTENSION = "properties";
+
+ /**
+ * Returns an unique key for the source type.
+ *
+ * @return "properties".
+ */
+ public String getKey()
+ {
+ return KEY;
+ }
+
+ /**
+ * Gets the filename extension this source type typically has.
+ *
+ * @return "properties".
+ */
+ public String getFilenameExtension()
+ {
+ return FILENAME_EXTENSION;
+ }
+
+ /**
+ * Returns a parser for this type of source.
+ *
+ * @return a source parser, not null.
+ */
+ public SourceParser getParser()
+ {
+ return new PropertiesSourceParser();
+ }
+
+ /**
+ * Returns a hash code of this instance consistent with equals..
+ * As all instances of this class are equal to each other,
+ * the hash code is always the same.
+ *
+ * @return 1.
+ */
+ @Override
+ public int hashCode()
+ {
+ return 1;
+ }
+
+ /**
+ * Checks whether other is equal to this instance.
+ * All instances of this class are equal to each other.
+ *
+ * @return true if <code>other</code> is a PropertiesSourceType, false
+ * otherwise.
+ */
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ if (!other.getClass().equals(PropertiesSourceType.class))
+ {
+ return false;
+ }
+ return true;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org