Saturday, June 22, 2013

Java 7 - Autocloseable and Suppressed Exception



Summary

- The new interface AutoCloseable becomes the superinterface of Closeable.
- The try-with-resources statement is a try statement that declares one or more resources.
- A resource is an object that must be closed after the program is finished with it.
- The try-with-resources statement ensures that each resource is closed at the end of the statement.
- Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.

From: http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

See also:
http://www.slideshare.net/alsdias/savedfiles?s_title=new-features-of-jdk-7&user_login=denizoguz



Example

Follow the comments on the code below, a full example to show the suppressed exception.

 


package exception.java7;

import java.io.Closeable;
import java.io.IOException;

/**
 * exception.java7.Autocloseable_main.java<br>
 * project: javaLab<br>
 * <br>
 * target: java 7 AutoCloseable example with suppressed exception. <br>
 */
public class Autocloseable_main {

    public Autocloseable_main() {
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        //event1();
        event2();
    }

    /**
     * <pre>
     * Event1's output:
     *
     * [INFO]: opening a resource
     * [INFO]: event1(): doing something
     * [INFO]: closing a resource
     * exception.java7.AppException: [WARN]: application failure.
     *     at exception.java7.Autocloseable_main.event1(Autocloseable_main.java:40)
     *     at exception.java7.Autocloseable_main.main(Autocloseable_main.java:31)
     *     Suppressed: exception.java7.AException: [ERROR]: resource failure.
     *         at exception.java7.AResource.close(Autocloseable_main.java:77)
     *         at exception.java7.Autocloseable_main.event1(Autocloseable_main.java:41)
     *         ... 1 more
     *
     * </pre>
     */
    public static void event1() {
        try (AResource resource = new AResource(false);) {
            System.out.println("[INFO]: event1(): doing something");
            if(!resource.success) throw new AppException("[WARN]: application failure.");
        } catch (AException | AppException e) {
            e.printStackTrace();
        }
    }
  
    /**
     * <pre>
     * Event2's output:
     *
     * [INFO]: opening a resource
     * [INFO]: event2(): doing something
     * [INFO]: closing a resource
     * exception.java7.AException: [ERROR]: resource failure.
     *     at exception.java7.AResource.close(Autocloseable_main.java:91)
     *     at exception.java7.Autocloseable_main.event2(Autocloseable_main.java:66)
     *     at exception.java7.Autocloseable_main.main(Autocloseable_main.java:32)
     *
     * </pre>
     */
    public static void event2() {
        try (AResource resource = new AResource(false);) {
            System.out.println("[INFO]: event2(): doing something");
            if(resource.success) throw new AppException("[ERROR]: application failure.");
        } catch (AException | AppException e) {
            e.printStackTrace();
        }
    }
  
}

class AResource implements Closeable {
  
    boolean success = false;
  
    public AResource() {
        System.out.println("[INFO]: opening a resource");
    }

    public AResource(boolean success) {
        System.out.println("[INFO]: opening a resource");
        this.success = success;
    }
  
    @Override
    public void close() throws AException {
        System.out.println("[INFO]: closing a resource");
        boolean notdone = true;
        if (notdone) {
            throw new AException("[ERROR]: resource failure.");
        }
    }
}

class AException extends IOException {

    private static final long serialVersionUID = 1L;
  
    public AException(String msg) {
        super(msg);
    }
}


class AppException extends Exception {

    private static final long serialVersionUID = 1L;

    public AppException(String msg) {
        super(msg);
    }
}

Tuesday, June 18, 2013

Exception in thread "main" java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()

Problem:

Exception in thread "main" java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
    at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:324)
    at br.com.adr.model.persistence.pojos.EmployeeTest.main(EmployeeTest.java:36)




Solution:

Switch the attribute on the persistence configuration:




To:



Eclipse faq: view-handler references to com.sun.facelets.faceletviewhandler that does not implement interface javax.faces.application.viewhandler




On a jsf 2.0 project, using eclipse, I got this warning on the faces-config.xml file at:
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>

The message was:

view-handler references to "com.sun.facelets.FaceletViewHandler" that does not implement interface javax.faces.application.ViewHandler


Solution
Problem solved configuring "roject faces" JPA.
Follow the picture:










Installing vmwaretool on linux and handling an odd failure


To install vmwaretools on debian 7 (wheezy):


- First install the dependencies as root:
  apt-get install gcc make binutils linux-headers-$(uname -r)
  or just: apt-get install gcc make linux-headers-$(uname -r)



After extract to a temporary folder the vmware-tools-distrib.tar.gz file or whatever named.
  su
  chmod -R 777 vmware-tools-distrib
  cd vmware-tools-distrib
 ./vmware-install.pl

 

Then answer yes/no or just type enter accepting all questions.

See:
http://www.linkovitch.me.uk/blog/?p=732


Eventually, I got the error message thrown by the vmwaretool installer:


/tmp/vmware-root/modules/vmhgfs-only/fsutil.c: In function 'HgfsChangeFileAttributes':
/tmp/vmware-root/modules/vmhgfs-only/fsutil.c:610:4: error: assignment of read-only member 'i_nlink'
/tmp/vmware-root/modules/vmhgfs-only/file.c:128:4: warning: initialization from incompatible pointer type [enabled by default]make[4]: ***
[/tmp/vmware-root/modules/vmhgfs-only/fsutil.o] Error 1make[4]: *** Waiting for unfinished jobs....

/tmp/vmware-root/modules/vmhgfs-only/file.c:128:4: warning: (near initialization for 'HgfsFileFileOperations.fsync') [enabled by default]
/tmp/vmware-root/modules/vmhgfs-only/tcp.c:53:30: error: expected ')' before numeric constant
/tmp/vmware-root/modules/vmhgfs-only/tcp.c:56:25: error: expected ')' before 'int'
/tmp/vmware-root/modules/vmhgfs-only/tcp.c:59:33: error: expected ')' before 'int'
make[4]: *** [/tmp/vmware-root/modules/vmhgfs-only/tcp.o] Error 1
make[3]: *** [_module_/tmp/vmware-root/modules/vmhgfs-only] Error 2
make[2]: *** [sub-make] Error 2
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-4-686-pae'
make: *** [vmhgfs.ko] Error 2
make: Leaving directory `/tmp/vmware-root/modules/vmhgfs-only'

Checking the output, at first sight, it seems like some version incompatibility, but ...



Solution:

The windows 7 was reinstalled, and the vmware workstation application was updated to the latest release (8.06).

Problem over!

05/31/2013 12:41:07 PM

grub fails returning "stage1 not read correctly"


grub stage1 not read correctly
/boot/grub/stage1 was not read correctly
 
This message is usually obtained during procedures that grub requires to read its configuration files but it was not able to parse them adequately although they are found.

There are many possible reasons.
First check your grub version.

Partition of ext4 type requires grub2 and it will cause this message.

For instance, Debian 7 (wheezy) installation uses grub2 and if you trying to reinstall grub using prior version the parsing incompatibility will cause the message. Other Debian based distributions will certainly run that way.
So, try the procedures below, but without warranty at all.
They work pretty well for me, and are frequently used.



Installing grub2

Follow the procedure as root.

1. Check if the environement already has a previous grub command.

grub --version
if it returns a message, probably is grub1, which returns something like ... 0.97.
grub1 which does not work with ext4 .


To check grub2, do:

grub-install --version
$grub-install (GRUB) 1.99-27+deb7u1


2. Remove the old version if installed:

sudo apt-get purge grub


3. Install the grub2 version:

sudo apt-get install grub2
apt-get install grub2


4. Test the installation:

grub-install --version
$grub-install (GRUB) 1.99-27+deb7u1


Restoring boot

Partition resizing or another operation may invalidate the boot.
In this case it is necessary to restore the grub configuration.

Two alternatives:
- using command line.
- using the Debian's recue interface.
  

Method #1 - using command line.

Boot the machine from "Debian's Installation CD or DVD".
It doesn't matter if from .iso file, virtual machines,  CD or DVD.
Go to:

Advanced options, Rescue mode
Device to use as root file: /dev/sda5
Execute a shell in /dev/sda5


After you get access to the prompt, issue the following commands:


su
mount /dev/sda1 /boot
grub-install /dev/sda


Shall return a success message.

To exit, type exit twice.
Restart machine.


Method #2 - using the Debian's recue interface

Boot the machine from "Debian's Installation CD or DVD".
It doesn't matter if from .iso file, virtual machines,  CD or DVD.
Go to:

Advanced options, Rescue mode
Device to use as root file: /dev/sda5
Execute a shell in /dev/sda5

After you get access to the prompt, type exit.
It's gonna appear a dialog to reinstall grub.
Use it.
Restart machine.


More about grub

Additional information like grub's notation, the documentation of prior version (grub1) is still usefull.





Saturday, June 15, 2013

How to use Yahoo web services for any country


 Suppose you desire to get the weather for the Rio Janeiro city, in Rio Janeiro state, in Brazil.
 The Yahoo's weather web services requires the WOEID.

 To discover the WOEID, do:

 1. Point your browser to:
http://weather.yahoo.com/brazil/
 or
http://weather.yahooapis.com/forecastrss?w=455825


 In the "search box" type the text below and press 'Go':

Rio de Janeiro, RJ, Brazil




After the page is redirected, the WOEID is shown in its URL as a number at the end:
http://weather.yahoo.com/brazil/rio-de-janeiro/rio-de-janeiro-455825/

 


Use this number to call the web service as follow:
http://weather.yahooapis.com/forecastrss?w=455825

You can use the URL directly on the browser or programatically.



If desired to get the temperature in Celsius degrees, append to the end of the url the following:
&u=c


org.codehaus.plexus.util.xml.XmlStreamReader error message on maven's pom.xml using Eclipse



In a maven project, if you get the error message:

 org.codehaus.plexus.util.xml.XmlStreamReader

on the pom.xml file, means that the "XmlStreamReader" class found errors when parsing it.

If a new project, so without compilation, go to its root directory (where the pom.xml file is placed) and run "mvn install". After, refresh you project.

If not a new project, try running "mvn install -U", also under the root directory. After, refresh you project.

If the problem persists and can not be identified visually, probably it's an "encoding" issue or phantom characters.


Solution #1 - Fixing Encoding

If you are using UTF-8, check the header of the pom.xml file.
Add the following at the first line:

<?xml version="1.0" encoding="UTF-8"?>

If not using UTF-8, discover your enconding.

Most used:
Brazil = ISO-8859-1
Windows-1252
UTF-16
us-ascii


More information at:
http://en.wikipedia.org/wiki/Character_encoding



Solution #2 - Phantom Characters


Phantom chars (not printable characters) are generating the errors during parsing. Do the following:

1. Copy the content using Ctrl+C, Ctrl+V to another temporary place.
2. Delete the original file and create a new one using the content from the temporary place.

If the problem persists, use an editor that trims not printable chars, for instance Notepad++ (windows) or gedit(linux).


Before:



After:







Solution #3 -  Eclipse's bug due to memory

Check if your memory is low, less than 200KB.
If *nix, use "free -h" command.
If windows, you can use a widget or the command "perfom /res".
With slow level of system's memory, Iclipse begins to behavior slightly different, small malfunctions up to a full freezing.
Save your files and stop Eclipse's server, if using one, then restart it.
Check memory again, and you'll see that the level is highly increased.
For this reason, due to mysterious project's malfunctions, I track the system memory and once in while I restart Eclipse if it
was working under low level memory, even though no problems happened yet in order to avoid the mysterious malfunctions.



Tuesday, January 15, 2013

The Possible New Future for Mobiles



some topics stand out:

Recently (and ironically) Microsoft bought all of Netscape’s patents from AOL for $1 billion. These include such foundational patents of the web as Secure Socket Layer (SSL), cookies and JavaScript.
One motivation for Microsoft’s acquisition of Netscape’s patents could be to use them in a patent war with Google to stop the Chrome browser’s ascendance in its tracks. The mobile version of Chrome will be a major competitor to Apple’s Safari as well as Mozilla’s new Firefox OS.

The Mozilla entry is not only a browser, but a full-on operating system that can run mobile devices.

The Netscape technology bought by Microsoft, possibly trying to stuck Chrome, and the Firefox OS, supplying support for resources which were before just supplied by the operating system, lead us to a future completely different from the present.
The operating system will no more define the mobile market, split into Android, Apple and Microsoft.

You will buy connectivity considering cost/benefit (ROI – return on investiment) and the O.S. will become a secondary subject, or even optional.

The new Market will fight offering the best final resources under the users’ point of views, where the way to achieve them is no more relevant.

The new rules will change the IT scenarios as a consequence in just few years like a Tsunami, considering that a new embedded O.S. may offer some concepts inherited from the virtual machines were additional O.S. compliances and services may be available to the applications, turning the native O.S. transparent and no more decisive.

Better considering such possibility when planning at long term.

Friday, January 11, 2013

Thunderbird - Inbox is full

If you get the message that your Inbox is full when you start thunderbird, check the following:

1. Open thunderbird as usual, ignore the warning and check all the inbox folders for those accounts that are pop and not imap type. To discover the type, go to  menu, tools, account settings, and point an account,
then "Server Settings" and check on the right the "Server Type" on the top, close to the tittle.

Let all pop accounts' input folders empty, moving their contents to another folder or deleting it.
Once the pop inbox folders are empty, close thunderbird.

2. If desired, check your server's inbox using a web email through your browser or use an imap account version in thunderbird. In such cases,  probably you'll find find the emails that were not downloaded to your machine because the local input folder was considered full, but they are still there, on the server, waiting to be downloaded.

Note: An imap account differs from pop because the former access you email on the server and latter downloads the server content to your machine, saving on the local repository.

3. Go to your local repository, the place where you save your emails in your machine.

Note: If you don't know this place, you can find it clicking on menu, tools, account settings, on the left panel point to local folders then on the right you get your local repository path into the local directory input box.

There you're gonna find two files and one folder:

Inbox.mozmsgs (folder)
Inbox
Inbox.msf

Delete the Inbox and the Inbox.msf files, and start thunderbird again but at this time the warning shall have gone.

Note: thunderbird will recreate those files automatically when restarted, fixing the problem.


IMPORTANT:

If you have any important email that you can't find in you inbox, check it first on the server's input box.
If you still didn't find it, than instead of performing the procedure above, create a new local repository,
switching the path (see note on the 3rd step and just set a new temporary path).
Restart thunderbird and check again. If found, you can return to the original path, execute the procedure above and then you manually move the files downloaded to the temporary repository, created before, to your usual local repository.



Wednesday, January 2, 2013

Value Object vs. DTO


This subject is a controversial issue.
Check different sources below.

Reading the different definitions, I think that :

- Value Object are simple objects passed by value.

- DTO are tranfer objects, so serializable.

- Depending on the context, both may have same meaning, as referred by the J2EE documentation below, when a Transfer Object is passed by value or treated like so, but they do not represent the same concept.
 
- Summarizing:

  A DTO is linked to the concept of its pattern.
 
  A Transfer Object is an object that servers the purpose of a wrapped data transport object.
  So, it can be used in DTO pattern or anywhere else.
 
  A Value Object is a small simple object not based on identity, but on its values' equality.
   
    Depending on the context, things can assume the same role, so they seam similar on its purpose but not on their natures.


----------------------------------------------------------------------------------------------------------------------------------------------

Entity beans aren’t serializable.
We find that we must define additional data transfer objects (DTOs, also called value objects) when we need to transport data to a remote
client tier.
The use of fine-grained method calls (multiple method calls) from the client to a remote entity bean instance is not scalable.
DTOs provide a way of batching remote data access.
The DTO pattern results in the growth of parallel class hierarchies, where each entity of the domain model is represented as both an
entity bean and a DTO.

Use a Transfer Object to encapsulate the business data.
A single method call is used to send and retrieve the Transfer Object.
When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with
its attribute values, and pass it by value to the client.

Clients usually require more than one value from an enterprise bean.
To reduce the number of remote calls and to avoid the associated overhead, it is best to use Transfer Objects to transport the data from
the enterprise bean to its client.

When an enterprise bean uses a Transfer Object, the client makes a single remote method invocation to the enterprise bean to
request the Transfer Object instead of numerous remote method calls to get individual attribute values.
The enterprise bean then constructs a new Transfer Object instance, copies values into the object and returns it to the client.
The client receives the Transfer Object and can then invoke accessor (or getter) methods on the Transfer Object to get the individual
attribute values from the Transfer Object.
Or, the implementation of the Transfer Object may be such that it makes all attributes public.
Because the Transfer Object is passed by value to the client, all calls to the Transfer Object instance are local calls instead of remote
method invocations.


FROM:
http://java.sun.com/blueprints/corej2eepatterns/Pattern/TransferObject.html


  My Note: 
Within this context, it makes sense to assume Value Object as synonym to Transfer Object , because the Transfer Object is passed by value to the client.
Outside this context, a "Transfer Object" is not necessarily a "Value Object" cause instead of being passed by value it may contains references or representations.

Setback
If the Transfer Object comes like a big ship navigating up and down, other problems are raised - throughput (network traffic) and memory usages.
See Adam's comment, below on his blog.

----------------------------------------------------------------------------------------------------------------------------------------------
Data transfer object (DTO) is a design pattern used to transfer data between software application subsystems.
DTOs are often used in conjunction with data access objects to retrieve data from a database.

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behavior except  for
storage and retrieval of its own data (accessors and mutators).

In a traditional EJB (Enterprise JavaBeans) architecture, DTOs serve dual purposes:

First, they work around the problem that entity beans  pre-ejb 3.0 are not serializable;

Second, they implicitly define an assembly phase where all data to be used by the view are fetched and  marshalled into the
DTOs before returning control to the presentation tier.

A third reason of using DTOs could be that  certain layers of the
application should not be able to access the underlying data access objects, and hence change the data.

A value object is a small simple object, like money or a date range, whose equality isn't based on identity.

FROM:
http://en.wikipedia.org/wiki/Data_transfer_object
http://en.wikipedia.org/wiki/Value_object

----------------------------------------------------------------------------------------------------------------------------------------------


A value object is a small simple object, like money or a date range, whose equality isn't based on identity.

FROM:  Wikipeadia


----------------------------------------------------------------------------------------------------------------------------------------------


The pattern which is known today as Data Transfer Object was mistakenly (see this definition) called Value Object in the first version of the Core
J2EE Patterns.
 

The name was corrected in the second edition of the Core J2EE Patterns book, but the name alue Objectbecame very popular and is still used as an
alias for the actual DTOs.
 

There is, however, a real difference between both patterns: A Data Transfer Object (DTO) is just as stupid data container which is used to transport
data between layers and tiers.
It mainly contains of attributes.
 

Actually you can even use public attributes without any getters / setters, but this will probably cause too much meetings and discussions :-).
 

DTOs are anemic in general and do not contain any business logic.
DTOs are often java.io.Serializable - its only needed if you are going to transfer the data across JVMs.
 

A Value Object [1,2] represents itself a fix set of data and is similar to a Java enum.
A Value Object doesn't have any identity, it is entirely identified by its value and is immutable.
A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.

@FROM:
Adam's blog


Wednesday, December 26, 2012

java - Calendar.java and GregorianCalendar.java - how to by a full implementation


Some day, while I was implementing a DAO layer,  it was required to create an order which the dispatch date was the order date plus 7 days.
Some additional business rules like postponing due to weekend, holidays, etc. added additional complexity.
So, I decided to create a CalendarSvc (calendar service) class to handle the required issues concerning date and time.

The following class offers that and many other facilities to support many date/time operations.

For instance:

    /**
     * Obtains the dispatch date.
     * @return date plus dispatch period.
     */
    public static Date dispatchDate(Date date) {
        CalendarSvc dispatchDate = new CalendarSvc(date.getTime() + (dispatchPeriod * CalendarSvc.DAYMSEC));
        return
dispatchDate.date();
    }


where  dispatchPeriod is a variable defined on your config.ini that holds the number of days which is supposed to be dispatched (in this case was:  dispatchPeriod = 7)

There are other examples on the header comment.

You're gonna find some references to another classes, but they are self-explanatory and I suppose that their name is enough to suggest the simple extra implementation required.


CalendarSvc.java
------------------------------------------------------------------------------------------------------------------

package javaLib.time.calendar;

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;
import java.util.TimeZone;

import javaLib.services.StrSvc;
import javaLib.time.DateTime;

/**
 * javaLib.time.calendar.Days2Calendar.java

 * project: javaLib

 *

 * target: Calendar services using GregorianCalendar.

 *

 *

 *
 * notes:
 *

 * Example#1 - difference between:
 *
 *    Date date = CalendarSvc.dmy("31/12/2012", "/").date();
 *
 * 
 *        CalendarSvc before = new CalendarSvc();
 *     try {
 *       Thread.sleep(10);
 *     } catch (InterruptedException e) {
 *       e.printStackTrace();
 *     }
 *     CalendarSvc after = new CalendarSvc();
 *     System.out.println(before.diffMillisec(after.getDate()));
 *     // same as:
 *     System.out.println(after.getDate().getTimeInMillis() - before.getDate().getTimeInMillis());
 * 
 *     CalendarSvc before = new CalendarSvc();
 *     System.out.println(before.getDate());
 *     System.out.println(before.ymdDate());
 *     System.out.println(before.ymdTimeDate());
 *     System.out.println(before.getDate().getTimeInMillis());
 * 
 *     CalendarSvc after = new CalendarSvc(2012,12,31);
 *     System.out.println(after.getDate());
 *     System.out.println(after.ymdTimeDate());
 *     System.out.println(after.getDate().getTimeInMillis());
 * 
 *     Long diff = before.diffMillisec(after.getDate());
 *     System.out.println("difference in milliseconds = " + diff);
 *     System.out.println("difference in days = " + CalendarSvc.millisec2days(diff));
 *     System.out.println("difference in days = " + before.daysBetween(after.getDate()));
 * 
 *     System.out.println("\n--- 1");
 *     Date d1 = new Date();
 *     long t = d1.getTime() + 3600000;
 *     Date d2 = new Date();
 *     d2.setTime(t);
 *     System.out.println("d1 = " + d1);
 *     System.out.println("d1.getTime() = " + d1.getTime());
 *     System.out.println("d2 = " + d2);
 *     System.out.println("d2.getTime() = " + d2.getTime());
 *     System.out.println("t = " + t);
 *
 *     CalendarSvc calendarSvc = CalendarSvc.dmy("12/08/2012", "/");
 *     System.out.println(calendarSvc.dmyDate());
 *     
 *     
 * Example#2 - using Date():
 *  
 *     System.out.println("\n--- 2");
 *     
 *     Date d1 = new Date();
 *     CalendarSvc date1 = new CalendarSvc(d1.getTime());
 *     System.out.println(date1.getDate());
 *     System.out.println(date1.ymdTimeDate());
 *     System.out.println(date1.getDate().getTimeInMillis());
 *     
 * 
 * Example#3 - adding days and difference between:
 * 
 *     System.out.println("\n--- 3");
 *     
 *     CalendarSvc date3 = new CalendarSvc();
 *     System.out.println("today = " + date3.ymdTimeDate());
 *     System.out.println(date3.dayOfWeek());
 *     System.out.println(date3.getDate().getTimeInMillis());
 *     
 *     int days = 7;
 *     date3.addDays(days);
 *     
 *     System.out.println("today + " + days + " = " + date3.ymdTimeDate());
 *     System.out.println(date3.ymdTimeDate());
 *     System.out.println(date3.dayOfWeek());
 *     System.out.println(date3.getDate().getTimeInMillis());
 * 

 *
 * @see prj:
 * @author alsdias@yahoo.com.br
 * @version v.1.0.0 - Dec 26, 2012
 */
public class CalendarSvc implements ICalendarSvc {

    protected GregorianCalendar date = null;
    protected int year = 0;
    protected int month = 0;
    protected int day = 0;
    protected int hour = 0;
    protected int minute = 0;
    protected int second = 0;
    protected long millisec = 0L;
    protected Locale locale = null;
    protected TimeZone timezone = null;
   
   
    /** one day in milliseconds */
    public static final long DAYMSEC = 86400000L; // 24L * 60L * 60L * 1000L;
   
    private String dateDelimiter = "/";
    private String timeDelimiter = ":";

    protected DateFormatSymbols symbols;
    protected String[] shortMonthList, monthList, weekdayList;
   
   
    private void setDefaults() {
        locale = Locale.getDefault();
        timezone = TimeZone.getDefault();
        date = new GregorianCalendar(timezone, locale);
    }
   
    /**
     * Common initialization procedures.
     */
    private void init() {
        year = date.get(GregorianCalendar.YEAR);
        month = date.get(GregorianCalendar.MONTH) + 1;
        day = date.get(GregorianCalendar.DAY_OF_MONTH);
        hour = date.get(GregorianCalendar.HOUR_OF_DAY);
        minute = date.get(GregorianCalendar.MINUTE);
        second = date.get(GregorianCalendar.SECOND);
        millisec = date.get(GregorianCalendar.MILLISECOND);
        symbols = ((SimpleDateFormat)DateFormat.getInstance()).getDateFormatSymbols();
        monthList = symbols.getMonths();
        shortMonthList = symbols.getShortMonths();
        weekdayList = symbols.getWeekdays();
    }
    /**
     * Constructor using default values for timezone and locale.
     */
    public CalendarSvc() {
        setDefaults();
        init();
    }

    /**
     * Constructor for specific locale.
     * @param locale
     */
    public CalendarSvc(Locale locale) {
        this.locale = locale;
        timezone = TimeZone.getDefault();
        date = new GregorianCalendar(timezone, locale);
        init();
    }
   
    /**
     * Constructor using specific timezone and locale.
     */
    public CalendarSvc(TimeZone timezone, Locale locale) {
        locale = Locale.getDefault();
        timezone = TimeZone.getDefault();
        date = new GregorianCalendar(timezone, locale);
        init();
    }
   
    /**
     * Constructor for creating a specific date.
     * @param year
     * @param month_
     * @param day day of month
     */
    public CalendarSvc(int year, int month, int day) {
        setDefaults();
        date.set(GregorianCalendar.YEAR, year);
        date.set(GregorianCalendar.MONTH, month - 1);
        date.set(GregorianCalendar.DAY_OF_MONTH, day);
        init();
    }

    /**
     * Constructor for creating a specific date and time.
     * @param year
     * @param month
     * @param day
     * @param hour
     * @param minute
     * @param sec
     */
    public CalendarSvc(int year, int month, int day, int hour, int minute, int sec) {
        setDefaults();
        date.set(GregorianCalendar.YEAR, year);
        date.set(GregorianCalendar.MONTH, month-1);
        date.set(GregorianCalendar.DAY_OF_MONTH, day);
        date.set(GregorianCalendar.HOUR_OF_DAY, hour);
        date.set(GregorianCalendar.MINUTE, minute);
        date.set(GregorianCalendar.SECOND, sec);
        init();
    }

    public CalendarSvc(long milliseconds) {
        setDefaults();
        Date time = new Date();
        time.setTime(milliseconds);
        date.setTime(time);
        init();
    }
   
/*-----------------------------------------------------------------------------------------------------------------------
 ***SERVICES
-----------------------------------------------------------------------------------------------------------------------*/

    public String dayOfWeek() {
        return date.getDisplayName(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.ALL_STYLES, locale);
    }
   
    /**
     * Adds a number of days to the date.
     * @param number
     */
    public void addDays(int number) {
        Date time = new Date();
        time.setTime(time.getTime() + number * CalendarSvc.DAYMSEC);
        CalendarSvc newcal = new CalendarSvc(time.getTime());
        this.date = newcal.getDate();
        init();
    }
   
   
    /**
     * Obtains the days between the current date and another.
     * @param other
     * @return
     */
    public long daysBetween(Calendar other) {
        return CalendarSvc.millisec2days(other.getTimeInMillis() - this.date.getTimeInMillis());
    }
   
   
    /**
     * Returns YEAR/MONTH/DAY if default delimiter is used.
     * @return
     */
    public String ymdDate() {
        return year + dateDelimiter + month + dateDelimiter + day;
    }
   
    /**
     * Obtains CalendarSvc from a YMD formal date string.
     * Ex: ymd("2012/08/12", "/");
     * @param sdate
     * @param delimiter
     * @return
     */
    public static CalendarSvc ymd(String sdate, String delimiter) {
        StringTokenizer stokens = new StringTokenizer(sdate, delimiter);
        return new CalendarSvc(Integer.valueOf(stokens.nextToken()), Integer.valueOf(stokens.nextToken()), Integer.valueOf(stokens.nextToken()));
    }
   
    /**
     * Obtains CalendarSvc from a DMY formal date string.
     * Ex: ymd("12/08/2012", "/");
     * @param sdate
     * @param delimiter
     * @return
     */
    public static CalendarSvc dmy(String sdate, String delimiter) {
        StringTokenizer stokens = new StringTokenizer(sdate, delimiter);
        int year = Integer.valueOf(stokens.nextToken());
        int month = Integer.valueOf(stokens.nextToken());
        int day = Integer.valueOf(stokens.nextToken());
        return new CalendarSvc(day, month, year);
    }
   
    /**
     * Returns DAY/MONTH/YEAR if default delimiter is used.
     * @return
     */
    public String dmyDate() {
        return day + dateDelimiter + month + dateDelimiter + year;
    }
   
    /**
     * Returns YEAR/MONTH/DAY HOUR:MINUTE:SECOND:MILLISECOND if default delimiters are used.
     * @return
     */
    public String ymdTimeDate() {
        return year + dateDelimiter + month + dateDelimiter + day + " " + hour + timeDelimiter + minute + timeDelimiter + minute + timeDelimiter + millisec;
    }

   
    /**
     * Returns the present instant as follow: YYYYMMDD_hh:mm:ss:SSS).
     * Example: 080381_17:35:01:897
     * @param language
     * @param country
     * @return timestamp format as follow: yyMMDD_H:mm:ss:SSS
     */
    public static String timestamp(String language, String country) {
        Date today = new Date();   
        Locale locale = new Locale(language, country);
        SimpleDateFormat formatter = new SimpleDateFormat("yyMMDD_H:mm:ss:SSS", locale);
        String output = formatter.format(today);
        return output;
    }

    /**
     * Returns the present instant as follow: YYYYMMDD_hh:mm:ss:SSS).
     * Example: 080381_17:35:01:897
     * @return timestamp format as follow: yyMMDD_H:mm:ss:SSS
     */
    public String timestamp() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyMMDD_H:mm:ss:SSS", locale);
        String output = formatter.format(date.getTime());
        return output;
    }

   
    /**
     * Returns the present instant according to format parameter.
     * Example: 080381_17:35:01:897
     * @param language
     * @param country
     * @param format Sun's SimpleDateFormat string pattern. For instance: yyMMDD_H:mm:ss:SSS
     * @return timestamp formatted. If null or empty, assumes default = &quot;yyMMDD_H:mm:ss:SSS&quot;
     */
    public static String timestamp(String language, String country, String format) {
        if(format == null || format.isEmpty()) format = "yyMMDD_H:mm:ss:SSS";
        Date today = new Date();   
        Locale locale = new Locale(language, country);
        SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
        String output = formatter.format(today);
        return output;
    }
   
    /**
     * Returns the present instant according to format parameter.
     * Example: 080381_17:35:01:897
     * @param format Sun's SimpleDateFormat string pattern. For instance: yyMMDD_H:mm:ss:SSS
     * @return timestamp formatted. If null or empty, assumes default = &quot;yyMMDD_H:mm:ss:SSS&quot;
     */
    public String timestamp(String format) {
        if(format == null || format.isEmpty()) format = "yyMMDD_H:mm:ss:SSS";
        SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
        String output = formatter.format(date.getTime());
        return output;
    }
   
    /**
     * Returns a timestamp string without the milliseconds, formatted as follow if delimiter = &quot;_&quot;:<br>
     * YYYYMMDD_hhmmss
     * @param timestamp formatted as follow: YYYYMMDD_hhmmss_msec<br>
     * If null or empty returns an empty string. If size &lt; 17 or missing time returns exception.
     * @param delimiter the string used to delimiter the date fields.<br>
     * If null or empty, assumes default = "/".
     * @return For instance, if delimiter = &quot;_&quot;, returns YYYYMMDD_hhmmss .<br>
     * @throws StrException
     */
    public static String getTimestampMinusMsec(String timestamp, String delimiter) throws Exception {
        String exceptionMsg = "[ERROR]: javaLib.time.TimeSvc.getTimestampMinusMsec";
        if(timestamp == null || timestamp.isEmpty()) return "";
        if(timestamp.length() < 17) throw new Exception(exceptionMsg + ": invalid timestamp format - length = " + timestamp.length());
        if(delimiter == null || delimiter.isEmpty()) delimiter = "/";
        ArrayList<String> fields = StrSvc.str2arrayList(timestamp, delimiter);
        if(fields.size() < 2) throw new Exception(exceptionMsg + ": invalid timestamp format - fields size = " + fields.size());
        return fields.get(0) + "_" + fields.get(1);
    }

    /**
     * Returns a timestamp string without the milliseconds, formatted as follow if delimiter = &quot;_&quot;:<br>
     * YYYYMMDD_hhmmss
     * @param timestamp formatted as follow: YYYYMMDD_hhmmss_msec<br>
     * If null or empty returns an empty string. If size &lt; 17 or missing time returns exception.
     * @param delimiter the string used to delimiter the date fields.<br>
     * If null or empty, assumes default = "/".
     * @return For instance, if delimiter = &quot;_&quot;, returns YYYYMMDD_hhmmss .<br>
     * @throws StrException
     */
    public String getTimestampMinusMsec(String timestamp) throws Exception {
        String exceptionMsg = "[ERROR]: javaLib.time.TimeSvc.getTimestampMinusMsec";
        if(timestamp == null || timestamp.isEmpty()) return "";
        if(timestamp.length() < 17) throw new Exception(exceptionMsg + ": invalid timestamp format - length = " + timestamp.length());
        ArrayList<String> fields = StrSvc.str2arrayList(timestamp, dateDelimiter);
        if(fields.size() < 2) throw new Exception(exceptionMsg + ": invalid timestamp format - fields size = " + fields.size());
        return fields.get(0) + "_" + fields.get(1);
    }


    /**
     * Converts time in milliseconds since Epoch to timestamp.
     * @param millisec time in milliseconds since Epoch.
     * @return timestamp in the format: YYYYMMDD_hhmmss_msec <br>
     * If null or empty argument, returns empty string.
     * @throws StrException
     */
    public static String millisecToTimestamp(String millisec) throws Exception {
        if(millisec == null || millisec.isEmpty()) return "";
        int timekey_ = 0;
        try {
            timekey_ = Integer.parseInt(millisec);
        } catch (Exception e) {
            throw new Exception("[exception]: br.gov.datasus.synopsis.millisecToTimestamp: invalid millisec value");
        }
        DateTime dt = new DateTime(null, timekey_);
        return dt.timestamp();
    }

    /**
     * Converts a timestamp into milliseconds since Epoch.
     * @param timestamp in the format: YYYYMMDD_hhmmss_msec
     * @return time in milliseconds since Epoch.
     * @throws StrException
     */
    public static long timestampToMillisec(String timestamp) throws Exception {
        DateTime dt = new DateTime(timestamp);
        return dt.get_timeInMillis();
    }
   
    /**
     * Converts to milliseconds.
     * @param dateParts array where array[0]=YYYY, array[1]=MM, array[2]=DD.
     * @return milliseconds from the Epoch(01/01/1970).
     * @throws StrException
     */
    public Long milliseconds(int[] dateParts) throws Exception {
        if(dateParts == null || dateParts.length < 3) throw new Exception("[ERROR]: invalid syntax: missing date or values");
        Calendar cal = Calendar.getInstance(locale);
            cal.set(dateParts[0], dateParts[1], dateParts[2]);  
        return cal.getTimeInMillis();
    }


    /**
     * Converts to milliseconds a string of date using a format pattern.
     * @param s_date
     * @param pattern
     * @return milliseconds from the Epoch(01/01/1970).
     * @throws StrException
     */
    public static Long milliseconds(String s_date, String pattern) throws Exception {
        String errorMsg = "[ERROR]: invalid syntax: missing date or values";
        if(StrSvc.isNullEmpty(s_date) || StrSvc.isNullEmpty(pattern))
            throw new Exception(errorMsg);
        try {
            Date date = new SimpleDateFormat(pattern).parse(s_date);
            return date.getTime();
        } catch (ParseException e) {
            throw new Exception(errorMsg + " due to: " + e.getMessage());
        }
    }

    /**
     * Converts milliseconds to a time string according to its patterns.
     * @param milliseconds
     * @param pattern
     * @return time string
     */
    public static String time(Long milliseconds, String pattern) {
        SimpleDateFormat formato = new SimpleDateFormat(pattern);  
        return formato.format(new Date(milliseconds));
    }
   

    /**
     * Conversion of milliseconds to days.
     * @param millisec
     * @return
     */
    public static long millisec2days(Long millisec) {
        return millisec / 86400000;
    }
   
    /**
     * Calculates in milliseconds the residual time in the year (from supplied date to the end of the year).
     * @param date the present date.
     * @return residual time in milliseconds.
     */
    public static long residualMillisecInYear(Calendar date) {
        GregorianCalendar lastday = new GregorianCalendar(date.get(GregorianCalendar.YEAR), 12, 31);
        return lastday.getTimeInMillis() - date.getTimeInMillis();
    }

    /**
     * Calculates the time difference compared to another in milliseconds.
     * @param now
     * @param other
     * @return difference in milliseconds.
     */
    public long diffMillisec(Calendar other) {
        return other.getTimeInMillis() - date.getTimeInMillis();
    }
   
   
    /**
     * Calculates the time difference between two dates in milliseconds.
     * @param now
     * @param after
     * @return difference in milliseconds.
     */
    public static long diffMillisec(Calendar now, Calendar after) {
        return after.getTimeInMillis() - now.getTimeInMillis();
    }
   
   
    /**
     * Converts days to number of years, months and days.
     *
     * @param days
     * @return
     */
    public Integer[] days2calendar(int days) {
        int max_year = date.getActualMaximum(GregorianCalendar.DAY_OF_YEAR);
        int max_month = date.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        Integer[] ymd = {0,0,0};
        ymd[0] = (days >= max_year) ? days/max_year : 0;
        int m = days - (ymd[0] * max_year);
        ymd[1] = (m >= max_month) ? m/max_month : 0;
        ymd[2] = m - (ymd[1] * max_month);
        return ymd;
    }

    /**
     * Straight accessor for Date object.
     * @return Date object.
     */
    public Date date() {
        return date.getTime();
    }

    /**
     * Obtains the short month notation.<br>
     * Jan = 1, Feb = 2, ... Dec = 12.
     * @param index 1-12
     * @return short month notation, otherwise empty.
     */
    @Override
    public String shortMonth(int index) {
        if(index < 1 || index > 13) return "";
        return shortMonthList[index];
    }
   
    /**
     * Obtains the month full notation.<br>
     * January = 1, February = 2, ... December = 12.
     * @param index 1-12
     * @return full month notation, otherwise empty.
     */
    @Override
    public String month(int index) {
        if(index < 1 || index > 13) return "";
        return monthList[index];
    }
   
   
/*-----------------------------------------------------------------------------------------------------------------------
 ***GETTERS/SETTERS
-----------------------------------------------------------------------------------------------------------------------*/
   
   
    public int getHour() {
        return hour;
    }

    public GregorianCalendar getDate() {
        return date;
    }
    public void setDate(GregorianCalendar date) {
        this.date = date;
    }
    public int getYear() {
        return year;
    }
    public void setYear(int year) {
        this.year = year;
    }
    public int getMonth() {
        return month;
    }
    public void setMonth(int month) {
        this.month = month;
    }
    public int getDay() {
        return day;
    }
    public void setDay(int day) {
        this.day = day;
    }
    public void setHour(int hour) {
        this.hour = hour;
    }

    public int getMinute() {
        return minute;
    }

    public void setMinute(int minute) {
        this.minute = minute;
    }

    public int getSecond() {
        return second;
    }

    public void setSecond(int second) {
        this.second = second;
    }

    public long getMillisec() {
        return millisec;
    }
    public void setMillisec(long millisec) {
        this.millisec = millisec;
    }
   
    public String getDateDelimiter() {
        return dateDelimiter;
    }
    public void setDateDelimiter(String dateDelimiter) {
        this.dateDelimiter = dateDelimiter;
    }
    public String getTimeDelimiter() {
        return timeDelimiter;
    }
    public void setTimeDelimiter(String timeDelimiter) {
        this.timeDelimiter = timeDelimiter;
    }
   
    /*-----------------------------------------------------------------------------------------------------------------------
     ***GETTERS/SETTERS
    -----------------------------------------------------------------------------------------------------------------------*/

    public DateFormatSymbols getSymbols() {
        return symbols;
    }

    public void setSymbols(DateFormatSymbols symbols) {
        this.symbols = symbols;
    }

    public String[] getMonthList() {
        return monthList;
    }

    public void setMonthList(String[] monthList) {
        this.monthList = monthList;
    }

    public String[] getWeekdayList() {
        return weekdayList;
    }

    public void setWeekdayList(String[] weekdayList) {
        this.weekdayList = weekdayList;
    }


    public String[] getShortMonthList() {
        return shortMonthList;
    }


    public void setShortMonthList(String[] shortMonthList) {
        this.shortMonthList = shortMonthList;
    }

    @Override
    public Locale getLocale() {
        return locale;
    }

    @Override
    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    /**
     * For testing purpose.
     * @param args
     */
//    public static void main(String[] args) {
//       
//    }
   
}

mysql - error 1005 (hy000) at line ... can't create table

Creating the database:
 
$ mysql -uroot -pmysql < my_tester_createdb_2.sql

Returns:
ERROR 1005 (HY000) at line 202: Can't create table './tester/#sql-d2d_146.frm' (errno: 150)


Solution

Search for a foreign key reference mistake like:

 - incompatible types
 - unsigned (when it shouldn't )







hibernate error: path expected for join

To ORM (Object Relational Mapping), a path is a reference inside the target object that leads to its respective associations.

For instance, this WRONG HQL statement:

select prod.nome, cat.nome from ProductVO as prod join CategoryVO as cat

causes the exception:

app.exception.DaoException: [SYSTEM]: Path expected for join! [select prod.nome, cat.nome from app.model.persistence.hbn.vo.ProductVO as prod join
CategoryVO as cat]


The mistake is that the statement was created thinking as it were SQL way of doing things.

But, the ORM way of doing things is:

select prod.nome, cat.nome from ProductVO as prod join prod.CategoryVO as cat

The path is supplied by prod.CategoryVO as cat, which is the referenced object.

Wednesday, December 5, 2012

hibernate: java.lang.noclassdeffounderror: com/mchange/v2/c3p0/datasources

Problem

If you are using c3p0 connection pool for hibernate, then you probably have
on the hibernate.cfg.xml file the following configuration:

<!-- c3p0 connection pool (use the built-in) -->
  <property name="connection.pool_size">c3p0</property>
  <property name="c3p0.min_size">5</property>
  <property name="c3p0.max_size">20</property>
  <property name="c3p0.timeout">1800</property>
  <property name="c3p0.max_statements">50</property>


When you run the application, it throws an exception like below:



21:03:25,016  INFO C3P0ConnectionProvider:82 - Connection properties: {user=root, password=****}
21:03:25,016  INFO C3P0ConnectionProvider:85 - autocommit mode: false
21:03:25,023  WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_size' and c3p0-style property 'c3p0.max_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.max_size' will be used and c3p0-style property 'c3p0.max_size' will be ignored!
21:03:25,023  WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.min_size' and c3p0-style property 'c3p0.min_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.min_size' will be used and c3p0-style property 'c3p0.min_size' will be ignored!
21:03:25,024  WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.timeout' and c3p0-style property 'c3p0.timeout' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.timeout' will be used and c3p0-style property 'c3p0.timeout' will be ignored!
21:03:25,024  WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_statements' and c3p0-style property
'c3p0.max_statements' have been set in hibernate.properties.Hibernate-style property 'hibernate.c3p0.max_statements' will be used and c3p0-style property 'c3p0.max_statements' will be ignored!
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Exception in thread "main" java.lang.ExceptionInInitializerError
  at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:43)
  at test.db.AdminVO_test.showList(AdminVO_test.java:120)
  at test.db.AdminVO_test.main(AdminVO_test.java:46)
Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
  at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154)
  at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
  at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
  at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
  at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
  at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
  at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:39)
  ... 2 more
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
  at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  ... 10 more




Solution

Missing  the c3p0 jar files on the project's build path.
Download the jar file, for instance:
c3p0-0.9.1.2.jar

Monday, November 19, 2012

SEVERE: The system cannot infer the transport information from the http://localhost:8080/axis2/services/


Issue
 
Web Services that returns the following exception:

SEVERE: The system cannot infer the transport information from the  http://localhost:8080/axis2/services/DataService URL.
Exception in thread "main" org.apache.axis2.AxisFault: The system cannot infer the transport information from the  http://localhost:8083/axis2/services/DataService URL.

 
Solution

If the URL is really correct, try checking the spaces on the url.

Example of a undesirable initial space causing the problem (yellow):
String url = " http://localhost:8080/axis2/services/DataService";

To avoid such problem, instead of:
DataServiceStub service = new DataServiceStub(url)

do:
DataServiceStub service = new DataServiceStub(url.trim());

Thursday, November 15, 2012

Cannot resolve the name '...' to a(n) 'type definition' component


Suppose you are validating the a xml file against a XML Schema (a .xsd file), and an exception message returns like this:


org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'createNewAdRequest' to a(n) 'type definition' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)

Check the if the type declaration is accessible, in order words, has the same scope.


For instance, here is the test.xml file:

<ClassifiedList>
    <ClassifiedAd>
        <id>1234</id>
        <content>
            Vintage 1963 T-Bird.  Less than 300 miles.
            Driven by my daughter until I took it away.
            Serious inquires only. 555-3264 after 7 PM.
        </content>
        <endDate>4/15/2007</endDate>
        <startDate>4/1/2007</startDate>
        <createNewAdRequest>
            <content>YYY</content>
            <endDate>YYY</endDate>
        </createNewAdRequest>
    </ClassifiedAd>  
</ClassifiedList>


And here the respctive XML Schema file - test.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element type="ClassifiedList" name="ClassifiedList" />
    <xs:complexType name="ClassifiedList">
      <xs:sequence>
        <xs:element minOccurs="0" type="ClassifiedAd"
                        name="ClassifiedAd" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>

    <xs:element type="ClassifiedAd" name="ClassifiedAd" />
    <xs:complexType name="ClassifiedAd">
      <xs:sequence>
        <xs:element type="xs:int" name="id" />
        <xs:element type="xs:string" name="content" />
        <xs:element type="xs:string" name="endDate" />
        <xs:element type="xs:string" name="startDate" />
        <xs:element type="createNewAdRequest" name="createNewAdRequest" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
       
    <xs:element name="createNewAdRequest">
        <xs:complexType name="createNewAdRequest">
            <xs:sequence>
                <xs:element type="xs:string" name="content" />
                <xs:element type="xs:string" name="endDate" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
   
</xs:schema>


The text highlighted in blue defines a new type under its element scope.
So, it is not accessible from outside.
Switch the blue text by the orange below, where the complex type is defined in the same scope of  <ClassifiedList> element.
       
        <xs:complexType name="createNewAdRequest">
            <xs:sequence>
                <xs:element type="xs:string" name="content" />
                <xs:element type="xs:string" name="endDate" />
            </xs:sequence>
        </xs:complexType>
   

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...