Example usage for org.dom4j Element getStringValue

List of usage examples for org.dom4j Element getStringValue

Introduction

In this page you can find the example usage for org.dom4j Element getStringValue.

Prototype

String getStringValue();

Source Link

Document

Returns the XPath string-value of this node.

Usage

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

@SuppressWarnings("unchecked")
    protected void sequentialXMLImportRecordSet(Element dbImport, String dbTable, String parentName,
            long parentId) {
        try {/* w ww .  ja  va2 s .  c  om*/
            String id = new String();
            DBTableInfo parentInfo = DBTableIdMgr.getInstance().getInfoByTableName(dbTable.toLowerCase());
            // get the records
            List records = dbImport.selectNodes("//" + dbTable); //$NON-NLS-1$
            //String lowerdbTable = lowerFirstChar(dbTable);
            DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(dbTable.toLowerCase());
            String primaryKey = info.getPrimaryKeyName();
            List ids = dbImport.selectNodes("//" + primaryKey); //$NON-NLS-1$

            if (records.size() < 1) {
                log.debug("Cannot import. Given database type:" + dbTable //$NON-NLS-1$
                        + " does not exsist in import file"); //$NON-NLS-1$
            } else {
                // loop for each record
                for (int k = 0; k < records.size(); k++) {
                    Vector collectionIds = new Vector(20);
                    Vector collectionNames = new Vector(20);
                    // keep this id to compare against it's collection
                    Element idElement = (Element) ids.get(k);
                    id = idElement.getStringValue();
                    // make the agent and the element
                    Object agent = parentInfo.getClassObj().newInstance();
                    Map<String, Object> agentMap = new HashMap<String, Object>();
                    Element dbElement = (Element) records.get(k);
                    Iterator i = dbElement.elementIterator();
                    do {// do for each element in the record
                        Element element = (Element) i.next();

                        Object value = findTypeRecordSet(element, dbTable, parentId, parentName);// the
                                                                                                 // parent
                                                                                                 // is
                                                                                                 // itself,
                                                                                                 // just
                                                                                                 // a
                                                                                                 // dummy
                                                                                                 // variable
                        if (value != null && value != "OneToMany" && value != "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            agentMap.put(element.getName(), value);
                        }
                        // ignore many-to-many for now
                        else if (value == "OneToMany" || value == "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {// RECURSE
                         // get assoicated ids
                            List temp_collection_ids = element
                                    .selectNodes("//" + dbTable + "[" + primaryKey + " = \"" + id //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                            + "\"]/" + element.getName() + "/*"); //$NON-NLS-1$ //$NON-NLS-2$
                            // get collection info and still dont add it
                            if (!temp_collection_ids.isEmpty()) {
                                // get child dbName
                                String childDbName = getDbName(temp_collection_ids);
                                collectionNames.addElement(childDbName);
                                for (int index = 0; index < temp_collection_ids.size(); index++) {
                                    collectionIds.addElement(temp_collection_ids.get(index));
                                }
                            }
                        } else
                        // else, dont add it
                        {
                            // if it is an id, just ignore. otherwise print out error
                            if (!element.getName().equals(primaryKey)) {
                                log.debug("did not add " + element.getName() //$NON-NLS-1$
                                        + " to the element " + dbTable); //$NON-NLS-1$
                            }
                        }
                    } while (i.hasNext());

                    // populate and save
                    BeanUtils.populate(agent, agentMap);

                    this.session.save(agent);

                    // if there was a collection, then recurse
                    if (!collectionIds.isEmpty()) {
                        long newParentId = new Long(session.getIdentifier(agent).toString()).longValue();
                        // import all children
                        sequentialXMLImportRecursion(collectionNames, collectionIds, dbTable, newParentId);
                    }
                }
            }
        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
            ex.printStackTrace();
        }
    }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

/**
     * Imports a table from a given xml file
     * @param dbImport the opend xml file elememt
     * @param dbTable the class name of the table
     *///from w  w w .j a  v  a2 s.com
    @SuppressWarnings("unchecked")
    protected Object dynamicXMLImportRecReturn(Element dbImport, String dbTable) {
        Object agent = new Object();
        try {
            String id = new String();
            DBTableInfo parentInfo = DBTableIdMgr.getInstance().getInfoByTableName(dbTable.toLowerCase());

            List records = dbImport.selectNodes("//" + dbTable); //$NON-NLS-1$
            String lowerdbTable = lowerFirstChar(dbTable);
            // List attributes = dbImport.selectNodes("//@"+lowerdbTable+"Id");
            // TODO shouldl not assume this is the dbprimary key, use dbtablemgr
            List ids = dbImport.selectNodes("//" + lowerdbTable + "Id");// assume this is dbs id //$NON-NLS-1$ //$NON-NLS-2$
                                                                        // name
            if (records.size() < 1) {
                log.debug("Cannot import. Given database type:" + dbTable //$NON-NLS-1$
                        + " does not exsist in import file"); //$NON-NLS-1$
            } else {
                // loop for each record
                for (int k = 0; k < records.size(); k++) {
                    // keep this id to compare against it's collection
                    Element idElement = (Element) ids.get(k);
                    // id = attribute.getText();
                    id = idElement.getStringValue();
                    // make the agent and the element
                    agent = parentInfo.getClassObj().newInstance();
                    Map<String, Object> agentMap = new HashMap<String, Object>();
                    Element dbElement = (Element) records.get(k);
                    Iterator i = dbElement.elementIterator();
                    do {// do for each element in the record
                        Element element = (Element) i.next();

                        Object value = findType(element, dbTable, agent, " ");// the parent is //$NON-NLS-1$
                                                                              // itself, just a
                                                                              // dummy variable

                        if (value != null && value != "OneToMany" && value != "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            agentMap.put(element.getName(), value);

                        }
                        // ignore many-to-many for now
                        else if (value == "OneToMany" || value == "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {// RECURSE
                         // is it a collection, add all associated records
                         // get assoicated ids
                         // TODO shouldl not assume things are in order
                            List collectingevent_ids = element.selectNodes("//" + dbTable + "[" //$NON-NLS-1$ //$NON-NLS-2$
                                    + id + "]/" + element.getName() + "/*");// +upperElement); //$NON-NLS-1$ //$NON-NLS-2$

                            if (!collectingevent_ids.isEmpty()) {
                                // add all the assoctions to aDbElement
                                // get child dbName
                                String childDbName = getDbName(collectingevent_ids);
                                // make a parent object
                                BeanUtils.populate(agent, agentMap);

                                // Collection collection = xmlImportRecursion(locality,
                                // upperElement, collectingevent_ids, parent, lowerdbTable);
                                Set collection = xmlImportRecursion(agentMap, childDbName, collectingevent_ids,
                                        agent, lowerdbTable);
                                if (collection != null) {
                                    agentMap.put(element.getName(), collection);
                                } else {
                                    log.debug("error on the collection " //$NON-NLS-1$
                                            + element.getName() + " with parent " + dbTable); //$NON-NLS-1$
                                }
                            }
                        } else
                        // else, dont add it
                        {
                            // if it is an id, just ignore. otherwise print out error
                            if (!element.getName().equals(lowerdbTable + "Id")) //$NON-NLS-1$
                            {
                                log.debug("did not add " + element.getName() //$NON-NLS-1$
                                        + " to the element " + dbTable); //$NON-NLS-1$
                            }
                        }
                    } while (i.hasNext());

                    // populate and save
                    BeanUtils.populate(agent, agentMap);
                    this.session.saveOrUpdate(agent);

                }
            }

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
            ex.printStackTrace();
        }
        return agent;
    }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

@SuppressWarnings("unchecked")
    protected void sequentialDatabaseImport(Element dbImport, String dbTable, String parentName, long parentId,
            boolean recursion) {
        try {/*from  w  w  w.  j  a  v  a  2 s.c  o  m*/
            String id = new String();
            DBTableInfo parentInfo = DBTableIdMgr.getInstance().getInfoByTableName(dbTable.toLowerCase());
            // get the records
            List records = dbImport.selectNodes("//" + dbTable); //$NON-NLS-1$
            DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(dbTable.toLowerCase());
            String primaryKey = info.getPrimaryKeyName();
            List ids = dbImport.selectNodes("//" + primaryKey); //$NON-NLS-1$

            if (records.size() < 1) {
                log.debug("Cannot import. Given database type:" + dbTable //$NON-NLS-1$
                        + " does not exsist in import file"); //$NON-NLS-1$
            } else {
                // loop for each record
                for (int k = 0; k < records.size(); k++) {
                    Vector collectionIds = new Vector(20);
                    Vector collectionNames = new Vector(20);
                    // keep this id to compare against it's collection
                    Element idElement = (Element) ids.get(k);
                    id = idElement.getStringValue();
                    // make the agent and the element
                    Object agent = parentInfo.getClassObj().newInstance();
                    HashMap<String, Object> agentMap = new HashMap<String, Object>();
                    Element dbElement = (Element) records.get(k);
                    Iterator i = dbElement.elementIterator();
                    do {// do for each element in the record
                        Element element = (Element) i.next();

                        // Object value = findTypeSequential(element, dbTable, parentId, parentName
                        // );//the parent is itself, just a dummy variable
                        Object value = findTypeDataBase(element, dbTable, parentId, parentName);// the
                                                                                                // parent
                                                                                                // is
                                                                                                // itself,
                                                                                                // just
                                                                                                // a
                                                                                                // dummy
                                                                                                // variable
                        if (value != null && value != "OneToMany" && value != "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            agentMap.put(element.getName(), value);
                        }
                        // ignore many-to-many for now
                        else if (value == "OneToMany" || value == "ManyToMany") //$NON-NLS-1$ //$NON-NLS-2$
                        {// RECURSE
                            if (recursion) {
                                // get assoicated ids
                                List temp_collection_ids = element.selectNodes("//" + dbTable + "[" //$NON-NLS-1$ //$NON-NLS-2$
                                        + primaryKey + " = \"" + id + "\"]/" + element.getName() //$NON-NLS-1$ //$NON-NLS-2$
                                        + "/*"); //$NON-NLS-1$
                                // get collection info and still dont add it
                                if (!temp_collection_ids.isEmpty()) {
                                    // get child dbName
                                    String childDbName = getDbName(temp_collection_ids);
                                    collectionNames.addElement(childDbName);
                                    for (int index = 0; index < temp_collection_ids.size(); index++) {
                                        collectionIds.addElement(temp_collection_ids.get(index));
                                    }
                                }
                            }
                        } else
                        // else, dont add it
                        {
                            // if it is an id, just ignore. otherwise print out error
                            if (!element.getName().equals(primaryKey)) {
                                log.debug("did not add " + element.getName() //$NON-NLS-1$
                                        + " to the element " + dbTable); //$NON-NLS-1$
                            }
                        }
                    } while (i.hasNext());

                    // populate and save
                    BeanUtils.populate(agent, agentMap);

                    this.session.save(agent);

                    // if there was a collection, then recurse
                    /*
                     * if(!collectionIds.isEmpty()) { long newParentId = new
                     * Long(session.getIdentifier(agent).toString()).longValue(); //import all
                     * children sequentialXMLImportRecursion(collectionNames, collectionIds,
                     * dbTable, newParentId); }
                     */
                }
            }
        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
            ex.printStackTrace();
        }
    }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

    /**
         * set the value of an element to the correct type
         * @param compareMe the element/*from  w  ww. j a v  a  2 s  .c  o  m*/
         * @param dbTable the class name of the table
         * @param parentObject the parent record
         * @param parentName the parentName
         * @return an object, "ManyToMany", "OneToMany", or null if it could not find the type
         */
        protected Object findType(Element compareMe, String dbTable, Object parentObject, String parentName) {
            try { // get the fieldinfo
                String lowerdbTable = dbTable.toLowerCase();
                DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable);
                // find element with compareme.getName()
                DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName());
                // if the element is an id, ignore it
                if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$
                {
                    // if it is a normal field
                    if (fieldInfo != null) {
                        String type = fieldInfo.getType();
                        // check the type
                        if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            return compareMe.getStringValue();

                        } else if (type.equals("java.util.Date")) //$NON-NLS-1$
                        {
                            Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$
                                    .getStringValue());
                            return dtTmp;

                        } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$
                        {
                            Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue());
                            return tmstmp;
                        } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$
                        {
                            int num = new Integer(compareMe.getStringValue()).intValue();
                            return num;

                        } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$
                        {
                            Boolean bool = Boolean.valueOf(compareMe.getStringValue());
                            return bool;
                        } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$
                        {
                            BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue());
                            return num;
                        } else if (type.equals("java.lang.Double")) //$NON-NLS-1$
                        {
                            double num = new Double(compareMe.getStringValue()).doubleValue();
                            return num;
                        } else if (type.equals("java.lang.Float")) //$NON-NLS-1$
                        {
                            float num = new Float(compareMe.getStringValue()).floatValue();
                            return num;
                        } else if (type.equals("java.lang.Long")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();
                            return num;
                        } else if (type.equals("java.lang.Short")) //$NON-NLS-1$
                        {
                            short num = new Short(compareMe.getStringValue()).shortValue();
                            return num;
                        } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$
                        {
                            byte num = new Byte(compareMe.getStringValue()).byteValue();
                            return num;
                        } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$
                        {
                            Calendar date = dateString2Calendar(compareMe.getStringValue());
                            return date;
                        }
                    } else
                    // check if it is a many-to-one
                    {
                        DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName());
                        if (tablerel != null && tablerel.getType().name() == "ManyToOne") //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();

                            if (compareMe.getName().equals(parentName)) {
                                return parentObject;
                            }
                            // else check if the xml fiel is there,
                            // if so run it
                            // otherwise make a generic thing
                            // some things cant be generic
                            // also check the order of how buildsampledb does it ^.^
                            // a generic map
                            // get the classtype
                            /*
                             * if(compareMe.getName() == "deaccessionPreparation"){ String className =
                             * tablerel.getClassName().substring(29).toLowerCase();//strip working
                             * set Object tableObject2 = genericDBObject2(className, num); return
                             * tableObject2; }
                             */// else{
                                // if(compareMe.getName() == "referenceWork"){File path = new
                                // File(importFolderPath+"ReferenceWork"+".xml");
                            try {// if a generic exsists
                                File path = new File(
                                        importFolderPath + capFirstChar(compareMe.getName()) + "Generic.xml"); //$NON-NLS-1$
                                Element dbImport2 = XMLHelper.readFileToDOM4J(path);
                                Object tableObject = dynamicXMLImportRecReturn(dbImport2,
                                        capFirstChar(compareMe.getName()));
                                return tableObject;
                            } catch (FileNotFoundException e) {
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, e);
                                // normal
                                String className = tablerel.getClassName().substring(29).toLowerCase();// strip working set
                                Object tableObject = genericDBObject2(className, num);
                                return tableObject;
                            }
                            // }else{
                            /*
                             * Element dbImport = XMLHelper.readFileToDOM4J(path); Object
                             * tableObject = dynamicXMLImportRecReturn(dbImport,
                             * capFirstChar(compareMe.getName())); return tableObject;
                             */
                            // }
                            // check if its a collection (one-to-many)
                        } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$
                                || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$
                        {
                            // if many-to-many
                            if (compareMe.getName().equals(parentName + "s")) {
//$NON-NLS-0$
                                return "ManyToMany"; //$NON-NLS-1$
                            }
                            // else one-to-many
                            return "OneToMany"; //$NON-NLS-1$
                        } else {
                            log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$
                                    + ", with data:" + compareMe.getData()); //$NON-NLS-1$
                        }
                    }
                }
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
                ex.printStackTrace();
            }
            return null;
        }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

    protected Object findTypeSequential(Element compareMe, String dbTable, long parentId, String parentName) {
            try { // get the fieldinfo
                String lowerdbTable = dbTable.toLowerCase();
                DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable);
                /*//from   w  w w.j a v a  2 s.com
                 * List<DBTableIdMgr.FieldInfo> list = info.getFields();
                 * //log.debug(compareMe.getName()); for( DBTableIdMgr.FieldInfo i: list){
                 * System.out.println(i.getName()); }
                 */
                // find element with compareme.getName()
                DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName());
                // if the element is an id, ignore it
                if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$
                {
                    // if it is a normal field
                    if (fieldInfo != null) {
                        String type = fieldInfo.getType();
                        // check the type
                        if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            return compareMe.getStringValue();

                        } else if (type.equals("java.util.Date")) //$NON-NLS-1$
                        {
                            Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$
                                    .getStringValue());
                            return dtTmp;

                        } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$
                        {
                            Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue());
                            return tmstmp;
                        } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$
                        {
                            int num = new Integer(compareMe.getStringValue()).intValue();
                            return num;

                        } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$
                        {
                            Boolean bool = Boolean.valueOf(compareMe.getStringValue());
                            return bool;
                        } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$
                        {
                            BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue());
                            return num;
                        } else if (type.equals("java.lang.Double")) //$NON-NLS-1$
                        {
                            double num = new Double(compareMe.getStringValue()).doubleValue();
                            return num;
                        } else if (type.equals("java.lang.Float")) //$NON-NLS-1$
                        {
                            float num = new Float(compareMe.getStringValue()).floatValue();
                            return num;
                        } else if (type.equals("java.lang.Long")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();
                            return num;
                        } else if (type.equals("java.lang.Short")) //$NON-NLS-1$
                        {
                            short num = new Short(compareMe.getStringValue()).shortValue();
                            return num;
                        } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$
                        {
                            byte num = new Byte(compareMe.getStringValue()).byteValue();
                            return num;
                        } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$
                        {
                            Calendar date = dateString2Calendar(compareMe.getStringValue());
                            return date;
                        }
                    } else
                    // check if it is a many-to-one
                    {
                        DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName());
                        if (tablerel != null && tablerel.getType().name() == "ManyToOne") //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();

                            if (compareMe.getName().equals(lowerFirstChar(parentName)))// if they
                                                                                       // equal, load
                                                                                       // the parent
                                                                                       // from the
                                                                                       // database
                            {
                                String className = tablerel.getClassName().substring(29).toLowerCase();// strip
                                                                                                       // working
                                                                                                       // set
                                Object tableObject = genericDBObject2(className, parentId);
                                return tableObject;
                            }
                            // else check if the xml file is there,
                            // if so run it
                            // otherwise make a generic thing
                            // some things cant be generic
                            // also check the order of how buildsampledb does it ^.^
                            // a generic map
                            // get the classtype
                            /*
                             * if(compareMe.getName() == "deaccessionPreparation"){ String className =
                             * tablerel.getClassName().substring(29).toLowerCase();//strip working
                             * set Object tableObject2 = genericDBObject2(className, num); return
                             * tableObject2; }
                             */// else{
                                // if(compareMe.getName() == "referenceWork"){File path = new
                                // File(importFolderPath+"ReferenceWork"+".xml");
                            try {// if a generic exsists
                                File path = new File(
                                        importFolderPath + capFirstChar(compareMe.getName()) + "Generic.xml"); //$NON-NLS-1$
                                Element dbImport2 = XMLHelper.readFileToDOM4J(path);
                                Object tableObject = dynamicXMLImportRecReturn(dbImport2,
                                        capFirstChar(compareMe.getName()));
                                return tableObject;

                            } catch (FileNotFoundException e) {
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, e);
                                // normal
                                String className = tablerel.getClassName().substring(29).toLowerCase();// strip working set
                                Object tableObject = genericDBObject2(className, num);
                                return tableObject;
                            }
                            // }else{
                            /*
                             * Element dbImport = XMLHelper.readFileToDOM4J(path); Object
                             * tableObject = dynamicXMLImportRecReturn(dbImport,
                             * capFirstChar(compareMe.getName())); return tableObject;
                             */
                            // }
                            // check if its a collection (one-to-many)
                        } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$
                                || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$
                        {
                            // if many-to-many
                            if (compareMe.getName().equals(parentName + "s")) {
//$NON-NLS-0$
                                return "ManyToMany"; //$NON-NLS-1$
                            }
                            // else one-to-many
                            return "OneToMany"; //$NON-NLS-1$
                        } else {
                            log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$
                                    + ", with data:" + compareMe.getData()); //$NON-NLS-1$
                        }
                    }
                }
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
                ex.printStackTrace();
            }
            return null;
        }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

    protected Object findTypeRecordSet(Element compareMe, String dbTable, @SuppressWarnings("unused") long parentId,
                String parentName) {
            try { // get the fieldinfo
                String lowerdbTable = dbTable.toLowerCase();
                DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable);

                // find element with compareme.getName()
                DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName());
                // if the element is an id, ignore it
                // TODO: shouldl check for primary key
                if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$
                {//from  w w  w .ja  va2 s  .  c o  m
                    // if it is a normal field
                    if (fieldInfo != null) {
                        String type = fieldInfo.getType();
                        // check the type
                        if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            return compareMe.getStringValue();

                        } else if (type.equals("java.util.Date")) //$NON-NLS-1$
                        {
                            Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$
                                    .getStringValue());
                            return dtTmp;

                        } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$
                        {
                            Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue());
                            return tmstmp;
                        } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$
                        {
                            int num = new Integer(compareMe.getStringValue()).intValue();
                            return num;

                        } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$
                        {
                            Boolean bool = Boolean.valueOf(compareMe.getStringValue());
                            return bool;
                        } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$
                        {
                            BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue());
                            return num;
                        } else if (type.equals("java.lang.Double")) //$NON-NLS-1$
                        {
                            double num = new Double(compareMe.getStringValue()).doubleValue();
                            return num;
                        } else if (type.equals("java.lang.Float")) //$NON-NLS-1$
                        {
                            float num = new Float(compareMe.getStringValue()).floatValue();
                            return num;
                        } else if (type.equals("java.lang.Long")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();
                            return num;
                        } else if (type.equals("java.lang.Short")) //$NON-NLS-1$
                        {
                            short num = new Short(compareMe.getStringValue()).shortValue();
                            return num;
                        } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$
                        {
                            byte num = new Byte(compareMe.getStringValue()).byteValue();
                            return num;
                        } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$
                        {
                            Calendar date = dateString2Calendar(compareMe.getStringValue());
                            return date;
                        }
                    } else
                    // check if it is a many-to-one
                    {
                        DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName());
                        // check for many to one, and make sure it has a value
                        if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$
                                && !compareMe.getStringValue().equals("")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();

                            String className = tablerel.getClassName().substring(29);// strip working
                                                                                     // set
                                                                                     // TODO: remove this condition for agent
                            if (className.equals("Agent")) //$NON-NLS-1$
                            {
                                className = className.toLowerCase();
                                Object tableObject = genericDBObject2(className, num);
                                return tableObject;
                            }
                            Object tableObject = getParentDBObject(className, num);
                            return tableObject;
                            // check if its a collection (one-to-many)
                        } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$
                                || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$
                        {
                            // if many-to-many
                            if (compareMe.getName().equals(parentName + "s")) {
//$NON-NLS-0$
                                return "ManyToMany"; //$NON-NLS-1$
                            }
                            // else one-to-many
                            return "OneToMany"; //$NON-NLS-1$
                        } else {
                            log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$
                                    + ", with data:" + compareMe.getData()); //$NON-NLS-1$
                        }
                    }
                }
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
                if (ex.toString().startsWith("java.lang.NumberFormatException")) {
//$NON-NLS-0$
                    return null;
                }
                // else
                ex.printStackTrace();
            }
            return null;
        }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

    protected Object findTypeDataBase(Element compareMe, String dbTable, @SuppressWarnings("unused") long parentId,
                String parentName) {
            try { // get the fieldinfo
                String lowerdbTable = dbTable.toLowerCase();
                DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable);

                // find element with compareme.getName()
                DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName());
                // if the element is an id, ignore it
                // TODO: shouldl check for primary key
                if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$
                {//from  w ww .j  a va  2 s  . c om
                    // if it is a normal field
                    if (fieldInfo != null) {
                        String type = fieldInfo.getType();
                        // check the type
                        if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            return compareMe.getStringValue();

                        } else if (type.equals("java.util.Date")) //$NON-NLS-1$
                        {
                            Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$
                                    .getStringValue());
                            return dtTmp;

                        } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$
                        {
                            Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue());
                            return tmstmp;
                        } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$
                        {
                            int num = new Integer(compareMe.getStringValue()).intValue();
                            return num;

                        } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$
                        {
                            Boolean bool = Boolean.valueOf(compareMe.getStringValue());
                            return bool;
                        } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$
                        {
                            BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue());
                            return num;
                        } else if (type.equals("java.lang.Double")) //$NON-NLS-1$
                        {
                            double num = new Double(compareMe.getStringValue()).doubleValue();
                            return num;
                        } else if (type.equals("java.lang.Float")) //$NON-NLS-1$
                        {
                            float num = new Float(compareMe.getStringValue()).floatValue();
                            return num;
                        } else if (type.equals("java.lang.Long")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();
                            return num;
                        } else if (type.equals("java.lang.Short")) //$NON-NLS-1$
                        {
                            short num = new Short(compareMe.getStringValue()).shortValue();
                            return num;
                        } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$
                        {
                            byte num = new Byte(compareMe.getStringValue()).byteValue();
                            return num;
                        } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$
                        {
                            Calendar date = dateString2Calendar(compareMe.getStringValue());
                            return date;
                        }
                    } else
                    // check if it is a many-to-one
                    {
                        DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName());
                        // check for many to one, and make sure it has a value
                        if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$
                                && !compareMe.getStringValue().equals("")) //$NON-NLS-1$
                        {
                            long num = new Long(compareMe.getStringValue()).longValue();

                            String className = tablerel.getClassName().substring(29);// strip working
                                                                                     // set
                                                                                     // TODO: remove this condition for agent
                            if (className.equals("Agent")) //$NON-NLS-1$
                            {
                                className = className.toLowerCase();
                                Object tableObject = genericDBObject2(className, num);
                                return tableObject;
                            } else {
                                Object tableObject = loadOrCreateParentDataBaseObject(className, num);
                                return tableObject;
                            }
                            // check if its a collection (one-to-many)
                        } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$
                                || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$
                        {
                            // if many-to-many
                            if (compareMe.getName().equals(parentName + "s")) {
//$NON-NLS-0$
                                return "ManyToMany"; //$NON-NLS-1$
                            }
                            // else one-to-many
                            return "OneToMany"; //$NON-NLS-1$
                        } else {
                            log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$
                                    + ", with data:" + compareMe.getData()); //$NON-NLS-1$
                        }
                    }
                }
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
                if (ex.toString().startsWith("java.lang.NumberFormatException")) {
//$NON-NLS-0$
                    return null;
                }
                // else
                ex.printStackTrace();
            }
            return null;
        }

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

License:Open Source License

    protected Object findTypeDataBaseParent(Element compareMe, String dbTable,
                @SuppressWarnings("unused") long parentId, String parentName) {
            try { // get the fieldinfo
                String lowerdbTable = dbTable.toLowerCase();
                DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable);
                String primaryKey = info.getPrimaryKeyName();

                // find element with compareme.getName()
                DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName());
                // if the element is an id, ignore it

                // if( !compareMe.getName().equals( lowerFirstChar(dbTable) + "Id") )
                // {
                // if(!primaryKey.equals(compareMe.getName()))
                // {
                // if it is a normal field
                if (fieldInfo != null || primaryKey.equals(compareMe.getName()))
                // if(fieldInfo != null )
                {/*w w  w.  ja  va 2  s .c o m*/
                    String type = new String();
                    if (fieldInfo == null) {// it is an id
                        type = "java.lang.Integer"; //$NON-NLS-1$
                        System.out.println(compareMe.getStringValue());
                    } else {
                        type = fieldInfo.getType();
                    }

                    // check the type
                    if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$
                    {
                        return compareMe.getStringValue();

                    } else if (type.equals("java.util.Date")) //$NON-NLS-1$
                    {
                        Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$
                                .getStringValue());
                        return dtTmp;

                    } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$
                    {
                        Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue());
                        return tmstmp;
                    } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$
                    {
                        int num = new Integer(compareMe.getStringValue()).intValue();
                        return num;

                    } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$
                    {
                        Boolean bool = Boolean.valueOf(compareMe.getStringValue());
                        return bool;
                    } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$
                    {
                        BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue());
                        return num;
                    } else if (type.equals("java.lang.Double")) //$NON-NLS-1$
                    {
                        double num = new Double(compareMe.getStringValue()).doubleValue();
                        return num;
                    } else if (type.equals("java.lang.Float")) //$NON-NLS-1$
                    {
                        float num = new Float(compareMe.getStringValue()).floatValue();
                        return num;
                    } else if (type.equals("java.lang.Long")) //$NON-NLS-1$
                    {
                        long num = new Long(compareMe.getStringValue()).longValue();
                        return num;
                    } else if (type.equals("java.lang.Short")) //$NON-NLS-1$
                    {
                        short num = new Short(compareMe.getStringValue()).shortValue();
                        return num;
                    } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$
                    {
                        byte num = new Byte(compareMe.getStringValue()).byteValue();
                        return num;
                    } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$
                    {
                        Calendar date = dateString2Calendar(compareMe.getStringValue());
                        return date;
                    }
                } else
                // check if it is a many-to-one
                {
                    DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName());
                    // check for many to one, and make sure it has a value
                    if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$
                            && !compareMe.getStringValue().equals("")) //$NON-NLS-1$
                    {
                        long num = new Long(compareMe.getStringValue()).longValue();

                        String className = tablerel.getClassName().substring(29);// strip working set
                        // TODO: remove this condition for agent
                        if (className.equals("Agent")) //$NON-NLS-1$
                        {
                            className = className.toLowerCase();
                            Object tableObject = genericDBObject2(className, num);
                            return tableObject;
                        } else {
                            Object tableObject = loadOrCreateParentDataBaseObject(className, num);
                            return tableObject;
                        }
                        // check if its a collection (one-to-many)
                    } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$
                            || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$
                    {
                        // if many-to-many
                        if (compareMe.getName().equals(parentName + "s")) {
//$NON-NLS-0$
                            return "ManyToMany"; //$NON-NLS-1$
                        }
                        // else one-to-many
                        return "OneToMany"; //$NON-NLS-1$
                    } else {
                        log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$
                                + ", with data:" + compareMe.getData()); //$NON-NLS-1$
                    }
                }
                // }
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
                if (ex.toString().startsWith("java.lang.NumberFormatException")) {
//$NON-NLS-0$
                    return null;
                }
                // else
                ex.printStackTrace();
            }
            return null;
        }

From source file:edu.wustl.geneconnect.bizlogic.AbstractBizLogicFactory.java

License:BSD License

/**
 * This method updates module map by parsing xml file
 * @param xmlFileName file to be parsed//from  ww w.j a v  a2  s  .c om
 * @return  moduleMap Map
 */
public final Map updateModuleMap(String xmlFileName) {
    Map moduleMap = new HashMap();
    SAXReader saxReader = new SAXReader();
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(xmlFileName);
    Document document = null;

    try {

        document = saxReader.read(inputStream);
        Element businessLogics = document.getRootElement();
        Iterator businessLogicIterator = businessLogics
                .elementIterator(GCConstants.BUSINESS_LOGIC_ELEMENT_ITERATOR);
        Element businessLogic = null;
        Element businessAction = null;
        Element instanceType = null;
        String instanceTypeString = null;
        String businessActionString = null;
        /**
         * Iterate over bizlogic.xml file and find the class ned to instantiate and return it.
         */
        while (businessLogicIterator.hasNext()) {
            try {
                businessLogic = (Element) businessLogicIterator.next();
                businessAction = businessLogic.element(GCConstants.BUSINESS_ACTION_ELEMENT);
                instanceType = businessLogic.element(GCConstants.INSTANCE_TYPE_ELEMENT);
                //               moduleMap.put(businessAction.getStringValue(), Class.forName(
                //                     instanceType.getStringValue()).newInstance());
                moduleMap.put(businessAction.getStringValue(), instanceType.getStringValue());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (DocumentException e) {
        throw new GCRuntimeException(e);
    } catch (Exception e) {
        throw new GCRuntimeException(e);
    }
    return moduleMap;
}

From source file:eu.scape_project.planning.xml.ProjectExportAction.java

License:Apache License

/**
 * Returns a list of object IDs that are stored in the document without
 * binary data./*from   ww  w  .  j av  a 2s. c o m*/
 * 
 * @param doc
 *            the document to search
 * @return a list of IDs
 */
private List<Integer> getBinaryObjectIds(Document doc) {

    // Get data elements that have data and a number as content
    XPath xpath = doc.createXPath("//plato:data[@hasData='true' and number(.) = number(.)]");

    Map<String, String> namespaceMap = new HashMap<String, String>();
    namespaceMap.put("plato", PlanXMLConstants.PLATO_NS);
    xpath.setNamespaceURIs(namespaceMap);

    @SuppressWarnings("unchecked")
    List<Element> elements = xpath.selectNodes(doc);

    List<Integer> objectIds = new ArrayList<Integer>(elements.size());
    for (Element element : elements) {
        objectIds.add(Integer.parseInt(element.getStringValue()));
    }
    return objectIds;
}