private static void writeDataPolicy(XMLStreamWriter writer, DataPolicy dp) throws XMLStreamException { writer.writeStartElement(Element.DATA_ROLE.getLocalName()); writeAttribute(writer, Element.NAME.getLocalName(), dp.getName()); writeAttribute( writer, Element.DATA_ROLE_ANY_ATHENTICATED_ATTR.getLocalName(), String.valueOf(dp.isAnyAuthenticated())); writeAttribute( writer, Element.DATA_ROLE_ALLOW_TEMP_TABLES_ATTR.getLocalName(), String.valueOf(dp.isAllowCreateTemporaryTables())); writeElement(writer, Element.DESCRIPTION, dp.getDescription()); // permission for (DataPolicy.DataPermission permission : dp.getPermissions()) { writer.writeStartElement(Element.PERMISSION.getLocalName()); writeElement(writer, Element.RESOURCE_NAME, permission.getResourceName()); if (permission.getAllowCreate() != null) { writeElement(writer, Element.ALLOW_CREATE, permission.getAllowCreate().toString()); } if (permission.getAllowRead() != null) { writeElement(writer, Element.ALLOW_READ, permission.getAllowRead().toString()); } if (permission.getAllowUpdate() != null) { writeElement(writer, Element.ALLOW_UPADTE, permission.getAllowUpdate().toString()); } if (permission.getAllowDelete() != null) { writeElement(writer, Element.ALLOW_DELETE, permission.getAllowDelete().toString()); } if (permission.getAllowExecute() != null) { writeElement(writer, Element.ALLOW_EXECUTE, permission.getAllowExecute().toString()); } if (permission.getAllowAlter() != null) { writeElement(writer, Element.ALLOW_ALTER, permission.getAllowAlter().toString()); } if (permission.getAllowLanguage() != null) { writeElement(writer, Element.ALLOW_LANGUAGE, permission.getAllowLanguage().toString()); } if (permission.getCondition() != null) { writeElement(writer, Element.CONDITION, permission.getCondition()); } writer.writeEndElement(); } // mapped role names for (String roleName : dp.getMappedRoleNames()) { writeElement(writer, Element.MAPPED_ROLE_NAME, roleName); } writer.writeEndElement(); }
private static void parseDataRole(XMLStreamReader reader, DataPolicyMetadata policy) throws XMLStreamException { Properties props = getAttributes(reader); policy.setName(props.getProperty(Element.NAME.getLocalName())); policy.setAnyAuthenticated( Boolean.parseBoolean( props.getProperty(Element.DATA_ROLE_ANY_ATHENTICATED_ATTR.getLocalName()))); policy.setAllowCreateTemporaryTables( Boolean.parseBoolean( props.getProperty(Element.DATA_ROLE_ALLOW_TEMP_TABLES_ATTR.getLocalName()))); while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { Element element = Element.forName(reader.getLocalName()); switch (element) { case DESCRIPTION: policy.setDescription(reader.getElementText()); break; case PERMISSION: PermissionMetaData permission = new PermissionMetaData(); parsePermission(reader, permission); policy.addPermission(permission); break; case MAPPED_ROLE_NAME: policy.addMappedRoleName(reader.getElementText()); break; default: throw new XMLStreamException( AdminPlugin.Util.gs( "unexpected_element2", reader.getName(), Element.DESCRIPTION.getLocalName(), Element.PERMISSION.getLocalName(), Element.MAPPED_ROLE_NAME.getLocalName()), reader.getLocation()); } } }