List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR
String LINE_SEPARATOR
To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.
Click Source Link
The line.separator
System Property.
From source file:org.apache.ojb.broker.metadata.FieldDescriptor.java
public String toXML() { RepositoryTags tags = RepositoryTags.getInstance(); String eol = SystemUtils.LINE_SEPARATOR; //opening tag + attributes StringBuffer result = new StringBuffer(1024); result.append(" "); result.append(tags.getOpeningTagNonClosingById(FIELD_DESCRIPTOR)); result.append(" "); result.append(eol);// w w w . ja v a 2s . com // // id // String id = new Integer(getColNo()).toString(); // result += /*" " +*/ tags.getAttribute(ID, id) + eol; // name result.append(" "); result.append(tags.getAttribute(FIELD_NAME, this.getAttributeName())); result.append(eol); // table not yet implemented // column result.append(" "); result.append(tags.getAttribute(COLUMN_NAME, this.getColumnName())); result.append(eol); // jdbc-type result.append(" "); result.append(tags.getAttribute(JDBC_TYPE, this.getColumnType())); result.append(eol); // primarykey if (this.isPrimaryKey()) { result.append(" "); result.append(tags.getAttribute(PRIMARY_KEY, "true")); result.append(eol); } // nullable if (this.isRequired()) { result.append(" "); result.append(tags.getAttribute(NULLABLE, "false")); result.append(eol); } // indexed not yet implemented // autoincrement if (this.isAutoIncrement()) { result.append(" "); result.append(tags.getAttribute(AUTO_INCREMENT, "true")); result.append(eol); } // locking if (this.isLocking()) { result.append(" "); result.append(tags.getAttribute(LOCKING, "true")); result.append(eol); } // updateLock // default is true so only write if false if (!this.isUpdateLock()) { result.append(" "); result.append(tags.getAttribute(UPDATE_LOCK, "false")); result.append(eol); } // default-fetch not yet implemented // conversion if (this.getFieldConversion().getClass() != FieldConversionDefaultImpl.class) { result.append(" "); result.append(tags.getAttribute(FIELD_CONVERSION, getFieldConversion().getClass().getName())); result.append(eol); } // length if (this.isLengthSpecified()) { result.append(" "); result.append(tags.getAttribute(LENGTH, "" + getLength())); result.append(eol); } // precision if (this.isPrecisionSpecified()) { result.append(" "); result.append(tags.getAttribute(PRECISION, "" + getPrecision())); result.append(eol); } // scale if (this.isScaleSpecified()) { result.append(" "); result.append(tags.getAttribute(SCALE, "" + getScale())); result.append(eol); } // access result.append(" "); result.append(tags.getAttribute(ACCESS, this.getAccess())); result.append(eol); result.append(" />"); result.append(eol); return result.toString(); }
From source file:org.apache.ojb.broker.metadata.IndexDescriptor.java
public String toXML() { RepositoryTags tags = RepositoryTags.getInstance(); String eol = SystemUtils.LINE_SEPARATOR; //opening tag + attributes StringBuffer result = new StringBuffer(1024); result.append(" <"); result.append(tags.getTagById(INDEX_DESCRIPTOR)); result.append(" "); // index name result.append(tags.getAttribute(NAME, getName())); result.append(" "); // unique attribute result.append(tags.getAttribute(UNIQUE, "" + isUnique())); result.append(">"); result.append(eol);//from www. ja v a2 s.c o m // index columns for (int i = 0; i < indexColumns.size(); i++) { String l_name = (String) indexColumns.elementAt(i); result.append(" "); result.append(tags.getOpeningTagNonClosingById(INDEX_COLUMN)); result.append(" "); result.append(tags.getAttribute(NAME, l_name)); result.append(" />"); result.append(eol); } // closing tag result.append(" "); result.append(tags.getClosingTagById(INDEX_DESCRIPTOR)); result.append(" "); result.append(eol); return result.toString(); }
From source file:org.apache.ojb.broker.metadata.JdbcConnectionDescriptor.java
public String toXML() { RepositoryTags tags = RepositoryTags.getInstance(); String eol = SystemUtils.LINE_SEPARATOR; StringBuffer strReturn = new StringBuffer(1024); strReturn.append(eol);/* w w w. j a v a 2 s.c o m*/ strReturn.append(" <!-- Descriptor for Connection "); strReturn.append(getProtocol()); strReturn.append(":"); strReturn.append(getSubProtocol()); strReturn.append(":"); strReturn.append(getDbAlias()); strReturn.append(" -->"); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getOpeningTagNonClosingById(JDBC_CONNECTION_DESCRIPTOR)); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(JCD_ALIAS, this.getJcdAlias())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(DEFAULT_CONNECTION, "" + this.isDefaultConnection())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(DBMS_NAME, this.getDbms())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(JDBC_LEVEL, "" + this.getJdbcLevel())); strReturn.append(eol); //username is optional String user = getUserName(); if (user != null) { strReturn.append(" "); strReturn.append(tags.getAttribute(USER_NAME, user)); strReturn.append(eol); } // password is optional String passwd = getPassWord(); if (passwd != null) { strReturn.append(" "); strReturn.append(tags.getAttribute(USER_PASSWD, passwd)); strReturn.append(eol); } // JDBC Datasource or DriverManager information are alternatives: String dsn = getDatasourceName(); if (dsn != null) { strReturn.append(" "); strReturn.append(tags.getAttribute(DATASOURCE_NAME, this.getDatasourceName())); strReturn.append(eol); } else { strReturn.append(" "); strReturn.append(tags.getAttribute(DRIVER_NAME, this.getDriver())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(URL_PROTOCOL, this.getProtocol())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(URL_SUBPROTOCOL, this.getSubProtocol())); strReturn.append(eol); strReturn.append(" "); strReturn.append(encode(tags.getAttribute(URL_DBALIAS, this.getDbAlias()))); strReturn.append(eol); } strReturn.append(" "); strReturn.append(tags.getAttribute(EAGER_RELEASE, "" + this.getEagerRelease())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(BATCH_MODE, "" + this.getBatchMode())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(USE_AUTOCOMMIT, "" + this.getUseAutoCommit())); strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getAttribute(IGNORE_AUTOCOMMIT_EXCEPTION, "" + this.isIgnoreAutoCommitExceptions())); strReturn.append(eol); strReturn.append(" >"); strReturn.append(eol); strReturn.append(eol); strReturn.append(this.getConnectionPoolDescriptor().toXML()); strReturn.append(eol); if (this.getSequenceDescriptor() != null) { strReturn.append(this.getSequenceDescriptor().toXML()); } strReturn.append(eol); strReturn.append(" "); strReturn.append(tags.getClosingTagById(JDBC_CONNECTION_DESCRIPTOR)); strReturn.append(eol); return strReturn.toString(); }
From source file:org.apache.ojb.broker.metadata.ObjectCacheDescriptor.java
public String toXML() { RepositoryTags tags = RepositoryTags.getInstance(); String eol = SystemUtils.LINE_SEPARATOR; StringBuffer buf = new StringBuffer(1024); //opening tag + attributes buf.append(" "); buf.append(tags.getOpeningTagNonClosingById(OBJECT_CACHE)); buf.append(eol);/* ww w . j av a2 s.com*/ buf.append(" "); buf.append(tags.getAttribute(CLASS_NAME, "" + getObjectCache() != null ? getObjectCache().getName() : "")); buf.append(" >"); buf.append(eol); buf.append(" <!-- "); buf.append(eol); buf.append(" Add proprietary ObjectCache implementation properties here, using custom attributes"); buf.append(eol); buf.append(" e.g. <attribute attribute-name=\"timeout\" attribute-value=\"2000\"/>"); buf.append(eol); buf.append(" -->"); buf.append(eol); XmlHelper.appendSerializedAttributes(buf, " ", getConfigurationProperties()); buf.append(" "); buf.append(tags.getClosingTagById(OBJECT_CACHE)); buf.append(eol); return buf.toString(); }
From source file:org.apache.ojb.broker.metadata.RepositoryPersistor.java
/** * Write the {@link DescriptorRepository} to the given output object. *///www . j a v a 2 s .co m public void writeToFile(DescriptorRepository repository, ConnectionRepository conRepository, OutputStream out) { RepositoryTags tags = RepositoryTags.getInstance(); try { if (log.isDebugEnabled()) log.debug("## Write repository file ##" + repository.toXML() + "## End of repository file ##"); String eol = SystemUtils.LINE_SEPARATOR; StringBuffer buf = new StringBuffer(); // 1. write XML header buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + eol); buf.append("<!DOCTYPE descriptor-repository SYSTEM \"repository.dtd\" >" + eol + eol); // strReturn += "<!DOCTYPE descriptor-repository SYSTEM \"repository.dtd\" [" + eol; // strReturn += "<!ENTITY database-metadata SYSTEM \""+ConnectionRepository.DATABASE_METADATA_FILENAME+"\">" + eol; // strReturn += "<!ENTITY user SYSTEM \"repository_user.xml\">" + eol; // strReturn += "<!ENTITY junit SYSTEM \"repository_junit.xml\">" + eol; // strReturn += "<!ENTITY internal SYSTEM \"repository_internal.xml\"> ]>" + eol + eol; buf.append( "<!-- OJB RepositoryPersistor generated this file on " + new Date().toString() + " -->" + eol); buf.append(tags.getOpeningTagNonClosingById(RepositoryElements.MAPPING_REPOSITORY) + eol); buf.append(" " + tags.getAttribute(RepositoryElements.REPOSITORY_VERSION, DescriptorRepository.getVersion()) + eol); buf.append(" " + tags.getAttribute(RepositoryElements.ISOLATION_LEVEL, repository.getIsolationLevelAsString()) + eol); buf.append(">" + eol); if (conRepository != null) buf.append(eol + eol + conRepository.toXML() + eol + eol); if (repository != null) buf.append(repository.toXML()); buf.append(tags.getClosingTagById(RepositoryElements.MAPPING_REPOSITORY)); PrintWriter pw = new PrintWriter(out); pw.print(buf.toString()); pw.flush(); pw.close(); } catch (Exception e) { log.error("Could not write to output stream" + out, e); } }
From source file:org.apache.ojb.broker.metadata.SequenceDescriptor.java
public String toXML() { RepositoryTags tags = RepositoryTags.getInstance(); String eol = SystemUtils.LINE_SEPARATOR; StringBuffer buf = new StringBuffer(1024); //opening tag + attributes buf.append(" "); buf.append(tags.getOpeningTagNonClosingById(SEQUENCE_MANAGER)); buf.append(eol);//www . j ava2 s.com buf.append(" "); buf.append(tags.getAttribute(SEQUENCE_MANAGER_CLASS, "" + getSequenceManagerClass().getName())); buf.append(" >"); buf.append(eol); buf.append(" <!-- "); buf.append(eol); buf.append(" Add sequence manger properties here, using custom attributes"); buf.append(eol); buf.append(" e.g. <attribute attribute-name=\"grabSize\" attribute-value=\"20\"/>"); buf.append(eol); buf.append(" -->"); buf.append(eol); XmlHelper.appendSerializedAttributes(buf, " ", getConfigurationProperties()); buf.append(" "); buf.append(tags.getClosingTagById(SEQUENCE_MANAGER)); buf.append(eol); return buf.toString(); }
From source file:org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory.java
/** * @see org.apache.ojb.broker.transaction.tm.TransactionManagerFactory *//*from www. ja v a 2s .co m*/ public synchronized TransactionManager getTransactionManager() throws TransactionManagerFactoryException { if (tm == null) { StringBuffer msg = new StringBuffer(); String[][] lookupInfo = getLookupInfo(); String EOL = SystemUtils.LINE_SEPARATOR; for (int i = 0; i < lookupInfo.length; i++) { String description = lookupInfo[i][0]; String methodName = lookupInfo[i][1]; String className = lookupInfo[i][2]; try { if (className == null) { tm = jndiLookup(description, methodName); } else { tm = instantiateClass(description, className, methodName); } msg.append("Successfully requested TM for " + description + EOL); } catch (Exception e) { if (className == null) msg.append("Error on TM request for " + description + ", using jndi-lookup '" + methodName + "'" + EOL + e.getMessage() + EOL); else msg.append("Error on TM request for " + description + ", using method '" + methodName + "' for class '" + className + "'" + EOL + e.getMessage() + EOL); } if (tm != null) break; } // if we don't get an TM instance throw exception if (tm == null) { throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg); } } return tm; }
From source file:org.apache.ojb.broker.util.ExceptionHelper.java
/** * Method which support the conversion of {@link java.sql.SQLException} to * OJB's runtime exception (with additional message details). * * @param message The error message to use, if <em>null</em> a standard message is used. * @param ex The exception to convert (mandatory). * @param sql The used sql-statement or <em>null</em>. * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target object or <em>null</em>. * @param values The values set in prepared statement or <em>null</em>. * @param logger The {@link org.apache.ojb.broker.util.logging.Logger} to log an detailed message * to the specified {@link org.apache.ojb.broker.util.logging.Logger} or <em>null</em> to skip logging message. * @param obj The target object or <em>null</em>. * @return A new created {@link org.apache.ojb.broker.PersistenceBrokerSQLException} based on the specified * arguments./*from w ww. ja va 2 s . c o m*/ */ public static PersistenceBrokerSQLException generateException(String message, SQLException ex, String sql, ClassDescriptor cld, ValueContainer[] values, Logger logger, Object obj) { /* X/OPEN codes within class 23: 23000 INTEGRITY CONSTRAINT VIOLATION 23001 RESTRICT VIOLATION 23502 NOT NULL VIOLATION 23503 FOREIGN KEY VIOLATION 23505 UNIQUE VIOLATION 23514 CHECK VIOLATION */ String eol = SystemUtils.LINE_SEPARATOR; StringBuffer msg = new StringBuffer(eol); eol += "* "; if (ex instanceof BatchUpdateException) { BatchUpdateException tmp = (BatchUpdateException) ex; if (message != null) { msg.append("* ").append(message); } else { msg.append("* BatchUpdateException during execution of sql-statement:"); } msg.append(eol).append("Batch update count is '").append(tmp.getUpdateCounts()).append("'"); } else if (ex instanceof SQLWarning) { if (message != null) { msg.append("* ").append(message); } else { msg.append("* SQLWarning during execution of sql-statement:"); } } else { if (message != null) { msg.append("* ").append(message); } else { msg.append("* SQLException during execution of sql-statement:"); } } if (sql != null) { msg.append(eol).append("sql statement was '").append(sql).append("'"); } String stateCode = null; if (ex != null) { msg.append(eol).append("Exception message is [").append(ex.getMessage()).append("]"); msg.append(eol).append("Vendor error code [").append(ex.getErrorCode()).append("]"); msg.append(eol).append("SQL state code ["); stateCode = ex.getSQLState(); if ("23000".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=INTEGRITY CONSTRAINT VIOLATION"); else if ("23001".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=RESTRICT VIOLATION"); else if ("23502".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=NOT NULL VIOLATION"); else if ("23503".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=FOREIGN KEY VIOLATION"); else if ("23505".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=UNIQUE VIOLATION"); else if ("23514".equalsIgnoreCase(stateCode)) msg.append(stateCode).append("=CHECK VIOLATION"); else msg.append(stateCode); msg.append("]"); } if (cld != null) { msg.append(eol).append("Target class is '").append(cld.getClassNameOfObject()).append("'"); FieldDescriptor[] fields = cld.getPkFields(); msg.append(eol).append("PK of the target object is ["); for (int i = 0; i < fields.length; i++) { try { if (i > 0) msg.append(", "); msg.append(fields[i].getPersistentField().getName()); if (obj != null) { msg.append("="); msg.append(fields[i].getPersistentField().get(obj)); } } catch (Exception ignore) { msg.append(" PK field build FAILED! "); } } msg.append("]"); } if (values != null) { msg.append(eol).append(values.length).append(" values performed in statement: ").append(eol); for (int i = 0; i < values.length; i++) { ValueContainer value = values[i]; msg.append("["); msg.append("jdbcType=").append(JdbcTypesHelper.getSqlTypeAsString(value.getJdbcType().getType())); msg.append(", value=").append(value.getValue()); msg.append("]"); } } if (obj != null) { msg.append(eol).append("Source object: "); try { msg.append(obj.toString()); } catch (Exception e) { msg.append(obj.getClass()); } } // message string for PB exception String shortMsg = msg.toString(); if (ex != null) { // add causing stack trace Throwable rootCause = ExceptionUtils.getRootCause(ex); if (rootCause == null) rootCause = ex; msg.append(eol).append("The root stack trace is --> "); String rootStack = ExceptionUtils.getStackTrace(rootCause); msg.append(eol).append(rootStack); } msg.append(SystemUtils.LINE_SEPARATOR).append("**"); // log error message if (logger != null) logger.error(msg.toString()); // throw a specific type of runtime exception for a key constraint. if ("23000".equals(stateCode) || "23505".equals(stateCode)) { throw new KeyConstraintViolatedException(shortMsg, ex); } else { throw new PersistenceBrokerSQLException(shortMsg, ex); } }
From source file:org.apache.ojb.broker.util.factory.ConfigurableFactory.java
protected String buildArgumentString(Class[] types, Object[] args) { StringBuffer buf = new StringBuffer(); String eol = SystemUtils.LINE_SEPARATOR; buf.append(eol + "* Factory types: "); if (types != null) { for (int i = 0; i < types.length; i++) { Class type = types[i]; buf.append(eol + (i + 1) + " - Type: " + (type != null ? type.getName() : null)); }//from w ww . j a v a 2 s .co m } else buf.append(eol + "none"); buf.append(eol + "* Factory arguments: "); if (args != null) { for (int i = 0; i < args.length; i++) { Object obj = args[i]; buf.append(eol + (i + 1) + " - Argument: " + obj); } } else buf.append(eol + "none"); return buf.toString(); }
From source file:org.apache.ojb.broker.util.logging.LoggerFactoryImpl.java
/** * * @param forceError//www .jav a 2 s . c om */ protected synchronized void reassignBootLogger(boolean forceError) { // if the boot logger was already reassigned do nothing if (!bootLoggerIsReassigned) { Logger newBootLogger = null; String name = getBootLogger().getName(); try { // 1. try to use a Logger instance based on the configuration files newBootLogger = createLoggerInstance(name); } catch (Exception e) { /*ignore*/} if (newBootLogger == null) { // 2. if no logging library can be found, use OJB's console logger newBootLogger = createPoorMansLogger_Boot(); } if (getBootLogger() instanceof StringBufferLoggerImpl) { /* if the StringBuffer based Logger was used for OJB bootstrap process get the logging statement string and log it on the "real" Logger instance */ StringBufferLoggerImpl strLogger = (StringBufferLoggerImpl) getBootLogger(); String bootMessage = strLogger.flushLogBuffer(); String eol = SystemUtils.LINE_SEPARATOR; if (forceError || strLogger.isErrorLog()) { newBootLogger.error("-- boot log messages -->" + eol + bootMessage); } else { newBootLogger.info("-- boot log messages -->" + eol + bootMessage); } } bootLogger = newBootLogger; bootLoggerIsReassigned = true; } }