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.websvc.rest.spi;
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
All development project type supporting REST framework should provide one instance of this in project lookup.

Author(s):
Nam Nguyen
public abstract class RestSupport {
    public static final String SWDP_LIBRARY = "restlib"//NOI18N
    public static final String RESTAPI_LIBRARY = "restapi"//NOI18N
    protected static final String GFV3_RESTLIB = "restlib_gfv3ee6"// NOI18N
    protected static final String GFV31_RESTLIB = "restlib_gfv31ee6"// NOI18N
    public static final String PROP_SWDP_CLASSPATH = "libs.swdp.classpath"//NOI18N
    public static final String PROP_RESTBEANS_TEST_DIR = "restbeans.test.dir"//NOI18N
    public static final String PROP_RESTBEANS_TEST_FILE = "restbeans.test.file";//NOI18N
    public static final String PROP_RESTBEANS_TEST_URL = "restbeans.test.url";//NOI18N
    public static final String PROP_BASE_URL_TOKEN = "base.url.token";//NOI18N
    public static final String PROP_APPLICATION_PATH = "rest.application.path";//NOI18N
    public static final String BASE_URL_TOKEN = "___BASE_URL___";//NOI18N
    public static final String RESTBEANS_TEST_DIR = "build/generated-sources/rest-test";//NOI18N
    public static final String COMMAND_TEST_RESTBEANS = "test-restbeans";//NOI18N
    public static final String COMMAND_DEPLOY = "run-deploy";//NOI18N
    public static final String TEST_RESBEANS = "test-resbeans";//NOI18N
    public static final String TEST_RESBEANS_HTML =  + ".html";//NOI18N
    public static final String TEST_RESBEANS_JS =  + ".js";
    public static final String TEST_RESBEANS_CSS =  + ".css";//NOI18N
    public static final String TEST_RESBEANS_CSS2 = "css_master-all.css";//NOI18N
    public static final String REST_SERVLET_ADAPTOR = "ServletAdaptor";//NOI18N
    public static final String REST_SERVLET_ADAPTOR_CLASS = "com.sun.jersey.spi.container.servlet.ServletContainer"//NOI18N
    public static final String REST_SERVLET_ADAPTOR_CLASS_OLD = "com.sun.ws.rest.impl.container.servlet.ServletAdaptor";  //NOI18N 
    public static final String REST_SPRING_SERVLET_ADAPTOR_CLASS = "com.sun.jersey.spi.spring.container.servlet.SpringServlet";    //NOI18N
    public static final String REST_SERVLET_ADAPTOR_MAPPING = "/resources/*";//NOI18N
    public static final String PARAM_WEB_RESOURCE_CLASS = "webresourceclass";//NOI18N
    public static final String WEB_RESOURCE_CLASS = "webresources.WebResources";//NOI18N
    public static final String REST_API_JAR = "jsr311-api.jar";//NOI18N
    public static final String REST_RI_JAR = "jersey";//NOI18N
    public static final String IGNORE_PLATFORM_RESTLIB = "restlib.ignore.platform";//NOI18N
    public static final String JSR311_JAR_PATTERN = "jsr311-api.*\\.jar";//NOI18N
    public static final String JERSEY_API_LOCATION = "modules/ext/rest";//NOI18N
    public static final String JTA_USER_TRANSACTION_CLASS = "javax/transaction/UserTransaction.class";  //NOI18
    public static final String J2EE_SERVER_TYPE = "j2ee.server.type";       //NOI18N
    public static final String TOMCAT_SERVER_TYPE = "tomcat";       //NOI18N
    public static final String GFV3_SERVER_TYPE = "gfv3";          //NOI18N
    public static final String GFV2_SERVER_TYPE = "J2EE";          //NOI18N
    public static final int PROJECT_TYPE_DESKTOP = 0; //NOI18N
    public static final int PROJECT_TYPE_WEB = 1; //NOI18N
    public static final int PROJECT_TYPE_NB_MODULE = 2; //NOI18N
    
    private AntProjectHelper helper;
    protected final Project project;

    
Creates a new instance of RestSupport
    public RestSupport(Project project) {
        if (project == null) {
            throw new IllegalArgumentException("Null project");
        }
        this. = project;
    }
   
    
Handles upgrades between different jersey releases.
    public abstract void upgrade();

    
Ensure the project is ready for REST development. Typical implementation would need to invoke addSwdpLibraries REST development with servlet container would need to add servlet adaptor to web.xml.
    public abstract void ensureRestDevelopmentReady() throws IOException;

    
Cleanup the project from previously added REST development support artifacts. This should not remove any user source code.
    public abstract void removeRestDevelopmentReadiness() throws IOException;

    
Is the REST development setup ready: SWDP library added, REST adaptors configured, generic test client created ?
    public abstract boolean isReady();
    
    
Get persistence.xml file.
    public abstract FileObject getPersistenceXml();

    
Get Data Source for JNDI name

Parameters:
jndiName JNDI name
Returns:
    public abstract Datasource getDatasource(String jndiName);
  
    public FileObject findSourceRoot() {
        return findSourceRoot(getProject());
    }
    
    public static FileObject findSourceRoot(Project project) {
        SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
                .);
        if (sourceGroups != null && sourceGroups.length > 0) {
            return sourceGroups[0].getRootFolder();
        }
        return null;
    }
    
    private static ClassPath getClassPathProject projectString type ) {
        ClassPathProvider provider = project.getLookup().lookup(
                ClassPathProvider.class);
        if ( provider == null ){
            return null;
        }
        Sources sources = project.getLookup().lookup(Sources.class);
        if ( sources == null ){
            return null;
        }
        SourceGroup[] sourceGroups = sources.getSourceGroups(
                . );
        List<ClassPathclassPaths = new ArrayList<ClassPath>( sourceGroups.length); 
        for (SourceGroup sourceGroup : sourceGroups) {
            String sourceGroupId = sourceGroup.getName();
            if ( sourceGroupId!= null && sourceGroupId.contains("test")) {  // NOI18N
                continue;
            }
            FileObject rootFolder = sourceGroup.getRootFolder();
            ClassPath path = provider.findClassPathrootFoldertype);
            classPaths.addpath );
        }
        return ClassPathSupport.createProxyClassPathclassPaths.toArray
                new ClassPathclassPaths.size()] ));
    }
    public void addModelListener(PropertyChangeListener listener) {
        .add(listener);
        if ( != null) {
            .addPropertyChangeListener(listener);
        }
    }
    public void removeModelListener(PropertyChangeListener listener) {
        .remove(listener);
        if ( != null) {
            .removePropertyChangeListener(listener);
        }
    }
    
        FileObject sourceRoot = findSourceRoot();
        if ( == null && sourceRoot != null) {
            ClassPathProvider cpProvider = getProject().getLookup().lookup(ClassPathProvider.class);
            if (cpProvider != null) {
                ClassPath compileCP = cpProvider.findClassPath(sourceRoot.);
                ClassPath bootCP = cpProvider.findClassPath(sourceRoot.);
                ClassPath sourceCP = cpProvider.findClassPath(sourceRoot.);
                if (compileCP != null && bootCP != null) {
                    MetadataUnit metadataUnit = MetadataUnit.create(
                            bootCP,
                            extendWithJsr311Api(compileCP),
                            sourceCP,
                            null);
                     = RestServicesMetadataModelFactory.createMetadataModel(metadataUnit);
                    for (PropertyChangeListener pcl : ) {
                        .addPropertyChangeListener(pcl);
                    }
                }
            }
        }
        return ;
    }
        FileObject sourceRoot = findSourceRoot();
        if ( == null && sourceRoot != null) {
            ClassPathProvider cpProvider = getProject().getLookup().lookup(ClassPathProvider.class);
            /*
             * Fix for BZ#158250 -  NullPointerException: The classPath parameter cannot be null 
             * 
             MetadataUnit metadataUnit = MetadataUnit.create(
                    cpProvider.findClassPath(sourceRoot, ClassPath.BOOT),
                    cpProvider.findClassPath(sourceRoot, ClassPath.COMPILE),
                    cpProvider.findClassPath(sourceRoot, ClassPath.SOURCE),
                    null);*/
            MetadataUnit metadataUnit = MetadataUnit.create(
                    getClassPath(getProject(), .),
                    getClassPath(getProject(), .),
                    getClassPath(getProject(), .),
                    null
                    );
             =
                    RestServicesMetadataModelFactory.createApplicationMetadataModel(metadataUnit);
        }
        return ;
    }
    protected void refreshRestServicesMetadataModel() {
        if ( != null) {
            for (PropertyChangeListener pcl : ) {
                .removePropertyChangeListener(pcl);
            }
             = null;
        }
        try {
            RestServicesModel model = getRestServicesModel();
            if (model != null) {
                model.runReadAction(new MetadataModelAction<RestServicesMetadataVoid>() {
                    @Override
                    public Void run(RestServicesMetadata metadatathrows IOException {
                        metadata.getRoot().sizeRestServiceDescription();
                        return null;
                    }
                });
            }
        } catch (IOException ex) {
            Logger.getLogger(this.getClass().getName()).log(.ex.getLocalizedMessage(), ex);
        }
    }
    
    public static ClassPath extendWithJsr311Api(ClassPath classPath) {
        File jerseyRoot = InstalledFileLocator.getDefault().locate(nullfalse);
        if (jerseyRoot != null && jerseyRoot.isDirectory()) {
            File[] jsr311Jars = jerseyRoot.listFiles(new JerseyFilter());
            if (jsr311Jars != null && jsr311Jars.length>0) {
                return extendClassPath(classPathjsr311Jars[0]);
            }
        }
        return classPath;
    }
    
    public static ClassPath extendClassPath(ClassPath classPathFile path) {
        if (path == null) {
            return classPath;
        }
        try {
            PathResourceImplementation jsr311Path = getPathResource(path);
            List<PathResourceImplementationroots = new ArrayList<PathResourceImplementation>();
            roots.add(jsr311Path);
            for (FileObject fo : classPath.getRoots()) {
                roots.add(ClassPathSupport.createResource(fo.getURL()));
            }
            return ClassPathSupport.createClassPath(roots);
        } catch (Exception ex) {
            return classPath;
        }
    }
    private static PathResourceImplementation getPathResource(File paththrows MalformedURLException {
        URL url = path.toURI().toURL();
        if (FileUtil.isArchiveFile(url)) {
            url = FileUtil.getArchiveRoot(url);
        } else {
            url = path.toURI().toURL();
            String surl = url.toExternalForm();
            if (!surl.endsWith("/")) {
                url = new URL(surl + "/");
            }
        }
        return ClassPathSupport.createResource(url);
    }
    public abstract void extendBuildScripts() throws IOException;
    
    
    public abstract FileObject generateTestClient(File testdirString url
        throws IOException
    
    
Generates test client. Typically RunTestClientAction would need to call this before invoke the build script target.

Parameters:
destDir directory to write test client files in.
url base url of rest service
Returns:
test file object, containing token BASE_URL_TOKEN whether used or not.
    public FileObject generateTestClient(File testdirthrows IOException {        
        
        if (! testdir.isDirectory()) {
            FileUtil.createFolder(testdir);
        }
        String[] replaceKeys1 = {
            "TTL_TEST_RESBEANS""MSG_TEST_RESBEANS_INFO"
        };
        String[] replaceKeys2 = {
            "MSG_TEST_RESBEANS_wadlErr""MSG_TEST_RESBEANS_No_AJAX""MSG_TEST_RESBEANS_Resource",
            "MSG_TEST_RESBEANS_See""MSG_TEST_RESBEANS_No_Container""MSG_TEST_RESBEANS_Content"
            "MSG_TEST_RESBEANS_TabularView""MSG_TEST_RESBEANS_RawView""MSG_TEST_RESBEANS_ResponseHeaders"
            "MSG_TEST_RESBEANS_Help""MSG_TEST_RESBEANS_TestButton""MSG_TEST_RESBEANS_Loading"
            "MSG_TEST_RESBEANS_Status""MSG_TEST_RESBEANS_Headers""MSG_TEST_RESBEANS_HeaderName",
            "MSG_TEST_RESBEANS_HeaderValue""MSG_TEST_RESBEANS_Insert""MSG_TEST_RESBEANS_NoContents"
            "MSG_TEST_RESBEANS_AddParamButton""MSG_TEST_RESBEANS_Monitor""MSG_TEST_RESBEANS_No_SubResources"
            "MSG_TEST_RESBEANS_SubResources""MSG_TEST_RESBEANS_ChooseMethod""MSG_TEST_RESBEANS_ChooseMime"
            "MSG_TEST_RESBEANS_Continue""MSG_TEST_RESBEANS_AdditionalParams""MSG_TEST_RESBEANS_INFO"
            "MSG_TEST_RESBEANS_Request""MSG_TEST_RESBEANS_Sent""MSG_TEST_RESBEANS_Received"
            "MSG_TEST_RESBEANS_TimeStamp""MSG_TEST_RESBEANS_Response""MSG_TEST_RESBEANS_CurrentSelection",
            "MSG_TEST_RESBEANS_DebugWindow""MSG_TEST_RESBEANS_Wadl""MSG_TEST_RESBEANS_RequestFailed"
            
        };
        FileObject testFO = copyFile(testdirreplaceKeys1true);
        copyFile(testdirreplaceKeys2false);
        copyFile(testdir);
        copyFile(testdir);
        copyFile(testdir"expand.gif");
        copyFile(testdir"collapse.gif");
        copyFile(testdir"item.gif");
        copyFile(testdir"cc.gif");
        copyFile(testdir"og.gif");
        copyFile(testdir"cg.gif");
        copyFile(testdir"app.gif");
        File testdir2 = new File(testdir"images");
        testdir2.mkdir();
        copyFile(testdir"images/background_border_bottom.gif");
        copyFile(testdir"images/pbsel.png");
        copyFile(testdir"images/bg_gradient.gif");
        copyFile(testdir"images/pname.png");
        copyFile(testdir"images/level1_deselect.jpg");
        copyFile(testdir"images/level1_selected-1lvl.jpg");
        copyFile(testdir"images/primary-enabled.gif");
        copyFile(testdir"images/masthead.png");
        copyFile(testdir"images/masthead_link_enabled.gif");
        copyFile(testdir"images/masthead_link_roll.gif");
        copyFile(testdir"images/primary-roll.gif");
        copyFile(testdir"images/pbdis.png");
        copyFile(testdir"images/secondary-enabled.gif");
        copyFile(testdir"images/pbena.png");
        copyFile(testdir"images/tbsel.png");
        copyFile(testdir"images/pbmou.png");
        copyFile(testdir"images/tbuns.png");
        return testFO;
    }
    /*
     * Copy File, as well as replace tokens, overwrite if specified
     */
    public static FileObject copyFile(File testdirString nameString[] replaceKeysboolean overwritethrows IOException {
        FileObject dir = FileUtil.toFileObject(testdir);
        FileObject fo = dir.getFileObject(name);
        if (fo == null) {
            fo = dir.createData(name);
        } else {
            if(!overwrite)
                return fo;
        }
        FileLock lock = null;
        BufferedWriter writer = null;
        BufferedReader reader = null;
        try {
            lock = fo.lock();
            OutputStream os = fo.getOutputStream(lock);
            writer = new BufferedWriter(new OutputStreamWriter(os));
            InputStream is = RestSupport.class.getResourceAsStream("resources/"+name);
            reader = new BufferedReader(new InputStreamReader(is));
            String line;
            String lineSep = "\n";//Unix
            if(. == '\\')//Windows
                lineSep = "\r\n";
            String[] replaceValues = null;
            if(replaceKeys != null) {
                replaceValues = new String[replaceKeys.length];
                for(int i=0;i<replaceKeys.length;i++)
                    replaceValues[i] = NbBundle.getMessage(RestSupport.classreplaceKeys[i]);
            }
            while((line = reader.readLine()) != null) {
                for(int i=0;i<replaceKeys.length;i++)
                    line = line.replaceAll(replaceKeys[i], replaceValues[i]);
                writer.write(line);
                writer.write(lineSep);
            }
        } finally {
            if (writer != null) {
                writer.close();
            }
            if (lock != nulllock.releaseLock();
            if (reader != null) {
                reader.close();
            }
        }      
        return fo;
    }
    
    public static FileObject modifyFile(FileObject foMap<String,Stringreplace
        throws IOException 
    {
        StringWriter content = new StringWriter();
        FileLock lock = null;
        BufferedWriter writer = null;
        BufferedReader reader = null;
        try {
            lock = fo.lock();
            writer = new BufferedWriter(content);
            InputStream is = fo.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is));
            String line;
            String lineSep = "\n";//Unix
            if(. == '\\')//Windows
                lineSep = "\r\n";
            while((line = reader.readLine()) != null) {
                for(Entry<String,Stringentry : replace.entrySet()){
                    line = line.replaceAll(entry.getKey(), entry.getValue());
                }
                writer.write(line);
                writer.write(lineSep);
            }
        } finally {
            if (writer != null) {
                writer.close();
            }
            if ( reader!= null ){
                reader.close();
            }
            StringBuffer buffer = content.getBuffer();
            try {
                OutputStream outputStream = fo.getOutputStreamlock );
                writer = new BufferedWriternew OutputStreamWriteroutputStream ) );
                writer.writebuffer.toString() );
            }
            finally {
                if (writer != null) {
                    writer.close();
                }
            }
            if (lock != null) {
                lock.releaseLock();
            }
            if (reader != null) {
                reader.close();
            }
        }      
        return fo;
    }
    
    /*
     * Copy File only
     */    
    public static void copyFile(File testdirString namethrows IOException {
        String path = "resources/"+name;
        File df = new File(testdirname);
        if(!df.exists()) {
            InputStream is = null;
            OutputStream os = null;
            try {
                is = RestSupport.class.getResourceAsStream(path);
                os = new FileOutputStream(df);
                int c;
                while ((c = is.read()) != -1) {
                    os.write(c);
                }
            } finally {
                if(os != null) {
                    os.flush();
                    os.close();
                }
                if(is != null)
                    is.close();            
            }
        }
    }
    
    
Add SWDP library for given source file on specified class path types.

Parameters:
classPathTypes types of class path to add ("javac.compile",...)
addJersey add REST Jersey Library or not.
jaxRsClassName jsr311 class name that should be checked for presence on classpath, e.g. "javax/ws/rs/ApplicationPath.class".
    protected void addSwdpLibrary(String[] classPathTypesboolean addJerseyString jaxRsClassNamethrows IOException {
        FileObject srcRoot = findSourceRoot();
        if (srcRoot != null) {
            ClassPath cp = ClassPath.getClassPath(srcRoot.);
            if (cp.findResource(jaxRsClassName) == null) {
                Library restapiLibrary = LibraryManager.getDefault().getLibrary();
                if (restapiLibrary == null) {
                    return;
                }
                addSwdpLibrary(classPathTypesrestapiLibrary);
            }
            if (addJersey) {
                Library swdpLibrary = LibraryManager.getDefault().getLibrary();
                if (swdpLibrary == null) {
                    return;
                }
                addSwdpLibrary(classPathTypesswdpLibrary);
            }
        }
        
    }

    
Add SWDP library for given source file on specified class path types.

Parameters:
source source file object for which the libraries is added.
classPathTypes types of class path to add ("javac.compile",...)
    protected void addSwdpLibrary(String[] classPathTypesLibrary libthrows IOException {
        if (sgs == null || sgs.length < 1) {
            throw new IOException("Project has no Java sources"); //NOI18N
        }
        FileObject sourceRoot = sgs[0].getRootFolder();
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.addLibraries(new Library[] {lib}, sourceRoottype);
            } catch(UnsupportedOperationException ex) {
                Logger.getLogger(getClass().getName()).info(type+" not supported.");
            }
        }
    }
    
    protected void addSwdpLibrary(String[] classPathTypesURL[] urlsthrows IOException {
        SourceGroup[] sgs = ProjectUtils.getSources().getSourceGroups(
                .);
        if (sgs == null || sgs.length < 1) {
            throw new IOException("Project has no Java sources"); //NOI18N
        }
        ClassPath classPath = getCompileClassPath(sgs);
        URL[] roots = urls;
        if ( classPath != null ){
            List<URLtoAdd = new ArrayList<URL>(urls.length);
            for (URL url : urls) {
                if ( !contains(classPathurl)){
                    toAdd.addurl );
                }
            }
            roots = toAdd.toArraynew URL[toAdd.size()] );
        }
        
        FileObject sourceRoot = sgs[0].getRootFolder();
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.addRoots(rootssourceRoottype);
            } catch(UnsupportedOperationException ex) {
                Logger.getLogger(getClass().getName()).info(type+" not supported.");
            }
        }
    }
    
    public void removeSwdpLibrary(String[] classPathTypesthrows IOException {
        Library swdpLibrary = LibraryManager.getDefault().getLibrary();
        if (swdpLibrary == null) {
            return;
        }
         
        Library restapiLibrary = LibraryManager.getDefault().getLibrary();
        if (restapiLibrary == null) {
            
        }
        FileObject sourceRoot = sgs[0].getRootFolder();
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.removeLibraries(new Library[] {restapiLibraryswdpLibrary }, sourceRoottype);
            } catch(UnsupportedOperationException ex) {
                Logger.getLogger(getClass().getName()).info(type+" not supported.");
            }
        }
    }
    
    public Project getProject() {
        return ;
    }

    
Should be overridden by sub-classes
    public boolean hasSwdpLibrary() {
        return ! needsSwdpLibrary(getProject());
    }

    
A quick check if swdp is already part of classpath.
    private static boolean needsSwdpLibrary(Project restEnableProject) {
        // check if swdp is already part of classpath
        SourceGroup[] sgs = ProjectUtils.getSources(restEnableProject).getSourceGroups(.);
        if (sgs.length < 1) {
            return false;
        }
        FileObject sourceRoot = sgs[0].getRootFolder();
        ClassPath classPath = ClassPath.getClassPath(sourceRoot.);
        //this package name will change when open source, should just rely on subclass to use file names
        FileObject restClass = classPath.findResource();  
        if (restClass != null) {
            return false;
        }
        return true;
    }
    
    public abstract boolean isRestSupportOn();
    public void setProjectProperty(String nameString value) {
        if (getAntProjectHelper() == null) {
            return;
        }
        ep.setProperty(namevalue);
        try {
            ProjectManager.getDefault().saveProject(getProject());
        } catch(IOException ioe) {
            Logger.getLogger(this.getClass().getName()).log(.ioe.getLocalizedMessage(), ioe);
        }
    }
    public String getProjectProperty(String name) {
        if (getAntProjectHelper() == null) {
            return null;
        }
        return .getStandardPropertyEvaluator().getProperty(name);
    }
    public void removeProjectProperties(String[] propertyNames) {
        if (getAntProjectHelper() == null) {
            return;
        }
        for (String name : propertyNames) {
            ep.remove(name);
        }
        try {
            ProjectManager.getDefault().saveProject(getProject());
        } catch(IOException ioe) {
            Logger.getLogger(this.getClass().getName()).log(.ioe.getLocalizedMessage(), ioe);
        }
    }
    
    protected boolean ignorePlatformRestLibrary() {
        Boolean ignore = v != null ? Boolean.valueOf(v) : true;
        if (ignore == .) {
            return false;
        }
        return true;
    }
    
        if ( == null) {
            JAXWSSupportProvider provider = .getLookup().lookup(JAXWSSupportProvider.class);
            if (provider != null) {
                JAXWSSupport support = provider.findJAXWSSupport(.getProjectDirectory());
                if (support != null) {
                     = support.getAntProjectHelper();
                }
            }
        }
        return ;
    }
    /*public class RestServicesChangeListener implements PropertyChangeListener {
        RestServicesChangeListener() {
        }
        
        public void propertyChange(PropertyChangeEvent evt) {
            //System.out.println("updating rest services");
            try {
                final int[] serviceCount = new int[1];
                restServicesMetadataModel.runReadAction(new MetadataModelAction<RestServicesMetadata, Void>() {
                    public Void run(RestServicesMetadata metadata) throws IOException {
                        serviceCount[0] = metadata.getRoot().sizeRestServiceDescription();
                        return null;
                    }
                });
                if (serviceCount[0] > 0) {
                    ensureRestDevelopmentReady();
                } else {
                    removeRestDevelopmentReadiness();
                }
            } catch (IOException ex) {
                Logger.getLogger(this.getClass().getName()).log(Level.INFO, ex.getLocalizedMessage(), ex);
            }
            //System.out.println("done updating rest services");
        }
    }*/
    
    
Check to see if there is JTA support.
    public boolean hasJTASupport() {
        // check if swdp is already part of classpath
        if (sgs.length < 1) {
            return false;
        }
        FileObject sourceRoot = sgs[0].getRootFolder();
        ClassPath classPath = ClassPath.getClassPath(sourceRoot.);
        //this package name will change when open source, should just rely on subclass to use file names
        FileObject utxClass = classPath.findResource("javax/transaction/UserTransaction.class"); // NOI18N
        if (utxClass != null) {
            return true;
        }
        return false;
    }
    
    
Check to see if there is Spring framework support.
    public boolean hasSpringSupport() {
          // check if swdp is already part of classpath
        if (sgs.length < 1) {
            return false;
        }
        FileObject sourceRoot = sgs[0].getRootFolder();
        ClassPath classPath = ClassPath.getClassPath(sourceRoot.);
        //this package name will change when open source, should just rely on subclass to use file names
        FileObject utxClass = classPath.findResource("org/springframework/transaction/annotation/Transactional.class"); // NOI18N
        if (utxClass != null) {
            return true;
        }
        return false;
    }
     public String getServerType() {
        return getProjectProperty();
    }
    public boolean isServerTomcat() {
        String serverType = getServerType();
        if (serverType != null) {
            return serverType.toLowerCase().contains();
        }
        return false;
    }
    public boolean isServerGFV3() {
        if ( getServerType() == null ){
            return false;
        }
        return getServerType().startsWith();
    }
    public boolean isServerGFV2() {
        return .equals(getServerType());
    }
    public String getApplicationPath() throws IOException {
        return "resources"// default application path
    }
    
        J2eeModuleProvider provider = (J2eeModuleProvider.getLookup().
            lookup(J2eeModuleProvider.class);
        FileObject[] fobjs = provider.getSourceRoots();
        if (fobjs.length > 0) {
            FileObject configRoot = fobjs[0];
            FileObject webInf = configRoot.getFileObject("WEB-INF");        //NOI18N
            if (webInf != null) {
                return webInf.getFileObject("applicationContext""xml");      //NOI18N
            }
        }
        return null;
    }
    
    public abstract File getLocalTargetTestRest();
    
    public abstract String getBaseURL() throws IOException;
    
    public abstract void deploy() throws IOException;
    
    public String getContextRootURL() {
        String portNumber = "8080"//NOI18N
        String host = "localhost"//NOI18N
        String contextRoot = "";
        J2eeModuleProvider provider = .getLookup().lookup(J2eeModuleProvider.class);
        Deployment.getDefault().getServerInstance(provider.getServerInstanceID());
        String serverInstanceID = provider.getServerInstanceID();
        if (serverInstanceID == null ) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    NbBundle.getMessage(RestSupport.class"MSG_MissingServer"), 
                    .));
        } else {
            // getting port and host name
            ServerInstance serverInstance = Deployment.getDefault().
                getServerInstance(serverInstanceID);
            try {
                ServerInstance.Descriptor instanceDescriptor = 
                    serverInstance.getDescriptor();
                if (instanceDescriptor != null) {
                    int port = instanceDescriptor.getHttpPort();
                    if (port>0) {
                        portNumber = String.valueOf(port);
                    }
                    String hostName = instanceDescriptor.getHostname();
                    if (hostName != null) {
                        host = hostName;
                    }
                }
            } 
            catch (InstanceRemovedException ex) {
                
            }
        }
        J2eeModuleProvider.ConfigSupport configSupport = provider.getConfigSupport();
        try {
            contextRoot = configSupport.getWebContextRoot();
        } catch (ConfigurationException e) {
            // TODO the context root value could not be read, let the user know about it
        }
        if (contextRoot.length() > 0 && contextRoot.startsWith("/")) { //NOI18N
            contextRoot = contextRoot.substring(1);
        }
        return "http://"+host+":"+portNumber+"/"//NOI18N
                (contextRoot.length()>0 ? contextRoot+"/" : ""); //NOI18N
    }
    protected static class JerseyFilter implements FileFilter {
        private Pattern pattern;
        JerseyFilter(String regexp) {
             = Pattern.compile(regexp);
        }
        public boolean accept(File pathname) {
            return .matcher(pathname.getName()).matches();
        }
    }
    public abstract int getProjectType();
    
    private ClassPath getCompileClassPath(SourceGroup[] groups ){
        ClassPathProvider provider = .getLookup().lookup
                ClassPathProvider.class);
        if ( provider == null ){
            return null;
        }
        ClassPath[] paths = new ClassPathgroups.length];
        int i=0;
        for (SourceGroup sourceGroup : groups) {
            FileObject rootFolder = sourceGroup.getRootFolder();
            pathsi ] = provider.findClassPathrootFolder.);
            i++;
        }
        return ClassPathSupport.createProxyClassPathpaths );
    }
    
    private boolean containsClassPath classPath , URL url ){
        List<ClassPath.Entryentries = classPath.entries();
        for (ClassPath.Entry entry : entries) {
            if ( entry.getURL().equals(url)){
                return true;
            }
        }
        return false;
    }