1 19 20 package org.netbeans.mdrant; 21 22 import java.util.Iterator ; 23 24 import org.apache.tools.ant.BuildException; 25 26 import javax.jmi.model.MofPackage; 27 import javax.jmi.model.ModelPackage; 28 29 33 public class Instantiate extends MdrTask.Sub { 34 35 private String name; 36 private String extent; 37 private String packageName; 38 39 40 public Instantiate() { 41 } 42 43 public void execute() throws Exception { 44 45 if ( name == null ) { 46 throw new BuildException( "Name for newly instantiated package has to be sppecified. Use the \"name\" attribute" ); 47 } 48 49 if ( extent == null && packageName == null ) { 50 getRepository().createExtent( name ); 51 } 52 else { 53 if ( extent == null ) { 54 throw new BuildException( "Extent containing the package has to be specified. Use the \"extent\" attribute" ); 55 } 56 if ( packageName == null ) { 57 throw new BuildException( "The package has to be specified. Use the \"package\" attribute" ); 58 } 59 60 MofPackage mp = getModelPackage(); 61 62 if ( mp == null ) { 63 throw new BuildException( packageName + " does not exist in extent " + extent ); 64 } 65 66 getRepository().createExtent( name, mp ); 67 } 68 69 } 70 71 73 public void setName( String name ) { 74 this.name = name; 75 } 76 77 public void setExtent( String extent ) { 78 this.extent = extent; 79 } 80 81 public void setPackage( String packageName ) { 82 this.packageName = packageName; 83 } 84 85 87 88 private MofPackage getModelPackage() { 89 90 ModelPackage mofPackage = (ModelPackage)getRepository().getExtent( extent ); 91 MofPackage result; 92 93 for (Iterator it = mofPackage.getMofPackage().refAllOfClass().iterator(); it.hasNext();) { 94 result = (MofPackage) it.next(); 95 if (result.getName().equals( packageName )) { 96 return result; 97 } 98 } 99 100 return null; 101 } 102 103 104 } 105 | Popular Tags |