donaldp 02/04/20 18:28:54
Modified: api/src/java/org/apache/myrmidon/api/metadata
ModelElement.java
Log:
Add some helper methods
* getChildren(String)
* getChild(String)
Revision Changes Path
1.4 +59 -1 jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/metadata/ModelElement.java
Index: ModelElement.java
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/metadata/ModelElement.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ModelElement.java 20 Apr 2002 23:12:02 -0000 1.3
+++ ModelElement.java 21 Apr 2002 01:28:54 -0000 1.4
@@ -21,7 +21,7 @@
* sub-elements or text content (one or the other - not both).</p>
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.3 $ $Date: 2002/04/20 23:12:02 $
+ * @version $Revision: 1.4 $ $Date: 2002/04/21 01:28:54 $
* @see Modeller
* @see ModelException
*/
@@ -104,6 +104,64 @@
return (ModelElement[])m_children.
toArray( new ModelElement[ m_children.size() ] );
}
+ }
+
+ /**
+ * Return an array of child <code>ModelElement</code> objects
+ * that have specified name.
+ *
+ * @param name The name of the child <code>ModelElement</code>
+ * objects to return.
+ * @return an array of <code>ModelElement</code> objects
+ */
+ public ModelElement[] getChildren( final String name )
+ {
+ if( null == m_children )
+ {
+ return EMPTY_MODEL_ELEMENT_ARRAY;
+ }
+ else
+ {
+ final ArrayList children = new ArrayList();
+ final int size = m_children.size();
+
+ for( int i = 0; i < size; i++ )
+ {
+ final ModelElement configuration = (ModelElement)m_children.get( i );
+ if( name.equals( configuration.getName() ) )
+ {
+ children.add( configuration );
+ }
+ }
+
+ return (ModelElement[])children.
+ toArray( new ModelElement[ children.size() ] );
+ }
+ }
+
+ /**
+ * Return the first child <code>ModelElement</code> with specified
+ * name.
+ *
+ * @param name the name of ModelElement to search for
+ * @return the ModelElement or null if none
+ */
+ public ModelElement getChild( final String name )
+ {
+ if( null != m_children )
+ {
+ final int size = m_children.size();
+ for( int i = 0; i < size; i++ )
+ {
+ final ModelElement child = (ModelElement)m_children.get( i );
+ if( name.equals( child.getName() ) )
+ {
+ return child;
+ }
+ }
+ }
+
+ return null;
}
/**
--
To unsubscribe, e-mail: <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>
|