hi,
digging further into the api:
there seems to be a way to wrap content instances into beans providing nice accessor functions etc.
- i've set up our content type, it works as expected
- created the bean class with "/opt/vignette/cms/Content/8_0/bin/vgnbeangen -h vcmhost:27110 -v -u vgnadmin -p vignette -f pk_ctds.jar PkAppMessage". inspecting the jar, it shows the interface and implementation class as it should ...
- added the jar to my project
when running the code on my local dev machine from the java command line, it breaks @ this line:
BeanFactory factory = BeanFactoryFactory.getFactory();
what am i missing? what is needed to make this work? which environment? could you point me to documentation describing scenarios like this?
thanks,
markus
--------------------------------------------------------------------------------
login successful.
search for folder 'AppResources/messages/common', show CIs.
mo: demoTag
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.pk.vcm.util.RetrieveBean.getBeansForCis(RetrieveBean.java:126)
at com.pk.vcm.util.RetrieveBean.main(RetrieveBean.java:74)
Caused by: com.vignette.as.client.api.bean.ContentBeanException: 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 com.vignette.as.client.api.beangen.JavaBeanGenUtil.setupGlobalInfo(JavaBeanGenUtil.java:81)
at com.vignette.as.client.api.beangen.JavaBeanGenUtil.getInterfaceBaseName(JavaBeanGenUtil.java:103)
at com.vignette.as.client.api.beangen.BeanFactoryBase.setContentInstanceInterfaceBase(BeanFactoryBase.java:573)
at com.vignette.as.client.api.beangen.BeanFactoryBase.<init>(BeanFactoryBase.java:54)
at com.vignette.as.client.api.wrapper.WrapperBeanFactory.<init>(WrapperBeanFactory.java:26)
at com.vignette.as.client.api.bean.BeanFactoryFactory.<clinit>(BeanFactoryFactory.java:17)
... 2 more
Caused by: 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(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342)
at javax.naming.InitialContext.lookup(InitialContext.java:409)
at com.vignette.as.client.api.beangen.JavaBeanGenUtil.setupGlobalInfo(JavaBeanGenUtil.java:76)
... 7 more
--------------------------------------------------------------------------------
the code
public class RetrieveBean {
public static void main(String[] args) {
try {
login();
String path = "AppResources/messages/common";
log("search for folder '"+path+"', show CIs.");
Project p = Project.findProjectByPath( path);
getBeansForCis( p, "");
} catch (Exception e) {
e.printStackTrace();
}
}
//-----------------------------------------------------------------------------------------------
// login ...
private static void login() {
String host = "vcmhost";
String port = "27110";
String user = "vcm";
String passwd = "vcmpwd";
AuthnBundle bundle = new AuthnBundle();
bundle.setFactory("weblogic.jndi.WLInitialContextFactory");
bundle.setAuthType(AuthnConsts.WEBLOGIC_CONTEXT);
bundle.setProtocol("t3");
bundle.setUsername(user);
bundle.setPassword(passwd);
bundle.setPort(port);
bundle.setHost(host);
bundle.setEnableSSL(false);
try {
LoginMgr loginMgr = new LoginMgr();
loginMgr.login(bundle);
CMS cms = ConfigUtil.getCMS();
log( "login successful.");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void getBeansForCis( Project f, String prefix) {
IPagingList ip;
try {
// Do top level CIs first...
RequestParameters rp=new RequestParameters();
rp.setTopRelationOnly(false);
rp.setUserDataReturnMode( RequestParameters.DataReturnMode.FULL);
ip = f.getManagedObjectsByType( rp, "PkAppMessage");
for (int i=0;i < ip.size();i++) {
ManagedObject mo = (ManagedObject) ip.get(i);
log( prefix+"mo: "+mo.getName());
BeanFactory factory = BeanFactoryFactory.getFactory();
ManagedObjectBean bean = factory.createBean(mo);
PkAppMessage pkam = (PkAppMessage) bean;
log ( "bean: "+pkam.getMessage());
}
} catch(Exception e) {
log(e);
}
}
private static void log( Object o) {
System.out.println( o.toString());
}
}