1 package org.codehaus.mojo.axistools.admin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }