admin@glassfish.java.net

Re: code review: admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation

From: kedar <Kedar.Mhaswade_at_Sun.COM>
Date: Tue, 30 Jan 2007 18:48:59 -0800

Please run all the validation cases.

The diff's are rather too difficult to read.

Also, I am not so sure if some of the classes
are auto-generated, in which case your changes
would be lost.

I have inherited this code and am trying to understand
it a little better myself, so I am not sure if
there would be any regressions. Can you make
sure that there are no regressions?

Thanks,
Kedar

Lloyd L Chambers wrote:
> TIMEOUT: COB 1/30/07
>
> These changes modify the validator code so that it can initialize the
> NodeList using multiple threads; the list naturally can be divided
> into 1 piece for each processor, yielding nearly linear scaling. See
> DomainMgr.NodeListProcessor and DomainMgr. loadDescriptors().
>
> While there are other non-threadable aspects to DomainMgr, this
> optimization scales perfectly, shaving a percent or two off startup
> time on a multi-core machine (>2). Part of the optimization is the
> change from Hashtable and Vector to HashMap and ArrayList; needlessly
> synchronized classes for this piece of code.
>
> Also, the worrisome lack of 'final', and considerations that more than
> one thread can be calling the validation code lead to the desire to
> make the AttrType class and its subclasses all be immutable, which
> renders thread-safety issues moot. I was able to do this with a
> slight change to the code such that the constructors for the various
> AttrType subclasses take all required fields, thus allowing them to be
> final.
>
> The key changes are in DomainMgr.java, though they are smaller than
> they appear; a big block of code was simply moved into the doRun()
> method of a thread.
>
> Lloyd
>
> -------------
>
> MB2:/gf/build/glassfish lloyd$ cvs diff -u -w
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation
> ?
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/.DS_Store
>
> cvs server: Diffing
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrClassName.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrClassName.java,v
>
> retrieving revision 1.4
> diff -u -w -r1.4 AttrClassName.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrClassName.java
> 25 Dec 2005 03:44:18 -0000 1.4
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrClassName.java
> 31 Jan 2007 02:30:47 -0000
> @@ -41,7 +41,7 @@
> /* Class for attribute type file */
> -public class AttrClassName extends AttrType {
> +public final class AttrClassName extends AttrType {
>
> public AttrClassName(String name, String type, boolean optional) {
> super(name,type, optional);
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrFile.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrFile.java,v
>
> retrieving revision 1.4
> diff -u -w -r1.4 AttrFile.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrFile.java
> 25 Dec 2005 03:44:18 -0000 1.4
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrFile.java
> 31 Jan 2007 02:30:47 -0000
> @@ -41,17 +41,12 @@
> /* Class for attribute type file */
> -public class AttrFile extends AttrType {
> +public final class AttrFile extends AttrType {
> + final boolean checkExists;
>
> - boolean checkExists;
> -
> - public AttrFile(String name, String type, boolean optional) {
> + public AttrFile(String name, String type, boolean optional,
> boolean checkExists ) {
> super(name,type, optional);
> - checkExists = false;
> - }
> -
> - public void setCheckExists(boolean flag) {
> - checkExists = flag;
> + this.checkExists = checkExists;
> }
>
> public void validate(Object o, ValidationContext valCtx) {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrInt.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrInt.java,v
>
> retrieving revision 1.5
> diff -u -w -r1.5 AttrInt.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrInt.java
> 8 May 2006 17:19:56 -0000 1.5
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrInt.java
> 31 Jan 2007 02:30:47 -0000
> @@ -38,15 +38,21 @@
> /* Class for attribute type Integer */
> -public class AttrInt extends AttrType {
> +public final class AttrInt extends AttrType {
>
> public static final int IGNORE_LOW = -2147483648;
> public static final int IGNORE_HIGH = 2147483638;
> - int highRange;
> - int lowRange;
> + final int highRange;
> + final int lowRange;
>
> - public AttrInt(String name, String type, boolean optional) {
> + public AttrInt(
> + final String name,
> + final String type,
> + final boolean optional,
> + final int lowRange,
> + final int highRange ) {
> super(name,type, optional);
> +
> this.highRange = IGNORE_HIGH;
> this.lowRange = IGNORE_LOW;
> }
> @@ -57,14 +63,6 @@
>
> public int getLowRange() {
> return lowRange;
> - }
> -
> - public void setHighRange(int high) {
> - highRange = high;
> - }
> -
> - public void setLowRange(int low) {
> - lowRange = low;
> }
>
> public void validate(Object value, ValidationContext valCtx) {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrString.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrString.java,v
>
> retrieving revision 1.8
> diff -u -w -r1.8 AttrString.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrString.java
> 8 May 2006 17:19:56 -0000 1.8
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrString.java
> 31 Jan 2007 02:30:47 -0000
> @@ -23,7 +23,8 @@
> package com.sun.enterprise.config.serverbeans.validation;
> -import java.util.Vector;
> +import java.util.List;
> +import java.util.Collections;
> /**
> Class which contains Meta data for all types of attributes which
> is present in Validation Descriptor
> @@ -40,33 +41,33 @@
> /* Class for attribute type String */
>
> -public class AttrString extends AttrType {
> -
> - int maxLength;
> - Vector ee;
> - String expr;
> -
> - public AttrString(String name, String type, boolean optional) {
> +public final class AttrString extends AttrType {
> + final int maxLength;
> + final List<String> ee;
> + final String expr;
> +
> + public AttrString(
> + final String name,
> + final String type,
> + final boolean optional,
> + final int maxLength,
> + final List<String> enumString,
> + final String regex
> + ) {
> super(name,type, optional);
> - this.maxLength = 0;
> - ee = null;
> - expr = null;
> + this.maxLength = maxLength;
> + this.ee = enumString == null ? null :
> Collections.unmodifiableList( enumString );
> + this.expr = regex;
> }
>
> - public void setRegExpression(String str) {
> - expr = str;
> - }
> -
> - public void setEnumstring(Vector vec) {
> - ee = vec;
> - }
>
> public int getMaxLength() {
> return maxLength;
> }
>
> - public void setMaxLength(int max) {
> - maxLength = max;
> + public List<String>
> + getEnumeration() {
> + return ee;
> }
>
> public void validate(Object o, ValidationContext valCtx) {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrType.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrType.java,v
>
> retrieving revision 1.8
> diff -u -w -r1.8 AttrType.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrType.java
> 8 May 2006 17:19:56 -0000 1.8
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrType.java
> 31 Jan 2007 02:30:47 -0000
> @@ -25,7 +25,8 @@
> import java.util.logging.Logger;
> -import java.util.Hashtable;
> +import java.util.Map;
> +import java.util.HashMap;
> import com.sun.logging.LogDomains;
> import com.sun.enterprise.config.ConfigBean;
> @@ -45,18 +46,18 @@
> /* Base Class for all types of attribute */
>
> public class AttrType {
> - String name;
> - String type;
> - boolean optional = false; // iff true then attribute can be set to
> - // a null
> - Hashtable _specRules;
> + final String name;
> + final String type;
> + final boolean optional;
> +
> + final Map<String,Object> _specRules;
> final static protected Logger _logger =
> LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
> public AttrType(final String name, final String type, final
> boolean optional) {
> this.name = name;
> this.type = type;
> this.optional = optional;
> - _specRules = new Hashtable();
> + _specRules = new HashMap<String,Object>();
> }
>
>
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrUniqueJNDI.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrUniqueJNDI.java,v
>
> retrieving revision 1.4
> diff -u -w -r1.4 AttrUniqueJNDI.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrUniqueJNDI.java
> 25 Dec 2005 03:44:20 -0000 1.4
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/AttrUniqueJNDI.java
> 31 Jan 2007 02:30:47 -0000
> @@ -58,7 +58,7 @@
> /* Class for attribute type Resource (to check uniqueness of jndiname
> across resources) */
> -public class AttrUniqueJNDI extends AttrType {
> +public final class AttrUniqueJNDI extends AttrType {
>
> public AttrUniqueJNDI(String name, String type, boolean optional) {
> super(name,type, optional);
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/DomainMgr.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/DomainMgr.java,v
>
> retrieving revision 1.9
> diff -u -w -r1.9 DomainMgr.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/DomainMgr.java
> 8 May 2006 17:19:56 -0000 1.9
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/DomainMgr.java
> 31 Jan 2007 02:30:47 -0000
> @@ -32,7 +32,9 @@
> import org.xml.sax.SAXException;
> import org.xml.sax.InputSource;
> import java.io.IOException;
> -import java.util.Vector;
> +import java.util.List;
> +import java.util.ArrayList;
> +
> import java.util.StringTokenizer;
> import java.lang.Class;
> import java.lang.reflect.Constructor;
> @@ -57,6 +59,11 @@
> import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
> import com.sun.enterprise.admin.meta.MBeanRegistry;
> +
> +import com.sun.appserv.management.util.misc.RunnableBase;
> +import com.sun.appserv.management.util.misc.TimingDelta;
> +import com.sun.appserv.management.util.misc.Timings;
> +
> /**
> * Class which loads all the validator descriptor information from a
> xml file into a hash map.
> * Validator uses this Hash Map and invokes the particular test case
> depending on xml tag
> @@ -66,15 +73,14 @@
> */
> public class DomainMgr implements ConfigContextEventListener {
> + private static final Timings TIMINGS = Timings.newInstance(
> "DomainMgr" );
>
> // Logging
> - static Logger _logger =
> LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
> -
> - LocalStringManagerImpl smh =
> StringManagerHelper.getLocalStringsManager();
> - HashMap tests = new HashMap();
> - transient private long lastModified = 0;
> - public NameListMgr _nameListMgr;
> - public MBeanRegistry _mbeanRegistry;
> + static final Logger _logger =
> LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
> + final LocalStringManagerImpl smh =
> StringManagerHelper.getLocalStringsManager();
> + final HashMap<String,GenericValidator> tests = new
> HashMap<String,GenericValidator>();
> + public final NameListMgr _nameListMgr;
> + public final MBeanRegistry _mbeanRegistry;
> public DomainMgr() {
>
> this(MBeanRegistryFactory.getAdminContext().getAdminConfigContext(),
> false);
> }
> @@ -84,18 +90,26 @@
> }
>
> public DomainMgr(ConfigContext ctx, boolean bStaticContext,
> MBeanRegistry registry) {
> + final TimingDelta delta = new TimingDelta();
> loadDescriptors();
> +TIMINGS.add( "DomainMgr-1", delta );
> _nameListMgr = new NameListMgr(ctx, bStaticContext);
> +TIMINGS.add( "DomainMgr-2", delta );
> if(registry==null)
> _mbeanRegistry =
> MBeanRegistryFactory.getAdminMBeanRegistry();
> else
> _mbeanRegistry = registry;
> +TIMINGS.add( "DomainMgr-3", delta );
> +System.out.println("\n" + TIMINGS.toString() );
> }
>
> MBeanRegistry getMBeanRegistry()
> {
> return _mbeanRegistry;
> }
> +
> + private DomainMgr getThis() { return this; }
> +
> // Get the path of validation descriptor xml file from System
> property class path
> private String getTestFile() throws Exception {
> URL propertiesFile =
> DomainMgr.class.getClassLoader().getResource(
> @@ -105,19 +119,217 @@
> return propertiesFile.toString();
> }
> + private final class NodeListProcessor extends RunnableBase {
> + private final NodeList mNodeList;
> + private final int mStartIndex;
> + private final int mCount;
> + private final HashMap<String,GenericValidator> mTests = new
> HashMap<String,GenericValidator>();
> +
> + public NodeListProcessor(final NodeList nodeList, final int
> startIndex, final int count) {
> + mNodeList = nodeList;
> + mStartIndex = startIndex;
> + mCount = count;
> + }
> +
> + public HashMap<String,GenericValidator> getTests() { return
> mTests; }
> +
> + protected void doRun() throws Exception {
> + final TimingDelta delta = new TimingDelta();
> + final NodeList list = mNodeList;
> +
> + for (int offset = 0; offset < mCount; ++offset) {
> + final Element e = (Element) list.item( mStartIndex +
> offset );
> + final String elementName = e.getAttribute("name");
> + String elementXPath = e.getAttribute("xpath");
> + String elementCustomClass =
> e.getAttribute("custom-class") ;
> + String testName = e.getAttribute("test-name");
> + if(testName==null || testName.length()==0)
> + {
> + testName = XPathHelper.convertName(elementName);
> + }
> + if (null == elementCustomClass ||
> elementCustomClass.length() == 0){
> + elementCustomClass = testName;
> + }
> + String[] required_children = null;
> + String[] exclusive_list = null;
> + String elemList = e.getAttribute("required-children");
> + if(elemList!=null && elemList.length()>0)
> + {
> + required_children = elemList.split(",");
> + }
> + elemList = e.getAttribute("exclusive-list");
> + if(elemList!=null && elemList.length()>0)
> + {
> + exclusive_list = elemList.split(",");
> + }
> + String key = e.getAttribute("key");
> + if(key!=null && key.length()==0)
> + key = null;
> + List<AttrType> attributes = new ArrayList<AttrType>();
> + final NodeList nl = e.getChildNodes();
> + for (int index=0,j=0;j<nl.getLength();j++) {
> + String temp;
> + final String nodeName =
> nl.item(j).getNodeName().trim();
> + String nameValue=null;
> + String typeValue=null;
> + NamedNodeMap nodeMap=null;
> + AttrType attr=null;
> +
> + final Node n = nl.item(j);
> +
> + if("attribute".equals(nodeName) ||
> "optional-attribute".equals(nodeName)) {
> + nodeMap = n.getAttributes();
> +
> + nameValue = getAttr(nodeMap, "name");
> + typeValue = getAttr(nodeMap, "type");
> + if("string".equals(typeValue))
> + {
> + temp = getAttr(nodeMap, "max-length");
> + final int maxLength = (temp == null) ? 0
> : Integer.parseInt(temp);
> +
> + List<String> enumString = null;
> + temp = getAttr(nodeMap, "enumeration");
> + if ( temp != null )
> + {
> + enumString = new ArrayList<String>();
> + final String[] strs = temp.split(",");
> + for(int k=0; k<strs.length; k++)
> + {
> + enumString.add(strs[k]);
> + }
> + }
> + final String regex = getAttr(nodeMap,
> "regex");
> +
> + attr = new AttrString(nameValue, typeValue,
> +
> "optional-attribute".equals(nodeName),
> + maxLength, enumString, regex );
> + }
> + else if("file".equals(typeValue))
> + {
> + temp = getAttr(nodeMap, "exists");
> + final boolean checkExists = (temp == null) ?
> + false :
> "true".equalsIgnoreCase(temp);
> +
> + attr = new AttrFile(nameValue, typeValue,
> +
> "optional-attribute".equals(nodeName), checkExists );
> + }
> + else if("integer".equals(typeValue))
> + {
> + int lowRange = AttrInt.IGNORE_LOW;
> + int highRange = AttrInt.IGNORE_HIGH;
> + temp = getAttr(nodeMap, "range");
> + if(temp != null)
> + {
> + final String[] strs = temp.split(",");
> + if(!strs[0].equals("NA"))
> + lowRange =
> Integer.parseInt(strs[0]);
> + if(!strs[1].equals("NA"))
> + highRange =
> Integer.parseInt(strs[1]);
> + }
> +
> + attr = new AttrInt(nameValue,typeValue,
> +
> "optional-attribute".equals(nodeName), lowRange, highRange );
> + }
> + else if("classname".equals(typeValue))
> + attr = new AttrClassName(nameValue,
> typeValue, "optional-attribute".equals(nodeName));
> + else if("address".equals(typeValue))
> + attr = new
> AttrAddress(nameValue,typeValue, "optional-attribute".equals(nodeName));
> + else if("jndi-unique".equals(typeValue))
> + attr = new
> AttrUniqueJNDI(nameValue,typeValue,
> "optional-attribute".equals(nodeName));
> +
> + if(attr != null)
> + {
> + attr.addRuleValue("belongs-to",
> getAttrAsList(nodeMap, "belongs-to"));
> + attr.addRuleValue("references-to",
> getAttrAsList(nodeMap, "references-to"));
> + attr.addRuleValue("le-than",
> getAttr(nodeMap, "le-than"));
> + attr.addRuleValue("ls-than",
> getAttr(nodeMap, "ls-than"));
> + attr.addRuleValue("ge-than",
> getAttr(nodeMap, "ge-than"));
> + attr.addRuleValue("gt-than",
> getAttr(nodeMap, "gt-than"));
> +
> + attributes.add(index++,attr);
> + }
> + }
> + }
> + final ValidationDescriptor desc =
> + new ValidationDescriptor( getThis(), elementName,
> + elementXPath, elementCustomClass,
> + key, attributes, required_children,
> exclusive_list);
> + final GenericValidator validator=
> getGenericValidator(desc);
> +
> + if(validator != null) {
> + mTests.put(testName, validator);
> + }
> + }
> + }
> + };
> +
> + // Loads all validation descriptors from XML file into the
> Hash Map
> + public boolean loadDescriptors() {
> + final TimingDelta delta = new TimingDelta();
> + boolean allIsWell = true;
> +
> + try {
> + //tests.clear();
> + final DocumentBuilder db =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> + final InputSource is = new InputSource(getTestFile());
> + final Document doc = db.parse(is);
> + final NodeList nodeList =
> doc.getElementsByTagName("element");
> +
> + // divide the task up if more than two processors are
> present
> + final int numNodes = nodeList.getLength();
> + int numProcessors =
> Runtime.getRuntime().availableProcessors();
> + if ( numProcessors <= 2 ) {
> + numProcessors = 1; // other threads are running
> in AdminService
> + }
> +
> + final NodeListProcessor[] processors = new
> NodeListProcessor[ numProcessors ];
> + final int numPer = numNodes / numProcessors;
> + int offset = 0;
> + for( int i = 0; i < numProcessors - 1; ++i ) {
> + processors[i] = new NodeListProcessor( nodeList,
> offset, numPer );
> + processors[i].submit( RunnableBase.SUBMIT_ASYNC );
> + offset += numPer;
> + }
> + final int remaining = numNodes - offset;
> + processors[numProcessors-1] = new
> NodeListProcessor(nodeList, offset, remaining);
> + processors[numProcessors-1].submit(
> RunnableBase.SUBMIT_SYNC ); // run on this thread
> +
> + // wait for each, and take its results
> + for (int i=0; i < numProcessors; ++i) {
> + processors[i].waitDoneThrow();
> + tests.putAll( processors[i].getTests() );
> + }
> + } catch (ParserConfigurationException e) {
> + _logger.log(Level.WARNING, "parser_error", e);
> + allIsWell = false;
> + } catch (SAXException e) {
> + _logger.log(Level.WARNING, "sax_error", e);
> + allIsWell = false;
> + } catch (IOException e) {
> + _logger.log(Level.WARNING, "error_loading_xmlfile", e);
> + allIsWell = false;
> + } catch(Exception e) {
> + _logger.log(Level.WARNING, "error", e);
> + allIsWell = false;
> + }
> + return allIsWell;
> + }
> +
> +
> + /*
> // Loads all validation descriptors from XML file into the Hash Map
> public boolean loadDescriptors() {
> boolean allIsWell = true;
>
> try {
> //tests.clear();
> - DocumentBuilder db =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> - InputSource is = new InputSource(getTestFile());
> - Document doc = db.parse(is);
> - NodeList list = doc.getElementsByTagName("element");
> + final DocumentBuilder db =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> + final InputSource is = new InputSource(getTestFile());
> + final Document doc = db.parse(is);
> + final NodeList list = doc.getElementsByTagName("element");
> for (int i=0;i<list.getLength();i++) {
> - Element e = (Element) list.item(i);
> - String elementName = e.getAttribute("name");
> + final Element e = (Element) list.item(i);
> + final String elementName = e.getAttribute("name");
> String elementXPath = e.getAttribute("xpath");
> String elementCustomClass =
> e.getAttribute("custom-class") ;
> String testName = e.getAttribute("test-name");
> @@ -143,17 +355,17 @@
> String key = e.getAttribute("key");
> if(key!=null && key.length()==0)
> key = null;
> - Vector attributes = new Vector();
> + List<AttrType> attributes = new ArrayList<AttrType>();
> NodeList nl = e.getChildNodes();
> for (int index=0,j=0;j<nl.getLength();j++) {
> String temp;
> - String nodeName = nl.item(j).getNodeName().trim();
> + final String nodeName =
> nl.item(j).getNodeName().trim();
> String nameValue=null;
> String typeValue=null;
> NamedNodeMap nodeMap=null;
> AttrType attr=null;
>
> - Node n = nl.item(j);
> + final Node n = nl.item(j);
>
> if("attribute".equals(nodeName) ||
> "optional-attribute".equals(nodeName)) {
> nodeMap = n.getAttributes();
> @@ -162,36 +374,51 @@
> typeValue = getAttr(nodeMap, "type");
> if("string".equals(typeValue))
> {
> - attr = new AttrString(nameValue,
> typeValue, "optional-attribute".equals(nodeName) );
> - if((temp=getAttr(nodeMap,
> "max-length"))!=null)
> -
> ((AttrString)attr).setMaxLength(Integer.parseInt(temp));
> - if((temp=getAttr(nodeMap,
> "enumeration"))!=null)
> + temp = getAttr(nodeMap, "max-length");
> + final int maxLength = (temp == null) ? 0
> : Integer.parseInt(temp);
> +
> + List<String> enumString = null;
> + temp = getAttr(nodeMap, "enumeration");
> + if ( temp != null )
> {
> - Vector ee = new Vector();
> - String[] strs = temp.split(",");
> + enumString = new ArrayList<String>();
> + final String[] strs = temp.split(",");
> for(int k=0; k<strs.length; k++)
> - ee.add(strs[k]);
> - ((AttrString)attr).setEnumstring(ee);
> + {
> + enumString.add(strs[k]);
> + }
> }
> -
> ((AttrString)attr).setRegExpression(getAttr(nodeMap, "regex"));
> + final String regex = getAttr(nodeMap,
> "regex");
> +
> + attr = new AttrString(nameValue, typeValue,
> +
> "optional-attribute".equals(nodeName),
> + maxLength, enumString, regex );
> }
> else if("file".equals(typeValue))
> {
> - attr = new AttrFile(nameValue, typeValue,
> "optional-attribute".equals(nodeName));
> - if("true".equals(getAttr(nodeMap,
> "exists")))
> - ((AttrFile)attr).setCheckExists(true);
> + temp = getAttr(nodeMap, "exists");
> + final boolean checkExists = (temp == null) ?
> + false :
> "true".equalsIgnoreCase(temp);
> +
> + attr = new AttrFile(nameValue, typeValue,
> +
> "optional-attribute".equals(nodeName), checkExists );
> }
> else if("integer".equals(typeValue))
> {
> - attr = new AttrInt(nameValue,typeValue,
> "optional-attribute".equals(nodeName));
> - if((temp = getAttr(nodeMap, "range")) !=
> null)
> + int lowRange = AttrInt.IGNORE_LOW;
> + int highRange = AttrInt.IGNORE_HIGH;
> + temp = getAttr(nodeMap, "range");
> + if(temp != null)
> {
> - String[] strs = temp.split(",");
> + final String[] strs = temp.split(",");
> if(!strs[0].equals("NA"))
> -
> ((AttrInt)attr).setLowRange(Integer.parseInt(strs[0]));
> + lowRange =
> Integer.parseInt(strs[0]);
> if(!strs[1].equals("NA"))
> -
> ((AttrInt)attr).setHighRange(Integer.parseInt(strs[1]));
> + highRange =
> Integer.parseInt(strs[1]);
> }
> +
> + attr = new AttrInt(nameValue,typeValue,
> +
> "optional-attribute".equals(nodeName), lowRange, highRange );
> }
> else if("classname".equals(typeValue))
> attr = new AttrClassName(nameValue,
> typeValue, "optional-attribute".equals(nodeName));
> @@ -218,9 +445,11 @@
> elementXPath, elementCustomClass,
> key, attributes, required_children,
> exclusive_list);
> final GenericValidator validator=
> getGenericValidator(desc);
> - if(validator != null)
> +
> + if(validator != null) {
> tests.put(testName, validator);
> }
> + }
> } catch (ParserConfigurationException e) {
> _logger.log(Level.WARNING, "parser_error", e);
> allIsWell = false;
> @@ -236,6 +465,7 @@
> }
> return allIsWell;
> }
> + */
>
> private String getAttr(NamedNodeMap nodeMap, String attrName)
> {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/GenericValidator.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/GenericValidator.java,v
>
> retrieving revision 1.14
> diff -u -w -r1.14 GenericValidator.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/GenericValidator.java
> 8 May 2006 17:19:56 -0000 1.14
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/GenericValidator.java
> 31 Jan 2007 02:30:47 -0000
> @@ -23,7 +23,7 @@
> package com.sun.enterprise.config.serverbeans.validation;
> -import java.util.Vector;
> +import java.util.List;
> import java.net.InetAddress;
> import java.net.UnknownHostException;
> import com.sun.enterprise.config.ConfigContextEvent;
> @@ -361,12 +361,12 @@
> }
> }
>
> - Vector attrs = desc.getAttributes();
> + final List<AttrType> attrs = desc.getAttributes();
> //Attributes validation
> for(int i=0; i<attrs.size(); i++)
> {
> try {
> - validateAttribute((AttrType) attrs.get(i), valCtx);
> + validateAttribute( attrs.get(i), valCtx);
> } catch(IllegalArgumentException e) {
> valCtx.result.failed(e.getMessage());
> } catch(Exception e) {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/NameListMgr.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/NameListMgr.java,v
>
> retrieving revision 1.4
> diff -u -w -r1.4 NameListMgr.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/NameListMgr.java
> 25 Dec 2005 03:44:23 -0000 1.4
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/NameListMgr.java
> 31 Jan 2007 02:30:47 -0000
> @@ -34,7 +34,8 @@
> import java.util.ArrayList;
> import java.util.StringTokenizer;
> -import java.util.Hashtable;
> +import java.util.HashMap;
> +import java.util.Map;
> import java.util.Enumeration;
> import java.lang.Class;
> @@ -103,16 +104,16 @@
> public class NameListMgr {
>
> // Logging
> - static Logger _logger =
> LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
> - LocalStringManagerImpl _localStrings =
> StringManagerHelper.getLocalStringsManager();
> + static final Logger _logger =
> LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
> + final LocalStringManagerImpl _localStrings =
> StringManagerHelper.getLocalStringsManager();
> - Hashtable _lists;
> - boolean _precreateAndKeepLists;
> - ConfigContext _ctx;
> + final HashMap<String,NameList> _lists;
> + final boolean _precreateAndKeepLists;
> + final ConfigContext _ctx;
>
>
> public NameListMgr(ConfigContext ctx, boolean
> precreateAndKeepLists) {
> - _lists = new Hashtable();
> + _lists = new HashMap<String,NameList>();
> _precreateAndKeepLists = precreateAndKeepLists;
> _ctx = ctx;
> loadDescriptors();
> @@ -125,10 +126,8 @@
>
> if(_lists!=null)
> {
> - Enumeration keys = _lists.keys();
> - while(keys.hasMoreElements())
> + for( final String key : _lists.keySet() )
> {
> - String key = (String)keys.nextElement();
> str = str + "\n" +
> ((NameList)_lists.get(key)).toString();
> }
> }
> @@ -229,7 +228,7 @@
> }
> // Loads all namelist descriptors and instantiate correspondent
> name lists
> - public boolean loadDescriptors() {
> + private boolean loadDescriptors() {
> boolean allIsWell = true;
>
> try {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationContext.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationContext.java,v
>
> retrieving revision 1.7
> diff -u -w -r1.7 ValidationContext.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationContext.java
> 16 Mar 2006 22:46:06 -0000 1.7
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationContext.java
> 31 Jan 2007 02:30:47 -0000
> @@ -34,21 +34,19 @@
> public class ValidationContext {
> - public Result result;
> - public Object value;
> - public Object classObject;
> - public String beanName;
> - public ConfigContext context;
> - public String name;
> - public String choice;
> - public LocalStringManagerImpl smh;
> - public String primaryKeyName;
> - public ValidationDescriptor validationDescriptor;
> + public final Result result;
> + public final Object value;
> + public final Object classObject;
> + public final String beanName;
> + public final ConfigContext context;
> + public final String name;
> + public final String choice;
> + public final LocalStringManagerImpl smh;
> + public final String primaryKeyName;
> + public final ValidationDescriptor validationDescriptor;
> //-------------- prepared in GenericValidator
> public String attrName;
> public Object attrValue;
> -
> -
> public ValidationContext(Result result, Object value, Object
> classObject, String beanName, ConfigContext context, String name,
> String choice, String primaryKeyName, LocalStringManagerImpl smh,
> ValidationDescriptor validationDescriptor) {
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationDescriptor.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationDescriptor.java,v
>
> retrieving revision 1.6
> diff -u -w -r1.6 ValidationDescriptor.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationDescriptor.java
> 25 Dec 2005 03:44:25 -0000 1.6
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/ValidationDescriptor.java
> 31 Jan 2007 02:30:47 -0000
> @@ -23,7 +23,7 @@
> package com.sun.enterprise.config.serverbeans.validation;
> -import java.util.Vector;
> +import java.util.List;
> /**
> * Class which contains all the descriptor information for a
> particular element in a object used
> @@ -33,20 +33,19 @@
> @version 2.0
> */
> -public class ValidationDescriptor {
> -
> - String elementName;
> - String xPath;
> - String customValidatorClass;
> - String key;
> - Vector attrType;
> - DomainMgr domainMgr;
> - String[] requiredChildren;
> - String[] exclusiveChildren;
> +public final class ValidationDescriptor {
> + final String elementName;
> + final String xPath;
> + final String customValidatorClass;
> + final String key;
> + final List<AttrType> attrType;
> + final DomainMgr domainMgr;
> + final String[] requiredChildren;
> + final String[] exclusiveChildren;
>
> public ValidationDescriptor(DomainMgr domainMgr, String elementName,
> String xPath, String customValidatorClass,
> - String key, Vector attrType,
> + String key, List<AttrType> attrType,
> String[] required_children, String[] exclusive_children) {
> this.domainMgr = domainMgr;
> this.elementName = elementName;
> @@ -73,7 +72,7 @@
> public String getKey() {
> return key;
> }
> - public Vector getAttributes() {
> + public List<AttrType> getAttributes() {
> return attrType;
> }
> cvs server: Diffing
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/config
>
> cvs server: Diffing
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/tests
>
> Index:
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/tests/WebServiceEndpointTest.java
>
> ===================================================================
> RCS file:
> /cvs/glassfish/admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/tests/WebServiceEndpointTest.java,v
>
> retrieving revision 1.2
> diff -u -w -r1.2 WebServiceEndpointTest.java
> ---
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/tests/WebServiceEndpointTest.java
> 25 Dec 2005 03:44:41 -0000 1.2
> +++
> admin/validator/src/java/com/sun/enterprise/config/serverbeans/validation/tests/WebServiceEndpointTest.java
> 31 Jan 2007 02:30:47 -0000
> @@ -57,21 +57,32 @@
> attr instanceof AttrString)
> {
> ConfigBean parent = valCtx.getParentBean();
> +
> + String regEx = null;
> if(parent instanceof J2eeApplication)
> {
> - ((AttrString)attr).setRegExpression(
> -
> "[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*#[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*");
>
> + regEx =
> +
> "[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*#[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*";
>
> }
> else
> {
> - ((AttrString)attr).setRegExpression(
> - "[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*");
> + regEx = "[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;]*";
> }
> - super.validateAttribute(ownerBean, attr, value, valCtx);
> - ((AttrString)attr).setRegExpression(null);
> +
> + final AttrString tempAttr = new AttrString(
> + attr.getName(),
> + attr.getType(),
> + attr.getOptional(),
> + ((AttrString)attr).getMaxLength(),
> + ((AttrString)attr).getEnumeration(),
> + regEx );
> +
> + super.validateAttribute(ownerBean, tempAttr, value, valCtx);
> }
> else
> + {
> super.validateAttribute(ownerBean, attr, value, valCtx);
> + }
> }
> }
> MB2:/gf/build/glassfish lloyd$
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>