public void setXmlDocument(Node doc) throws Schema2BeansRuntimeException { if (doc instanceof Document) { this.document = (Document)doc; this.setNodeFactory((Document)doc); // // The factory/writer should know about the doc now // and no more about the original InputStream. // (if the user specified a factory/writer) // Object o = GraphManager.factoryMap.get(doc); if (o != null) { this.docFactory = (GraphManager.Factory)o; GraphManager.factoryMap.remove(doc); } o = GraphManager.writerMap.get(doc); if (o != null) { this.docWriter = (GraphManager.Writer)o; GraphManager.writerMap.remove(doc); } } else throw new Schema2BeansRuntimeException(Common.getMessage( "CantFindFactory_msg")); }
public void setAbstract(String uniqueName, String name, boolean value) { //System.out.println("Setting javaType of "+name+" to "+javaType); if (this.curElementType == Common.ATTLIST) { } else { // Get the element reference GraphNode node; try { node = getGraphNode(uniqueName, name, GET); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } node.setAbstract(value); } }
/** * Create the root element of the graph */ public void createRoot(String dtdName, String beanName, int option, Class type) throws Schema2BeansRuntimeException { BeanProp prop = new BeanProp(this, dtdName, beanName, option, type, true); try { this.graphManager.createRootBinding(this, prop, null); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } this.isRoot = true; }
void adjustPathRoot() { if (this.parsingPath.startsWith("../")) { // NOI18N int i = this.parsingPath.lastIndexOf("../"); // NOI18N int n = i/3; do { for (int j=0; j<this.roots.length; j++) { if (this.roots[j].isRoot()) throw new Schema2BeansRuntimeException(Common.getMessage( "CantAccessBaseBeanNode_msg", this.parsingPath)); this.roots[j] = this.roots[j].parent(); } } while(n-- > 0); this.parsingPath = this.parsingPath.substring(i+3); } }
public void readSchema(org.w3c.dom.Element node) { String schemaLocation = node.getAttribute("schemaLocation"); // NOI18N if (includedAlready.containsKey(schemaLocation)) return; includedAlready.put(schemaLocation, null); //System.out.println("Attempting to include "+schemaLocation); ParserSchemaState oldState = new ParserSchemaState(); try { readSchemaFromLocation(schemaLocation, true); } catch (org.xml.sax.SAXException e) { throw new Schema2BeansRuntimeException(Common.getMessage("MSG_FailedToParse", schemaLocation), e); } catch (java.io.IOException e) { throw new Schema2BeansRuntimeException(Common.getMessage("MSG_FailedToParse", schemaLocation), e); } finally { oldState.reload(); } //System.out.println("Finished reading include\n"); /* if (oldNamespaceTable != null) namespaceTable = oldNamespaceTable; */ }
throw new Schema2BeansRuntimeException(e); } catch (IOException e) { throw new Schema2BeansRuntimeException(e);
public void readSchema(org.w3c.dom.Element node) { String namespace = node.getAttribute("namespace"); // NOI18N String schemaLocation = node.getAttribute("schemaLocation"); // NOI18N //System.out.println("Attempting to import "+schemaLocation); ParserSchemaState oldState = new ParserSchemaState(); if (namespace != null && !namespace.equals("")) targetNamespace = namespace; try { readSchemaFromLocation(schemaLocation, false); } catch (org.xml.sax.SAXException e) { throw new Schema2BeansRuntimeException(Common.getMessage("MSG_FailedToParse", schemaLocation), e); } catch (java.io.IOException e) { throw new Schema2BeansRuntimeException(Common.getMessage("MSG_FailedToParse", schemaLocation), e); } finally { oldState.reload(); } //System.out.println("Finished reading import\n"); }
throw new Schema2BeansRuntimeException(Common.getMessage("MSG_FailedToParse", schemaLocation), e); } finally { currentParsedURI = oldParsedURI;
/** * Write the current schema2beans graph as an XML document. */ public void write(OutputStream out) throws IOException, Schema2BeansRuntimeException { try { reindent(); if (this.graphManager != null) { this.graphManager.write(out); } else throw new IllegalStateException(Common. getMessage("CantWriteBeanNotInDOMTree_msg")); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } }
throw new Schema2BeansRuntimeException(Common. getMessage("CantInstantiateBean_msg", e.getMessage()));
/** * Write the current schema2beans graph as an XML document without reformating * * @param bean * @param outputStream * @throws IOException */ public static void write(BaseBean bean, OutputStream outputStream) throws IOException { try { GraphManager graphManager = bean.graphManager(); if (graphManager != null) { graphManager.write(outputStream); } else { throw new IllegalStateException(Common.getMessage("CantWriteBeanNotInDOMTree_msg")); } } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } }
public void createBean(Node node, GraphManager mgr) throws Schema2BeansRuntimeException { if (this.isRoot) { mgr.completeRootBinding(this, node); } this.graphManager = mgr; try { mgr.fillProperties(this.beanProps(), node); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } }
public void setExtension(String uniqueName, String typeName, String extendsName) throws Schema2BeansException { if (curElementType == Common.ATTLIST) { } else { GraphNode node; GraphNode extendsNode; try { node = getGraphNode(uniqueName, typeName, GET); extendsNode = getGraphNode(null, extendsName, REFERENCE); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } node.setExtension(extendsNode); } }
public class IterateChoiceProperties implements java.util.Iterator { private ArrayList groups; private int index; public IterateChoiceProperties() { this.groups = new ArrayList(); this.index = 0; } void add(BeanProp prop) { if (prop.group != null && !this.groups.contains(prop.group)) this.groups.add(prop.group); } public boolean hasNext() { return (this.index < this.groups.size()); } public Object next() throws NoSuchElementException { if (hasNext()) { BeanProp.GroupProp gp = (BeanProp.GroupProp)this.groups.get(this.index++); return (BaseProperty[])gp.list(); } else throw new NoSuchElementException(); } public void remove() throws UnsupportedOperationException, IllegalStateException { throw new UnsupportedOperationException();
private boolean checkVetoable(boolean raise) { if (Common.isVetoable(this.type) || Common.isBean(this.type)) return true; if (raise) { if (!Common.isBean(this.type)) { throw new Schema2BeansRuntimeException(Common. getMessage("PropertyDoesntSupportVeto_msg", this.beanName)); } } return false; }
findRootNode(); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e);
/** * Called to request that the graph node named name be of a certain * Java class. If the current element type is an attribute, then * we set the javaType of that attribute instead. * @param javaType is the name of a Java class (eg, "java.lang.Integer", or "int"). */ public void javaType(String uniqueName, String name, String javaType) { //System.out.println("Setting javaType of "+name+" to "+javaType); if (this.curElementType == Common.ATTLIST) { curAttr.setJavaType(javaType); } else { // Get the element reference GraphNode node; try { node = getGraphNode(uniqueName, name, GET); } catch (Schema2BeansException e) { throw new Schema2BeansRuntimeException(e); } node.setJavaType(javaType); node.setCreated(false); } }
/** * Returns the position of the indexed property element. * If the type of the property is a bean, use the == comparison, * else use the equals() method. * If the element is not found, return -1. */ public int indexOf(String name, Object value) throws Schema2BeansRuntimeException { BeanProp bp = this.beanProp(name); if (bp == null) throw new Schema2BeansRuntimeException(Common. getMessage("UnknownPropertyName_msg", name)); if (Common.isArray(bp.type)) { boolean isBean = Common.isBean(bp.type); int size = bp.size(); for (int i=0; i<size; i++) { Object obj = bp.getValue(i); if (isBean && (obj == value)) return i; else if (!isBean && (obj.equals(value))) return i; } } return -1; }