Results 1 to 2 of 2
  1. #1
    doobster is offline Member
    Join Date
    Dec 2014
    Posts
    1
    Rep Power
    0

    Default Confused between object types and instances

    Hi all. I'm completely new to JAVA and have a project I'm trying to complete. Basically I am trying to rewrite the code that's here https://developers.google.com/accoun...rizingrequests under "Other" in Coldfusion, since we already had a program that worked with version 2 of Google's API, which is now discontinued.

    The real issue I'm having is in these couple of lines:

    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    If JSON_FACTORY is of type JsonFactory, then how is it assigned to JacksonFactory.getDefaultInstance()? This parameters gets passed later on to GoogleCalendar API via the following:

    import com.google.api.services.calendar.Calendar;

    // Initialize Calendar service with valid OAuth credentials
    Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
    .setApplicationName("applicationName").build();

    The builder for the calendar expects com.google.api.client.json.JsonFactory as the type for the second parameter, but JSON_FACTORY is an instance of JacksonFactory.

    Ultimately I have to get this code working in Coldfusion, but that's giving me the error "Unable to find a constructor for class com.google.api.services.calendar.Calendar that accepts parameters of type ( com.google.api.client.http.javanet.NetHttpTranspor t, com.google.api.client.json.jackson2.JacksonFactory , com.google.api.client.googleapis.auth.oauth2.Googl eCredential$Builder )". Here's my code from Coldfusion:

    ServiceAccountEmail='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx';
    GoogleCredential=CreateObject('java','com.google.a pi.client.googleapis.auth.oauth2.GoogleCredential' );
    GoogleNetHttpTransport=CreateObject('java','com.go ogle.api.client.googleapis.javanet.GoogleNetHttpTr ansport');
    httpTransportObj=CreateObject('java','com.google.a pi.client.http.HttpTransport');
    JacksonFactory=CreateObject('java','com.google.api .client.json.jackson2.JacksonFactory');
    JSON_FACTORY=JacksonFactory.getDefaultInstance();
    httpTransport=httpTransportObj.init();
    httpTransport=GoogleNetHttpTransport.newTrustedTra nsport();
    credential=CreateObject('java','com.google.api.cli ent.googleapis.auth.oauth2.GoogleCredential$Builde r');
    credential.setTransport(httpTransport);
    credential.setJsonFactory(JSON_FACTORY);
    credential.setServiceAccountId(ServiceAccountEmail );
    objFile=CreateObject("java","java.io.File").init(K eyFilename);
    credential.setServiceAccountPrivateKeyFromP12File( objFile);
    credential.setServiceAccountScopes(ListToArray('ht tps://www.google.com/calendar/feeds'));
    credential.build();
    CalObj=CreateObject('java','com.google.api.service s.calendar.Calendar');
    gCal=CalObj.init(httpTransport,JSON_FACTORY,creden tial);

    Ross.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Confused between object types and instances

    Java Code:
    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    JSON_FACTORY is declared as aninstance of JsonFactory. That's what the bit to the left of the '=' is saying.
    Since this compiles then that implies that getInstance() of JacksonFactory returns something that extends the JsonFactory abstract class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to get multiple instances of an object/class
    By xEthan in forum New To Java
    Replies: 3
    Last Post: 08-04-2013, 01:40 AM
  2. 2 instances of an object that draws an image
    By Bobbyloujo in forum New To Java
    Replies: 3
    Last Post: 10-26-2012, 11:46 PM
  3. Preventing duplicate instances of an object
    By monkeyhead in forum New To Java
    Replies: 2
    Last Post: 11-07-2011, 07:28 PM
  4. Object Reflection: Creating new instances
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:13 PM
  5. Naming object instances
    By oldgit in forum New To Java
    Replies: 9
    Last Post: 02-07-2008, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •