Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    *
    * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
    *
    * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    * Other names may be trademarks of their respective owners.
    *
    * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common
   * Development and Distribution License("CDDL") (collectively, the
   * "License"). You may not use this file except in compliance with the
   * License. You can obtain a copy of the License at
   * http://www.netbeans.org/cddl-gplv2.html
   * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   * specific language governing permissions and limitations under the
   * License.  When distributing the software, include this License Header
   * Notice in each file and include the License file at
   * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the GPL Version 2 section of the License file that
   * accompanied this code. If applicable, add the following below the
   * License Header, with the fields enclosed by brackets [] replaced by
   * your own identifying information:
   * "Portions Copyrighted [year] [name of copyright owner]"
   *
   * Contributor(s):
   *
   * The Original Software is NetBeans. The Initial Developer of the Original
   * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   * Microsystems, Inc. All Rights Reserved.
   *
   * If you wish your version of this file to be governed by only the CDDL
   * or only the GPL Version 2, indicate your decision by adding
   * "[Contributor] elects to include this software in this distribution
   * under the [CDDL or GPL Version 2] license." If you do not indicate a
   * single choice of license, a recipient has the option to distribute
   * your version of this file under either the CDDL, the GPL Version 2 or
   * to extend the choice of license to its licensees as provided above.
   * However, if you add GPL Version 2 code and therefore, elected the GPL
   * Version 2 license, then the option applies only if the new code is
   * made subject to such option by the copyright holder.
   */
  package org.netbeans.modules.xml.jaxb.util;
  
  import java.io.File;
  import java.net.URI;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;

Author(s):
gmpatil
lgao
 
 public class ProjectHelper {
 
     public static final int PROJECT_TYPE_J2SE = 0;
     public static final int PROJECT_TYPE_EJB = 1;
     public static final int PROJECT_TYPE_WEB = 2;
     
     private static final String JAXB_ANT_XTN_NAME = "jaxb"//NOI18n    
     private static final String JAXB_LIB_NAME = "jaxb"//NOI18N
     private static final String PROP_BUILD_DIR = "build.dir"//NOI18N
     private static final String PROP_SRC_DIR = "src.dir"//NOI18N
     private static final String PROP_SRC_ROOT = "source.root"//NOI18N
     private static final String NBPROJECT_DIR = "nbproject"//NOI18N    
     private static final String XML_BINDING_CONFIG_FILE_NAME = "xml_binding_cfg.xml"//NOI18N
     private static final String XML_BINDING_BUILD_FILE_NAME = "xml_binding_build.xml"//NOI18N
     private static final String FILE_OBJECT_SEPARATOR = "/"// NOI18N
     private static final String XSL_RESOURCE = "org/netbeans/modules/xml/jaxb/resources/JAXBBuild.xsl"//NOI18N
     private static final String EJB_XSL_RESOURCE = "org/netbeans/modules/xml/jaxb/resources/JAXBBuild_ejb.xsl"//NOI18N
     private static final String WEB_XSL_RESOURCE = "org/netbeans/modules/xml/jaxb/resources/JAXBBuild_web.xsl"//NOI18N
     private static final String BUILD_GEN_JAXB_DIR = "build/generated-sources/jaxb"//NOI18N
     private static final String NON_JAVA_SE_CONFIG_DIR = "conf/xml-resources/jaxb"//NOI18N
     private static final String JAVA_SE_CONFIG_DIR = "xml-resources/jaxb"//NOI18N
     private static final String PROP_XJC_DEF_CLASSPATH = "jaxbwiz.xjcdef.classpath" ;//NOI18N
     private static final String PROP_XJC_RUN_CLASSPATH = "jaxbwiz.xjcrun.classpath" ;//NOI18N
     private static final String PROP_JAXB_GEN_SRC_CLASSPATH = "jaxbwiz.gensrc.classpath";//NOI18N
     private static final String PROP_VAL_JAXB_LIB_CLASSPATH = "${libs.jaxb.classpath}";//NOI18N
     private static final String JAXB_CONTEXT_CLASS_RES_PATH = "javax/xml/bind/JAXBContext.class"//NOI18N
     private static final String CLASSPATH_ENDORSED = "classpath/endorsed"//NOI18N
     private static final String JAXB_ENDORSED="JAXB-ENDORSED"//NOI18N
 
     public static final String IDE_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-xml-wsdl-model.jar"// NOI18N
     public static final String IDE_MODULE_INSTALL_CBN = "org.netbeans.modules.xml.wsdl.model"// NOI18N
 
     // Make sure nobody instantiates this class.
     private ProjectHelper(){ }
     
     public static void refreshBuildScript(Project prj) {
         try {
             Source xmlSource = new StreamSource(getXMLBindingConfigFile(prj));
             Source xslSource = null;
             int projType = getProjectType(prj);
             if (projType == ){
                 xslSource = new StreamSource(
                     ProjectHelper.class.getClassLoader().getResourceAsStream(
                     ));
             } else if (projType == ){
                 xslSource = new StreamSource(
                     ProjectHelper.class.getClassLoader().getResourceAsStream(
                     ));
             } else {
                 xslSource = new StreamSource(
                     ProjectHelper.class.getClassLoader().getResourceAsStream(
                     ));
             }
 
             Result result = new StreamResult(getXMLBindingBuildFile(prj));
             TransformerFactory fact = TransformerFactory.newInstance();
             try {
                 fact.setAttribute("indent-number", 4); //NOI18N
             } catch (Exception ex){
                 //Ignore Xalan does not recognize "indent-number"
             }
             Transformer xformer = fact.newTransformer(xslSource);
             xformer.setOutputProperty(."yes"); //NOI18N
             xformer.setOutputProperty(."xml"); //NOI18N
             xformer.transform(xmlSourceresult);
         } catch (Exception ex) {
             Exceptions.printStackTrace(ex);
         }
     }
 
     private static String getProperty(Project prjString filePath
             String name) {
         AntProjectHelper aph = getAntProjectHelper(prj);
         EditableProperties ep = aph.getProperties(filePath);
         String str = null;
         String value = ep.getProperty(name);
         if (value != null) {
             PropertyEvaluator pe = aph.getStandardPropertyEvaluator();
             str = pe.evaluate(value);
         }
         return str;
     }
 
     private static void saveProperty(Project prjString filePathString name
             String value) {
         AntProjectHelper aph = getAntProjectHelper(prj);
         EditableProperties ep = aph.getProperties(filePath);
         if (value != null) {
             ep.put(namevalue);
             aph.putProperties(filePathep);
         }
     }
 
     private static String getProjectProperty(Project prjString prop) {
         return getProperty(prj.prop);
     }
 
     private static String getPrivateProperty(Project prjString prop) {
         return getProperty(prj.prop);
     }
 
     private static void savePrivateProperty(Project prjString prop
             String value) {
         saveProperty(prj.prop
                 value);
     }
 
     private static void saveProjectProperty(Project prjString prop
             String value) {
         saveProperty(prj.prop
                 value);
     }
 
     public static String getProjectSourceDir(Project prj) {
                 ); 
     }
 
     public static File getSourceDirectoryFile(Project prj) {
         return new File(getProjectSourceDir(prj));
     }
 
     public static String getProjectBuildDir(Project prj) {
                 ); 
     }
 
     public static String getProjectSourceRoot(Project prj) {
                 ); 
     }
 
     public static File getProjectDirectory(Project prj) {
         return FileUtil.toFile(prj.getProjectDirectory());
     }
 
     public static String getProjectRelativePath(Project prjString absPath) {
         String relPath = null;
         if (absPath != null) {
             String projectDirectory = 
                     getProjectDirectory(prj).getAbsolutePath();
 
             if (absPath.toLowerCase().indexOf(projectDirectory.toLowerCase()) 
                     != -1) {
                 relPath = absPath.substring(projectDirectory.length() + 1);
             } else {
                 relPath = absPath;
             }
         }
 
         return relPath;
     }
 
     private static void addJAXBLibrary(Project prj) {
         SourceGroup[] sgs = ProjectUtils.getSources(prj).getSourceGroups(
                 .);
         ClassPath compileClassPath = ClassPath.getClassPath(sgs[0]
                 .getRootFolder(), .);
         ClassPath bootClassPath = ClassPath.getClassPath(sgs[0]
                 .getRootFolder(), .);
         ClassPath classPath = ClassPathSupport.createProxyClassPath(
                 new ClassPath[]{compileClassPathbootClassPath});
         FileObject jaxbClass = classPath.findResource(
                 ); 
         if (jaxbClass == null) {
             // Add JAXB jars if not in the classpath
             Library jaxbLib = LibraryManager.getDefault().getLibrary(
                     );
             Sources srcs = ProjectUtils.getSources(prj);
             if (srcs != null) {
                 SourceGroup[] srg = srcs.getSourceGroups(
                         .);
                 if ((srg != null) && (srg.length > 0)) {
                     try {
                         ProjectClassPathModifier.addLibraries(
                                 new Library[]{jaxbLib}, srg[0].getRootFolder(), 
                                 .);
                     } catch (IOException ex) {
                         Exceptions.printStackTrace(ex);
                     }
                 }
             }
         }
     }
 
     public static int getProjectType(Project prj) {
         String prjClzName = prj.getClass().getName();
         int prjType = ;
         if (prjClzName.indexOf("EjbJarProject") != -1) {//NOI18N
             prjType = ;
         } else if (prjClzName.indexOf("WebProject") != -1) {//NOI18N
             prjType = ;
         }
 
         return prjType;
     }
 
     public static Schemas getXMLBindingSchemas(Project prj) {
         Schemas scs = null;
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
             String projName = fo.getName();
             File projDir = FileUtil.toFile(fo);
             File configFile = null;
             try {
                 configFile = new File(projDir + . 
                         + );
                 if (configFile.exists()) {
                     scs = Schemas.read(configFile);
                 } else {
                     scs = new Schemas();
                     Lookup lookup = prj.getLookup();
                     if (lookup != null) {
                         ProjectInformation pi = lookup.lookup(
                                 ProjectInformation.class);
                         if (pi != null) {
                             projName = pi.getName();
                         }
                     }
                     scs.setProjectName(projName);
                     scs.setDestdir();
                     scs.setVersion(.);
                 }
             } catch (Exception ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
         return scs;
     }
 
     private static File getXMLBindingBuildFile(Project prj) {
         File buildFile = null;
 
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
             File projDir = FileUtil.toFile(fo);
 
             try {
                 buildFile = new File(projDir + . 
                         + );
             } catch (Exception ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
 
         return buildFile;
     }
 
     private static File getXMLBindingConfigFile(Project prj) {
         File configFile = null;
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
             File projDir = FileUtil.toFile(fo);
 
             try {
                 configFile = new File(projDir + . 
                         + );
             } catch (Exception ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
         return configFile;
     }
 
     private static void saveXMLBindingSchemas(Project prjSchemas scs) {
         try {
             File configFile = getXMLBindingConfigFile(prj);
             if (configFile != null) {
                 scs.write(configFile);
             }
         } catch (Exception ex) {
             Exceptions.printStackTrace(ex);
         }
     }
 
     private static XjcOptions populateXjcOptions(WizardDescriptor wiz) {
         XjcOptions xjcOpts = new XjcOptions();
         Map<StringBooleanoptions = (Map<StringBoolean>) wiz.getProperty(
                 .);
         if (options != null) {
             Set<Stringkeys = options.keySet();
             Iterator<Stringitr = keys.iterator();
             String key = null;
             Boolean value;
             XjcOption xjcOption = null;
 
             while (itr.hasNext()) {
                 key = itr.next();
                 value = options.get(key);
                 xjcOption = new XjcOption();
                 xjcOption.setName(key);
                 xjcOption.setValue(value.toString());
                 xjcOpts.addXjcOption(xjcOption);
             }
         }
         return xjcOpts;
     }
 
     public static FileObject retrieveResource(FileObject targetFolder
             URI source){
         Retriever retriever = Retriever.getDefault();
         FileObject result = null;
         try {
             result = retriever.retrieveResource(targetFoldersource);
         } catch (UnknownHostException ex) {
             Exceptions.printStackTrace(ex);
         } catch (URISyntaxException ex) {
             Exceptions.printStackTrace(ex);
         } catch (IOException ex) {
             Exceptions.printStackTrace(ex);
         }
 
         if (result == null) {
             // XXX TODO Handle or log exception.
             // Map map = retriever.getRetrievedResourceExceptionMap();
         }
         return result;
     }
 
     private static String replace(String strString replace,
             String replaceWith){
         return str.replaceFirst(replacereplaceWith);
     }
     
     private static Map<StringStringgetOrigNewLocationMap(Schema oSchema,
             String newNameString schemasRootFolder){
         Map<StringStringret = new HashMap<StringString>();
         String replace = schemasRootFolder + "/" + oSchema.getName(); //NOI18N
         String replaceWith = schemasRootFolder + "/" + newName//NOI18N
         
         SchemaSources ss = oSchema.getSchemaSources();
         SchemaSource[] ssArray = ss.getSchemaSource();
         for (SchemaSource s : ssArray){
             ret.put(s.getOrigLocation(), 
                     replace(s.getLocation(), replacereplaceWith));
         }
         
         Bindings bindings = oSchema.getBindings();
         if (bindings != null){
             Binding[] bs = bindings.getBinding();
             for (Binding b : bs){
                 ret.put(b.getOrigLocation(), 
                     replace(b.getLocation(), replacereplaceWith));
             }
         }
         
         Catalog c = oSchema.getCatalog();
         if ((c != null) && (c.getOrigLocation() != null)){
             ret.put(c.getOrigLocation(), 
                     replace(c.getLocation(), replacereplaceWith));
         }
         return ret;
     }
      
 
     private static void deleteStaleResources(FileObject projRootFo
             Map<StringStringmapList<Stringfiles2skip) {
 
         Set<Stringkeys = map.keySet();
         FileObject fo = null;
         String relPath = null;
         for (String keykeys){
             relPath = map.get(key);
             if (!files2skip.contains(relPath)){
                 fo = projRootFo.getFileObject(relPath);
                 if (fo != null){
                     try {
                         fo.delete();
                     } catch (Exception ex){
                         Exceptions.printStackTrace(ex);
                     }
                 }
             }
         }
     }
 
     public static Schema importResources(Project projectWizardDescriptor wiz,
             Schema oSchemathrows IOException {
         // If Schema name is changed rename the directory to 
         // new name. We should not over write again Schema, 
         // Binding and catalog files.
         
         Map<StringStringres2Skip = null;
         Map<StringStringtobeRemoved = null;
         List<StringnewProjFiles = new ArrayList<String>();
         String oSchemaName = null;
 
         FileObject projFO = project.getProjectDirectory();
         FileObject projectSchemaDir = getFOProjectSchemaDir(project);        
         File projSchemasDir = FileUtil.toFile(projectSchemaDir);       
         File projDir = FileUtil.toFile(projFO);       
         
         Schema schema = new Schema();
         SchemaSources sss = new SchemaSources();
         SchemaSource ss = null;        
         Bindings bindings = new Bindings(); 
         Binding binding = null;
         Catalog catalog = new Catalog();
 
         schema.setName((Stringwiz.getProperty(
                 .));
         schema.setPackage((Stringwiz.getProperty(
                 .));
         schema.setCatalog(catalog);
         schema.setBindings(bindings);
         schema.setSchemaSources(sss);
         schema.setType((Stringwiz.getProperty(
                 .));
         schema.setXjcOptions(populateXjcOptions(wiz));
                         
         // If schema name is changed rename the old directory.
         if (oSchema != null) {
             //FileUtil.getRelativePath(projFO, newFileFO)
             res2Skip = getOrigNewLocationMap(oSchemaschema.getName(),
                     FileUtil.getRelativePath(projFOprojectSchemaDir));
             tobeRemoved = new HashMap<StringString>();
             tobeRemoved.putAll(res2Skip) ;
 
             oSchemaName = oSchema.getName();
 
             if (! oSchemaName.equals(schema.getName())){
                 File oSchemaDir = new File(projSchemasDiroSchemaName);
                 // Do we need this?
                 if (!oSchemaDir.exists()) {
                     // Do not use File.mkdirs();
                     // see  http://www.netbeans.org/servlets/BrowseList?list=nbdev&by=thread&from=827178
                     //oSchemaDir.mkdirs();
                     FileUtil.createFolder(oSchemaDir);
                 }
 
                 FileObject oSchemaDirFO = FileUtil.toFileObject(oSchemaDir);
                 FileLock fl = null;
                 try {
                     fl = oSchemaDirFO.lock();
                     oSchemaDirFO.rename(flschema.getName(), null);
                 } catch (Exception ex){
                     Exceptions.printStackTrace(ex);
                 } finally {
                     if (fl != null){
                         fl.releaseLock();
                     }
                 }
             }
         } else {
             res2Skip = new HashMap<StringString>();
             tobeRemoved = new HashMap<StringString>();
         }
 
         
         File schemaDir = new File(projSchemasDirschema.getName());
         if (!schemaDir.exists()) {
             //schemaDir.mkdirs();
             FileUtil.createFolder(schemaDir);
         }
         
         FileObject schemaDirFO = FileUtil.toFileObject(schemaDir);
         File srcFile = null;
         File targetFile = null;
         FileObject newFileFO = null;
         String url = null;
         URL remoteSchema = null;
 
         List<StringxsdFileList = (List<String>) wiz.getProperty(
                 . );
 
         List<StringbindingFileList = (List<String>) wiz.getProperty(
                 .);
 
         String catlogFile = (Stringwiz.getProperty(
                 .);
         
         boolean srcLocTypeUrl = ..equals(
                 (Stringwiz.getProperty(
                 .));
         if (xsdFileList != null){
             // Schema files 
             for (int i = 0; i < xsdFileList.size(); i++) {
                 if (srcLocTypeUrl) {
                     // URL
                     url = xsdFileList.get(i);
                     ss = new SchemaSource();
                     ss.setOrigLocation(url);
                     ss.setOrigLocationType(
                             .);
                     sss.addSchemaSource(ss);                        
                     tobeRemoved.remove(url);
                     if (res2Skip.get(url) == null){
                         remoteSchema = new URL(url);
                         try {
                             newFileFO = retrieveResource(schemaDirFO
                                     remoteSchema.toURI());
                         } catch (URISyntaxException ex) {
                             throw new IOException(ex.getMessage());
                         }
                         ss.setLocation(FileUtil.getRelativePath(projFO,
                                 newFileFO));
                         newProjFiles.add(FileUtil.getRelativePath(projFO,
                                 newFileFO));
                     } else {
                         ss.setLocation(res2Skip.get(url));
                         newProjFiles.add(res2Skip.get(url));
                     }
                 } else {
                     // Local file
                     ss = new SchemaSource();
                     ss.setOrigLocation(xsdFileList.get(i));
                     sss.addSchemaSource(ss);                        
                     tobeRemoved.remove(xsdFileList.get(i));
                     if (res2Skip.get(xsdFileList.get(i)) == null){
                         //srcFile = new File(xsdFileList.get(i));
                         srcFile = FileSysUtil.Relative2AbsolutePath(projDir
                                 xsdFileList.get(i));                        
                         targetFile = new File(schemaDirsrcFile.getName());
                         if (targetFile.exists()) {
                             targetFile.delete();
                         }
                         newFileFO = retrieveResource(schemaDirFO,
                                 srcFile.toURI());
                         ss.setLocation(FileUtil.getRelativePath(projFO
                                 newFileFO));
                         newProjFiles.add(FileUtil.getRelativePath(projFO
                                 newFileFO));
                     } else {
                         ss.setLocation(res2Skip.get(xsdFileList.get(i)));
                         newProjFiles.add(res2Skip.get(xsdFileList.get(i)));
                     }
                 }
             }            
         }
 
         if (bindingFileList != null){        
             // Binding files
             for (int i = 0; i < bindingFileList.size(); i++) {
                 // All binding files are from local sources
                 // Assumes there is not name conflict between other binding and 
                 // Schema files.
                 binding = new Binding();
                 binding.setOrigLocation(bindingFileList.get(i));
                 bindings.addBinding(binding);                    
                 tobeRemoved.remove(bindingFileList.get(i));
 
                 if (res2Skip.get(bindingFileList.get(i)) == null){
                     //srcFile = new File(bindingFileList.get(i));
                     srcFile = FileSysUtil.Relative2AbsolutePath(projDir,
                             bindingFileList.get(i));
                     targetFile = new File(schemaDirsrcFile.getName());
                     if (targetFile.exists()) {
                         targetFile.delete();
                     }
 
                     newFileFO = retrieveResource(schemaDirFOsrcFile.toURI());
 
                     binding.setLocation(FileUtil.getRelativePath(projFO
                             newFileFO));
                     newProjFiles.add(FileUtil.getRelativePath(projFO
                             newFileFO));
                 } else {
                     binding.setLocation(res2Skip.get(bindingFileList.get(i)));
                     newProjFiles.add(res2Skip.get(bindingFileList.get(i)));
                 }
             }
         }
         
         //Catalog file
         if (catlogFile != null){
             catalog.setOrigLocation(catlogFile);
             tobeRemoved.remove(catlogFile);
 
             if (res2Skip.get(catlogFile) == null){
                 //srcFile = new File(catlogFile);
                 srcFile = FileSysUtil.Relative2AbsolutePath(projDir
                         catlogFile);
                 targetFile = new File(schemaDirsrcFile.getName());
                 if (targetFile.exists()) {
                     targetFile.delete();
                 }
 
                 newFileFO = retrieveResource(schemaDirFOsrcFile.toURI());            
                 catalog.setLocation(FileUtil.getRelativePath(projFO,
                     newFileFO));
                 newProjFiles.add(FileUtil.getRelativePath(projFO,
                     newFileFO));
             } else {
                 catalog.setLocation(res2Skip.get(catlogFile));
                 newProjFiles.add(res2Skip.get(catlogFile));
             }
         }
         
         deleteStaleResources(projFOtobeRemovednewProjFiles);
         return schema;
     }
 
     public static AntProjectHelper getAntProjectHelper(Project project) {
         try {
             Method getAntProjectHelperMethod = project.getClass().getMethod(
                     "getAntProjectHelper"); //NOI18N
             if (getAntProjectHelperMethod != null) {
                 AntProjectHelper helper = (AntProjectHelper
                         getAntProjectHelperMethod.invoke(project);
 
                 return helper;
             }
         } catch (NoSuchMethodException nme) {
             Exceptions.printStackTrace(nme);
         } catch (Exception ex) {
             Exceptions.printStackTrace(ex);
         }
 
         return null;
     }
 
     public static FileObject getFOForProjectBuildFile(Project prj) {
         FileObject buildFileFo = null;
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
             buildFileFo = fo.getFileObject("build.xml"); //NOI18N
         }
         return buildFileFo;
     }
 
     public static FileObject getFOForNBProjectDir(Project prj) {
         return prj.getProjectDirectory().getFileObject();
     }
 
     public static FileObject getFOForBindingConfigFile(Project prj) {
         FileObject configFile = null;
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
 
             try {
                 fo.getFileObject( + ).refresh();
                 configFile = fo.getFileObject( 
                         +  + );
             } catch (Exception ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
         return configFile;
     }
 
     public static FileObject getFOForBindingBuildFile(Project prj) {
         FileObject buildFileFo = null;
         if (prj != null) {
             FileObject fo = prj.getProjectDirectory();
             try {
                 fo.getFileObject( + ).refresh();                
                 buildFileFo = fo.getFileObject( 
                         +  + );
             } catch (Exception ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
 
         return buildFileFo;
     }
 
     private static void createDirs(FileObject rootDirString relDir)  {
         File fileRootDir = FileUtil.toFile(rootDir);
         File fileRelDirs = new File(fileRootDirrelDir);
         if (!fileRelDirs.exists()) {
             // Do not use fileRelDirs.mkdirs();
             // see  http://www.netbeans.org/servlets/BrowseList?list=nbdev&by=thread&from=827178
             try {
                 FileUtil.createFolder(rootDirrelDir);
             } catch (IOException ex){
                 Exceptions.printStackTrace(ex);
             }
         }
     }
 
     public static FileObject getFOProjectSchemaDir(Project project) {
         String srcDirStr = null;
         FileObject foSchemaDir = null;
         FileObject foProjDir = project.getProjectDirectory();
         if ((getProjectType(project) == 
                 || (getProjectType(project) == )) {
             srcDirStr = getProjectSourceRoot(project);
             FileObject srcDir = foProjDir.getFileObject(srcDirStr);
             createDirs(srcDir);
             foSchemaDir = srcDir.getFileObject();//NOI18N
         } else {
             FileObject srcDir = foProjDir;
             createDirs(srcDir);
             foSchemaDir = srcDir.getFileObject(); //NOI18N
         }
         return foSchemaDir;
     }
     
     private static void addClasspathProperties(Project prj){
         String xjcClasspath = getProjectProperty(prj);
         boolean modified = false;
         if ((xjcClasspath == null) || ("".equals(xjcClasspath))){
             saveProjectProperty(prj
                     );
             modified = true;
         }
 
         String xjcRunClasspath = getProjectProperty(prj);
         if ((xjcRunClasspath == null) || ("".equals(xjcRunClasspath))){
             saveProjectProperty(prj
                     );
             modified = true;
         }
         
         String jaxbGenSrcClasspath = getProjectProperty(prj
                 );
         if ((jaxbGenSrcClasspath == null) || ("".equals(jaxbGenSrcClasspath))){
             saveProjectProperty(prj
                     );
             modified = true;
         }
         
         if (modified){
             try{
                 ProjectManager.getDefault().saveProject(prj);
             }catch (IOException ioe) {
                 Exceptions.printStackTrace(ioe);
             }
         }
     }
     
     public static Schema addSchema(Project projectSchemas scsSchema schema){
         try {
             scs.addSchema(schema);
             saveXMLBindingSchemas(projectscs);
             refreshBuildScript(project);
             addClasspathProperties(project);
 
             // Register our build XML file, if not already.
             // http://wiki.netbeans.org/wiki/view/BuildScriptExtensibility
             // http://www.netbeans.org/issues/show_bug.cgi?id=93509
             AntBuildExtender ext = project.getLookup().lookup(
                     AntBuildExtender.class);
             if (ext != null && ext.getExtension() == null) {
                 FileObject jaxbBuildXml = getFOForBindingBuildFile(project);
                 AntBuildExtender.Extension jaxbBuild = ext.addExtension
                         jaxbBuildXml); 
                 jaxbBuild.addDependency(
                         .,
                         .);
                 ProjectManager.getDefault().saveProject(project);
                 String buildDir = getProjectBuildDir(project);
                 if (project.getProjectDirectory() != null){
                     FileObject buildFo = project.getProjectDirectory().getFileObject(buildDir);
                     if (buildFo != null){
                         buildFo.refresh();
                     }
                 }
             }
         } catch (IOException ioe) {
             Exceptions.printStackTrace(ioe);
         }
         return schema;
     }

    
Returns list of String Schema/Binding names used in the project.
 
     public static List<StringgetSchemaNames(Project project) {
         List<Stringret = new ArrayList<String>();
         Schemas scs = getXMLBindingSchemas(project);
         if (scs != null) {
             Schema[] schemas = scs.getSchema();
             for (Schema schema : schemas) {
                 ret.add(schema.getName());
             }
         }
         return ret;
     }
 
     public static void removeSchema(Project projectSchemas scs
             Schema schema){
         try {
             scs.removeSchema(schema);
             saveXMLBindingSchemas(projectscs);
             refreshBuildScript(project);
         } catch (Exception ex) {
             Exceptions.printStackTrace(ex);
         }
     }
 
     public static void compileXSDs(final Project project) {
         compileXSDs(projectfalse);
     }
 
     public static void compileXSDs(final Project project
             final boolean addLibs){
         executeAntTarget(projectaddLibs
                 .);
     }
 
     public static void cleanCompileXSDs(final Project project
             final boolean addLibs)
     {
         cleanCompileXSDs(projectaddLibsnull);
     }
     
     public static void cleanCompileXSDs(final Project project
             final boolean addLibsTaskListener listener ){
         executeAntTarget(projectaddLibs
                 .listener );
     }
     
     private static void executeAntTarget(final Project project,
             final boolean addLibs,
             final String antTarget)
     {
         executeAntTarget(projectaddLibsantTargetnull );
     }
 
     private static void executeAntTarget(final Project project,
             final boolean addLibs,
             final String antTargetTaskListener listener )
     {
         final ProgressHandle progressHandle = ProgressHandleFactory
                 .createHandle(NbBundle.getMessage(ProjectHelper.class
                 "MSG_JAXB_PROGRESS")); //NOI18N;
         progressHandle.start();
 
         Runnable run = new Runnable() {
             public void run() {
                 try {
                     if (addLibs) {
                         addJAXBLibrary(project);
                     }
 
                     FileObject buildXml = getFOForProjectBuildFile(project);
                     String[] args = new String[]{antTarget};
                                         
                     if (buildXml != null) {
                         ExecutorTask task = ActionUtils.runTarget(buildXml,
                                 argsnull);
                         task.waitFinished();
                         if (task.result() != 0) {
                             String mes = NbBundle.getMessage(
                                     ProjectHelper.class"MSG_ERROR_COMPILING"); //NOI18N
                             NotifyDescriptor desc = new NotifyDescriptor
                                     .Message(mes
                                     ..);
                             DialogDisplayer.getDefault().notify(desc);
                         }
                     }
                 } catch (IOException ioe) {
                     Exceptions.printStackTrace(ioe);
                 } catch (Exception e) {
                     Exceptions.printStackTrace(e);
                 } finally {
                     progressHandle.finish();
                 }
             }
         };
 
         Task task = RequestProcessor.getDefault().create(run);
         if ( listener != null ){
             task.addTaskListener(listener);
         }
         task.schedule(0);
     }
     
 //    private static boolean isJDK6(final Project prj) {
 //        boolean ret = false;
 //        JavaPlatformManager jpm = JavaPlatformManager.getDefault();
 //        if (jpm != null) {
 //            String platForm = getProjectProperty(prj, PLATFORM_ACTIVE);
 //            if (DEFAULT_PLATFORM.equals(platForm)) {
 //