Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   *
   * 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.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun 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-2006 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.j2ee.sun.ide.sunresources.resourcesloader;
 
 
 
 
 
 
Represents a SunResource object in the Repository.

Author(s):
nityad
 
 public class SunResourceDataObject extends XMLDataObject implements FileChangeListener { // extends MultiDataObject{
     private static final Logger LOG = Logger.getLogger(SunResourceDataObject.class.getName());
 
     private static String JDBC_CP = "jdbc-connection-pool"//NOI18N
     private static String JDBC_DS = "jdbc-resource"//NOI18N
     private static String PMF = "persistence-manager-factory-resource"//NOI18N
     private static String MAIL = "mail-resource"//NOI18N
    private static String JMS = "jms-resource"//NOI18N
    transient private ValidateXMLCookie validateCookie = null;
    transient private CheckXMLCookie checkCookie = null;
    
    ConnPoolBean cpBean = null;
    DataSourceBean dsBean = null;
    JavaMailSessionBean mailBean = null;
    JMSBean jmsBean = null;
    
    String resType;
    
        super(pfloader);
        pf.addFileChangeListener((FileChangeListener) WeakListeners.create(FileChangeListener.classthispf));
        
         = getResource(pf);
    }
       
    public <T extends Node.Cookie> T getCookie(Class<T> c) {
        Node.Cookie retValue = null;
        if (ValidateXMLCookie.class.isAssignableFrom(c)) {
            if ( == null) {
                InputSource in = DataObjectAdapters.inputSource(this);
                 = new ValidateXMLSupport(in);
            }
            return (T) ;
        } else if (CheckXMLCookie.class.isAssignableFrom(c)) {
            if ( == null) {
                InputSource in = DataObjectAdapters.inputSource(this);
                 = new CheckXMLSupport(in);
            }
            return (T) ;
        }
        
        if (retValue == null) {
            retValue = super.getCookie(c);
        }
        return (T) retValue;
    }
    
    
    public HelpCtx getHelpCtx() {
        return null// HelpCtx.DEFAULT_HELP;
        // If you add context help, change to:
        // return new HelpCtx(SunResourceDataObject.class);
    }
    
    protected Node createNodeDelegate() {
        if( != null){
            if(this..equals(this.)){
                Node node = new ConnPoolBeanDataNode(thisgetPool());
                return node;
            }if(this..equals(this.)){
                Node node = new DataSourceBeanDataNode(thisgetDataSource());
                return node;
            }if(this..equals(this.)){
                Node node = new PersistenceManagerBeanDataNode(thisgetPersistenceManager());
                return node;
            }if(this..equals(this.)){
                Node node = new JavaMailSessionBeanDataNode(thisgetMailSession());
                return node;
            }if(this..equals(this.)){    
                Node node = new JMSBeanDataNode(thisgetJMS());
                return node;
            }else{
                String mess = NbBundle.getMessage(SunResourceDataObject.class"Info_notSunResource"); //NOI18N
                .log(.mess);
                return new SunResourceDataNode(this);
            }    
        }else{
            return new SunResourceDataNode(this);
        }   
    }
    
    private String getResource(FileObject primaryFile) {
       String type = null;
       try {
            if((! primaryFile.isFolder()) && primaryFile.isValid()){
                InputStream in = primaryFile.getInputStream();
                Resources resources = DDProvider.getDefault().getResourcesGraph(in);
                
                // identify JDBC Connection Pool xml
                JdbcConnectionPool[] pools = resources.getJdbcConnectionPool();
                if(pools.length != 0){
                    ConnPoolBean currCPBean = ConnPoolBean.createBean(pools[0]);
                    type = this.;
                    setPool(currCPBean);
                }  
                
                // identify JDBC Resources xml
                JdbcResource[] dataSources = resources.getJdbcResource();
                if(dataSources.length != 0){
                    DataSourceBean currDSBean = DataSourceBean.createBean(dataSources[0]);
                    type = this.;
                    setDataSource(currDSBean);
                }
                
                // import Persistence Manager Factory Resources
                PersistenceManagerFactoryResource[] pmfResources = resources.getPersistenceManagerFactoryResource();
                if(pmfResources.length != 0){
                    PersistenceManagerBean currPMFBean = PersistenceManagerBean.createBean(pmfResources[0]);
                    type = this.;
                    setPersistenceManager(currPMFBean);
                }
                
                // import Mail Resources
                MailResource[] mailResources = resources.getMailResource();
                if(mailResources.length != 0){
                    JavaMailSessionBean currMailBean = JavaMailSessionBean.createBean(mailResources[0]);
                    type = this.;
                    setMailSession(currMailBean);
                }
                
                // import JMS Resources and convert to Admin Object
                JmsResource[] jmsResources = resources.getJmsResource();
                if (jmsResources.length != 0) {
                    JMSBean currJmsBean = JMSBean.createBean(jmsResources[0]);
                    type = this.;
                    setJMS(currJmsBean);
                }
                
                // import Admin Object Resources
                AdminObjectResource[] aoResources = resources.getAdminObjectResource();
                if(aoResources.length != 0){
                    JMSBean currJmsBean = JMSBean.createBean(aoResources[0]);
                    type = this.;
                    setJMS(currJmsBean);
                }
                
                ConnectorResource[] connResources = resources.getConnectorResource();
                ConnectorConnectionPool[] connPoolResources = resources.getConnectorConnectionPool();
                if(connResources.length != 0 && connPoolResources.length != 0){
                    JMSBean currJmsBean = JMSBean.createBean(resources);
                    type = this.;
                    setJMS(currJmsBean);
                }
            }
        }catch(NullPointerException npe){
            .log(."Unable to load *.sun-resource file"npe);
        }catch(Exception ex){
            .log(."Unable to load *.sun-resource file"ex);
        }
            return type;
        }
       
    private void setPool(ConnPoolBean in_cpBean){
        this. = in_cpBean;
    }
    
    private ConnPoolBean getPool(){
        return this.;
    }
    
    private void setDataSource(DataSourceBean in_dsBean){
        this. = in_dsBean;
    }
    
    private DataSourceBean getDataSource(){
        return this.;
    }
    
    private void setPersistenceManager(PersistenceManagerBean in_pmfBean){
        this. = in_pmfBean;
    }
    
        return this.;
    }
    
    private void setMailSession(JavaMailSessionBean in_mailBean){
        this. = in_mailBean;
    }
    
        return this.;
    }
    
    private void setJMS(JMSBean in_jmsBean){
        this. = in_jmsBean;
    }
    
    private JMSBean getJMS(){
        return this.;
    }
    
    public void fileAttributeChanged (FileAttributeEvent fe) {
        updateDataObject();
    }
    
    public void fileChanged (FileEvent fe) {
        updateDataObject();
    }
    
    public void fileDataCreated (FileEvent fe) {
        updateDataObject ();
    }
    
    public void fileDeleted (FileEvent fe) {
        updateDataObject ();
    }
    
    public void fileFolderCreated (FileEvent fe) {
        updateDataObject ();
    }
    
    public void fileRenamed (FileRenameEvent fe) {
        updateDataObject ();
    }
    
    private void updateDataObject(){
         = getResource(this.getPrimaryFile());       
    }
    
    public String getResourceType(){
        return ;
    }
  
New to GrepCode? Check out our FAQ X