mark baum

Greenhorn
+ Follow
since Aug 21, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by mark baum

Hi,

I'm trying to calculate the angle of 2 points anywhere on a circle in a clockwise or anticlockwise direction, so the angle can vary from 0 to 360 degrees, the center of the circle being 0,0.

I tried various methods, asin, atan like

double angle_Entry = Math.atan(y_1_km/x_1_km);
double angle_Current = Math.atan(y_2_km/x_2_km);
return angle_Current - angle_Entry;


and eventually also a vector based approach like this:

x1*x2 + y1*y2 (assuming that since both point have the same distance (radius), it's a unit vector and it's not necessary to divide through the radius)

All methods work fine until 180 degrees, but the test for 270 degrees always fail:

x_1_km = 0;
y_1_km = 100;
x_2_km = -100;
y_2_km = 0;

assertEquals(2*Math.PI*3/4, circleTrack.getAngleOf2PointsOnCircle(x_currentPosition_km, y_currentPosition_km, x_CircleEntrance_km, y_CircleEntrance_km), 0.0000000000001);

All attempts return 90 degrees instead of 270 (rsp 2*Math.PI*3/4). I saw the influence of the opposite sign, but my math skills seem to to be too long out of use to find how to solve the issue in a elegant way.

I was thinking that I could might write an algorithm defining the line on the diameter and use it to detect if the second point is on the same (first) half as first point or on the second half, that would resolve the issue. but I thought there must be an existing and maybe better solution for this.

Thanks for any help

Marc
15 years ago
Hi,

I'm relatively new to AOP/ aspectJ. I was looking in the doc for a possibility, how to capture any return value, in other words all methods not returning null (of any class). I saw ways to capture a method name and parameters, but not how would I capture a non-void method call?

Thanks for help
Hi,

I wrote the following test:



The program could read the file and gave the expected Output:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-autowire="byType">

<import resource="databaseContext.xml"/>
<import resource="transactionContext.xml"/>


<bean id="hyperlinkDao" class="org.schubi.du.dao.HybernateHyperLinkDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />

</bean>

</beans>

but then the ClassPathXmlApplicationContext threw the error


org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [src/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [src/applicationContext.xml] cannot be opened because it does not exist

Why's that? What did I do wrong?

Thanks for help

Mark
For the reengineering of a program we are looking for an experienced Java programmer, who would like to review our code and make suggestions for improvements,also contributions would be appreciated.

The program to reengineer is creating a multilingual directory service. The main difference to other similar services is the fact that links cannot be automatically added, but personally checked. The new version will be written from scratch in Spring and Hybernate.

We are a small group who started this as a private initiative in our spare time. To progress better, we decided to look for a professional, who could download our code and check it maybe once or twice a month. You can do this remote from home.

If you are interested, please send a mail to mbjava at active.ch with a cv and maybe some information or references about your former activities with Java, your availability and the rate you're expecting.

Note that any national, ethnical and religious provenience is welcome, in return we expect tolerance and open mind towards other culture as our service will definitely be intercultural.
16 years ago
Hi Scott,

The error message was

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.titan.clients.Client.main(Client.java:79)

Your comment brought me to a good point. I checked the ant file again and found the directory was added explicitly:

<pathelement location="${basedir}/client-config"/>

So I went to the run configuration, selected the tab "Classpath", selected User Entries, pressed "Advanced" and added the path to that dir called "client-config". And now, the initial configuration seems to work, and - eventually - it runs, but only once...

(output)
methods in TravelAgentBean:
...
remove
createCabin
findCabin
...
Master Suite
1
1
3



I have seen the note in Chapter 24 of Enterprise JavaBeans 3.0, 5th Edition by Richard Monson-Haefel:

You cannot run this program more than once
unless you stop JBoss, clean the database by invoking the Ant task clean.db, and restart
the application server. Otherwise, you will get the following error:
run.client:
[java] Exception in thread "main" java.lang.RuntimeException:
org.jboss.tm.JBossRollbackException: Unable to commit
, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=null:1099/7,
BranchQual=null:1099, localId=0:7], status=STATUS_NO_TR
ANSACTION; - nested throwable: (org.hibernate.exception.GenericJDBCException:


If I understood it correctly, you cannot execute twice, because the entries in the db are already there and do not allow a new creation.

But the error message I get is quite different. In fact it has the same error pattern as described in my other post https://coderanch.com/t/320810/EJB-JEE/java/invoke-method-existing-bean-JEE
and I still don't know, why the bean could be found in one run, but not in the next run.



Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at $Proxy0.createCabin(Unknown Source)
at com.titan.clients.Client.main(Client.java:96)
Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;

Thanks a lot for help

Markus
Hi,

I'm learning JEE and tried a basic example with an entity bean Person
and a stateless bean PersonFeederBean that is getting a list of persons and to persist them, print them and maybe remove them.

The PersonFeederBean is called by ClientPersonFeeder creating the list of person to store.

The code compiles in eclipse 3.2 with java compliance level 5, the jar can is deployed (on JBoss 404), the PersonFeederBean can be looked up and narrowed; to make sure it is not empty I added a test retrieving the methods; they are there.

But when I want to call one of these methods I get the error:

"$Proxy0.testInstanceAlive(Unknown Source)" as listed at the end of the code section.

Can anybody tell me, what went wrong?
I also wonder, what I might do to get rid of the java.lang.reflect.UndeclaredThrowableException, is there a strategy or documentation about it?

The last thing that bothers me, is the way the method narrow works: PortableRemoteObject.narrow(ref, [SESSIONBEANREMOTE].class);
Since I declared a Remote interface, but never a class with that name, there seems to be a pattern for this. Is there some good documentation about it?

Thanks for help

Markus



p.s. I checked the JDWP exit error, seems to be related to a debugger issue and happening after the exception...
Hi,

I'm trying to run the exercise 4.1 from "Enterprise JavaBeans 3.0", 5th Edition By Richard Monson-Haefel as described in Chapter 24.
I built the structure precisely as described in the example and it works when I run the the ant task "client.run". But it didn't run when I tried to run the Client class in eclipse.
I assumed from the error message that it didn't find the jndi.properties file in client-config, though I added the dir as a source file in the build path, I checked the class path and the path was there:

<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry kind="src" path="client-config"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>


So I replaced

Context context;
try
{
context = new InitialContext(properties);
Object ref = context.lookup("TravelAgentBean/remote");

with

Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"
);
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");

and it runs!

Apparently, the jndi.properties are not found...

I assume that the magic is in the ant file that uses "fork=yes"

<target name="run.client" depends="ejbjar">
<java classname="com.titan.clients.Client" fork="yes" dir=".">
<classpath refid="classpath"/>
</java>
</target>

How is it possible to add the client-config directory so Eclipse could read it properly?

Thanks for help

Markus
Sorry, I saw the wrong thought, if the target drive and dir are the same, the method writes to the same file...
18 years ago
Hi Ernest,

Thank you for the hint! It was true: the source and target file was on the same drive AND dir, but the name was different. But I'm a bit puzzeled, because I don't recall having read I must not use the same drive nor directory. So I cannot save a file in the same directory under another name with that method? Would there be an alternative in java to do this? (I searched on the net for doc but could not find any? can you please give me a hint for documentation on this?)

I also wonder if someone with more IO expertise could tell me, if this copy method would be robust for any type of file (binary ansi8 or 16 etc)

Thanks
18 years ago
I tried to copy a file following the example in the java and nutshell tutorials as listed below. I wrote a junit test that creates a file with one line of text. The file is there, it is found and opened and the text is there too until the call of file.read(buffer). That method returns -1, after the call the source file is empty and nothing is written to the targetFile.

Could that be connected to the 8 and 16bit problem mentioned in the java tutorial?

"Remember that FileReader and FileWriter read and write 16-bit characters. However, most native file systems are based on 8-bit bytes. These streams encode the characters as they operate according to the default character-encoding scheme. You can find out the default character-encoding by using System.getProperty("file.encoding"). To specify an encoding other than the default, you should construct an OutputStreamWriter on a FileOutputStream and specify the encoding."

Does anybody has a fileCopy function that copies any sort of file?

Thanks for help!

[ March 07, 2006: Message edited by: Jim Yingst ]
18 years ago
Hi,
I'm working with a Microsoft - ODBC Paradox Driver on NT 4 and always get the ErrorCode 1311 Cannot open any more tables.
Another time, I get the error message
ErrorCode :-5016 sqlException: [Microsoft][ODBC Paradox Driver] Unexpected error from external database driver (9482)
I made the connection a singleton as well as all classes wrapping data from the db, so that shouldn't be the problem. Did anybody meet this problem and knows how to solve it?
Thanks
Markus
[ April 25, 2002: Message edited by: markus baumgartner ]
Hi,
I searched everywhere to get an example which meta information getContentEncoding() is reading, but I only found the 1 line help from the sun doc. Does anybody has an example for this method or maybe knows a html-page to apply the function?
Thanks
Markus
Hi,
I'm trying to test my code thoroughly by using Junit. It's a great tool, but I'm spending a lot of time passing new method into the testclass and write a "test_" in front of it ;-(and oftenly forget to do it, too). I made a try and actually it would be possible to automate the creation of stubs for all existing methods of a class using the Reflection API (e.g. from myProcedure(int A, String B) to test_myProcedure_int_A_String_B
Before I'm going to create it on my own, I wanted to know, if anybody knows about an existing tool, that does the job?
Thanks
Markus

Originally posted by Jamie Robertson:
DatabaseMetaData.getTables method - warning: some databases need the tablename and parameters in all upper case
other way - put its own try/catch block on the table creation DDL

Jamie


I tried to use getTables() like this:
public boolean isTableExisting(String tableName) throws DB_Exception{
boolean tableExists = false;
String[] types = {"TABLE"};
try {
ResultSet tableNames = databaseMetaData_.getTables(null,"%", tableName , null); // instead of types
tableExists = true;
} catch (SQLException e) {
throw new DB_Exception("DBHandler.isTableExisting - SQLEXception: "+" sqlState "+e.getSQLState()+" errorcode: "+e.getErrorCode());
}
return tableExists;
}
but the method threw the SQLException (even when the tableName was written in upper case, as you suggested)
SQLEXception: sqlState S1C00 errorcode: 106
I found S1C00 stands for "Optional feature not implemented"
Does this mean the Paradox (vers 7) driver or db does not implement a method for that call or have I been doing something wrong?