org.newhart.jexample.JExample1.java Source code

Java tutorial

Introduction

Here is the source code for org.newhart.jexample.JExample1.java

Source

/**
 * Copyright 2012-2013 Clint Combs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.newhart.jexample;

import org.newhart.japi.annotation.Audit;
import org.newhart.japi.annotation.AuditData;
import org.newhart.*;
import org.newhart.mongodb.AuditStore;
import java.net.UnknownHostException;
import java.util.Date;
import com.mongodb.Mongo;
import com.mongodb.casbah.MongoConnection;

public class JExample1 {
    public static void main(final String args[]) throws UnknownHostException {
        final MongoConnection con = new MongoConnection(new Mongo("localhost"));
        final AuditStore store = new AuditStore(con);
        store.createAudit("audit_test", 100000000);

        final Date now = new Date();
        /*store.writeAuditRecord("org.newhart.jexample.JExample1", "123", "org.newhart.example.User",
           "low", now, now, now, "message",
           new java.util.HashMap(), new java.util.LinkedList(), new java.util.HashSet());*/
        testAudit(1, "test");
        testAuditException();
    }

    @Audit(name = "audit_test", msg = "", labeled = { "test", "label1" })
    private static void testAudit(@AuditData(name = "i") final int i, final String s) {
        System.out.print("testAudit()");
    }

    @Audit(name = "audit_test")
    private static void testAuditException() {
        System.out.print("testAuditException()");
        throw new RuntimeException("testing an exception");
    }
}