Search in sources :

Example 1 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class ACSCategoryDAOImpl method flushCategories.

public void flushCategories(Categories cats) {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    if (cats == null)
        throw new IllegalArgumentException("Null Categories argument");
    StringWriter FFWriter = new StringWriter();
    Marshaller FF_marshaller;
    try {
        FF_marshaller = new Marshaller(FFWriter);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    FF_marshaller.setValidation(false);
    try {
        FF_marshaller.marshal(cats);
    } catch (MarshalException e) {
        e.printStackTrace();
        return;
    } catch (ValidationException e) {
        e.printStackTrace();
        return;
    }
    try {
        conf.deleteConfiguration(CATEGORY_DEFINITION_PATH);
        conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
    } catch (org.omg.CORBA.UNKNOWN e) {
        try {
            conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } catch (CDBXMLErrorEx e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException("Category already exists");
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) IOException(java.io.IOException) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException)

Example 2 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class JNDIContext method lookup.

/**
	 * @see Context#lookup(Name)
	 * THIS IS OLD CDB implementation
	public Object lookup(Name name) throws NamingException {
		//System.out.println("CDBContext lookup on " + this.name + " for " + name.toString());
		String nameToLookup = this.name + "/" + name;
		String recordName = nameToLookup.substring(nameToLookup.lastIndexOf('/')+1);
		// get list from the server 
		String elements = dal.list_nodes(nameToLookup);
		try {
			if (elements.indexOf(recordName + ".xml") != -1) {
				String xml = dal.get_DAO(nameToLookup);
				return new JNDIXMLContext(nameToLookup, elements, xml);
			} else {
				if (elements.length() == 0 ) { // inside a XML?
					int slashIndex = nameToLookup.lastIndexOf('/');
					String newName;
					while( slashIndex != -1 ) {
						newName = nameToLookup.substring(0,slashIndex);
						recordName = newName.substring(newName.lastIndexOf('/')+1);
						elements = dal.list_nodes(newName);
						if (elements.indexOf(recordName + ".xml") != -1) {
							String xml = dal.get_DAO(newName);
							recordName = nameToLookup.substring(slashIndex+1);
							return new JNDIXMLContext(newName, elements, xml).lookup(recordName);
						}
						slashIndex = newName.lastIndexOf('/');
					}
					throw new NamingException("No name " + nameToLookup );
				}
				return new JNDIContext(nameToLookup, elements);
			}
		} catch (CDBRecordDoesNotExistEx e) {
			// if it does not exists then it is just a context
			return new JNDIContext(nameToLookup, elements);
		} catch (CDBXMLErrorEx e) {
			AcsJCDBXMLErrorEx acse = new AcsJCDBXMLErrorEx(e);
			throw new NamingException(acse.getFilename());
		}
	}*/
/**
     * This methos returns either a new JNDI_Context or a new JNDI_XMLContxt obj.
     */
public Object lookup(Name name) throws NamingException {
    final String lookupName = name.toString();
    final String fullLookupName = this.name + "/" + lookupName;
    String daoElements = dal.list_daos(fullLookupName);
    if (daoElements.length() == 0)
        daoElements = null;
    // is subnode
    StringTokenizer token = new StringTokenizer(elements);
    while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
        // is DAO?
        if (daoElements != null) {
            try {
                return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        } else
            return new JNDIContext(fullLookupName, dal.list_nodes(fullLookupName), logger);
    }
    if (daoElements != null) {
        // lookup in DAO
        token = new StringTokenizer(daoElements);
        while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
            try {
                return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        }
    }
    // not found
    throw new NamingException("No name " + fullLookupName);
}
Also used : StringTokenizer(java.util.StringTokenizer) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) NamingException(javax.naming.NamingException)

Example 3 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class WDALImpl method parseXML.

private void parseXML(String xml, XMLHandler xmlSolver) throws CDBXMLErrorEx {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
            logger.log(AcsLogLevel.NOTICE, info);
            throw xmlErr;
        }
    } catch (Throwable t) {
        String info = "SAXException " + t;
        CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
        logger.log(AcsLogLevel.NOTICE, info);
        throw xmlErr;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 4 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class BrowserJNDIContext method lookup.

/**
     * This methos returns either a new JNDI_Context or a new JNDI_XMLContxt obj.
     */
public Object lookup(Name name) throws NamingException {
    final String lookupName = name.toString();
    final String fullLookupName = this.name + "/" + lookupName;
    String daoElements = dal.list_daos(fullLookupName);
    if (daoElements.length() == 0)
        daoElements = null;
    // @todo TODO this creates DAO and wastes some of resources... DAL method to get resources would be nice
    boolean hasAttributes = false;
    try {
        // NOTE check only if needed
        if (daoElements == null)
            hasAttributes = dal.get_DAO_Servant(fullLookupName).get_string("_attributes").trim().length() > 0;
    } catch (Throwable th) {
    // noop
    }
    CDBLogic.setKey(fullLookupName);
    // is subnode
    StringTokenizer token = new StringTokenizer(elements);
    while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
        // is DAO?
        if (daoElements != null || hasAttributes) {
            try {
                return new BrowserJNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        } else
            return new BrowserJNDIContext(fullLookupName, dal.list_nodes(fullLookupName), logger);
    }
    if (daoElements != null) {
        // lookup in DAO
        token = new StringTokenizer(daoElements);
        while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
            try {
                return new BrowserJNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        }
    }
    // not found
    throw new NamingException("No name " + fullLookupName);
}
Also used : StringTokenizer(java.util.StringTokenizer) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) NamingException(javax.naming.NamingException)

Example 5 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class CDBDefault method setDefault.

/**
     * Recursively go throw the xml finding nodes with the same Type. If the type match,
     * compares the Name. If is the same name, sets the Default=true, in the other case
     * sets the Default attribute to false.
     * @param node_root the root of all components xml .
     * @param in_type  the type of the component.
     * @param in_name the name of the component to set up default.
     *                             
     */
public static void setDefault(XMLTreeNode node_root, String in_type, String in_name) {
    try {
        Iterator<String> nodesIter = node_root.getNodesMap().keySet().iterator();
        WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
        while (nodesIter.hasNext()) {
            String key = nodesIter.next();
            XMLTreeNode node = node_root.getNodesMap().get(key);
            String name = node.getFieldMap().get("Name");
            String type = node.getFieldMap().get("Type");
            String isDefault = node.getFieldMap().get("Default");
            String strTrue = "true";
            if (in_type.equals(type)) {
                if (strTrue.equals(isDefault)) {
                    if (in_name.equals(name))
                        return;
                    else {
                        //write Default = false
                        try {
                            //System.out.println("1-"+curl_allComponents+"\t"+name);
                            WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
                            wdao.set_string(name + "/Default", "false");
                        } catch (Exception e) {
                            //System.out.println("2-"+curl_allComponents+ "/" + name);
                            WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents + "/" + name);
                            wdao.set_string("Default", "false");
                        }
                    }
                } else if (in_name.equals(name)) {
                    //						write Default = true
                    try {
                        //System.out.println("3-"+curl_allComponents+ "\t" + name);
                        WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
                        wdao.set_string(name + "/Default", "true");
                    } catch (Exception e) {
                        //System.out.println("4-"+curl);
                        WDAO wdao = wdal.get_WDAO_Servant(curl);
                        wdao.set_string("Default", "true");
                    }
                }
            }
            XMLTreeNode value = node_root.getNodesMap().get(key);
            setDefault(value, in_type, in_name);
        }
    } catch (CDBXMLErrorEx e) {
        m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
        e.printStackTrace();
    } catch (Exception e) {
        m_logger.log(AcsLogLevel.NOTICE, "Error", e);
        e.printStackTrace();
    }
}
Also used : WDAL(com.cosylab.CDB.WDAL) WDAO(com.cosylab.CDB.WDAO) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) XMLTreeNode(com.cosylab.cdb.jdal.XMLTreeNode)

Aggregations

CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)10 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)8 StringReader (java.io.StringReader)3 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 WDAO (com.cosylab.CDB.WDAO)2 StringWriter (java.io.StringWriter)2 StringTokenizer (java.util.StringTokenizer)2 NamingException (javax.naming.NamingException)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 InputSource (org.xml.sax.InputSource)2 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)1 NamedLogger (alma.maci.loggingconfig.NamedLogger)1 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)1 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)1 WDAL (com.cosylab.CDB.WDAL)1 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)1 XMLTreeNode (com.cosylab.cdb.jdal.XMLTreeNode)1 IOException (java.io.IOException)1