Scott McGhee

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

Recent posts by Scott McGhee

I gave up and read an XSD tutorial and figured out what to do on my own. Here is the final XSD that worked like I wanted it to.
16 years ago
Some more notes here.

My issue is that I think the XSD is thinking the "value" element inside the label complex type is treated as a sub-tag and not the actual value of the tag - like it would expect thisinstead of thisOr maybe I'm mistaken?

When using this XSD to generate java code, I'm expecting to get a Label.java with a getter/setter for "value" to set the text inside the <label> tag.

I also want the XSD to be completely backwards compatible, so any existing XMLs in the database will not fail to parse.
16 years ago
I'm working on a project which currently has the following XSD defined:So one may see XML similar to this:But now we want to change the schema such that the following will be possibleBut I'm having trouble figuring out how to modify the XSD. I was thinking something like this:Can someone give me some advise?
16 years ago
Thank you Mike, that clears it up for me. The lookahead seems to be working, I tested on a few input strings and it looks good.

Also thanks Jeanne for pointing out the typo.
17 years ago
I'm struggling to figure out a single regular expression which will match a password having the following rules:

o Passwords must be 6-16 characters.
o Allowed characters are alphanumeric, hyphen(-) and underscore(_)
o They must contain both numbers and letters

Currently the code uses 3 regular expressions to accomplish the goal:


And then to check the password:



What is the easiest way to construct a single regular expression combining these 3?
17 years ago
Ok - here's the scenario:

Suppose i have a java program that has some .java file on disk, and what it needs to do now is compile the source code into a .class file and execute it.

I was able to do this pretty easily doing the following

1) using a Java process and executing a command line argument such as "javac XYZ.java" to compile the java class

2a) and then creating a simple URLClassLoader to load the .class and then execute it's main method using reflection

2b) or I could simply execute another command line argument with a java Process "java XYZ"

- - - - - - - - - - - - - - - -
Anyone know how to streamline this process? I mean without using any executing anything on the command line? Ideally i would be able to compile the .java even if I'm running on a machine that doesn't have a JDK. for example maybe the machine doesn't have a "javac.exe" to execute.
17 years ago
Thanks Jim! That was a very complete response, and it helps me a lot!

I think there are some really good ideas here, I'll probably try first to load all classes in the JAR and then dispose of that ClassLoader so that it initially gets garbage collected. If i run into any memory issues i'll consider changing it later. Thanks again!
17 years ago
My Application
- - - - - - - - - - - - - - - - - - - -
I work on a large web site which has back-end webservices accessible via a SOAP interface. Currently to generate a client, I use Axis to generate the client .java files (using the WSDL as input) and I compile them into a JAR file. In a client application one would create the request bean objects to send into the WebServicesGateway, and then process the response beans accordingly. Note that at any one time we would normally have 2 to 3 different versions of the WSDL depending on how many releases we have in development.

My Objective
- - - - - - - - - - - - - - - - - - - - -
Currently i find myself having to create these client JAR files a lot, and uploading them into my java test client (a web app) for my automated test scripts (i developed this tool which can generically test any JAR file).

What I'd like to be able to do is to update by java test client to be able to automate the JAR file creation - so that instead of being handed a JAR file to test (and then showing the generated forms), it will be handed the WSDL file.

I know there are some testing tools out there (even some that are free) which take a WSDL file, and then present you with a generic test client to test the interface. However, I would like to keep with the same theme of using an autogenerated JAR file (by either Axis or Websphere) to communicate to the SOAP layer.

Possible Solution
- - - - - - - - - - - - - - - - - - - -
I figured I could put the Axis.jar file (and other required jar files) into the classpath of my web application, then invoke the Wsdl2Java class to generate the .java files - then somehow compile the .java files into .class files and compress into a JAR file. I could then create a URLClassLoader to enclose this generated JAR file to display the test client.

My Problem
- - - - - - - - - - - - - - - - - -
Currently this involves compiling .java files, but aside from using the Runtime.exec() method to execute the javac.exe to compile the .java files, i don't know of any other way to compile java files. I have 2 issues with using Runtime.exec()

1) My web page could be deployed in any one of several Operating systems (windows/unix/linux) and web servers (Tomcat/websphere) and thus the precise location of a compatible 'javac.exe' may be unknown.

2) According to my 'Best practices' mandates, I'm not (strictly speaking) allowed to invoke a java process on the Operating systems in the shared hosting environments which the tool will be deployed to.

My Question
- - - - - - - - - - - - - - - - - - - -
1) Is this a stupid/crazy idea - and maybe there's something much better that I could do which would accomplish the same thing?

2) Does anyone know how I can compile .java files into .class files from inside a Java program without directly invoking javac.exe via Runtime.exec()?
17 years ago
One other thing:

Does anyone know how Eclipse creates the "Type Hierarchy" for an object?? This is kind of what I'd want - for example if I open the Type Hierarchy for the Plugin.class, it will show me all objects which implement the Plugin interface. That's pretty much exactly what i'd what, except it would be for classes within a given URLClassLoader instead of just the pre-defined classpath for the Java Project.
17 years ago

Originally posted by Jim Yingst:
Requiring a user config file may seem (mildly) undesirable, but it seems much better than, say, just picking the fist implementation you find, isn't it? That could lead to unpredictable, confusing results. Perhaps in some applications you could pop up a dialog and ask the user which plugin they'd prefer to use. But in general, that seems a poor choice.



I was thinking that one of the methods inside the Plugin interface would have a "knickname" method (like "getKnickName()"). My application is very similar to Ant, in that the plugins are actually processors for individual XML tags (but more specific to generating web page forms). So the processor looks at the tag name, then uses the tag name as the "knickname". Then I have a factory class which, given the knickname, will return an instance of the Plugin class which has that knickname. Currently the factory uses the "plugins.xml" to find the supported plugin class names.

I want the jar files to be as portable as possible - in fact my plan is to host the JAR files in a database so that the website can have an "admin console" to upload new JAR files.

So what i want to move away from is having a central plugin configuration, and instead simply control which JAR files are used in my ClassLoader. I even want the JAR files to allow versioning, so I'll create "JAR Groups" which can then support different versions of a single JAR file.

As for plugins in the actual class path - i think I'm going to host all the 'core' plugin files in a 'core' plugin JAR file (which i'll drop in the plugins directory). In this way, the Plugin factory class can be sure that any Plugin it needs to create will be located in a JAR located in one of the JAR URLs in the "JAR Group" (and definately not in the CLASSPATH).

Possible Solution
- - - - - - - - - - - - - - - - - -
So I tried the following approach (which seems to be working):

1) Input to the PluginFactory's constructor will be the URLClassLoader (which contains all the JAR file URLs)

2) Create an ZipInputStream to each of the URLs in the list, search each ZipEntry to find the name - if the name endsWith '.class', then convert the name to a className (replacing '/' with '.' and removing '.class')

3) Instantiate the Class object for this className (using the URLClassLoader) - check if that Class .isAssignableFrom(Plugin.class)

4) If it is a Plugin, then create an instance of that object and invoke the 'getKnickName()' method

5) Store the knickname as a key in some hashMap, the value of which will be the Class object

6) In the main 'createPlugin()' method, take input the knickname - lookup the Class object in the hashmap, and create an instance of that Class object

Concerns with the above
- - - - - - - - - - - - - - - - - - - -
Step 2 needs to 'reload' the JAR files through an input stream; so physically the JAR files will be loaded twice - once to check for .class files - and once when the URLClassLoader needs to actually load the class in step 3. (this is not ideal since i would like to only process the JAR file once, if at all possible)

Also - after step 2 & 3 the URLClassLoader will have instantiated and cached every available class in the JAR files. This could be a good thing, or a bad thing - depending on how you look at it.

What do you guys think - can i do better than my solution?

I'm not sure yet what I think about my solution, since I would only accrue the cost of looking at the JAR files 2 times once (when i create the instance of my PluginFactory class for a particular JAR Group).

Or maybe should I just give in and require my Plugin Admin console to request that when you add an additional plugin JAR file at runtime that you, in addition, provide the Class names of all supported Plugins.
[ June 01, 2007: Message edited by: Scott McGhee ]
17 years ago
I have a friend at work that said he believed that there was a "slow memory leak" (his terminology) in Java concerning ClassLoaders.

In our production environment (which runs 24/7), we found that there was some piece of code creating a ClassLoader object which internally created classes for temporary use. I'm not entirely sure what these classes were for (or if somehow this could be avoided), but they were very small class objects with auto-generated names. The names had something to do with JavaScript, which was really confusing to me since I'm not exactly sure what JavaScript classes are doing on the Server-side (check stack trace)

Apparently there was some Thread dump file which indicated that there were literally thousands of these Class objects sitting in memory (see stack trace). Potentially, if these Class objects don't get Garbage collected - after weeks of requests coming in - our application would eventually crash due to memory leaks.

Anyway - I'm pretty sure that the Object for the ClassLoader itself is ill-referenced once the http request is complete and is eventually garbage collected, but does anyone know if the Class objects created by ClassLoader.defineClass() will be garbageCollected?? Or maybe some other kind of memory behind the scenes being allocated and never de-allocated?

I know that there is some native code when these classes are defined - and as such i'd imagine the exact version of Java might be critical. I am using Java 1.4.1 inside or WAS 5.1 on my local (Its possible the sub versions are slightly different in our production boxes). The operating system on my local is Windows XP Pro, but on production it is some Unix Solaris box.
[ May 31, 2007: Message edited by: Scott McGhee ]
17 years ago
Thank you for the link, I read most of it (actually i've seen this before); however, I noticed that in "Step 2" (which is really what my question is about) it does not a lot of specifics.

Here are some of my issues:

- The plugin directory can have any number of JAR files, each JAR can have any number of classes extending the Plugin interface, each plugin can have a different package declaration.

- There will be some "core" plugins located somewhere inside the main classpath (system classloader)

- I am trying to avoid having to "hard-code" the plugin classnames in a plugins.xml

- if it is at all possible I would like to be able to scan any and all class files which would be available to a particular ClassLoader (and any of the parent ClassLoaders) and see if that class implements my Plugin interface.

- I don't want to hard code the plugin class names, and i want the plugin jar files to be as light-weight as possible (i don't want some file in the META-INF, for example, to declare the class names)

- taking Ant as an example, if you create a customized Ant Task - you would need to declare the classname in a 'taskdef' - this is the kind of thing i would like to avoid.
17 years ago
The application
- - - - - - - - - - - - - - - - - - - - -
I am creating a java application which has a Plugin interface (which contains several methods).

I also have a plugin directory, which contains a bunch of JAR files. In the application I create a URLClassLoader which loads all the JAR files in this directory.

The problem
- - - - - - - - - - - - - - - - - - - - -
Now I want to "inspect" all the classes supported by this URLClassLoader to find all concrete classes which implement my "Plugin" interface. Currently i have a "plugin.xml" which contains some information about each of the supported plugins (including the fully qualified class name); however, I would like to make this automated and have all the information about the class inside the definition of that class - and have the application search for all classes of the designated type using a defined ClassLoader.

Can someone give me any ideas on this? Basically I need something with the following signature: or even
[ May 31, 2007: Message edited by: Scott McGhee ]
17 years ago
Looking through the prototype documentation (http://www.prototypejs.org/api/ajax/updater) I found the following:

About evalScripts and defining functions

If you use evalScripts: true, any <script> block will be evaluated. This does not mean it will get included in the page: they won't. Their content will simply be passed to the native eval() function. There are two consequences to this:

  • The local scope will be that of Prototype's internal processing function. Anything in your script declared with var will be discarded momentarily after evaluation, and at any rate will be invisible to the remainder of the page scripts.
  • If you define functions in there, you need to actually create them, otherwise they won't be accessible to the remainder of the page scripts. ...



  • Which means when I declared the variable 'myVariable' it was not in the global scope and thus could not be evaluated by the function 'alertVariable' when the 'TEST' button is clicked.

    Does anyone know a way around this??
    [ May 01, 2007: Message edited by: Scott McGhee ]
    Sorry - can you check my post again.

    I changed it quite a bit: to further simplify I removed any references to combobox javascript.

    It is the same issue - but it should be easier to see the problem.