+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.List;
-
-import javax.smartcardio.ATR;
-
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.configuration.PlexusConfigurationException;
-import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class DomPlexusConfiguration
- implements PlexusConfiguration
-{
- private Element root;
-
- /**
- *
- */
- public DomPlexusConfiguration( Element root )
- {
- this.root = root;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#addChild(org.codehaus.plexus.configuration.PlexusConfiguration)
- */
- public void addChild( PlexusConfiguration configuration )
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getAttribute(java.lang.String)
- */
- public String getAttribute( String paramName )
- throws PlexusConfigurationException
- {
- return root.getAttribute( paramName );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getAttribute(java.lang.String, java.lang.String)
- */
- public String getAttribute( String name, String defaultValue )
- {
- String attribute = root.getAttribute( name );
- if ( attribute == null )
- {
- attribute = defaultValue;
- }
- return attribute;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getAttributeNames()
- */
- public String[] getAttributeNames()
- {
- NamedNodeMap attributes = root.getAttributes();
- String[] names = new String[attributes.getLength()];
- for ( int i = 0; i < names.length; i++ )
- {
- names[i] = attributes.item( i ).getLocalName();
- }
- return names;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChild(java.lang.String)
- */
- public PlexusConfiguration getChild( String child )
- {
- Element e = DomUtils.getChildElementByTagName( root, child );
- if (e != null)
- {
- return new DomPlexusConfiguration( e );
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChild(int)
- */
- public PlexusConfiguration getChild( int i )
- {
- NodeList childs = root.getChildNodes();
- for ( int j = 0; j < childs.getLength(); j++ )
- {
- Node child = childs.item( j );
- if ( child.getNodeType() == Node.ELEMENT_NODE )
- {
- if (i-- == 0)
- {
- return new DomPlexusConfiguration( (Element) child );
- }
- }
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChild(java.lang.String, boolean)
- */
- public PlexusConfiguration getChild( String child, boolean createChild )
- {
- PlexusConfiguration config = getChild( child );
- if (config == null && createChild )
- {
- // Creating a new child requires a Document
- throw new UnsupportedOperationException( "Not implemented" );
- }
- return config;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChildCount()
- */
- public int getChildCount()
- {
- int count = 0;
- NodeList childs = root.getChildNodes();
- for ( int i = 0; i < childs.getLength(); i++ )
- {
- Node child = childs.item( i );
- if ( child.getNodeType() == Node.ELEMENT_NODE )
- {
- count++;
- }
- }
- return count;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChildren()
- */
- public PlexusConfiguration[] getChildren()
- {
- int count = getChildCount();
- PlexusConfiguration[] children = new PlexusConfiguration[count];
- for ( int i = 0; i < children.length; i++ )
- {
- children[i] = getChild( i );
- }
- return children;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getChildren(java.lang.String)
- */
- public PlexusConfiguration[] getChildren( String name )
- {
- throw new UnsupportedOperationException( "Not implemented" );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getName()
- */
- public String getName()
- {
- return root.getNodeName();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getValue()
- */
- public String getValue()
- throws PlexusConfigurationException
- {
- return root.getNodeValue();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.configuration.PlexusConfiguration#getValue(java.lang.String)
- */
- public String getValue( String defaultValue )
- {
- String value = root.getTextContent();
- if ( value == null )
- {
- value = defaultValue;
- }
- return value;
- }
-}
* under the License.\r
*/\r
\r
+import java.io.PrintWriter;\r
import java.io.StringWriter;\r
+import java.io.Writer;\r
import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.List;\r
import org.springframework.context.ApplicationContextException;\r
import org.springframework.util.xml.DomUtils;\r
import org.w3c.dom.Element;\r
+import org.w3c.dom.NamedNodeMap;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
\r
/**\r
* A spring namespace handler to support plexus components creation and direct\r
}\r
else\r
{\r
- dependencies.put( name, new DomPlexusConfiguration( child ) );\r
+ StringWriter xml = new StringWriter();\r
+ flatten( child, new PrintWriter( xml ) );\r
+ dependencies.put( name, xml.toString() );\r
}\r
}\r
\r
}\r
\r
}\r
-\r
- public static String buildSpringId( String role, String roleHint )\r
+ /**\r
+ * @param childNodes\r
+ * @return\r
+ */\r
+ private void flatten( NodeList childNodes, PrintWriter out )\r
{\r
- return PlexusToSpringUtils.buildSpringId( role, roleHint );\r
+ for ( int i = 0; i < childNodes.getLength(); i++ )\r
+ {\r
+ Node node = childNodes.item( i );\r
+ if (node.getNodeType() == Node.ELEMENT_NODE )\r
+ {\r
+ flatten( (Element) node, out );\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * @param item\r
+ * @param out\r
+ */\r
+ private void flatten( Element el, PrintWriter out )\r
+ {\r
+ out.print( '<' );\r
+ out.print( el.getTagName() );\r
+ NamedNodeMap attributes = el.getAttributes();\r
+ for ( int i = 0; i < attributes.getLength(); i++ )\r
+ {\r
+ Node attribute = attributes.item( i );\r
+ out.print( " ");\r
+ out.print( attribute.getLocalName() );\r
+ out.print( "=\"" );\r
+ out.print( attribute.getTextContent() );\r
+ out.print( "\"" );\r
+ }\r
+ out.print( '>' );\r
+ flatten( el.getChildNodes(), out );\r
+ out.print( "</" );\r
+ out.print( el.getTagName() );\r
+ out.print( '>' );\r
}\r
}\r