View Javadoc
1   package org.codehaus.mojo.axistools.admin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.axis.AxisEngine;
23  import org.apache.axis.MessageContext;
24  import org.apache.axis.client.AxisClient;
25  import org.apache.axis.server.AxisServer;
26  import org.apache.axis.utils.Admin;
27  import org.apache.axis.utils.Messages;
28  import org.apache.axis.utils.XMLUtils;
29  import org.apache.maven.plugin.logging.Log;
30  import org.codehaus.mojo.axistools.axis.AxisPluginException;
31  import org.w3c.dom.Document;
32  
33  import java.io.BufferedWriter;
34  import java.io.FileInputStream;
35  import java.io.FileOutputStream;
36  import java.io.OutputStreamWriter;
37  import java.io.PrintWriter;
38  import java.io.Writer;
39  
40  /**
41   * @author mlake
42   */
43  public class AdminWrapper
44      extends Admin
45  {
46      private Log log;
47  
48      public AdminWrapper( Log log )
49      {
50          this.log = log;
51      }
52  
53      public void execute( String[] args )
54          throws AxisPluginException
55      {
56          int i = 0;
57  
58          try
59          {
60              AxisEngine engine;
61              if ( args[0].equals( "client" ) )
62              {
63                  engine = new AxisClient();
64              }
65              else
66              {
67                  engine = new AxisServer();
68              }
69  
70              engine.setShouldSaveConfig( false );
71              engine.init();
72              MessageContext msgContext = new MessageContext( engine );
73              Writer osWriter = new OutputStreamWriter( new FileOutputStream( args[1] ), XMLUtils.getEncoding() );
74              PrintWriter writer = new PrintWriter( new BufferedWriter( osWriter ) );
75  
76              try
77              {
78                  for ( i = 2; i < args.length; i++ )
79                  {
80                      log.debug( Messages.getMessage( "process00", args[i] ) );
81  
82                      Document doc = XMLUtils.newDocument( new FileInputStream( args[i] ) );
83                      Document result = process( msgContext, doc.getDocumentElement() );
84  
85                      if ( result != null )
86                      {
87                          System.out.println( XMLUtils.DocumentToString( result ) );
88                      }
89                  }
90                  Document document = Admin.listConfig( engine );
91                  XMLUtils.DocumentToWriter( document, writer );
92                  writer.println();
93              }
94              catch ( Exception e )
95              {
96                  log.error( Messages.getMessage( "errorProcess00", args[i] ), e );
97                  throw e;
98              }
99              finally
100             {
101                 writer.close();
102             }
103         }
104         catch ( Exception e )
105         {
106             throw new AxisPluginException( "Axis Admin had a problem, it returned a failure status: "
107                 + e.getMessage() );
108         }
109     }
110 }