> Maybe I have to parse the deployment descriptor ...
Hello John,
thank you for your thoughts on the matter!
>> Thank you, but my problem is not setting these values,
>> but reading them -- out EJB developer sets these values
[quoted text clipped - 6 lines]
> will vary with the store itself. EJB is supposed to _insulate_ clients
> from such things.
So at the end a database needs only one datatype: blob? hmmm ...
>> Maybe I have to parse the deployment descriptor ...
>
> If you choose this route (supposing you find a way to actually get your
> hands on the descriptors) it is probably not the main deployment
> descriptor you want but a container-specific descriptor extension.
I did so and with dom4j <http://dom4j.org/> it was quite easy.
I added the code at the end of this message.
> I would not recommend pursuing this.
> My actual recommendation is that the bean provider should _document_ the
> required supported ranges of property values, and the application
> assembler should take responsibility for setting up the mappings
> correctly. Bean clients should then behave per the documentation.
I prefer that my GUI behaves correctly without all this trouble.
So *I* want to be insulated from such things.
Also I don't like the idea of having the same information set twice.
> You could provide for client-side validation by putting per-property
> validation methods on the beans' home interfaces (or by other similar
> means) if that is necessary.
IMHO validation is best when the user *can't* insert invalid imput.
The GUI won't display it when it's invalid. When the sql-type is
int4, and you type in 'p' then nothing is inserted, if you paste in
'123456789' then '1234' is inserted, etc. -- without my intervention.
thanx!
Marcus
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class EntityInfo
{
public static void showEntityInfo(Class classInEJBJar)
{
InputStream is = null;
try
{
is = classInEJBJar.getResourceAsStream("/META-INF/jbosscmp-jdbc.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(is);
List entities = doc.selectNodes("//enterprise-beans/entity");
System.out.println("entities found: " + entities.size());
for (Iterator iter = entities.iterator(); iter.hasNext();)
{
Element entityElement = (Element) iter.next();
Element entityName = entityElement.element("ejb-name");
System.out.println(entityName.getTextTrim());
List cmpFields = entityElement.elements("cmp-field");
for (Iterator iterator = cmpFields.iterator(); iterator.hasNext();)
{
Element cmpFieldElement = (Element) iterator.next();
Element fieldNameElement = cmpFieldElement.element("field-name");
Element sqlTypeElement = cmpFieldElement.element("sql-type");
String sqlType = sqlTypeElement == null ? null :
sqlTypeElement.getTextTrim();
Field field = new Field(fieldNameElement.getTextTrim(), sqlType);
if (sqlTypeElement != null)
{
System.out.print(" " + fieldNameElement.getTextTrim());
System.out.print(": " + sqlTypeElement.getTextTrim());
System.out.println();
}
}
}
}
catch (Exception e)
{
/*
* this way other projects don't have to know about dom4j Exceptions
*/
throw new RuntimeException(e);
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException e)
{
}
}
}
}
}