1
votes

Im a java dev. and i now i'm facing with jackrabbit v.1.6.4. Now one of my goal is to create node in a web based jcr browser, so when i have to create node with mandatory property of course the Exception constrainviolation is throw.

My Question is exist a way, during the runtime creation to fetch the mandatory property? For example to assign to them with some default value and the will be able to save the node.

One very nice thing is to have the instance of PropDef form NodeTypeDef, but from the Node interface i'm only able to get the PropertyDefinition which in my case is useless.

So many many thanks to All

Have a nice day

J.

3

3 Answers

1
votes

so this piece of code do exactly what i want and i will provide to other users.

Anyway many thanks to all

                Node parent = (Node)session.getItem(path);//Jcr path to the parent node

                Node added = parent.addNode(newNodeName);//Add new node


                Workspace workspace = session.getWorkspace();                   
                NodeTypeManager ntMgr = workspace.getNodeTypeManager();

                NodeTypeRegistry ntReg=null;
                try {
                    ntReg = ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
                } catch (ClassCastException e) {
                    e.printStackTrace();
                }

                NameFactory nameFactory = NameFactoryImpl.getInstance();
                Name namejcr = nameFactory.create(type);

                EffectiveNodeType effnodetype = ntReg.getEffectiveNodeType(namejcr);



                //Here i get all the property definition for this type of node, so from here i
                //can know which of them are mandatory
                PropDef[] pdefs = effnodetype.getAllPropDefs();
0
votes

To determine whether a property is protected you can do:

PropertyDefinition propDef = property.getDefinition();
boolean isProtected = propDef.isProtected();

Or try something along these lines to determine whether a node type allows setting a certain property to a certain value:

Workspace workspace = session.getWorkspace(); 
NodeTypeManager ntMgr = wsp.getNodeTypeManager();
NodeType nt = ntMgr.getNodeType("nodeTypeName");
boolean canSet = nt.canSetProperty("propName", value);
0
votes

Of cource it's bin a while,

and Oak is avaible.

But today you could use the following:

javax.jcr.Property prop = xyz;
boolean isMandatoryProperty = prop.getDefinition().isMandatory();