Problems while accessing Java method through XSL .'I have a java class DirectoryReader.java with a static method totalPhotos which returns a int. In my XSL I have defined a namespace: xmlns:dirReader="xalan://com.mngi.eidos.util.DirectoryReader and I am trying to access the totalPhotos method like:
<xsl:variable name="totalPhotos" select="dirReader:totalPhotos($PhotoPath)"/>
Can someone please tell me what is wrong in my approach ?
I still get the following error
ERROR: 'The first argument to the
non-static Java function 'totalPhotos'
is not a valid object reference
Either the method totalPhotos must be static, or you must first create an instance of the class and pass that as the first argument to the call.
<xsl:variable name="dr" select="dirReader:new(....)"/>
<xsl:variable name="totalPhotos" select="dirReader:totalPhotos($dr,$PhotoPath)"/>
Adjust dirReader constructor arguments to your situation
Related
I know that an immutable array on XSLT 3.0 can be created as follows:
<xsl:variable name="array" as="element()*">
<Item>a</Item>
<Item>b</Item>
<Item>c</Item>
</xsl:variable>
Also, that is it possible to create a mutable variable using Saxon's assign function:
<xsl:variable name="var" select="'val'" saxon:assignable="yes"/>
Is it possible to combine the two? i.e. creating a mutable array that allows editing individual items?
Note that due to some technical restrictions I am to use only XSLT/Saxon functions, so JavaScript is off the table, unfortunately.
Thanks!
Having a mutable variable is a quite different thing from having a variable that contains a mutable value. The only way you can create a mutable value in Saxon is to use an external Java object.
But why would you want to? Tell us what you want to achieve, and we can help you achieve it using XSLT the way it was designed to be used, working with the language rather than fighting against it.
I have a class and this class has a method ("original_method") that uses two objects of different types. In this method there are two calls: one call to a method of the first object that returns a value which is then used for calling a method of the second object. I was wondering what is the correct way of unit testing such behavior (using google-test). Specifically, I want to test that the argument provided to the second object is indeed the value returned from the first.
Currently I achieve this using parametrized tests - the code below shows what I do:
TEST_P(SomeTestSuite, checkingIfCalledWithTheRightArgument)
{
EXPECT_CALL(*obj1, get_some_value()).WillOnce(Return(name_of_value));
EXPECT_CALL(*obj2, do_a_calculation(name_of_value));
obj0->call_original_method();
}
I have a fixture for my original class under testing, i have mocks for obj1 and obj2, I provide a value for "name_of_value" in the parameters and the test works.
My problem is that this doesn't seem to be the correct way, I believe I shouldn't have to pass a parameter to check such a functionality. I would appreciate if somebody could explain to me how i should have approached the problem.
Thank you.
EDIT:
I think I could do:
TEST_F(SomeTestSuite, checkingIfCalledWithTheRightArgument)
{
EXPECT_CALL(*obj1, get_some_value());
auto name_of_value = obj1->get_some_value();
EXPECT_CALL(*obj2, do_a_calculation(name_of_value));
obj0->call_original_method();
}
but I'm not sure if this captures (or actually tests) the original behaviour...
i have used v8 inside a class. Createcontext method is also inside a wrapper class. when i try to set global and map it to print function which is also inside the same class, i am getting error
invalid use of non-static member function
the line i used to set the method is
global->Set(v8::String::NewFromUtf8(isolate,"print"), v8::FunctionTemplate::New(isolate,this -> print));
can someone please explain me why this error happens and how to resolve it
The function you pass to FunctionTemplate::New must be static. Hence try making the print function inside your class static.
I'm having a bit of difficulty passing a reference type between webservices.
My set up is as follows.
I have a console application that references two web-services:
WebServiceOne
WebServiceTwo
WebServiceOne declares the details of a class I am using in my console application...let's call it MyClass.
My console application calls WebServiceOne to retrieve a list of MyClass.
It then sends each MyClass off to WebServiceTwo for processing.
Within in the project that holds WebServiceTwo, there is a reference to WebServiceOne so that I can have the declaration of MyClass.
The trouble I'm having is that, when I compile, it can't seem to determine that the MyClass passed from the console application is the same as the MyClass declared in WebServiceOne referenced in WebServiceTwo.
I basically get an error saying Console.WebServiceOne.MyClass is not the same as MyProject.WebServiceOne.MyClass.
Does anyone know if doing this is possible? Perhaps I'm referencing WebServiceOne incorrectly? Any idea what I might be doing wrong?
My only other option is to pass each of the properties of the reference type directly to WebServiceTwo as value types...but I'd like to avoid that since I'd end up passing 10-15 parameters.
Any help would be appreciated!
I had a chat with one of the more senior guys at my work and they proposed the following solution that has worked out well for me.
The solution was to use a Data Transfer Object and remove the reference to WebServiceOne in WebServiceTwo.
Basically, in WebServiceTwo I defined a representation of all the value type fields needed as BenefitDTO. This effectively allows me to package up all the fields into one object so I don't have to pass each of them as parameters in a method.
So for the moment, that seems to be the best solution...since it works and achieves my goal.
It's likely that I didn't explain my question very well...which explains why no one was able to help...
But thanks anyway! :-)
Move the types to a separate assembly and ensure that both services use this. In the web service reference there is probably some autogenerated code called Reference.cs. Alter this to use your types.
Edit: To reflect comments
In that case take the reference.cs from that web service you cannot control use it as the shared type.
Your error message explains the problem. The proxy class on the client side is not the same type as the original class on the server side, and never will be. Whether it's a reference type or a value type is irrelevant to how it works.
I don't quite understand what your exact problem is, but here are a few guesses:
If you are trying to compare two objects for equality, then you will have to write your own compare function that compares the values of each significant property/field in turn.
If you are trying to copy an object from one service to the other, then you will have to write your own copy function that copies the values of each significant property/field in turn.
If you were using WCF, you would have the option of bypassing all this and just sharing one class definition between the client and both services.
Refactored from bug_report_view.cc and bug_report_view.h, I extracted send_report(), report_phishing(), a few other smaller functions and BugReport::Cleanup into bug_report.cc and bug_report.h (my versions). Compiling now, I get:
[...]bug_report.cc:196: error: no matching function for call to ‘URLFetcher::URLFetcher(std::wstring&, URLFetcher::RequestType, BugReport::PostCleanup*)’
../chrome/browser/net/url_fetcher.h:136:
note: candidates are: URLFetcher::URLFetcher(const URLFetcher&)
../chrome/browser/net/url_fetcher.h:82:
note: URLFetcher::URLFetcher(const GURL&, URLFetcher::RequestType, URLFetcher::Delegate*)
For some reason, BugReport::PostCleanup (in my version) isn't recognized as a subclass of URLFetcher::Delegate, but BugReportView::PostCleanup (in the first links) is. So where did I mess up? Thanks.
The problem is not the type of the PostCleanup class. The problem is the type of the first parameter to the URLFetcher class constructor. The constructor expects a GURL &, you are passing a std::wstring called post_url. You will need to perform some kind of conversion between the two. Possibly something like this would be appropriate:
GURL post_url(l10n_util::GetString(IDS_BUGREPORT_POST_URL));
URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST,
new BugReport::PostCleanup);
In the code you have modified, the class has a GURL member which is initialised in the constructor, you have changed it to a variable referenced only in that one function, but changed the type.
At:
URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST,
new BugReport::PostCleanup);
it can't find an URLFetcher constructor thzat takes the parameters youn give it - the problem is presumably in url_fetcher.h, which you haven't shown.
BTW, there are a lot of other problems and bad practices exhibited in your code - it would be a good idea to instigate a full code review ASAP.
First version used member variable post_url_ second just local variable post_url.
Please describe what is GURL type - it is typedef on std::wstring or something other.