1 17 package org.apache.ldap.server.tools.schema; 18 19 20 import org.apache.ldap.server.schema.bootstrap.AbstractBootstrapSchema; 21 import org.apache.tools.ant.BuildException; 22 23 24 30 public class DirectorySchemaToolTask extends org.apache.tools.ant.Task 31 { 32 private String javaSrc; 33 private String pkg; 34 private String name; 35 private String owner; 36 private String [] dependencies; 37 private BuildException lastFault; 38 39 40 public void setJavaSrc( String javaSrc ) 41 { 42 this.javaSrc = javaSrc; 43 } 44 45 46 public void setPackage( String pkg ) 47 { 48 this.pkg = pkg; 49 } 50 51 52 public void setName( String name ) 53 { 54 this.name = name; 55 } 56 57 58 public void setOwner( String owner ) 59 { 60 this.owner = owner; 61 } 62 63 64 public void setDependencies( String deps ) 65 { 66 dependencies = deps.split( "," ); 67 68 for ( int ii = 0; ii < dependencies.length; ii++ ) 69 { 70 dependencies[ii] = dependencies[ii].trim(); 71 } 72 } 73 74 75 public void execute() throws BuildException 76 { 77 super.execute(); 78 DirectorySchemaTool tool; 79 80 try 81 { 82 tool = new DirectorySchemaTool(); 83 } 84 catch ( Exception e ) 85 { 86 lastFault = new BuildException( "Failed to create schema tool", e ); 87 throw lastFault; 88 } 89 90 AbstractBootstrapSchema schema = 91 new AbstractBootstrapSchema( owner, name, pkg, dependencies ){}; 92 tool.setSchema( schema ); 93 94 if ( javaSrc != null ) 95 { 96 tool.setJavaSrcDir( javaSrc ); 97 } 98 99 try 100 { 101 tool.generate(); 102 } 103 catch ( Exception e ) 104 { 105 lastFault = new BuildException( "Failed to generate " + name + 106 " schema classes in package " + pkg, e ); 107 throw lastFault; 108 } 109 } 110 111 112 public BuildException getLastFault() 113 { 114 return lastFault; 115 } 116 117 118 public boolean hasFaulted() 119 { 120 return lastFault != null; 121 } 122 123 124 public String toString() 125 { 126 StringBuffer buf = new StringBuffer (); 127 buf.append( "\nSCHEMA:\nname = " ).append( name ).append( '\n' ); 128 buf.append( "owner = " ).append( owner ).append( '\n' ); 129 buf.append( "package = " ).append( pkg ).append( '\n' ); 130 buf.append( "dependencies = " ); 131 132 for ( int ii = 0; ii < dependencies.length; ii++ ) 133 { 134 buf.append( dependencies[ii] ); 135 if ( ii < dependencies.length-1 ) 136 { 137 buf.append( ',' ); 138 } 139 } 140 141 return buf.toString(); 142 } 143 } 144 | Popular Tags |