Example usage for java.lang IllegalAccessException IllegalAccessException

List of usage examples for java.lang IllegalAccessException IllegalAccessException

Introduction

In this page you can find the example usage for java.lang IllegalAccessException IllegalAccessException.

Prototype

public IllegalAccessException(String s) 

Source Link

Document

Constructs an IllegalAccessException with a detail message.

Usage

From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java

public int addNgramAsIds(List<Integer> ngram) throws IllegalAccessException {
    // check if it is fixed
    if (_fixed)/* w  ww.j  ava2 s .  c o m*/
        throw new IllegalAccessException(
                "LanguageModel is already fixed, which means no more values can be added.");
    // check length
    assert ngram
            .size() <= _order : "Length of ngram must be lower or equal to the order of the language model.";
    assert ngram.size() > 0 : "Length of ngram must be larger than 0.";
    // add to bag of lm order
    int count = _ngrams_of_order.add(ngram);
    // add to bag of lower order
    if (ngram.size() == 1) {
        _sum_one_grams++;
        return count;
    }
    _ngrams_of_lower_order.add(ngram.subList(0, ngram.size() - 1));
    if (ngram.size() == 2)
        _sum_one_grams++;
    return count;
}

From source file:org.nordapp.web.servlet.IOServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    try {/*from ww  w  .ja  v a 2 s.com*/

        //@SuppressWarnings("unused")
        final String mandatorId = RequestPath.getMandator(req);
        final String uuid = RequestPath.getSession(req);

        //
        // Session handler (HTTP) and session control (OSGi)
        //
        //SessionControl ctrl = new HttpSessionControlImpl(context, req.getSession());
        SessionControl ctrl = new SessionControlImpl(context);
        ctrl.setMandatorID(mandatorId);
        ctrl.setCertID(uuid);

        //RequestHandler rqHdl = new RequestHandler(context, ctrl);

        ctrl.loadTempSession();
        ctrl.getAll();
        ctrl.incRequestCounter();
        ctrl.setAll();
        ctrl.saveTempSession();

        //
        // Session service
        //
        String cert = null;

        //The '0' session of the mandator
        Session mSession = SessionServiceImpl.getSession(context, cert, ctrl.getMandatorID(), "0");
        Integer baseIndex = ((Integer) mSession.getValue(Session.ENGINE_BASE_INDEX)).intValue();
        //String sessionId = session.getId();
        mSession = SessionServiceImpl.getSession(context, cert, ctrl.getMandatorID(),
                ctrl.decodeCert().toString());

        String[] elem = RequestPath.getPath(req);
        if (elem.length != 2)
            throw new MalformedURLException("The URL needs the form '" + req.getServletPath()
                    + "/function-id/file-uuid' but was '" + req.getRequestURI() + "'");

        BigInteger engineId = ctrl.decodeCert();
        String functionId = elem.length >= 1 ? elem[0] : null;
        String fileUuid = elem.length >= 2 ? elem[1] : null;

        mSession = SessionServiceImpl.getSession(context, cert, ctrl.getMandatorID(), ctrl.getCertID());
        if (mSession == null) {
            List<String> list = ctrl.getShortTimePassword();
            if (ctrl.getCertID() == null || (!list.contains(ctrl.getCertID())))
                throw new UnavailableException("Needs a valid User-Session.");
        }

        DatabaseService dbService = DatabaseServiceImpl.getDatabase(context, cert, ctrl.getMandatorID());
        if (dbService == null) {
            throw new UnavailableException(
                    "Needs a valid database service for mandator " + ctrl.getMandatorID() + ".");
        }

        ResponseHandler rsHdl = new ResponseHandler(context, ctrl);
        Map<String, String> headers = new HashMap<String, String>();

        try {
            //
            // Gets the engine base service
            //
            EngineBaseService engineBaseService = EngineBaseServiceImpl.getService(context,
                    ctrl.getMandatorID(), String.valueOf(baseIndex));
            if (engineBaseService == null)
                throw new IOException(
                        "The mandator base service is not available (maybe down or a version conflict).");

            //
            // Run the step
            //
            Mandator mandator = MandatorServiceImpl.getMandator(context, ctrl.getMandatorID());
            if (mandator == null)
                throw new IOException(
                        "The mandator service is not available (maybe down or a version conflict).");

            Engine engine = engineBaseService.getEngine(engineId);
            if (!engine.isLogin())
                throw new IllegalAccessException("There is no login to this session.");

            //
            // Initialize the work
            //

            engine.setLocalValue(httpSessionID, engineId.toString()); //ctrl.decodeCert().toString()

            IdRep processUUID = IdGen.getUUID();
            engine.setLocalValue(httpProcessID, processUUID);

            IOContainer ioc = new IOContainer();
            ioc.setProcessUUID(processUUID.toString());
            ioc.setField(openFileByID, fileUuid);
            engine.setLocalValue(httpIOContainer, ioc);

            //
            // Call script
            //

            try {
                engine.call(functionId);
            } catch (Exception e) {
                e.printStackTrace();
            }

            //Prints a file out
            //rsHdl.getSessionData(buffer, mSession);

            InputStream in = null;
            try {
                //DbDatabase dbs = dbService.getDatabase();
                //DbFileStore dbf = dbs.getFileStore();
                //DbFile file = dbf.getFileFromId( (String)engine.getLocalValue(openFileByRef) );
                String[] fn = ioc.getFilenames();
                if (fn.length == 0)
                    throw new IllegalArgumentException("There is no file specified to open (empty array).");

                DbFile file = (DbFile) ioc.getFile(fn[0]);

                in = file.getInputStream();

                headers.put("Content-Type", file.getMimetype());
                headers.put("Content-Length", String.valueOf(file.getLength()));

                rsHdl.avoidCaching(resp);
                rsHdl.sendFile(in, resp, headers);
            } finally {
                if (in != null)
                    in.close();

                ioc.cleanup();
                engine.setLocalValue(httpSessionID, null);
                engine.setLocalValue(httpProcessID, null);
                engine.setLocalValue(httpIOContainer, null);
            }

        } catch (Exception e) {
            logger.error("Error running the step.", e);
        }

    } catch (Exception e) {
        ResponseHandler rsHdl = new ResponseHandler(context, null);
        rsHdl.sendError(logger, e, resp, null);
    }
}

From source file:org.dbist.dml.AbstractDml.java

protected Query toPkQuery(Object obj, Object condition) throws Exception {
    Class<?> clazz;/*ww  w . j a va  2s  . co m*/
    if (obj instanceof Class)
        clazz = (Class<?>) obj;
    else if (obj instanceof String)
        clazz = getClass((String) obj);
    else
        clazz = obj.getClass();
    if (condition instanceof Object[] && ((Object[]) condition).length == 1)
        condition = ((Object[]) condition)[0];
    Query query = new Query();
    try {
        if (condition == null || condition instanceof Query)
            return (Query) condition;
        Table table = getTable(clazz);
        if (ValueUtils.isPrimitive(condition)) {
            String[] pkFieldNames = table.getPkFieldNames();
            if (ValueUtils.isEmpty(pkFieldNames))
                throw new DbistRuntimeException("Couln't find primary key of table " + table.getName());
            query.addFilter(table.getPkFieldNames()[0], condition);
            return query;
        } else if (condition instanceof Object[]) {
            if (ValueUtils.isEmpty(condition))
                throw new IllegalAccessException("Requested pk condition is empty.");
            Object[] array = (Object[]) condition;
            if (ValueUtils.isPrimitive(array[0])) {
                int i = 0;
                String[] pkFieldNames = table.getPkFieldNames();
                if (ValueUtils.isEmpty(pkFieldNames))
                    throw new DbistRuntimeException("Couln't find primary key of table " + table.getName());
                int pkFieldSize = pkFieldNames.length;
                for (Object item : array) {
                    query.addFilter(pkFieldNames[i++], item);
                    if (i == pkFieldSize)
                        break;
                }
                return query;
            }
        } else if (condition instanceof List) {
            if (ValueUtils.isEmpty(condition))
                throw new IllegalAccessException("Requested pk condition is empty.");
            @SuppressWarnings("unchecked")
            List<?> list = (List<Object>) condition;
            if (ValueUtils.isPrimitive(list.get(0))) {
                int i = 0;
                String[] pkFieldNames = table.getPkFieldNames();
                if (ValueUtils.isEmpty(pkFieldNames))
                    throw new DbistRuntimeException("Couln't find primary key of table " + table.getName());
                int pkFieldSize = pkFieldNames.length;
                for (Object item : list) {
                    query.addFilter(pkFieldNames[i++], item);
                    if (i == pkFieldSize)
                        break;
                }
                return query;
            }
        }
        query = toQuery(table, condition, table.getPkFieldNames());
        return query;
    } finally {
        //         query.setPageIndex(0);
        //         query.setPageSize(2);
    }
}

From source file:squash.booking.lambdas.GetBookingsLambdaTest.java

@Test
public void testGetBookingsThrowsCorrectExceptionWhenBookingManagerThrowsSomethingElse() throws Exception {
    // When any exception other than those explicitly checked for is thrown
    // we should convert it as described here.

    doTestGetBookingsThrowsCorrectExceptionWhenBookingManagerThrows(new IllegalAccessException("Grrr.."));
}

From source file:de.xirp.plugin.SecurePluginView.java

/**
 * Prints a log message that the access to the given method was
 * not allowed./*from w  w  w.jav a2  s . co m*/
 * 
 * @param methodName
 *            the method name for which the access wasn't allowed
 */
private void accessNotAllowed(String methodName) {
    try {
        throw new IllegalAccessException(I18n.getString("SecurePluginView.exception.noPermission1", //$NON-NLS-1$
                methodName, getName()));
    } catch (IllegalAccessException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    }
}

From source file:jenkins.metrics.api.MetricsRootAction.java

/**
 * Utility method to check a request against the CORS requirements.
 *
 * @param req the request to check.// w  ww.  j a  va 2  s .co  m
 * @throws IllegalAccessException if the request is not a POST or OPTIONS (with Origin header) or a GET request
 *                                with the appropriate authorization key.
 */
@SuppressWarnings("unchecked")
private static void requireCorrectMethod(@NonNull StaplerRequest req) throws IllegalAccessException {
    if (!(req.getMethod().equals("POST")
            || (req.getMethod().equals("OPTIONS") && StringUtils.isNotBlank(req.getHeader("Origin")))
            || (req.getMethod().equals("GET") && getKeyFromAuthorizationHeader(req) != null))) {
        throw new IllegalAccessException("POST is required");
    }
}

From source file:org.neo4art.literature.analyzer.DocumentsNLPLinkedListAnalyzer.java

/**
 * Support method meant to check you called {@link #storeItOnGraph()} before running all sort of statistics
 * /*w  w w  .  j  av a 2s . c  o  m*/
 * @throws IllegalAccessException if documents aren't stored on graph
 */
private void assertDocumentListIsStoredOnGraph() {
    if (!this.storedOnGraph) {
        throw new RuntimeException(new IllegalAccessException(
                "You must save documents on the graph first by calling 'storeItOnTheGraph'"));
    }
}

From source file:org.apache.hadoop.chukwa.datastore.ViewStore.java

public void delete() throws IllegalAccessException {
    try {//www  .  j  av  a 2 s .c om
        if (this.view == null) {
            get();
        }
        if (this.view != null) {
            StringBuilder viewPath = new StringBuilder();
            if (view.getPermissionType().intern() == PUBLIC) {
                viewPath.append(publicViewPath);
            } else {
                viewPath.append(usersViewPath);
                viewPath.append(File.separator);
                viewPath.append(uid);
            }
            viewPath.append(File.separator);
            viewPath.append(view.getName());
            viewPath.append(".view");
            Path viewFile = new Path(viewPath.toString());
            try {
                FileSystem fs = FileSystem.get(config);
                fs.delete(viewFile, true);
            } catch (IOException ex) {
                log.error(ExceptionUtil.getStackTrace(ex));
            }
        } else {
            throw new IllegalAccessException("Unable to delete user view, view does not exist.");
        }
    } catch (Exception e) {
        log.error(ExceptionUtil.getStackTrace(e));
        throw new IllegalAccessException("Unable to access user view.");
    }
}

From source file:org.intermine.bio.postprocess.PostProcessUtil.java

/**
 * Return an iterator over the results of a query that connects two classes by a third using
 * arbitrary fields.//from ww  w .  j ava2 s.c  om
 * eg. To find Genes, Exon pairs where
 *   "gene.transcripts CONTAINS transcript AND transcript.exons CONTAINS exon"
 * pass Gene.class, "transcripts", Transcript.class, "exons", Exon.class
 * @param os an ObjectStore to query
 * @param sourceClass the first class in the query
 * @param sourceClassFieldName the field in the sourceClass which should contain the
 * connectingClass
 * @param connectingClass the class referred to by sourceClass.sourceFieldName
 * @param connectingClassFieldName the field in connectingClass which should contain
 * destinationClass
 * @param destinationClass the class referred to by
 * connectingClass.connectingClassFieldName
 * @param orderBySource if true query will be ordered by sourceClass
 * @return an iterator over the results - (Gene, Exon) pairs
 * @throws ObjectStoreException if problem reading ObjectStore
 * @throws IllegalAccessException if one of the field names doesn't exist in the corresponding
 * class.
 */
public static Iterator<ResultsRow<InterMineObject>> findConnectingClasses(ObjectStore os,
        Class<? extends FastPathObject> sourceClass, String sourceClassFieldName,
        Class<? extends FastPathObject> connectingClass, String connectingClassFieldName,
        Class<? extends FastPathObject> destinationClass, boolean orderBySource)
        throws ObjectStoreException, IllegalAccessException {

    Query q = new Query();

    // we know that all rows will be distinct because there shouldn't be more than one relation
    // connecting the two objects
    q.setDistinct(false);
    QueryClass qcSource = new QueryClass(sourceClass);
    q.addFrom(qcSource);
    q.addToSelect(qcSource);
    if (orderBySource) {
        q.addToOrderBy(qcSource);
    }
    QueryClass qcConnecting = new QueryClass(connectingClass);
    q.addFrom(qcConnecting);
    QueryClass qcDest = new QueryClass(destinationClass);
    q.addFrom(qcDest);
    q.addToSelect(qcDest);
    if (!orderBySource) {
        q.addToOrderBy(qcDest);
    }
    ConstraintSet cs = new ConstraintSet(ConstraintOp.AND);
    QueryCollectionReference ref1 = new QueryCollectionReference(qcSource, sourceClassFieldName);
    ContainsConstraint cc1 = new ContainsConstraint(ref1, ConstraintOp.CONTAINS, qcConnecting);
    cs.addConstraint(cc1);
    QueryReference ref2;

    Map<String, FieldDescriptor> descriptorMap = os.getModel().getFieldDescriptorsForClass(connectingClass);
    FieldDescriptor fd = descriptorMap.get(connectingClassFieldName);

    if (fd == null) {
        throw new IllegalAccessException(
                "cannot find field \"" + connectingClassFieldName + "\" in class " + connectingClass.getName());
    }

    if (fd.isReference()) {
        ref2 = new QueryObjectReference(qcConnecting, connectingClassFieldName);
    } else {
        ref2 = new QueryCollectionReference(qcConnecting, connectingClassFieldName);
    }
    ContainsConstraint cc2 = new ContainsConstraint(ref2, ConstraintOp.CONTAINS, qcDest);
    cs.addConstraint(cc2);
    q.setConstraint(cs);

    ((ObjectStoreInterMineImpl) os).precompute(q, Constants.PRECOMPUTE_CATEGORY);
    Results res = os.execute(q, 5000, true, true, true);

    @SuppressWarnings("unchecked")
    Iterator<ResultsRow<InterMineObject>> retval = (Iterator) res.iterator();
    return retval;
}

From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java

public Integer getOrAddWord(W word) throws IllegalAccessException {
    Integer index = _inv_index.get(word);
    if (index != null)
        return index;
    if (_fixed)//from  ww w.  j  a v a  2s . c  o m
        throw new IllegalAccessException(
                "LanguageModel is already fixed, which means no more values can be added.");
    index = _index.size();
    _index.add(word);
    _inv_index.put(word, index);
    return index;
}