You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/08/21 05:27:38 UTC

Compiling error returning service interface in service locator method

Hello, in my DMSServiceLocator.class, I have a method called getParser() with
a return type called Parser.  I'm trying to return a service called
AutoMateParser with an Impl that extends Parser, however I'm' getting a
compiling error saying Parser is required, found AutoMateParser. When I
return new AutoMateServiceImpl() rather than my service interface, I receive
no compiling errors. It doesn't appear my getParser() method realizes
autoMateParser is of the same type. I tried casting AutoMateParser with
Parser, "return (Parser) autoMateParser;" which resolved compiling errors,
but received a cast exception. I'm wondering if anybody knows how to do
this. Thanks in advance.

below is a sample of my code. 

AppModule

public static void bind(ServiceBinder binder) {
        binder.bind(AutoMateParser.class, AutoMateParserImpl.class);
}

public class DMSServiceLocator {

    @Inject
    private AutoMateParser autoMateParser;

    public Parser getParser() {
        if(automate) {
        return autoMateParser();
        } else {
           //Different data scrubber, but also extends Parser
           return homenetParser();
        }
    }

}

public class AutoMateParserImpl extends Parser implements AutoMateParser {
    protected Vehicle parseCar(String vehicleData) {
        //some data scrubbing code
    }
}

public class Parser {
    //some csv line reader code
    protected abstract Vehicle parseCar(String carData);
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by George Christman <gc...@cardaddy.com>.
There's no interface to Parser, Parser is just an extended class located in
my service package along with my AutoMateParserImpl. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645p5715658.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by Joakim Olsson <jo...@unbound.se>.
Hi George,

It sounds like your Parser interface is located in one of Tapestrys
blessed packages (pages, components, mixins etc.)

/Joakim


On Tue, Aug 21, 2012 at 5:27 AM, George Christman
<gc...@cardaddy.com> wrote:
> Hello, in my DMSServiceLocator.class, I have a method called getParser() with
> a return type called Parser.  I'm trying to return a service called
> AutoMateParser with an Impl that extends Parser, however I'm' getting a
> compiling error saying Parser is required, found AutoMateParser. When I
> return new AutoMateServiceImpl() rather than my service interface, I receive
> no compiling errors. It doesn't appear my getParser() method realizes
> autoMateParser is of the same type. I tried casting AutoMateParser with
> Parser, "return (Parser) autoMateParser;" which resolved compiling errors,
> but received a cast exception. I'm wondering if anybody knows how to do
> this. Thanks in advance.
>
> below is a sample of my code.
>
> AppModule
>
> public static void bind(ServiceBinder binder) {
>         binder.bind(AutoMateParser.class, AutoMateParserImpl.class);
> }
>
> public class DMSServiceLocator {
>
>     @Inject
>     private AutoMateParser autoMateParser;
>
>     public Parser getParser() {
>         if(automate) {
>         return autoMateParser();
>         } else {
>            //Different data scrubber, but also extends Parser
>            return homenetParser();
>         }
>     }
>
> }
>
> public class AutoMateParserImpl extends Parser implements AutoMateParser {
>     protected Vehicle parseCar(String vehicleData) {
>         //some data scrubbing code
>     }
> }
>
> public class Parser {
>     //some csv line reader code
>     protected abstract Vehicle parseCar(String carData);
> }
>
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 21 Aug 2012 11:26:21 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Well I think I need to create an interface to ParserImpl, "Parser" and  
> in the AutoMateParser interface extend Parser. However as I know now  
> this is deff not an issue in how I'm using the services, but rather a  
> George's Java skill issue lol. I've never written a Java program outside  
> of Tapestry, so I
> sometimes easily confuse the two.

As we say here in Brazil, living and learning. :)

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by George Christman <gc...@cardaddy.com>.
Well I think I need to create an interface to ParserImpl, "Parser" and in the
AutoMateParser interface extend Parser. However as I know now this is deff
not an issue in how I'm using the services, but rather a George's Java skill
issue lol. I've never written a Java program outside of Tapestry, so I
sometimes easily confuse the two. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645p5715670.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Just make getParser() return AutoMateParser instead of Parser. That's  
object-oriented programming: if you have something that is defined by an  
interface, use the interface. ;)

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by George Christman <gc...@cardaddy.com>.
btw, my Parser.class is an abstract class. Sorry, I missed that in my
example. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645p5715664.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Compiling error returning service interface in service locator method

Posted by George Christman <gc...@cardaddy.com>.
The IDE suggest the cast because the AutoMateParser is not a sub-type of
Parser, only AutoMateParserImpl is. Just not sure how to make that work.
Any thoughts? Still new to binding, but should I be binding
AutoMateParserImpl to a Parser interface?

On Tue, Aug 21, 2012 at 8:02 AM, Thiago H de Paula Figueiredo [via
Tapestry] <ml...@n5.nabble.com> wrote:

> On Tue, 21 Aug 2012 00:27:38 -0300, George Christman
> <[hidden email] <http://user/SendEmail.jtp?type=node&node=5715660&i=0>>
> wrote:
>
> > Hello, in my DMSServiceLocator.class, I have a method called getParser()
>
> > with a return type called Parser.  I'm trying to return a service called
> > AutoMateParser with an Impl that extends Parser, however I'm' getting a
> > compiling error saying Parser is required, found AutoMateParser. When I
> > return new AutoMateServiceImpl() rather than my service interface, I
> > receive
> > no compiling errors. It doesn't appear my getParser() method realizes
> > autoMateParser is of the same type. I tried casting AutoMateParser with
> > Parser, "return (Parser) autoMateParser;" which resolved compiling
> > errors, but received a cast exception.
>
> This is not a compiler error, but an exception instead. In addition, when
>
> you bind a service based on an interface, the instance of it you get is a
>
> proxy to the implementation class, not an instance of the service
> implementation, so this ClassCastException is expected. Why do you need to
>
> do this cast? This looks like a bad implementation decision in your code.
>
> --
> Thiago H. de Paula Figueiredo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5715660&i=1>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5715660&i=2>
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645p5715660.html
>  To unsubscribe from Compiling error returning service interface in
> service locator method, click here<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5715645&code=Z2NocmlzdG1hbkBjYXJkYWRkeS5jb218NTcxNTY0NXwxNjMyOTYxMjA3>
> .
> NAML<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Compiling-error-returning-service-interface-in-service-locator-method-tp5715645p5715662.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

Re: Compiling error returning service interface in service locator method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 21 Aug 2012 00:27:38 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hello, in my DMSServiceLocator.class, I have a method called getParser()  
> with a return type called Parser.  I'm trying to return a service called
> AutoMateParser with an Impl that extends Parser, however I'm' getting a
> compiling error saying Parser is required, found AutoMateParser. When I
> return new AutoMateServiceImpl() rather than my service interface, I  
> receive
> no compiling errors. It doesn't appear my getParser() method realizes
> autoMateParser is of the same type. I tried casting AutoMateParser with
> Parser, "return (Parser) autoMateParser;" which resolved compiling  
> errors, but received a cast exception.

This is not a compiler error, but an exception instead. In addition, when  
you bind a service based on an interface, the instance of it you get is a  
proxy to the implementation class, not an instance of the service  
implementation, so this ClassCastException is expected. Why do you need to  
do this cast? This looks like a bad implementation decision in your code.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org