Example usage for javax.naming InitialContext InitialContext

List of usage examples for javax.naming InitialContext InitialContext

Introduction

In this page you can find the example usage for javax.naming InitialContext InitialContext.

Prototype

public InitialContext() throws NamingException 

Source Link

Document

Constructs an initial context.

Usage

From source file:br.ufc.ivela.web.action.GenericAction.java

public void addHistory(String title, String description, String... params) {
    if (historyRemote == null) {
        try {//from  w  w w.j a  v a2  s. c o  m
            InitialContext initialContext = new InitialContext();
            java.lang.Object ejbRemoteRef = initialContext
                    .lookup("HistoryBean#br.ufc.ivela.ejb.interfaces.HistoryRemote");
            historyRemote = (HistoryRemote) javax.rmi.PortableRemoteObject.narrow(ejbRemoteRef,
                    HistoryRemote.class);
        } catch (NamingException e) {
            e.printStackTrace();
            historyRemote = null;
        }
    }

    List<History> historyList = historyRemote.getBySystemUser(getAuthenticatedUser().getId());
    boolean insert = true;
    for (History h : historyList) {
        if (h.getDescription().equalsIgnoreCase(description) && h.getTitle().equalsIgnoreCase(title)) {
            List<HistoryParams> historyParamsList = historyParamsRemote.getByHistory(h.getId());
            int equal = 0;
            for (int i = 0; i < params.length; i++) {
                for (HistoryParams hp : historyParamsList) {
                    if (hp.getParam().equalsIgnoreCase(String.valueOf(i))
                            && hp.getValue().equalsIgnoreCase(params[i])) {
                        equal++;
                        break;
                    }
                }
            }
            if (equal == params.length) {
                insert = false;
                break;
            }
        }
    }
    if (insert) {
        History history = new History();
        history.setSystemUser(getAuthenticatedUser());
        history.setDatetime(new Date());
        history.setTitle(title);
        history.setDescription(description);
        Long id = historyRemote.add(history);
        for (int i = 0; params != null && i < params.length; i++) {
            HistoryParams historyParams = new HistoryParams();
            historyParams.setHistoryId(id);
            historyParams.setParam(String.valueOf(i));
            historyParams.setValue(params[i]);
            historyParamsRemote.add(historyParams);
        }
    }
}

From source file:com.idega.slide.webdavservlet.DomainConfig.java

private static Context getEnvContext() throws NamingException {
    InitialContext initialContext = new InitialContext();
    return (Context) initialContext.lookup("java:comp/env");
}

From source file:com.duroty.application.files.manager.FilesManager.java

/**
 * Creates a new MailManager object.//from ww  w.  j a  v a 2  s  .  co m
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws NamingException
 */
public FilesManager(HashMap mail)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, NamingException {
    super();

    String messageFactory = (String) mail.get(Constants.MESSAGES_FACTORY);

    if ((messageFactory != null) && !messageFactory.trim().equals("")) {
        Class clazz = null;
        clazz = Class.forName(messageFactory.trim());
        this.messageable = (Messageable) clazz.newInstance();
        this.messageable.setProperties(mail);
    }

    this.folderAll = (String) mail.get(Constants.MAIL_FOLDER_ALL);
    this.folderInbox = (String) mail.get(Constants.MAIL_FOLDER_INBOX);
    this.folderSent = (String) mail.get(Constants.MAIL_FOLDER_SENT);
    this.folderTrash = (String) mail.get(Constants.MAIL_FOLDER_TRASH);
    this.folderBlog = (String) mail.get(Constants.MAIL_FOLDER_BLOG);
    this.folderDraft = (String) mail.get(Constants.MAIL_FOLDER_DRAFT);
    this.folderSpam = (String) mail.get(Constants.MAIL_FOLDER_SPAM);
    this.folderImportant = (String) mail.get(Constants.MAIL_FOLDER_IMPORTANT);
    this.folderHidden = (String) mail.get(Constants.MAIL_FOLDER_HIDDEN);
    this.folderChat = (String) mail.get(Constants.MAIL_FOLDER_CHAT);
    this.folderFiles = (String) mail.get(Constants.MAIL_FOLDER_FILES);
    this.quoteSizeAlert = Integer.valueOf((String) mail.get(Constants.MAIL_QUOTE_SIZE_ALERT)).intValue();

    tidy.setUpperCaseTags(true);
    tidy.setInputEncoding(Charset.defaultCharset().displayName());
    tidy.setOutputEncoding(Charset.defaultCharset().displayName());
    tidy.setMakeBare(true);
    tidy.setMakeClean(true);
    tidy.setShowWarnings(false);
    tidy.setErrout(new PrintWriter(new NullWriter()));
    tidy.setWord2000(true);
    tidy.setDropProprietaryAttributes(true);
    tidy.setFixBackslash(true);
    tidy.setXHTML(true);

    //tidy.setXmlOut(true);
    tidy.setWrapSection(true);
    tidy.setWrapScriptlets(true);
    tidy.setWrapPhp(true);
    tidy.setQuiet(true);
    tidy.setBreakBeforeBR(true);
    tidy.setEscapeCdata(true);
    tidy.setForceOutput(true);
    tidy.setHideComments(false);
    tidy.setPrintBodyOnly(true);
    tidy.setTidyMark(false);

    Map options = ApplicationConstants.options;

    Context ctx = new InitialContext();

    this.extensions = (HashMap) ctx.lookup((String) options.get(Constants.EXTENSION_CONFIG));
}

From source file:de.fhg.fokus.openride.services.favoritepoint.FavoritePointService.java

private FavoritePointControllerLocal lookupFavoritePointControllerBeanLocal() {
    try {/*  ww  w .  j  av a2  s  . c  o  m*/
        javax.naming.Context c = new InitialContext();
        return (FavoritePointControllerLocal) c.lookup(
                "java:global/OpenRideServer/OpenRideServer-ejb/FavoritePointControllerBean!de.fhg.fokus.openride.customerprofile.FavoritePointControllerLocal");
    } catch (NamingException ne) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
        throw new RuntimeException(ne);
    }
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *///from w  w  w . ja va  2  s  .  c om
public void testGetObjectInstance_fnbluser() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnbluser");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr userName = new StringRefAddr("minIdle", "7");
    ref.add(userName);

    //
    // At the end this should be overwritten by the value in the fnblds.xml file
    //
    RefAddr url = new StringRefAddr("url", "this-is-the-url");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource);

    BasicDataSource bds = (BasicDataSource) result;
    assertEquals(7, bds.getMinIdle());

    //
    // These are read from the fnbluser.xml
    //
    assertEquals("fnbluserpwd", bds.getUsername());
    assertEquals("fnblpwd", bds.getPassword());
    assertEquals("org.fnbluser", bds.getDriverClassName());
    assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl());

}

From source file:com.netcracker.tss.web.servlet.customer.CustomerMMGServiceServlet.java

private MeetMyGuestBeanLocal getMeetMyGuestBean(HttpServletRequest req) {
    Context context;/*from w  w w  .  j  a  v  a2s .  c o  m*/
    try {
        context = new InitialContext();
        MeetMyGuestBeanLocalHome meetMyGuestBeanLocalHome = (MeetMyGuestBeanLocalHome) context
                .lookup("java:app/tss-ejb/MeetMyGuestBean!com.netcracker.ejb.MeetMyGuestBeanLocalHome");
        return meetMyGuestBeanLocalHome.create();
    } catch (NamingException ex) {
        Logger.getLogger(AdminGroupServlet.class.getName()).log(Level.SEVERE,
                "Can't find userBean with name java:app/tss-ejb/UserBean!com.netcracker.ejb.MeetMyGuestBeanLocal ",
                ex);
        throw new RuntimeException("Internal server error!");// maybe have
        // to create
        // custom
        // exception?
    }
}

From source file:csiro.pidsvc.mappingstore.Manager.java

/**************************************************************************
 *  Construction/destruction.//from w ww . j a v a2s  .c om
 */

public Manager() throws NamingException, SQLException, IOException {
    InitialContext initCtx = new InitialContext();
    Context envCtx = (Context) initCtx.lookup("java:comp/env");
    DataSource ds = (DataSource) envCtx.lookup(Settings.getInstance().getProperty("jndiReferenceName"));
    _connection = ds.getConnection();
    refreshCaseSensitivity();
}

From source file:de.zib.gndms.GORFX.context.service.globus.resource.TaskResourceBase.java

public TaskResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }/*w ww .j a va 2s  .c o  m*/
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/Task";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (TaskResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:edu.harvard.iq.dvn.core.web.study.StudyFileUI.java

public List<DataFileFormatType> getDataFileFormatTypes() {

    List dataFileFormatTypes = new ArrayList();
    if (isTabularDataFile()) {

        // first check for fixed field
        if ("text/x-fixed-field".equals(getStudyFile().getFileType())) {
            DataFileFormatType fixedFileType = new DataFileFormatType();
            fixedFileType.setName("Fixed-Field");
            fixedFileType.setValue("");
            dataFileFormatTypes.add(fixedFileType);

        }// w  w w.  j  a va2 s.c  o m

        // now add tab delimited
        DataFileFormatType tabDelimitedType = new DataFileFormatType();
        tabDelimitedType.setName("Tab Delimited");
        tabDelimitedType.setValue("D00");
        dataFileFormatTypes.add(tabDelimitedType);

        // and original file

        String originalFormatName = getStudyFile().getOriginalFileType();

        String userFriendlyOriginalFormatName = null;

        if (!StringUtil.isEmpty(originalFormatName)) {
            DataFileFormatType originalFileType = new DataFileFormatType();

            userFriendlyOriginalFormatName = FileUtil.getUserFriendlyOriginalType(getStudyFile());
            String originalTypeLabel = "";

            if (!StringUtil.isEmpty(userFriendlyOriginalFormatName)) {
                originalTypeLabel = userFriendlyOriginalFormatName;
            } else {
                originalTypeLabel = originalFormatName;
            }

            String originalFileLabel = "Saved original (" + originalTypeLabel + ")";
            originalFileType.setName(originalFileLabel);
            originalFileType.setValue(DataFileFormatType.ORIGINAL_FILE_DATA_FILE_FORMAT);
            dataFileFormatTypes.add(originalFileType);
        }

        // finally, add types from db
        StudyServiceLocal studyService = null;
        try {
            studyService = (StudyServiceLocal) new InitialContext().lookup("java:comp/env/studyService");
        } catch (Exception e) {
            e.printStackTrace();
            return dataFileFormatTypes;
        }

        List<DataFileFormatType> formatConversionsAvailable = studyService.getDataFileFormatTypes();

        // Go through the list of the conversion formats available and if 
        // we have the same format as the saved original there, knock it off 
        // the list. 
        // As of now (Feb. 2012), the only such real life case is 
        // application/x-stata; i.e., Stata is the only format that we 
        // currently support both for ingest and for online conversions;
        // but it may change in the future. 
        //      -- L.A. 
        // As of Mar. 2013: we now have another case - with the addition 
        // of R Data ingest. No code change was required to accommodate this;
        // there was however a mismatch/confusion with the mime types used 
        // on the download and ingest sides of the app: the ingest was 
        // (correctly) saving the orginal as "application/x-rlang-transport;
        // but for the downloads, for some strange reason this mime type 
        // was used for Splus exports (and for R, "application/X-R-2" was 
        // used -??). With that cleaned up, and as long as we keep our use of
        // MIME types consistent, this existing framework should be working
        // just fine. 

        String tmpOrigName = userFriendlyOriginalFormatName;

        // The datafile formats which we can generate online
        // are saved in the dataFileFormatType db table; as of now (Feb. 2012)
        // the table doesn't store the real mime type, only a short 
        // label ("Stata", "R", "Splus"); so in order to match this label with 
        // the "user-friendly" type from FileUtil, I have to do some simple
        // preprocessing:       -- L.A. 

        if (tmpOrigName != null && tmpOrigName.indexOf(" ") != -1) {
            tmpOrigName = tmpOrigName.substring(0, tmpOrigName.indexOf(" "));
        }
        for (DataFileFormatType dfmt : formatConversionsAvailable) {
            String fName = dfmt.getName();
            if (fName != null && (!fName.equals(tmpOrigName))) {
                dfmt.setName(dfmt.getName() + " (generated)");
                dataFileFormatTypes.add(dfmt);
            }
        }

    } else if (isNetworkDataFile()) {
        // now add tab delimited
        DataFileFormatType networkDataType = new DataFileFormatType();
        networkDataType.setName("GraphML");
        networkDataType.setValue("");
        dataFileFormatTypes.add(networkDataType);

        // and NO original file -- all the Network Data files are GraphML; 
        // no file conversion is performed on ingest; and it is the very
        // same GraphML file that we save as the original type. :)
        //          --Leonid
        // (it may change, again; but we'll revisit the issue if and when it happens. 
        /*
        if ( !StringUtil.isEmpty( getStudyFile().getOriginalFileType() ) ) {
        DataFileFormatType originalFileType = new DataFileFormatType();
        originalFileType.setName("Original File");
        originalFileType.setValue(DataFileFormatType.ORIGINAL_FILE_DATA_FILE_FORMAT);
        dataFileFormatTypes.add(originalFileType);
        }
         * 
         */

        // TODO: need to RData as download
    }
    return dataFileFormatTypes;
}