| | |
| | | |
| | | |
| | | /** |
| | | * Registers the provided configurable component with the Directory Server. |
| | | * |
| | | * @param component The configurable component to register. |
| | | */ |
| | | public static void registerConfigurableComponent(ConfigurableComponent |
| | | component) |
| | | { |
| | | DN componentDN = component.getConfigurableComponentEntryDN(); |
| | | JMXMBean mBean = directoryServer.mBeans.get(componentDN); |
| | | if (mBean == null) |
| | | { |
| | | mBean = new JMXMBean(componentDN); |
| | | mBean.addConfigurableComponent(component); |
| | | directoryServer.mBeans.put(componentDN, mBean); |
| | | } |
| | | else |
| | | { |
| | | mBean.addConfigurableComponent(component); |
| | | } |
| | | |
| | | |
| | | |
| | | // This is all code used to dynamically generate an admin definition from |
| | | // the configurable component. We'll only generate it if the |
| | | // org.opends.server.dumpComponents property is set to "true". |
| | | String propValue = System.getProperty("org.opends.server.dumpComponents"); |
| | | if ((propValue == null) || (! propValue.equals("true"))) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | try |
| | | { |
| | | DN entryDN = component.getConfigurableComponentEntryDN(); |
| | | ConfigEntry configEntry = |
| | | directoryServer.configHandler.getConfigEntry(entryDN); |
| | | ObjectClass structuralClass = |
| | | configEntry.getEntry().getStructuralObjectClass(); |
| | | ObjectClass superiorClass = structuralClass.getSuperiorClass(); |
| | | |
| | | String baseName; |
| | | String primaryName = structuralClass.getPrimaryName(); |
| | | if (primaryName.startsWith("ds-cfg-")) |
| | | { |
| | | baseName = primaryName.substring(7); |
| | | } |
| | | else |
| | | { |
| | | baseName = "___NAME___"; |
| | | } |
| | | |
| | | |
| | | LinkedList<String> lines = new LinkedList<String>(); |
| | | lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| | | lines.add("<adm:managed-object name=\"" + baseName + "\" plural-name=\"" + |
| | | baseName + "s\""); |
| | | lines.add(" package=\"org.opends.server.admin.std\""); |
| | | lines.add(" xmlns:adm=\"http://www.opends.org/admin\""); |
| | | lines.add(" xmlns:ldap=\"http://www.opends.org/admin-ldap\">"); |
| | | lines.add(" <adm:synopsis>"); |
| | | lines.add(" ___SYNOPSIS___"); |
| | | lines.add(" </adm:synopsis>"); |
| | | |
| | | |
| | | // Write information about the object class. |
| | | lines.add(" <adm:profile name=\"ldap\">"); |
| | | lines.add(" <ldap:object-class>"); |
| | | lines.add(" <ldap:oid>" + structuralClass.getOID() + "</ldap:oid>"); |
| | | lines.add(" <ldap:name>" + primaryName + "</ldap:name>"); |
| | | |
| | | if (superiorClass != null) |
| | | { |
| | | lines.add(" <ldap:superior>" + superiorClass.getNameOrOID() + |
| | | "</ldap:superior>"); |
| | | } |
| | | |
| | | lines.add(" </ldap:object-class>"); |
| | | lines.add(" </adm:profile>"); |
| | | |
| | | |
| | | // Write information about all of the configuration attributes. |
| | | for (org.opends.server.config.ConfigAttribute attr : |
| | | component.getConfigurationAttributes()) |
| | | { |
| | | if (attr instanceof org.opends.server.config.ReadOnlyConfigAttribute) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | primaryName = attr.getName(); |
| | | AttributeType type = getAttributeType(toLowerCase(primaryName), true); |
| | | if (primaryName.startsWith("ds-cfg-")) |
| | | { |
| | | baseName = primaryName.substring(7); |
| | | } |
| | | else |
| | | { |
| | | baseName = "___NAME___"; |
| | | } |
| | | |
| | | lines.add(" <adm:property name=\"" + baseName + "\""); |
| | | lines.add(" mandatory=\"" |
| | | + String.valueOf(attr.isRequired()) + "\""); |
| | | lines.add(" multi-valued=\"" |
| | | + String.valueOf(attr.isMultiValued()) + "\">"); |
| | | lines.add(" <adm:synopsis>"); |
| | | lines.add(" ___SYNOPSIS___"); |
| | | lines.add(" </adm:synopsis>"); |
| | | lines.add(" <adm:description>"); |
| | | |
| | | String description = attr.getDescription(); |
| | | int startPos = 0; |
| | | while (startPos < description.length()) |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(" "); |
| | | int remaining = description.length() - startPos; |
| | | if (remaining <= 73) |
| | | { |
| | | buffer.append(description.substring(startPos)); |
| | | startPos += remaining; |
| | | } |
| | | else |
| | | { |
| | | int endPos = startPos + 72; |
| | | while ((endPos > startPos) && (description.charAt(endPos) != ' ')) |
| | | { |
| | | endPos--; |
| | | } |
| | | if (description.charAt(endPos) == ' ') |
| | | { |
| | | buffer.append(description.substring(startPos, endPos)); |
| | | startPos = endPos + 1; |
| | | } |
| | | else |
| | | { |
| | | buffer.append(description.substring(startPos)); |
| | | startPos += remaining; |
| | | } |
| | | } |
| | | |
| | | lines.add(buffer.toString()); |
| | | } |
| | | |
| | | lines.add(" </adm:description>"); |
| | | if (attr.requiresAdminAction()) |
| | | { |
| | | lines.add(" <adm:requires-admin-action>"); |
| | | lines.add(" <adm:server-restart/>"); |
| | | lines.add(" </adm:requires-admin-action>"); |
| | | } |
| | | if (!attr.isRequired()) |
| | | { |
| | | lines.add(" <adm:default-behavior>"); |
| | | lines.add(" <adm:undefined/>"); |
| | | lines.add(" </adm:default-behavior>"); |
| | | } |
| | | lines.add(" <adm:syntax>"); |
| | | |
| | | if (attr instanceof org.opends.server.config.BooleanConfigAttribute) |
| | | { |
| | | lines.add(" <adm:boolean />"); |
| | | } |
| | | else if (attr instanceof org.opends.server.config.DNConfigAttribute) |
| | | { |
| | | lines.add(" <adm:dn />"); |
| | | } |
| | | else if (attr instanceof |
| | | org.opends.server.config.IntegerConfigAttribute) |
| | | { |
| | | org.opends.server.config.IntegerConfigAttribute intAttr = |
| | | (org.opends.server.config.IntegerConfigAttribute) attr; |
| | | String lineStr = " <adm:integer "; |
| | | if (intAttr.hasLowerBound()) |
| | | { |
| | | lineStr += " lower-limit=\"" + intAttr.getLowerBound() + "\" "; |
| | | } |
| | | |
| | | if (intAttr.hasUpperBound()) |
| | | { |
| | | lineStr += " upper-limit=\"" + intAttr.getUpperBound() + "\" "; |
| | | } |
| | | |
| | | lineStr += "/>"; |
| | | lines.add(lineStr); |
| | | } |
| | | else if (attr instanceof |
| | | org.opends.server.config.IntegerWithUnitConfigAttribute) |
| | | { |
| | | lines.add(" <!-- ___INTEGER_WITH_UNIT_TYPE___ -->"); |
| | | lines.add(" <adm:string />"); |
| | | } |
| | | else if (attr instanceof |
| | | org.opends.server.config.MultiChoiceConfigAttribute) |
| | | { |
| | | lines.add(" <adm:enumeration>"); |
| | | |
| | | org.opends.server.config.MultiChoiceConfigAttribute mcAttr = |
| | | (org.opends.server.config.MultiChoiceConfigAttribute) attr; |
| | | for (String allowedValue : mcAttr.allowedValues()) |
| | | { |
| | | lines.add(" <adm:value name=\"" + allowedValue + "\">"); |
| | | lines.add(" <adm:synopsis>"); |
| | | lines.add(" ___SYNOPSIS___"); |
| | | lines.add(" </adm:synopsis>"); |
| | | lines.add(" </adm:value>"); |
| | | } |
| | | |
| | | lines.add(" </adm:enumeration>"); |
| | | } |
| | | else if (attr instanceof |
| | | org.opends.server.config.StringConfigAttribute) |
| | | { |
| | | lines.add(" <adm:string />"); |
| | | } |
| | | else |
| | | { |
| | | lines.add(" <!-- ___UNKNOWN_CONFIG_ATTR_TYPE___ -->"); |
| | | lines.add(" <adm:string />"); |
| | | } |
| | | |
| | | lines.add(" </adm:syntax>"); |
| | | lines.add(" <adm:profile name=\"ldap\">"); |
| | | lines.add(" <ldap:attribute>"); |
| | | lines.add(" <ldap:oid>" + type.getOID() + "</ldap:oid>"); |
| | | lines.add(" <ldap:name>" + primaryName + "</ldap:name>"); |
| | | lines.add(" </ldap:attribute>"); |
| | | lines.add(" </adm:profile>"); |
| | | lines.add(" </adm:property>"); |
| | | } |
| | | |
| | | lines.add("</adm:managed-object>"); |
| | | |
| | | |
| | | File parentDir = new File("/tmp/admin-framework"); |
| | | if (! parentDir.exists()) |
| | | { |
| | | parentDir.mkdirs(); |
| | | } |
| | | |
| | | String dnString = entryDN.toNormalizedString(); |
| | | StringBuilder filename = new StringBuilder(); |
| | | filename.append(parentDir.getAbsolutePath()); |
| | | filename.append("/"); |
| | | for (int i=0; i < dnString.length(); i++) |
| | | { |
| | | char c = dnString.charAt(i); |
| | | if (Character.isLetter(c) || Character.isDigit(c)) |
| | | { |
| | | filename.append(c); |
| | | } |
| | | else |
| | | { |
| | | filename.append('_'); |
| | | } |
| | | } |
| | | filename.append(".xml"); |
| | | |
| | | java.io.BufferedWriter bw = |
| | | new java.io.BufferedWriter(new java.io.FileWriter( |
| | | filename.toString())); |
| | | for (String line : lines) |
| | | { |
| | | bw.write(line); |
| | | bw.newLine(); |
| | | } |
| | | bw.flush(); |
| | | bw.close(); |
| | | |
| | | System.err.println(); |
| | | System.err.println(); |
| | | System.err.println("---------- Registered Configurable Component " + |
| | | "----------"); |
| | | for (String line : lines) |
| | | { |
| | | System.err.println(line); |
| | | } |
| | | |
| | | System.err.println(); |
| | | System.err.println(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Deregisters the provided configurable component with the Directory Server. |
| | | * |
| | | * @param component The configurable component to deregister. |
| | | */ |
| | | public static void deregisterConfigurableComponent(ConfigurableComponent |
| | | component) |
| | | { |
| | | DN componentDN = component.getConfigurableComponentEntryDN(); |
| | | JMXMBean mBean = directoryServer.mBeans.get(componentDN); |
| | | if (mBean != null) |
| | | { |
| | | mBean.removeConfigurableComponent(component); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the provided invokable component with the Directory Server. |
| | | * |
| | | * @param component The invokable component to register. |